Package org.powertac.samplebroker.core
Class PowerTacBroker
- java.lang.Object
-
- org.powertac.samplebroker.core.PowerTacBroker
-
- All Implemented Interfaces:
BrokerContext
@Service public class PowerTacBroker extends Object implements BrokerContext
This is the top-level controller for a single broker session. It sets up the other components, maintains the clock, and terminates the session when the SimEnd message is received. It also implements the BrokerContext interface, delivering services to broker behavior modules.- Author:
- John Collins
-
-
Constructor Summary
Constructors Constructor Description PowerTacBroker()Default constructor for remote broker deployment
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description org.joda.time.InstantgetBaseTime()Returns the simulation base timeBrokergetBroker()Returns the "real" broker underneath this monstrosityList<String>getBrokerList()Returns the broker's list of competing brokers - non-publicStringgetBrokerUsername()Returns the username for this brokerlonggetServerTimeOffset()Returns the computed server time offset after login.protected intgetTimeslotCompleted()intgetUsageRecordLength()Returns the length of the standard data array (24h * 7d)voidhandleMessage(Competition comp)Handles the Competition instance that arrives at beginning of game.voidhandleMessage(BrokerAccept accept)BrokerAccept comes out when our authentication credentials are accepted and we become part of the game.voidhandleMessage(SimEnd se)Receives the SimEnd message, which ends the broker session.voidhandleMessage(SimPause sp)Receives the SimPause message, used to pause the clock.voidhandleMessage(SimResume sr)Receives the SimResume message, used to update the clock.voidhandleMessage(SimStart ss)Receives the SimStart message, used to start the clock.voidhandleMessage(TimeslotComplete tc)TimeslotComplete is the last message sent by the server in each timeslot.voidhandleMessage(TimeslotUpdate tu)Updates the sim clock on receipt of the TimeslotUpdate message, which should be the first to arrive in each timeslot.voidinit()Sets up the "adapter" broker, initializes the other services, registers for incoming messages.voidregisterMessageHandler(Object handler, Class<?> messageType)Delegates registrations to the routervoidrun()Logs in and waits for the sim to end.voidsendMessage(Object message)Sends an outgoing message.voidstartSession(org.apache.commons.configuration2.PropertiesConfiguration cli, File configFile, long end)Starts a new session, setting parameters from command-line and from config file.
-
-
-
Method Detail
-
startSession
public void startSession(org.apache.commons.configuration2.PropertiesConfiguration cli, File configFile, long end)Starts a new session, setting parameters from command-line and from config file.
-
init
public void init()
Sets up the "adapter" broker, initializes the other services, registers for incoming messages.
-
run
public void run()
Logs in and waits for the sim to end.
-
getBroker
public Broker getBroker()
Returns the "real" broker underneath this monstrosity- Specified by:
getBrokerin interfaceBrokerContext
-
getBrokerUsername
public String getBrokerUsername()
Returns the username for this broker- Specified by:
getBrokerUsernamein interfaceBrokerContext
-
getBaseTime
public org.joda.time.Instant getBaseTime()
Returns the simulation base time- Specified by:
getBaseTimein interfaceBrokerContext
-
getUsageRecordLength
public int getUsageRecordLength()
Returns the length of the standard data array (24h * 7d)- Specified by:
getUsageRecordLengthin interfaceBrokerContext
-
getBrokerList
public List<String> getBrokerList()
Returns the broker's list of competing brokers - non-public- Specified by:
getBrokerListin interfaceBrokerContext
-
getServerTimeOffset
public long getServerTimeOffset()
Returns the computed server time offset after login. Value is positive if the server's clock is ahead (shows a later time) of the broker's clock.
-
registerMessageHandler
public void registerMessageHandler(Object handler, Class<?> messageType)
Delegates registrations to the router- Specified by:
registerMessageHandlerin interfaceBrokerContext
-
sendMessage
public void sendMessage(Object message)
Sends an outgoing message. May need to be reimplemented in a remote broker.- Specified by:
sendMessagein interfaceBrokerContext
-
handleMessage
public void handleMessage(BrokerAccept accept)
BrokerAccept comes out when our authentication credentials are accepted and we become part of the game. Before this, we cannot send any messages other than BrokerAuthentication. Also, note that the ID prefix needs to be set before any server-visible entities are created (such as tariff specs).
-
handleMessage
public void handleMessage(Competition comp)
Handles the Competition instance that arrives at beginning of game. Here we capture all the customer records so we can keep track of their subscriptions and usage profiles.
-
handleMessage
public void handleMessage(SimPause sp)
Receives the SimPause message, used to pause the clock. While the clock is paused, the broker needs to ignore the local clock.
-
handleMessage
public void handleMessage(SimResume sr)
Receives the SimResume message, used to update the clock.
-
handleMessage
public void handleMessage(SimStart ss)
Receives the SimStart message, used to start the clock. The server's clock offset is subtracted from the start time indicated by the server.
-
handleMessage
public void handleMessage(SimEnd se)
Receives the SimEnd message, which ends the broker session.
-
handleMessage
public void handleMessage(TimeslotUpdate tu)
Updates the sim clock on receipt of the TimeslotUpdate message, which should be the first to arrive in each timeslot. We have to disable all the timeslots prior to the first enabled slot, then create and enable all the enabled slots.
-
handleMessage
public void handleMessage(TimeslotComplete tc)
TimeslotComplete is the last message sent by the server in each timeslot. This is normally when any broker would submit its bids, so that's when this Broker will do it.
-
getTimeslotCompleted
protected int getTimeslotCompleted()
-
-