FDA-1
Improved client - Now multiple clients can submit scans and only the one submitted the scan will receive the data as well as can abor the scan.
This commit is contained in:
@@ -154,7 +154,7 @@ public class AcquisitionEngine {
|
||||
public void terminate(String trackingId){
|
||||
|
||||
// If request is currently executed terminate it
|
||||
if(currentRequest.getTrackingId().equals(trackingId)){
|
||||
if(currentRequest!=null && currentRequest.getTrackingId().equals(trackingId)){
|
||||
terminate();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -68,6 +68,9 @@ public class RemoteAcquisitionMain {
|
||||
|
||||
private static Logger logger = Logger.getLogger(RemoteAcquisitionMain.class.getName());
|
||||
|
||||
StreamClient streamClient = null;
|
||||
private String trackingId;
|
||||
|
||||
/**
|
||||
* Main Program Process exit code: -1 if wrong number of arguments are
|
||||
* passed Process exit code: 3 if aborted via Ctrl+C
|
||||
@@ -128,7 +131,8 @@ public class RemoteAcquisitionMain {
|
||||
|
||||
try {
|
||||
for (File file : files) {
|
||||
executeScan(file, iterations, nogui);
|
||||
RemoteAcquisitionMain m = new RemoteAcquisitionMain();
|
||||
m.execute(file, iterations, nogui);
|
||||
}
|
||||
} catch (Exception ee) {
|
||||
logger.log(Level.SEVERE, "Acquisition failed due to: ", ee);
|
||||
@@ -143,8 +147,12 @@ public class RemoteAcquisitionMain {
|
||||
* @param iterations
|
||||
* @param nogui
|
||||
*/
|
||||
public static void executeScan(File file, Integer iterations, boolean nogui) {
|
||||
public void execute(File file, Integer iterations, boolean nogui) {
|
||||
|
||||
trackingId = UUID.randomUUID().toString();
|
||||
logger.info("TrackingID of job: " + trackingId);
|
||||
|
||||
|
||||
Configuration c;
|
||||
try {
|
||||
c = ModelManager.unmarshall(file);
|
||||
@@ -182,7 +190,7 @@ public class RemoteAcquisitionMain {
|
||||
|
||||
EventBus b = new AsyncEventBus(Executors.newSingleThreadExecutor());
|
||||
final RestClient client = new RestClient();
|
||||
StreamClient streamClient = null;
|
||||
|
||||
|
||||
|
||||
if (!nogui && c.getVisualization().size() > 0) {
|
||||
@@ -220,7 +228,7 @@ public class RemoteAcquisitionMain {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
try {
|
||||
client.stop();
|
||||
client.terminate(trackingId);
|
||||
} catch (Exception e1) {
|
||||
logger.log(Level.SEVERE, "Exception occured while aborting scan", e1);
|
||||
} finally {
|
||||
@@ -238,9 +246,7 @@ public class RemoteAcquisitionMain {
|
||||
frame.addWindowListener(new WindowAdapter() {
|
||||
@Override
|
||||
public void windowClosing(WindowEvent we) {
|
||||
if (client.isActive()) {
|
||||
client.stop();
|
||||
}
|
||||
client.terminate(trackingId);
|
||||
|
||||
int count = 0;
|
||||
while (client.isActive()) {
|
||||
@@ -279,7 +285,7 @@ public class RemoteAcquisitionMain {
|
||||
logger.finest("Received signal: " + signal);
|
||||
|
||||
try{
|
||||
client.stop();
|
||||
client.terminate(trackingId);
|
||||
}
|
||||
catch(Exception e){
|
||||
logger.log(Level.WARNING, "Stopping scan failed with exception", e);
|
||||
@@ -294,23 +300,16 @@ public class RemoteAcquisitionMain {
|
||||
|
||||
|
||||
|
||||
String trackingId = UUID.randomUUID().toString();
|
||||
logger.info("TrackingID of job: " + trackingId);
|
||||
|
||||
if(streamClient!=null){
|
||||
streamClient.filterTrackingId(trackingId);
|
||||
final StreamClient sclient = streamClient;
|
||||
Executors.newSingleThreadExecutor().execute(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
sclient.listen("tcp://emac:10000");
|
||||
streamClient.listen("tcp://emac:10000");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
client.acquire(trackingId, c);
|
||||
|
||||
|
||||
// TODO Need to be informed when stopped! - Progess Panel
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,8 +48,11 @@ public class RestClient {
|
||||
return target.path(trackingId).request().put(Entity.entity(jaxbElement, MediaType.APPLICATION_XML), String.class);
|
||||
}
|
||||
|
||||
public void stop(){
|
||||
// TODO in future only the actual request should be aborted!
|
||||
public void terminate(String trackingId){
|
||||
target.path(trackingId).request().delete();
|
||||
}
|
||||
|
||||
public void terminateAll(){
|
||||
target.request().delete();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user