visidia.simulation
Class Console

java.lang.Object
  extended by visidia.simulation.Console

public class Console
extends java.lang.Object

Console is the simulator main class. It manages event&ack queues&handlers, as well as the servers and the list of processes. Console offers a listener possibility: one can connect to the console to listen some simulation events. For example, the GUI can connect to the console to update the display regarding to simulation events.


Constructor Summary
Console(int simulationMode, SimulationConstants.SimulationType simulationType, Graph graph, ObjectWriter writer, ReplayInfo replayInfo)
          Instantiates a new console.
 
Method Summary
 int addAgentToVertex(Vertex vertex, Agent ag)
          Adds an agent to a specified vertex.
 void addCommandListener(CommandListener listener)
          Adds a command listener.
 Agent createAgentOnVertex(Vertex v, Agent agent)
          Creates a new agent on vertex.
 void deadAgent(AgentProcess sender)
          Dead agent.
 void generateDelayedCommandAck(VisidiaEvent event)
          Generate delayed command ack.
 java.lang.Object[] getActiveAgents()
          Gets the active agents.
 Agent getAgent(int agentId)
          Gets the agent.
 java.util.Collection<Agent> getAgentsVertexCollection(int vertexId)
          Returns the collection of agents which are on the vertex defined by its id.
 CommandListener[] getCommandListeners()
          Gets the command listeners.
 int getCountNextPulse()
          Gets the count next pulse.
 Graph getGraph()
          Gets the graph.
 java.lang.Object getLockSyncObject()
          Gets the lock sync object.
 int getNbProcesses()
          Gets the number of processes.
 ProcessType getProcess(int processId)
          Gets a process.
 int getPulse()
          Gets the pulse.
 int getSimulationId()
          Gets the simulation id.
 Statistics getStats()
          Gets the stats.
 SimulationConstants.SimulationStatus getStatus()
          Gets the simulation status.
 int getTerminatedAlgoStillMovingCount()
          Gets the terminated algo still moving count.
 int getTerminatedThreadCount()
          Gets the number of terminated threads.
 void killAgent(Agent agent)
          Kill agent.
 void notifyAllLockSync()
          Notify all threads waiting for lockSync object.
 void pause()
          Pauses console.
 void putAlgorithmOnNodes(Algorithm algorithm)
          Puts algorithm on nodes.
 int removeAgentFromVertex(Vertex vertex, Agent ag)
          Removes a specified agent from a specified vertex.
 void removeCommandListener(CommandListener listener)
          Removes a command listener.
 void reset()
          Resets console.
 void runCommand(Command cmd)
          Runs a command.
 void runningControl()
          Running control.
 void setCountNextPulse(int countNextPulse)
          Sets the count next pulse.
 void setPulse(int pulse)
          Sets the pulse.
 void setSimulationId(int simulationId)
          Sets the simulation id.
 void setStats(Statistics stats)
          Sets the stats.
 void setTerminatedAlgoStillMovingCount(int terminatedAlgoStillMovingCount)
          Sets the terminated algo still moving count.
 void start()
          Starts console.
 void stop()
          Stops console.
 void switchVertexOnOff(Vertex vertex)
          Switch vertex on/off.
 void terminatedAlgorithm(MessageProcess sender)
          Counts terminated threads on the graph.
 void terminateSimulation()
          Terminate simulation.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Console

public Console(int simulationMode,
               SimulationConstants.SimulationType simulationType,
               Graph graph,
               ObjectWriter writer,
               ReplayInfo replayInfo)
Instantiates a new console.

Parameters:
simulationMode - the simulation mode
simulationType - the simulation type
graph - the graph
writer - the writer
replayInfo - the replay info
Method Detail

getSimulationId

public int getSimulationId()
Gets the simulation id.

Returns:
the simulation id

setSimulationId

public void setSimulationId(int simulationId)
Sets the simulation id.

Parameters:
simulationId - the new simulation id

getLockSyncObject

public java.lang.Object getLockSyncObject()
Gets the lock sync object.

Returns:
the lock sync object

notifyAllLockSync

public void notifyAllLockSync()
Notify all threads waiting for lockSync object.


getCountNextPulse

public int getCountNextPulse()
Gets the count next pulse.

Returns:
the count next pulse

setCountNextPulse

public void setCountNextPulse(int countNextPulse)
Sets the count next pulse.

Parameters:
countNextPulse - the new count next pulse

getPulse

public int getPulse()
Gets the pulse.

Returns:
the pulse

setPulse

public void setPulse(int pulse)
Sets the pulse.

Parameters:
pulse - the new pulse

getTerminatedAlgoStillMovingCount

public int getTerminatedAlgoStillMovingCount()
Gets the terminated algo still moving count.

Returns:
the terminated algo still moving count

setTerminatedAlgoStillMovingCount

public void setTerminatedAlgoStillMovingCount(int terminatedAlgoStillMovingCount)
Sets the terminated algo still moving count.

Parameters:
terminatedAlgoStillMovingCount - the new terminated algo still moving count

getGraph

public final Graph getGraph()
Gets the graph.

Returns:
the graph

getNbProcesses

public int getNbProcesses()
Gets the number of processes.

Returns:
the number of processes

getTerminatedThreadCount

public int getTerminatedThreadCount()
Gets the number of terminated threads.

Returns:
the terminated thread count

getStatus

public SimulationConstants.SimulationStatus getStatus()
Gets the simulation status.

Returns:
the status

getStats

public Statistics getStats()
Gets the stats.

Returns:
the stats

setStats

public void setStats(Statistics stats)
Sets the stats.

Parameters:
stats - the new stats

getProcess

public ProcessType getProcess(int processId)
Gets a process.

Parameters:
processId - the process id
Returns:
the process

getAgentsVertexCollection

public java.util.Collection<Agent> getAgentsVertexCollection(int vertexId)
Returns the collection of agents which are on the vertex defined by its id.

Parameters:
vertexId - the vertex id
Returns:
the agents vertex collection

addCommandListener

public void addCommandListener(CommandListener listener)
Adds a command listener.

Parameters:
listener - the listener

removeCommandListener

public void removeCommandListener(CommandListener listener)
Removes a command listener.

Parameters:
listener - the listener

getCommandListeners

public CommandListener[] getCommandListeners()
Gets the command listeners.

Returns:
the command listeners

runningControl

public void runningControl()
Running control.


reset

public void reset()
Resets console.


start

public void start()
Starts console.


pause

public void pause()
Pauses console.


stop

public void stop()
Stops console.


terminateSimulation

public void terminateSimulation()
Terminate simulation.


terminatedAlgorithm

public void terminatedAlgorithm(MessageProcess sender)
                         throws java.lang.InterruptedException
Counts terminated threads on the graph. If the number equals the number of processes, it sends algorithm termination event.

Parameters:
sender - the sender
Throws:
java.lang.InterruptedException - the interrupted exception

deadAgent

public void deadAgent(AgentProcess sender)
               throws java.lang.InterruptedException
Dead agent.

Parameters:
sender - the sender
Throws:
java.lang.InterruptedException - the interrupted exception

putAlgorithmOnNodes

public void putAlgorithmOnNodes(Algorithm algorithm)
Puts algorithm on nodes.

Parameters:
algorithm - the algorithm

getActiveAgents

public java.lang.Object[] getActiveAgents()
Gets the active agents.

Returns:
the active agents

createAgentOnVertex

public Agent createAgentOnVertex(Vertex v,
                                 Agent agent)
Creates a new agent on vertex.

Parameters:
v - the vertex
agent - the agent to clone
Returns:
the new agent

getAgent

public Agent getAgent(int agentId)
Gets the agent.

Parameters:
agentId - the agent id
Returns:
the agent

addAgentToVertex

public int addAgentToVertex(Vertex vertex,
                            Agent ag)
Adds an agent to a specified vertex.

Parameters:
vertex - the vertex
ag - the agent
Returns:
the new number of agents on the vertex

removeAgentFromVertex

public int removeAgentFromVertex(Vertex vertex,
                                 Agent ag)
Removes a specified agent from a specified vertex. Returns the new number of agents on the vertex.

Parameters:
vertex - the vertex
ag - the agent
Returns:
the number of agents after removal
See Also:
addAgentToVertex(Vertex, Agent)

runCommand

public void runCommand(Command cmd)
                throws java.lang.InterruptedException
Runs a command.

Parameters:
cmd - the command
Throws:
java.lang.InterruptedException - the interrupted exception

generateDelayedCommandAck

public void generateDelayedCommandAck(VisidiaEvent event)
Generate delayed command ack.

Parameters:
event - the event

switchVertexOnOff

public void switchVertexOnOff(Vertex vertex)
Switch vertex on/off.

Parameters:
vertex - the vertex

killAgent

public void killAgent(Agent agent)
Kill agent.

Parameters:
agent - the agent