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 Details

    • PowerTacBroker

      public PowerTacBroker()
      Default constructor for remote broker deployment
  • Method Details

    • 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:
      getBroker in interface BrokerContext
    • getBrokerUsername

      public String getBrokerUsername()
      Returns the username for this broker
      Specified by:
      getBrokerUsername in interface BrokerContext
    • getBaseTime

      public org.joda.time.Instant getBaseTime()
      Returns the simulation base time
      Specified by:
      getBaseTime in interface BrokerContext
    • getUsageRecordLength

      public int getUsageRecordLength()
      Returns the length of the standard data array (24h * 7d)
      Specified by:
      getUsageRecordLength in interface BrokerContext
    • getBrokerList

      public List<String> getBrokerList()
      Returns the broker's list of competing brokers - non-public
      Specified by:
      getBrokerList in interface BrokerContext
    • 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:
      registerMessageHandler in interface BrokerContext
    • sendMessage

      public void sendMessage​(Object message)
      Sends an outgoing message. May need to be reimplemented in a remote broker.
      Specified by:
      sendMessage in interface BrokerContext
    • 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()