Skip to content

Commit

Permalink
HeadlessListener try to use processQueue
Browse files Browse the repository at this point in the history
  • Loading branch information
hqnghi88 committed Mar 29, 2022
1 parent 8d19a47 commit cbc1239
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,36 +70,40 @@ public class ManualExperimentJob extends ExperimentJob implements IExperimentCon
protected final Semaphore lock = new Semaphore(1);

/** The execution thread. */
private final Thread executionThread = new Thread(() -> {
while (experimentAlive) {
step();
}
}, "Front end scheduler");

// static class OwnRunnable implements Runnable {
//
// /** The sim. */
// final ManualExperimentJob sim;
//
// /**
// * Instantiates a new own runnable.
// *
// * @param s the s
// */
// OwnRunnable(final ManualExperimentJob s) {
// sim = s;
// }
//
// /**
// * Run.
// */
// @Override
// public void run() {
// while (sim.experimentAlive) {
// sim.step();
// }
// private final Thread executionThread = new Thread(() -> {
// while (experimentAlive) {
// step();
// }
// }
// }, "Front end scheduler");
public MyRunnable executionThread;
/**
* The Class OwnRunnable.
*/
static class MyRunnable implements Runnable {

/** The sim. */
final ManualExperimentJob sim;

/**
* Instantiates a new own runnable.
*
* @param s
* the s
*/
MyRunnable(final ManualExperimentJob s) {
sim = s;
}

/**
* Run.
*/
@Override
public void run() {
while (sim.experimentAlive) {
sim.step();
}
}
}

/** The disposing. */
private boolean disposing;
Expand All @@ -123,14 +127,15 @@ public ManualExperimentJob(ExperimentJob clone, GamaWebSocketServer s, WebSocket
socket = sk;
commands = new ArrayBlockingQueue<>(10);
// this.experiment = experiment;
executionThread.setUncaughtExceptionHandler(GamaExecutorService.EXCEPTION_HANDLER);
executionThread=new MyRunnable(this);
// executionThread.setUncaughtExceptionHandler(GamaExecutorService.EXCEPTION_HANDLER);
commandThread.setUncaughtExceptionHandler(GamaExecutorService.EXCEPTION_HANDLER);
try {
lock.acquire();
} catch (final InterruptedException e) {
}
commandThread.start();
executionThread.start();
// executionThread.start();
}

public boolean isDisposing() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,12 @@ public ExecutorBasedSimulationRuntime(final int n) {
}
});
}

@Override
public void execute(final Runnable r) {
executor.execute(r);
}


@Override
public void pushSimulation(final IExperimentJob s) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,12 @@
import msi.gama.headless.job.ExperimentJob;
import msi.gama.headless.job.IExperimentJob;
import msi.gama.headless.job.ManualExperimentJob;
import msi.gama.headless.runtime.SimulationRuntime.DebugStream;
import msi.gama.headless.script.ExperimentationPlanFactory;
import msi.gama.metamodel.agent.IAgent;
import msi.gama.metamodel.shape.IShape;
import msi.gaml.operators.Spatial;
import ummisco.gama.dev.utils.DEBUG;

/**
* The Class LaunchEndPoint.
Expand Down Expand Up @@ -165,7 +167,7 @@ public void launchGamlSimulation(final GamaWebSocketServer server, WebSocket soc
socket.send("exp@" + "" + socket.hashCode() + "@" + selectedJob.getExperimentID() + "@" + size + "@"
+ geom.getLocation().x + "@" + geom.getLocation().y);
selectedJob.exportVariables();
// server.getDefaultApp().processorQueue.pushSimulation(selectedJob);
server.getDefaultApp().processorQueue.execute(selectedJob.executionThread);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,4 +165,10 @@ public void setNumberOfThreads(final int numberOfThread) {

}

@Override
public void execute(Runnable r) {
// TODO Auto-generated method stub

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@ public void close() throws IOException {

}

/**
* execute Runnable.
*
* @param s
* the s
*/
void execute(final Runnable r);

/**
* Push simulation.
*
Expand Down

0 comments on commit cbc1239

Please sign in to comment.