Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Streaming Asynchronous Callback for Submit.
JENKINS-44427
- Loading branch information
Showing
2 changed files
with
65 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
src/main/java/org/jenkinsci/plugins/p4/client/SubmitStreamingCallback.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package org.jenkinsci.plugins.p4.client; | ||
|
||
import com.perforce.p4java.exception.P4JavaException; | ||
import com.perforce.p4java.impl.mapbased.server.Server; | ||
import com.perforce.p4java.server.IServer; | ||
import com.perforce.p4java.server.callback.IStreamingCallback; | ||
import hudson.model.TaskListener; | ||
|
||
import java.util.Map; | ||
|
||
public class SubmitStreamingCallback implements IStreamingCallback { | ||
|
||
private boolean done = false; | ||
private long change = 0; | ||
|
||
private final Server server; | ||
private final Validate validate; | ||
|
||
public SubmitStreamingCallback(IServer iserver, TaskListener listener) { | ||
this.server = (Server) iserver; | ||
this.validate = new Validate(listener); | ||
} | ||
|
||
@Override | ||
public boolean startResults(int key) throws P4JavaException { | ||
return true; | ||
} | ||
|
||
@Override | ||
public boolean endResults(int key) throws P4JavaException { | ||
done = true; | ||
return true; | ||
} | ||
|
||
@Override | ||
public boolean handleResult(Map<String, Object> map, int id) throws P4JavaException { | ||
String key = "submittedChange"; | ||
if(map.containsKey(key)) { | ||
try { | ||
change = Long.parseLong((String) map.get(key)); | ||
} catch (NumberFormatException e) { | ||
change = -1; | ||
} | ||
} | ||
return true; | ||
} | ||
|
||
public boolean isDone() { | ||
return done; | ||
} | ||
|
||
public long getChange() { | ||
return change; | ||
} | ||
|
||
} |