Package org.powertac.server
Class CompetitionControlService
- java.lang.Object
-
- org.powertac.server.CompetitionControlService
-
- All Implemented Interfaces:
CompetitionControl
@Service public class CompetitionControlService extends Object implements CompetitionControl
This is the competition controller. It has two major roles in the server:- Once the game is configured, the
init()method must be called. There are two versions of this method; theinit()version runs a "bootstrap" simulation that runs the customer models and the wholesale market for a limited period of time to collect an initial dataset from which brokers can bootstrap their internal models. During a bootstrap simulation, external brokers cannot log in; only the default broker is active. Theinit(filename)version loads bootstrap data from the named file, validates it, and then opens up the broker login process, most of which is delegated to the BrokerProxy. - Once the simulation starts, the
step() method is called everytimeslotLengthseconds. This runs throughtimeslotPhaseCountphases, calling theactivate()methods on registered components. Phases start at 1; by default there are four phases. - When the number of timeslots equals
timeslotCount, the simulation is ended.
- Author:
- John Collins
-
-
Constructor Summary
Constructors Constructor Description CompetitionControlService()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidhandleMessage(org.powertac.common.msg.BrokerAuthentication msg)Authenticate Broker.voidhandleMessage(org.powertac.common.msg.PauseRelease msg)Releases a broker-initiated pause.voidhandleMessage(org.powertac.common.msg.PauseRequest msg)Allows a broker to request a pause.voidinit()Initializes the service in preparation for a new simulationbooleanisBootstrapMode()True just in case the sim is running in bootstrap modebooleanisRunning()Expose simulation-running flagbooleanloginBroker(String username)Logs in a broker, just in case the broker is on the authorizedBrokerMap.voidpause()Signals that the clock is paused due to server overrun.voidregisterTimeslotPhase(TimeslotPhaseProcessor thing, int phase)Allows instances of TimeslotPhaseProcessor to register themselves to be activated during one of the processing phases in each timeslot.voidresume(long newStart)Signals that the clock is resumed.voidrunOnce(boolean bootstrapMode)Runs a simulation that is already set up.voidrunOnce(boolean bootstrapMode, boolean dumpConfigOnly)voidsetAlwaysAuthorizedBrokers(List<String> brokerList)Sets the list of broker usernames that are always authorized, even in bootstrap mode.voidsetAuthorizedBrokerList(List<String> brokerList)Sets the list of brokers allowed and expected to log in before starting a simulation.voidsetBootstrapTimeslotMillis(long length)Allows Spring to set the boostrap timeslot lengthvoidsetTimeslotPhaseCount(int count)Sets the number of phases into which a timeslot is divided for processing.voidshutDown()Shuts down the simulation and cleans up.voidstop()Signals the simulation thread to stop after processing is completed in the current timeslot.
-
-
-
Method Detail
-
init
public void init()
Initializes the service in preparation for a new simulation
-
setTimeslotPhaseCount
public void setTimeslotPhaseCount(int count)
Sets the number of phases into which a timeslot is divided for processing. Intended to be called by Spring initialization. The value must be at least as large as the maximum value of timeslotPhase among the service modules.
-
setAlwaysAuthorizedBrokers
public void setAlwaysAuthorizedBrokers(List<String> brokerList)
Sets the list of broker usernames that are always authorized, even in bootstrap mode. Normally this is just "defaultBroker". This method is intended to be called by Spring initialization.
-
setAuthorizedBrokerList
public void setAuthorizedBrokerList(List<String> brokerList)
Sets the list of brokers allowed and expected to log in before starting a simulation. The simulation will not start until all brokers in the list are logged in, unless a timeout is configured.- Specified by:
setAuthorizedBrokerListin interfaceCompetitionControl
-
runOnce
public void runOnce(boolean bootstrapMode)
Runs a simulation that is already set up. This is intended to be called from a method that knows whether we are running a bootstrap sim or a normal sim.- Specified by:
runOncein interfaceCompetitionControl
-
runOnce
public void runOnce(boolean bootstrapMode, boolean dumpConfigOnly)- Specified by:
runOncein interfaceCompetitionControl
-
loginBroker
public boolean loginBroker(String username)
Logs in a broker, just in case the broker is on the authorizedBrokerMap. Returns true if the broker is authorized, otherwise false.- Specified by:
loginBrokerin interfaceCompetitionControl
-
isRunning
public boolean isRunning()
Expose simulation-running flag- Specified by:
isRunningin interfaceCompetitionControl
-
stop
public void stop()
Signals the simulation thread to stop after processing is completed in the current timeslot.
-
shutDown
public void shutDown()
Shuts down the simulation and cleans up.- Specified by:
shutDownin interfaceCompetitionControl
-
registerTimeslotPhase
public void registerTimeslotPhase(TimeslotPhaseProcessor thing, int phase)
Allows instances of TimeslotPhaseProcessor to register themselves to be activated during one of the processing phases in each timeslot.- Specified by:
registerTimeslotPhasein interfaceCompetitionControl
-
isBootstrapMode
public boolean isBootstrapMode()
True just in case the sim is running in bootstrap mode- Specified by:
isBootstrapModein interfaceCompetitionControl
-
pause
public void pause()
Signals that the clock is paused due to server overrun. The pause must be communicated to brokers.
-
resume
public void resume(long newStart)
Signals that the clock is resumed. Brokers must be informed of the new start time in order to sync their own clocks.
-
handleMessage
public void handleMessage(org.powertac.common.msg.PauseRequest msg)
Allows a broker to request a pause. It may or may not be allowed. If allowed, then the pause will take effect when the current simulation cycle has finished, or immediately if no simulation cycle is currently in progress.
-
handleMessage
public void handleMessage(org.powertac.common.msg.PauseRelease msg)
Releases a broker-initiated pause. After the clock is re-started, the resume() method will be called to communicate a new start time.
-
handleMessage
public void handleMessage(org.powertac.common.msg.BrokerAuthentication msg)
Authenticate Broker.
-
setBootstrapTimeslotMillis
public void setBootstrapTimeslotMillis(long length)
Allows Spring to set the boostrap timeslot length
-
-