Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
simple web gui to communicate with gama headless daemon
- Loading branch information
Showing
5 changed files
with
238 additions
and
46 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
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
24 changes: 24 additions & 0 deletions
24
msi.gama.headless/src/msi/gama/headless/runtime/CompileEndPoint.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,24 @@ | ||
package msi.gama.headless.runtime; | ||
|
||
import java.io.FileNotFoundException; | ||
import java.io.IOException; | ||
import java.util.Arrays; | ||
|
||
import org.java_websocket.WebSocket; | ||
|
||
import msi.gama.headless.core.GamaHeadlessException; | ||
|
||
public class CompileEndPoint implements Endpoint{ | ||
|
||
@Override | ||
public void onOpen(WebSocket socket) { | ||
socket.send("Hello!"); | ||
} | ||
|
||
@Override | ||
public void onMessage(GamaWebSocketServer server, WebSocket socket, String message) { | ||
socket.send(message); | ||
|
||
} | ||
|
||
} |
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
75 changes: 75 additions & 0 deletions
75
msi.gama.headless/src/msi/gama/headless/runtime/LaunchEndPoint.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,75 @@ | ||
package msi.gama.headless.runtime; | ||
|
||
import java.io.FileNotFoundException; | ||
import java.io.IOException; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
import org.java_websocket.WebSocket; | ||
|
||
import msi.gama.common.GamlFileExtension; | ||
import msi.gama.headless.common.Globals; | ||
import msi.gama.headless.core.GamaHeadlessException; | ||
import msi.gama.headless.job.ExperimentJob; | ||
import msi.gama.headless.job.IExperimentJob; | ||
import msi.gama.headless.script.ExperimentationPlanFactory; | ||
import msi.gama.headless.xml.XMLWriter; | ||
|
||
public class LaunchEndPoint implements Endpoint { | ||
|
||
@Override | ||
public void onOpen(WebSocket socket) { | ||
socket.send("You have connected to chat"); | ||
} | ||
|
||
public void runGamlSimulation(GamaWebSocketServer server, final List<String> args) | ||
throws IOException, GamaHeadlessException { | ||
final String pathToModel = args.get(args.size() - 1); | ||
|
||
if (!GamlFileExtension.isGaml(pathToModel)) { | ||
System.exit(-1); | ||
} | ||
final String argExperimentName = args.get(args.size() - 2); | ||
final String argGamlFile = args.get(args.size() - 1); | ||
|
||
final List<IExperimentJob> jb = ExperimentationPlanFactory.buildExperiment(argGamlFile); | ||
ExperimentJob selectedJob = null; | ||
for (final IExperimentJob j : jb) { | ||
if (j.getExperimentName().equals(argExperimentName)) { | ||
selectedJob = (ExperimentJob) j; | ||
break; | ||
} | ||
} | ||
if (selectedJob == null) | ||
return; | ||
Globals.OUTPUT_PATH = args.get(args.size() - 3); | ||
|
||
// selectedJob.setBufferedWriter(new XMLWriter(Globals.OUTPUT_PATH + "/" + Globals.OUTPUT_FILENAME + ".xml")); | ||
|
||
// if (args.contains(THREAD_PARAMETER)) { | ||
// this.numberOfThread = Integer.parseInt(after(args, THREAD_PARAMETER)); | ||
// } else { | ||
// numberOfThread = SimulationRuntime.UNDEFINED_QUEUE_SIZE; | ||
// } | ||
server.getDefaultApp().processorQueue = new LocalSimulationRuntime(SimulationRuntime.UNDEFINED_QUEUE_SIZE); | ||
|
||
server.getDefaultApp().processorQueue.pushSimulation(selectedJob); | ||
|
||
} | ||
|
||
@Override | ||
public void onMessage(GamaWebSocketServer server, WebSocket socket, String message) { | ||
server.broadcast(message); | ||
System.out.println(socket + ": " + message); | ||
if (message.equals("run")) { | ||
try { | ||
runGamlSimulation(server, Arrays.asList("-gaml", "C:\\GAMA\\headless\\samples\\toto", | ||
"prey_predatorExp", "C:\\GAMA\\headless\\samples\\predatorPrey\\predatorPrey.gaml")); | ||
} catch (IOException |GamaHeadlessException e) { | ||
// TODO Auto-generated catch block | ||
e.printStackTrace(); | ||
} | ||
} | ||
} | ||
|
||
} |