public class Scheduler extends Agent
Scheduler.SimulationState.PAUSED
. The default delay between two steps is 0 ms (max speed).Activator
Modifier and Type | Class and Description |
---|---|
static class |
Scheduler.SimulationState
A simulation state.
|
AbstractAgent.ReturnCode, AbstractAgent.State
Constructor and Description |
---|
Scheduler()
This constructor is equivalent to
Scheduler(Double.MAX_VALUE) |
Scheduler(double endTime)
Constructor specifying the time at which the simulation ends.
|
Modifier and Type | Method and Description |
---|---|
void |
addActivator(Activator<? extends AbstractAgent> activator)
Adds an activator to the kernel engine.
|
protected void |
checkMail(Message m)
Changes my state according to a
SchedulingMessage and sends a reply to the sender as acknowledgment. |
void |
doSimulationStep()
Executes all the activators in the order they have been added, using
Activator.execute(Object...) , and then
increments the global virtual time of this scheduler by one unit. |
protected void |
end()
This method corresponds to the last behavior which is called by the MaDKit
kernel.
|
void |
executeAndLog(Activator<? extends AbstractAgent> activator)
Triggers the execute method of this
activator and logs it using the Level.FINER logging level |
int |
getDelay()
Returns the delay between two simulation steps
|
double |
getGVT()
Returns the simulation global virtual time.
|
JLabel |
getGVTLabel()
Returns a label giving the simulation time
|
JMenu |
getSchedulerMenu()
Returns a menu which could be used in any GUI.
|
JLabel |
getSchedulerStatusLabel()
Returns a label giving some information on the simulation process
|
JToolBar |
getSchedulerToolBar()
Returns a toolbar which could be used in any GUI.
|
double |
getSimulationDuration() |
Scheduler.SimulationState |
getSimulationState()
The state of the simualtion.
|
protected void |
live()
Scheduler's default behavior. default code is:
while (isAlive()) {
if (GVT > getSimulationDuration()) {
if (logger !
|
protected void |
paused()
Runs
checkMail(Message) every 1000 ms. |
void |
removeActivator(Activator<? extends AbstractAgent> activator)
Removes an activator from the kernel engine.
|
void |
removeAllActivators()
Remove all the activators which have been previously added
|
void |
setDelay(int delay)
Sets the delay between two simulation steps.
|
void |
setGVT(double GVT)
Sets the simulation global virtual time.
|
void |
setSimulationDuration(double endTime)
Sets the simulation time for which the scheduler should end the simulation.
|
protected void |
setSimulationState(Scheduler.SimulationState newState)
Changes the state of the scheduler
|
void |
setupFrame(AgentFrame frame)
Setup the default Scheduler GUI when launched with the default MaDKit GUI mechanism.
|
broadcastMessageWithRoleAndWaitForReplies, getThreadPriority, isDaemon, killAgent, pause, sendMessageAndWaitForReply, sendMessageAndWaitForReply, sendMessageAndWaitForReply, sendMessageAndWaitForReply, sendMessageWithRoleAndWaitForReply, sendMessageWithRoleAndWaitForReply, sendMessageWithRoleAndWaitForReply, sendMessageWithRoleAndWaitForReply, sendReplyAndWaitForReply, sendReplyAndWaitForReply, sendReplyWithRoleAndWaitForReply, sendReplyWithRoleAndWaitForReply, setThreadPriority, waitAnswer, waitAnswer, waitNextMessage, waitNextMessage, waitNextMessage, waitNextMessage
activate, broadcastMessage, broadcastMessageWithRole, bucketModeCreateGroup, bucketModeRequestRole, checkAgentAddress, compareTo, createGroup, createGroup, createGroup, createGroupIfAbsent, createGroupIfAbsent, createGroupIfAbsent, createGUIOnStartUp, destroyCommunity, destroyGroup, destroyRole, executeThisAgent, executeThisAgent, executeThisAgent, getAgentAddressIn, getAgentsWithRole, getAgentsWithRole, getAgentWithRole, getDistantAgentWithRole, getExistingCommunities, getExistingGroups, getExistingRoles, getKernelAddress, getLastReceivedMessage, getLastReceivedMessage, getLogger, getMadkitConfig, getMadkitProperty, getMadkitProperty, getMyGroups, getMyRoles, getName, getNetworkID, getOrganizationSnapShot, getReplyTo, getServerInfo, getSimpleNetworkID, getState, hasGUI, hashCode, hasRole, isAlive, isCommunity, isGroup, isKernelOnline, isMadkitPropertyTrue, isMessageBoxEmpty, isRole, killAgent, launchAgent, launchAgent, launchAgent, launchAgent, launchAgent, launchAgent, launchAgent, launchAgent, launchAgentBucket, launchAgentBucket, launchAgentBucket, launchAgentBucket, launchNode, launchXmlAgents, leaveGroup, leaveRole, nextMessage, nextMessage, nextMessages, proceedEnumMessage, purgeMailbox, receiveMessage, reload, requestRole, requestRole, sendMessage, sendMessage, sendMessageWithRole, sendMessageWithRole, sendReply, sendReplyWithRole, setLogLevel, setMadkitProperty, setMadkitProperty, setName, toString
public Scheduler()
Scheduler(Double.MAX_VALUE)
public Scheduler(double endTime)
endTime
- the GVT at which the simulation will automatically stoppublic int getDelay()
public void setDelay(int delay)
doSimulationStep()
.
The value is automatically adjusted between 0 and 400.delay
- the pause between two steps in milliseconds, an integer between 0 and 400: O is max speed.public double getGVT()
public void setGVT(double GVT)
GVT
- the actual simulation timepublic void setupFrame(AgentFrame frame)
setupFrame
in class AbstractAgent
frame
- the default frame which has been created by MaDKit for this
agent.AbstractAgent.setupFrame(AgentFrame)
public void addActivator(Activator<? extends AbstractAgent> activator)
activator
- an activator.public void removeActivator(Activator<? extends AbstractAgent> activator)
activator
- an activator.public void doSimulationStep()
Activator.execute(Object...)
, and then
increments the global virtual time of this scheduler by one unit. This also automatically calls the multicore mode of
the activator if it is set so. This method should be overridden to define customized scheduling policy. So default
implementation is :
@Override public void doSimulationStep() { if (logger != null) { logger.finer("Doing simulation step " + GVT); } for (final Activator extends AbstractAgent> activator : activators) { if (logger != null) logger.finer("Activating\n--------> " + activator); activator.execute(); } setGVT(getGVT() + 1);
public void executeAndLog(Activator<? extends AbstractAgent> activator)
activator
and logs it using the Level.FINER
logging levelactivator
- protected void end()
AbstractAgent
Here is a typical example:
@Override protected void end() { AbstractAgent.ReturnCode returnCode = leaveRole("a community", "a group", "my role"); if (returnCode == AbstractAgent.ReturnCode.SUCCESS){ if(logger != null) logger.info("I am leaving the artificial society"); } else{ if(logger != null) logger.warning("something wrong when ending, return code is "+returnCode); } if(logger != null) logger.info("I am done"); } }
end
in class AbstractAgent
public Scheduler.SimulationState getSimulationState()
Scheduler.SimulationState
protected void setSimulationState(Scheduler.SimulationState newState)
newState
- the new stateprotected void live()
while (isAlive()) { if (GVT > getSimulationDuration()) { if (logger != null) logger.info("Quitting: Simulation has reached end time " + getSimulationDuration()); return; } pause(getDelay()); checkMail(nextMessage()); switch (getSimulationState()) { case RUNNING: doSimulationStep(); break; case PAUSED: paused(); break; case STEP: simulationState = PAUSED; doSimulationStep(); break; case SHUTDOWN: return; // shutdown default: getLogger().severe("state not handled " + getSimulationState); } }
live
in class Agent
Agent.live()
protected void checkMail(Message m)
SchedulingMessage
and sends a reply to the sender as acknowledgment.m
- the received messageprotected void paused()
checkMail(Message)
every 1000 ms.public void removeAllActivators()
public void setSimulationDuration(double endTime)
endTime
- the end time to setpublic double getSimulationDuration()
public JToolBar getSchedulerToolBar()
public JMenu getSchedulerMenu()
public JLabel getSchedulerStatusLabel()
public JLabel getGVTLabel()
Fabien Michel, Olivier Gutknecht, Jacques Ferber - July 18 2017