Skip to content
Snippets Groups Projects
Commit 5484abaa authored by Ludovic Apvrille's avatar Ludovic Apvrille
Browse files

AVATAR simulator: sm of simulation engine rewritten

parent d9bc6996
No related branches found
No related tags found
No related merge requests found
......@@ -125,7 +125,7 @@ public class AvatarSimulationBlock {
return transactions;
}
public Vector<AvatarSimulationPendingTransaction> getPendingTransactions(Vector<AvatarSimulationTransaction> _allTransactions, long _clockValue, int _maxTransationsInARow) {
public Vector<AvatarSimulationPendingTransaction> getPendingTransactions(Vector<AvatarSimulationTransaction> _allTransactions, long _clockValue, int _maxTransationsInARow, long _bunchid) {
Vector<AvatarSimulationPendingTransaction> ll = new Vector<AvatarSimulationPendingTransaction>();
if (completed) {
......@@ -140,7 +140,7 @@ public class AvatarSimulationBlock {
completed = true;
return ll;
}
makeExecutedTransaction(_allTransactions, ass, _clockValue, null);
makeExecutedTransaction(_allTransactions, ass, _clockValue, null, _bunchid);
}
......@@ -237,45 +237,45 @@ public class AvatarSimulationBlock {
return ll;
}
public void runSoloPendingTransaction(AvatarSimulationPendingTransaction _aspt, Vector<AvatarSimulationTransaction> _allTransactions, long _clockValue, int _maxTransationsInARow) {
public void runSoloPendingTransaction(AvatarSimulationPendingTransaction _aspt, Vector<AvatarSimulationTransaction> _allTransactions, long _clockValue, int _maxTransationsInARow, long _bunchid) {
if (_aspt.involvedElement != null) {
executeElement(_allTransactions, _aspt.involvedElement, _clockValue, _aspt);
executeElement(_allTransactions, _aspt.involvedElement, _clockValue, _aspt, _bunchid);
/*if (lastTransaction != null) {
_clockValue = lastTransaction.clockValueWhenFinished;
}*/
}
executeElement(_allTransactions, _aspt.elementToExecute, _clockValue, _aspt);
executeElement(_allTransactions, _aspt.elementToExecute, _clockValue, _aspt, _bunchid);
//runToNextBlockingElement(_allTransactions, _clockValue, _maxTransationsInARow);
}
public void executeElement(Vector<AvatarSimulationTransaction>_allTransactions, AvatarStateMachineElement _elt, long _clockValue, AvatarSimulationPendingTransaction _aspt) {
public void executeElement(Vector<AvatarSimulationTransaction>_allTransactions, AvatarStateMachineElement _elt, long _clockValue, AvatarSimulationPendingTransaction _aspt, long _bunchid) {
// Stop state
if (_elt instanceof AvatarStopState) {
makeExecutedTransaction(_allTransactions, _elt, _clockValue, _aspt);
makeExecutedTransaction(_allTransactions, _elt, _clockValue, _aspt, _bunchid);
// Random
} else if (_elt instanceof AvatarState) {
makeExecutedTransaction(_allTransactions, _elt, _clockValue, _aspt);
makeExecutedTransaction(_allTransactions, _elt, _clockValue, _aspt, _bunchid);
// Random
} else if (_elt instanceof AvatarRandom) {
makeExecutedTransaction(_allTransactions, _elt, _clockValue, _aspt);
makeExecutedTransaction(_allTransactions, _elt, _clockValue, _aspt, _bunchid);
// Transition
} else if (_elt instanceof AvatarTransition) {
makeExecutedTransaction(_allTransactions, _elt, _clockValue, _aspt);
makeExecutedTransaction(_allTransactions, _elt, _clockValue, _aspt, _bunchid);
// Signal
} else if (_elt instanceof AvatarActionOnSignal) {
makeExecutedTransaction(_allTransactions, _elt, _clockValue, _aspt);
makeExecutedTransaction(_allTransactions, _elt, _clockValue, _aspt, _bunchid);
}
}
public void makeExecutedTransaction(Vector<AvatarSimulationTransaction> _allTransactions, AvatarStateMachineElement _elt, long _clockValue, AvatarSimulationPendingTransaction _aspt) {
public void makeExecutedTransaction(Vector<AvatarSimulationTransaction> _allTransactions, AvatarStateMachineElement _elt, long _clockValue, AvatarSimulationPendingTransaction _aspt, long _bunchid) {
AvatarTransition at;
String action;
int i;
......@@ -290,6 +290,7 @@ public class AvatarSimulationBlock {
ast.asb = this;
ast.concernedElement = null;
ast.initialClockValue = 0;
ast.bunchid = _bunchid;
if (lastTransaction != null) {
ast.initialClockValue = lastTransaction.clockValueWhenFinished;
}
......@@ -593,7 +594,11 @@ public class AvatarSimulationBlock {
public void removeLastTransaction(AvatarSimulationTransaction _ast) {
if (lastTransaction == _ast) {
transactions.removeElementAt(transactions.size()-1);
lastTransaction = transactions.get(transactions.size()-1);
if (transactions.size() > 0) {
lastTransaction = transactions.get(transactions.size()-1);
} else {
lastTransaction = null;
}
}
}
......
......@@ -66,6 +66,7 @@ public class AvatarSimulationTransaction {
public long duration;
public long clockValueWhenFinished;
public long id;
public long bunchid;
// Indicates whether the transaction is a silent transaction, or not
// Silent means that the transaction was automatically selecteed by the simulator ->
......@@ -105,8 +106,12 @@ public class AvatarSimulationTransaction {
return tmp;
}
public static synchronized void setID(long _id) {
ID = _id;
}
public String toString() {
String res = "" + id + " @" + clockValueWhenFinished + "/ " + duration + ": " +executedElement + " in block " + block.getName();
String res = "" + id + " bunchid:" + bunchid + " @" + clockValueWhenFinished + "/ " + duration + ": " +executedElement + " in block " + block.getName();
if (silent) {
res += " (silent)";
}
......
......@@ -56,12 +56,17 @@ import myutil.*;
public class AvatarSpecificationSimulation {
private static int MAX_TRANSACTION_IN_A_ROW = 1000;
public final static int OTHER = 0;
public final static int STOPPED = 1;
public final static int RUNNING = 2;
public final static int TERMINATED = 3;
public static int MAX_TRANSACTIONS = 100000000;
private int mode;
public final static int INITIALIZE = 0;
public final static int RESET = 1;
public final static int GATHER = 2;
public final static int EXECUTE = 3;
public final static int DONT_EXECUTE = 4;
public final static int TERMINATED = 5;
public final static int KILLED = 6;
private int state;
private AvatarSpecification avspec;
private AvatarSimulationInteraction asi;
......@@ -73,8 +78,14 @@ public class AvatarSpecificationSimulation {
//private Vector<AvatarSimulationPendingTransaction> pendingTimedTransactions;
private Vector<AvatarSimulationTransaction> allTransactions;
private boolean go = false;
private boolean stopped = false;
private boolean killed = false;
private boolean reset = false;
private boolean newState = false;
private long bunchid;
private int nbOfCommands = -1; // means: until it blocks
private int indexSelectedTransaction = -1;
......@@ -91,6 +102,8 @@ public class AvatarSpecificationSimulation {
iee = new IntExpressionEvaluator();
executeEmptyTransition = true;
executeStateEntering = true;
setState(INITIALIZE);
}
public AvatarSpecification getAvatarSpecification() {
......@@ -116,17 +129,20 @@ public class AvatarSpecificationSimulation {
// Remove timers
avspec.removeTimers();
reset();
}
public void reset() {
killed = false;
unsetNbOfCommands();
// Reinit clock
clockValue = 0;
// Reinit bunch id
bunchid = 0;
// Stop the first transaction
unsetNbOfCommands();
stopped = true;
// Reinit simulation
AvatarSimulationTransaction.reinit();
......@@ -145,13 +161,14 @@ public class AvatarSpecificationSimulation {
// Create the structure for pending and executed transactions
pendingTransactions = new Vector<AvatarSimulationPendingTransaction>();
allTransactions = new Vector<AvatarSimulationTransaction>();
}
public boolean isInDeadlock() {
return true;
}
public void runSimulation() {
/*public void runSimulation() {
setMode(RUNNING);
int index[];
Vector<AvatarSimulationPendingTransaction> selectedTransactions;
......@@ -161,65 +178,276 @@ public class AvatarSpecificationSimulation {
TraceManager.addDev("Simulation started at time: " + clockValue);
while((go == true) && !killed) {
while(!killed) {
while((go == true) && !killed) {
gatherPendingTransactions();
while((go == true) && !killed) {
gatherPendingTransactions();
if (pendingTransactions.size() == 0) {
go = false;
TraceManager.addDev("No more pending transactions");
} else {
if (stopped && go) {
setMode(STOPPED);
TraceManager.addDev("Simulation waiting for run");
waitForUnstopped();
if (go) {
setMode(RUNNING);
}
} else if (nbOfCommands == 0) {
if (getSilentTransactionToExecute(pendingTransactions) == null) {
stopSimulation();
stopSimulation(go);
}
}
if (!killed) {
silentTransactionExecuted = false;
selectedTransactions = selectTransactions(pendingTransactions);
if (selectedTransactions.size() == 0) {
go = false;
TraceManager.addDev("Deadlock: no transaction can be selected");
} else {
//TraceManager.addDev("* * * * * Nb of selected transactions: " + selectedTransactions.size());
go = performSelectedTransactions(selectedTransactions);
//TraceManager.addDev("NbOfcommands=" + nbOfCommands);
if (!silentTransactionExecuted) {
nbOfCommands --;
}
if (asi != null) {
asi.updateTransactionAndTime(allTransactions.size(), clockValue);
}g
//TraceManager.addDev("------------- new NbOfcommands=" + nbOfCommands);
}
}
}
}
}
setMode(TERMINATED);
TraceManager.addDev("Simulation finished at time: " + clockValue + "\n--------------------------------------");
waitForKillResetOrBackward();
go = true;
}
setMode(KILLED);
//printExecutedTransactions();
}*/
// Control function
public void runSimulation() {
int index[];
Vector<AvatarSimulationPendingTransaction> selectedTransactions;
TraceManager.addDev("Simulation started at time: " + clockValue);
//boolean executeNextState;
while(true) {
//TraceManager.addDev("State=" + state);
switch(state) {
case INITIALIZE:
initialize();
setState(RESET);
break;
case RESET:
reset();
setState(GATHER);
break;
case GATHER:
gatherPendingTransactions();
if (pendingTransactions.size() == 0) {
go = false;
setState(TERMINATED);
TraceManager.addDev("No more pending transactions");
} else {
if (stopped && go) {
setMode(STOPPED);
TraceManager.addDev("Simulation waiting for run");
waitForUnstopped();
if (go) {
setMode(RUNNING);
}
} else if (nbOfCommands == 0) {
if (nbOfCommands < 1) {
if (getSilentTransactionToExecute(pendingTransactions) == null) {
stopSimulation();
stopSimulation(go);
setState(DONT_EXECUTE);
} else {
setState(EXECUTE);
}
} else {
setState(EXECUTE);
}
if (!killed) {
silentTransactionExecuted = false;
selectedTransactions = selectTransactions(pendingTransactions);
if (selectedTransactions.size() == 0) {
go = false;
TraceManager.addDev("Deadlock: no transaction can be selected");
} else {
//TraceManager.addDev("* * * * * Nb of selected transactions: " + selectedTransactions.size());
go = performSelectedTransactions(selectedTransactions);
//TraceManager.addDev("NbOfcommands=" + nbOfCommands);
if (!silentTransactionExecuted) {
nbOfCommands --;
}
if (asi != null) {
asi.updateTransactionAndTime(allTransactions.size(), clockValue);
}
//TraceManager.addDev("------------- new NbOfcommands=" + nbOfCommands);
}
break;
case EXECUTE:
silentTransactionExecuted = false;
selectedTransactions = selectTransactions(pendingTransactions);
if (selectedTransactions.size() == 0) {
setState(TERMINATED);
TraceManager.addDev("Deadlock: no transaction can be selected");
} else {
if (performSelectedTransactions(selectedTransactions)) {
if (!silentTransactionExecuted) {
nbOfCommands --;
}
if (asi != null) {
asi.updateTransactionAndTime(allTransactions.size(), clockValue);
}
setState(GATHER);
} else {
setState(TERMINATED);
TraceManager.addDev("Error when executing transaction");
}
}
break;
case DONT_EXECUTE:
waitForExecute();
break;
case TERMINATED:
waitForResetOrNewState();
break;
case KILLED:
TraceManager.addDev("Simulation killed");
return;
default:
TraceManager.addDev("Unknown state");
setState(KILLED);
}
computeExternalCommands();
}
setMode(TERMINATED);
TraceManager.addDev("Simulation finished at time: " + clockValue + "\n--------------------------------------");
//printExecutedTransactions();
}
public synchronized void waitForExecute() {
while(!reset && !newState && !killed && !go) {
try {
wait();
} catch(Exception e){}
}
}
public synchronized void waitForResetOrNewState() {
while(!reset && !newState && !killed) {
try {
wait();
} catch(Exception e){}
}
}
public synchronized void computeExternalCommands() {
if (state == KILLED) {
return;
}
if (killed) {
killed = false;
reset = false;
newState = false;
stopped = false;
setState(KILLED);
return;
}
if (state == RESET) {
return;
}
if (reset) {
reset = false;
newState = false;
stopped = false;
setState(RESET);
return;
}
if (newState) {
newState = false;
setState(GATHER);
TraceManager.addDev("Going to gather");
return;
}
if (stopped && (state == EXECUTE)) {
stopped = false;
setState(DONT_EXECUTE);
}
if (go && (state == DONT_EXECUTE)) {
go = false;
setState(EXECUTE);
}
return;
}
public void setState(int _state) {
state = _state;
if (state == DONT_EXECUTE) {
unsetNbOfCommands();
}
if (asi != null) {
asi.setMode(state);
}
}
public int getState() {
return state;
}
public void setNbOfCommands(int _nbOfCommands) {
nbOfCommands = _nbOfCommands;
}
public void unsetNbOfCommands() {
nbOfCommands = -1;
}
// External control functions
public synchronized void killSimulation() {
killed = true;
notifyAll();
}
public synchronized void resetSimulation() {
TraceManager.addDev("reset on simulation");
reset = true;
notifyAll();
}
public synchronized void newStateInSimulation() {
newState = true;
notifyAll();
}
public synchronized void stopSimulation() {
stopped = true;
notifyAll();
}
public synchronized void goSimulation() {
go = true;
notifyAll();
}
// Simulation functions
public void gatherPendingTransactions() {
AvatarTransition tr;
pendingTransactions.clear();
// Gather all pending transactions from blocks
for(AvatarSimulationBlock asb: blocks) {
pendingTransactions.addAll(asb.getPendingTransactions(allTransactions, clockValue, MAX_TRANSACTION_IN_A_ROW));
pendingTransactions.addAll(asb.getPendingTransactions(allTransactions, clockValue, MAX_TRANSACTION_IN_A_ROW, bunchid));
}
//TraceManager.addDev("# of pending transactions before selection: " + pendingTransactions.size());
......@@ -543,28 +771,28 @@ public class AvatarSpecificationSimulation {
if (_pendingTransactions.size() == 1) {
long tempo_clock_Value = clockValue;
preExecutedTransaction(_pendingTransactions.get(0));
_pendingTransactions.get(0).asb.runSoloPendingTransaction(_pendingTransactions.get(0), allTransactions, tempo_clock_Value, MAX_TRANSACTION_IN_A_ROW);
_pendingTransactions.get(0).asb.runSoloPendingTransaction(_pendingTransactions.get(0), allTransactions, tempo_clock_Value, MAX_TRANSACTION_IN_A_ROW, bunchid);
postExecutedTransaction(_pendingTransactions.get(0));
previousBlock = _pendingTransactions.get(0).asb;
if (_pendingTransactions.get(0).linkedTransaction != null) {
tempo_clock_Value = clockValue;
AvatarSimulationTransaction transaction0 = _pendingTransactions.get(0).asb.getLastTransaction();
preExecutedTransaction(_pendingTransactions.get(0).linkedTransaction);
_pendingTransactions.get(0).linkedTransaction.asb.runSoloPendingTransaction(_pendingTransactions.get(0).linkedTransaction, allTransactions, tempo_clock_Value, MAX_TRANSACTION_IN_A_ROW);
_pendingTransactions.get(0).linkedTransaction.asb.runSoloPendingTransaction(_pendingTransactions.get(0).linkedTransaction, allTransactions, tempo_clock_Value, MAX_TRANSACTION_IN_A_ROW, bunchid);
postExecutedTransaction(_pendingTransactions.get(0).linkedTransaction);
AvatarSimulationTransaction transaction1 = _pendingTransactions.get(0).linkedTransaction.asb.getLastTransaction();
transaction1.linkedTransaction = transaction0;
}
if (!(_pendingTransactions.get(0).isSilent)) {
bunchid++;
}
return true;
} else if (_pendingTransactions.size() == 1) { // synchro
//Not yet handled
return false;
} else {
// error!
return false;
}
return false;
}
public void preExecutedTransaction(AvatarSimulationPendingTransaction _aspt) {
......@@ -619,8 +847,8 @@ public class AvatarSpecificationSimulation {
clockValue = _aspt.clockValueAtEnd;
}
public synchronized void backOneTransaction(boolean _ignoredSilent) {
if (mode != STOPPED) {
public synchronized void backOneTransactionBunch() {
if ( (state != DONT_EXECUTE) && (state != TERMINATED)) {
return;
}
......@@ -628,29 +856,61 @@ public class AvatarSpecificationSimulation {
return;
}
TraceManager.addDev("Backward size="+ allTransactions.size());
// Remove one transaction
// Getting last transaction
AvatarSimulationTransaction ast = allTransactions.get(allTransactions.size()-1);
allTransactions.removeElementAt(allTransactions.size()-1);
long bunchid = ast.bunchid;
if (ast.asb != null) {
ast.asb.removeLastTransaction(ast);
}
boolean isAllSilent = true;
// Must handle asynchronous messages
if (ast.receivedMessage != null) {
asynchronousMessages.add(0, ast.receivedMessage);
while((ast != null) && (ast.bunchid == bunchid)) {
allTransactions.removeElementAt(allTransactions.size()-1);
if (ast.asb != null) {
ast.asb.removeLastTransaction(ast);
}
if (!ast.silent) {
isAllSilent = false;
}
// Must handle asynchronous messages
if (ast.receivedMessage != null) {
asynchronousMessages.add(0, ast.receivedMessage);
}
if (ast.sentMessage != null) {
asynchronousMessages.remove(ast.sentMessage);
}
if (allTransactions.size() > 0) {
ast = allTransactions.get(allTransactions.size()-1);
} else {
ast = null;
}
}
if (ast.sentMessage != null) {
asynchronousMessages.remove(ast.sentMessage);
if (ast != null) {
bunchid = (allTransactions.get(allTransactions.size()-1).bunchid) + 1;
clockValue = ast.clockValueWhenFinished;
} else {
bunchid = 0;
clockValue = 0;
}
if ((ast.silent) && (!_ignoredSilent)) {
backOneTransaction(_ignoredSilent);
AvatarSimulationTransaction.setID(allTransactions.size());
TraceManager.addDev("Backward size="+ allTransactions.size());
if (isAllSilent) {
backOneTransactionBunch();
}
gatherPendingTransactions();
newState = true;
notifyAll();
}
public void printExecutedTransactions() {
......@@ -659,6 +919,14 @@ public class AvatarSpecificationSimulation {
}
}
/*public synchronized void waitForKillResetOrBackward() {
while(stopped && !killed) {
try {
wait();
} catch (Exception e) {
}
}
}
public synchronized void waitForUnstopped() {
while(stopped && !killed) {
......@@ -699,6 +967,8 @@ public class AvatarSpecificationSimulation {
}
}
public void setNbOfCommands(int _nbOfCommands) {
nbOfCommands = _nbOfCommands;
}
......@@ -715,7 +985,7 @@ public class AvatarSpecificationSimulation {
if (_go && !killed) {
setMode(RUNNING);
}
}
}*/
public AvatarSimulationBlock getPreviousBlock() {
return previousBlock;
......
......@@ -143,7 +143,7 @@ public class AvatarInteractiveSimulationActions extends AbstractAction {
actions[ACT_RUN_X_TRANSACTIONS] = new TAction("run-x-transactions", "Run x transactions", IconManager.imgic1306, IconManager.imgic1306, "Run x transactions", "Run simulation for x transactions. Works only if the simulator is \"ready\"", 'R');
actions[ACT_RUN_X_COMMANDS] = new TAction("run-x-commands", "Run x commands", IconManager.imgic1308, IconManager.imgic1308, "Run x commands", "Run simulation for x commands. Works only if the simulator is \"ready\"", 'R');
actions[ACT_BACK_ONE] = new TAction("back-one", "Back one transaction", IconManager.imgic46, IconManager.imgic47, "Back one transaction", "Go one transaction backward", 'B');
actions[ACT_BACK_ONE] = new TAction("back-one", "Back one transaction", IconManager.imgic47, IconManager.imgic47, "Back one transaction", "Go one transaction backward", 'B');
actions[ACT_RUN_EXPLORATION] = new TAction("run-exploration", "Run exploration", IconManager.imgic1326, IconManager.imgic1326, "Run exploration", "Explore branches of the simulation", 'R');
......
......@@ -65,6 +65,10 @@ public class BlockTableModel extends AbstractTableModel {
// From AbstractTableModel
public int getRowCount() {
if (nbOfRows == -1) {
computeData();
}
return nbOfRows;
}
......@@ -138,7 +142,11 @@ public class BlockTableModel extends AbstractTableModel {
return ;
}
nbOfRows = ass.getSimulationBlocks().size();
if (ass.getSimulationBlocks() != null) {
nbOfRows = ass.getSimulationBlocks().size();
}
nbOfRows = -1;
return;
}
......
......@@ -204,18 +204,27 @@ public class JFrameAvatarInteractiveSimulation extends JFrame implements AvatarS
nbOfAllExecutedElements = 0;
resetMetElements();
ass = new AvatarSpecificationSimulation(avspec, this);
ass.initialize();
//ass.initialize();
simulationThread = new Thread(this);
simulationThread.start();
}
public void run() {
previousTime = System.currentTimeMillis();
ass.runSimulation();
TraceManager.addDev("Simulation thread ended");
}
/*public void run() {
resetThread = false;
killThread = false;
previousTime = System.currentTimeMillis();
ass.runSimulation();
if (ass.getState() == AvatarSpecificationSimulation.INITIALIZE) {
ass.runSimulation();
}
if (killThread) {
return;
}
......@@ -231,7 +240,7 @@ public class JFrameAvatarInteractiveSimulation extends JFrame implements AvatarS
runningTGComponents = new LinkedList<TGComponent>();
nbOfAllExecutedElements = 0;
resetMetElements();
ass.reset();
ass.resetSimulation();
previousTime = System.currentTimeMillis();
run();
}
......@@ -257,7 +266,7 @@ public class JFrameAvatarInteractiveSimulation extends JFrame implements AvatarS
resetThread = true;
TraceManager.addDev("Reset thread = " + resetThread);
notifyAll();
}
}*/
......@@ -687,8 +696,10 @@ public class JFrameAvatarInteractiveSimulation extends JFrame implements AvatarS
}
public void close() {
killThread();
ass.killSimulation();
//killThread();
if (ass != null) {
ass.killSimulation();
}
dispose();
setVisible(false);
runningTGComponents.clear();
......@@ -698,7 +709,10 @@ public class JFrameAvatarInteractiveSimulation extends JFrame implements AvatarS
public void runSimulation() {
previousTime = System.currentTimeMillis();
ass.unstop();
if (ass != null) {
ass.setNbOfCommands(AvatarSpecificationSimulation.MAX_TRANSACTIONS);
ass.goSimulation();
}
}
public void runXCommands() {
......@@ -709,22 +723,32 @@ public class JFrameAvatarInteractiveSimulation extends JFrame implements AvatarS
} catch (Exception e) {
nb = 1;
}
ass.setNbOfCommands(nb);
previousTime = System.currentTimeMillis();
ass.unstop();
if (ass != null) {
ass.setNbOfCommands(nb);
previousTime = System.currentTimeMillis();
ass.goSimulation();
}
}
public void stopSimulation() {
ass.stopSimulation();
//previousTime = System.currentTimeMillis();
if (ass != null) {
ass.stopSimulation();
}
}
public void resetSimulation() {
resetThread();
ass.killSimulation();
//resetThread();
previousTime = System.currentTimeMillis();
if (ass != null) {
ass.resetSimulation();
}
//ass.killSimulation();
}
public void backwardOneTransaction() {
ass.backOneTransaction(true);
previousTime = System.currentTimeMillis();
ass.backOneTransactionBunch();
}
......@@ -768,7 +792,7 @@ public class JFrameAvatarInteractiveSimulation extends JFrame implements AvatarS
// Diagram animation?
if (!(busyMode == AvatarSpecificationSimulation.RUNNING)) {
if (!(busyMode == AvatarSpecificationSimulation.GATHER) && !(busyMode == AvatarSpecificationSimulation.EXECUTE)) {
updateMetElements();
animateDiagrams();
}
......@@ -789,15 +813,18 @@ public class JFrameAvatarInteractiveSimulation extends JFrame implements AvatarS
boolean b= true;
switch(busyMode) {
case AvatarSpecificationSimulation.STOPPED:
case AvatarSpecificationSimulation.DONT_EXECUTE:
actions[AvatarInteractiveSimulationActions.ACT_RUN_SIMU].setEnabled(true);
actions[AvatarInteractiveSimulationActions.ACT_BACK_ONE].setEnabled(true);
actions[AvatarInteractiveSimulationActions.ACT_RUN_X_COMMANDS].setEnabled(true);
actions[AvatarInteractiveSimulationActions.ACT_RESET_SIMU].setEnabled(true);
actions[AvatarInteractiveSimulationActions.ACT_STOP_SIMU].setEnabled(false);
b = true;
break;
case AvatarSpecificationSimulation.RUNNING:
case AvatarSpecificationSimulation.GATHER:
case AvatarSpecificationSimulation.EXECUTE:
actions[AvatarInteractiveSimulationActions.ACT_RUN_SIMU].setEnabled(false);
actions[AvatarInteractiveSimulationActions.ACT_BACK_ONE].setEnabled(false);
actions[AvatarInteractiveSimulationActions.ACT_RUN_X_COMMANDS].setEnabled(false);
actions[AvatarInteractiveSimulationActions.ACT_RESET_SIMU].setEnabled(false);
actions[AvatarInteractiveSimulationActions.ACT_STOP_SIMU].setEnabled(true);
......@@ -805,6 +832,17 @@ public class JFrameAvatarInteractiveSimulation extends JFrame implements AvatarS
break;
case AvatarSpecificationSimulation.TERMINATED:
actions[AvatarInteractiveSimulationActions.ACT_RUN_SIMU].setEnabled(false);
actions[AvatarInteractiveSimulationActions.ACT_BACK_ONE].setEnabled(true);
actions[AvatarInteractiveSimulationActions.ACT_RUN_X_COMMANDS].setEnabled(false);
actions[AvatarInteractiveSimulationActions.ACT_RESET_SIMU].setEnabled(true);
actions[AvatarInteractiveSimulationActions.ACT_STOP_SIMU].setEnabled(false);
b = true;
break;
case AvatarSpecificationSimulation.INITIALIZE:
case AvatarSpecificationSimulation.RESET:
case AvatarSpecificationSimulation.KILLED:
actions[AvatarInteractiveSimulationActions.ACT_RUN_SIMU].setEnabled(false);
actions[AvatarInteractiveSimulationActions.ACT_BACK_ONE].setEnabled(false);
actions[AvatarInteractiveSimulationActions.ACT_RUN_X_COMMANDS].setEnabled(false);
actions[AvatarInteractiveSimulationActions.ACT_RESET_SIMU].setEnabled(true);
actions[AvatarInteractiveSimulationActions.ACT_STOP_SIMU].setEnabled(false);
......@@ -853,15 +891,22 @@ public class JFrameAvatarInteractiveSimulation extends JFrame implements AvatarS
newTime += " (before:" + oldTime + ")";
}
time.setText(newTime);
info.setText(""+ass.getAllTransactions().size());
if (ass.getAllTransactions() != null) {
info.setText(""+ass.getAllTransactions().size());
} else {
info.setText("0");
}
switch(busyMode) {
case AvatarSpecificationSimulation.STOPPED:
case AvatarSpecificationSimulation.DONT_EXECUTE:
status.setText("Stopped");
status.setForeground(ColorManager.InteractiveSimulationText_UNKNOWN);
time.setForeground(ColorManager.InteractiveSimulationText_UNKNOWN);
info.setForeground(ColorManager.InteractiveSimulationText_UNKNOWN);
break;
case AvatarSpecificationSimulation.RUNNING:
case AvatarSpecificationSimulation.GATHER:
case AvatarSpecificationSimulation.EXECUTE:
case AvatarSpecificationSimulation.RESET:
case AvatarSpecificationSimulation.INITIALIZE:
status.setText("Running...");
status.setForeground(ColorManager.InteractiveSimulationText_BUSY);
time.setForeground(ColorManager.InteractiveSimulationText_BUSY);
......@@ -873,12 +918,23 @@ public class JFrameAvatarInteractiveSimulation extends JFrame implements AvatarS
time.setForeground(ColorManager.InteractiveSimulationText_TERM);
info.setForeground(ColorManager.InteractiveSimulationText_TERM);
break;
case AvatarSpecificationSimulation.KILLED:
status.setText("killed");
status.setForeground(ColorManager.InteractiveSimulationText_TERM);
time.setForeground(ColorManager.InteractiveSimulationText_TERM);
info.setForeground(ColorManager.InteractiveSimulationText_TERM);
break;
}
}
}
public void setContentOfListOfPendingTransactions() {
if (ass == null) {
return;
}
Vector<AvatarSimulationPendingTransaction> ll = ass.getPendingTransitions();
try {
listPendingTransactions.clearSelection();
selectedComponentForTransaction = null;
......@@ -904,6 +960,11 @@ public class JFrameAvatarInteractiveSimulation extends JFrame implements AvatarS
TGComponent tgc;
Object o;
if (allExecutedElements == null) {
nbOfAllExecutedElements = 0;
return;
}
if (allExecutedElements.size() > nbOfAllExecutedElements) {
for(int i=nbOfAllExecutedElements; i<allExecutedElements.size(); i++) {
o = allExecutedElements.get(i).getReferenceObject();
......@@ -919,7 +980,7 @@ public class JFrameAvatarInteractiveSimulation extends JFrame implements AvatarS
public void animateDiagrams() {
if (animate != null) {
if ((animate != null) && (ass != null) && (ass.getSimulationBlocks() != null)) {
if (animate.isSelected()) {
// We go through all blocks
runningTGComponents.clear();
......@@ -1047,7 +1108,7 @@ public class JFrameAvatarInteractiveSimulation extends JFrame implements AvatarS
//TraceManager.addDev("Adding reference object: " + aspt.linkedTransaction.elementToExecute.getReferenceObject());
selectedComponentForTransaction = (TGComponent)(aspt.linkedTransaction.elementToExecute.getReferenceObject());
}
if (!(busyMode == AvatarSpecificationSimulation.RUNNING)) {
if (!(busyMode == AvatarSpecificationSimulation.GATHER) && !(busyMode == AvatarSpecificationSimulation.EXECUTE)) {
ass.setIndexSelectedTransaction(listPendingTransactions.getSelectedIndex());
}
if (animate.isSelected() && (openDiagram.isSelected())) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment