Commit a14a6687 authored by ics's avatar ics
Browse files

Ploty2 save image...

parent b3ddcaa2
......@@ -18,8 +18,6 @@
package fr.ill.ics.nscclient.ploty;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
......@@ -47,7 +45,6 @@ public class PlotyInstance {
private static PlotyInstance instance;
private Server server;
private Server nomadserver;
private Application.Requester plotRequester;
private Application.Subscriber spySubcriber;
private Thread subscriberThread;
......@@ -114,23 +111,8 @@ public class PlotyInstance {
return false;
}
// Get the server endpoint.
String nomadserverEndpoint = ConfigManager.getInstance().getNomadServerEndpoint();
// Connect to the server.
nomadserver = new Server(nomadserverEndpoint);
Application.Instance ploty2main = null;
try {
ploty2main = nomadserver.connect(PLOTY_NAME);
} catch (ConnectionTimeout e) {
System.err.println("Timeout while connecting " + PLOTY_NAME);
return false;
}
// Create the requester.
spySubcriber = Application.Subscriber.create(ploty2main, "spy_publisher");
spySubcriber = Application.Subscriber.create(ploty, "spy_publisher");
// Start the thread.
subscriberThread = new Thread(new Runnable() {
......@@ -143,7 +125,7 @@ public class PlotyInstance {
if (data != null) {
try {
if (DataPlotMessages.SpyMultiPlotMessage.parseFrom(data[0]).getType() == fr.ill.ics.ploty.DataPlotMessages.SpyMultiPlotMessage.Type.SpyChange) {
notifySpyPlotChanged(DataPlotMessages.SpyMultiPlotMessage.parseFrom(data[0]).getName(), data[1]);
notifySpyPlotChanged(DataPlotMessages.SpyMultiPlotMessage.parseFrom(data[0]).getName());
}
}
catch (IOException e) {
......@@ -180,6 +162,10 @@ public class PlotyInstance {
// Terminate the subscriber.
spySubcriber.terminate();
if (ConfigManager.getInstance().getString(ConfigManager.CLIENT_TYPE_PROPERTY).contains("remote")) {
server.killAllAndWaitFor(PLOTY_NAME);
}
System.out.println("Unsubscribed from the spy plot change");
}
......@@ -302,28 +288,10 @@ public class PlotyInstance {
}
}
private void updateFile(String filename, byte[] buffer) throws IOException {
FileOutputStream fos;
fos = new FileOutputStream(filename);
fos.write(buffer);
fos.close();
}
private void notifySpyPlotChanged(String name, byte[] buffer) {
private void notifySpyPlotChanged(String name) {
synchronized (pendingChanges) {
try {
if (!ConfigManager.getInstance().getString(ConfigManager.CLIENT_TYPE_PROPERTY).contains("main")) {
updateFile(System.getenv("HOME") + SPY_PLOT_DIRECTORY + name, buffer);
}
PlotyNotification change = new PlotyNotification(name);
updatePendingChanges(change);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment