Class Broker

  • Direct Known Subclasses:
    DefaultBroker

    @Domain
    public class Broker
    extends Object
    A broker instance represents a competition participant. Broker instances are not communicated to other brokers; only usernames are considered public information and get communicated. Every entity that needs to trade in the wholesale market or post TariffSpecifications must be a broker.

    Brokers may be local or non-local (remote), and they may be wholesale or non-wholesale (retail) brokers. Remote brokers receive messages through JMS, while local brokers are assumed to reside in the server's process space where they receive messages by calls to their receiveMessage() methods. Local brokers must override receiveMessage() to see these messages, otherwise they will be dropped on the floor. Local brokers can send messages by calling BrokerProxy.routeMessage();

    Wholesale brokers are not permitted to offer tariffs, but may trade in the wholesale market, and they are not included in the balancing process.

    Author:
    Carsten Block, David Dauer, John Collins
    • Constructor Detail

      • Broker

        public Broker​(String username)
        Constructor for username only.
      • Broker

        public Broker​(String username,
                      boolean local,
                      boolean wholesale)
        Constructor to specify non-standard local/wholesale flags.
    • Method Detail

      • getId

        public long getId()
        Returns the unique ID for this broker
      • setKey

        public void setKey​(String key)
        Sets the jms key for a remote broker.
      • getKey

        public String getKey()
        Returns the jms ID for this broker.
      • setIdPrefix

        public void setIdPrefix​(int prefix)
        Sets the ID prefix for this broker. Intended to be called by competition control when a remote broker logs in.
      • getIdPrefix

        public int getIdPrefix()
        Returns the ID prefix for this broker. Used in the server to validate incoming messages. Should be non-zero only for remote brokers.
      • updateCash

        public void updateCash​(double depositAmount)
        Updates broker's cash position. Note that this operation does not generate a state log entry. To see the broker's cash balance in the state log, you have to create a new CashPosition.
      • getCashBalance

        public double getCashBalance()
        Returns broker's cash balance.
      • findMarketPositionByTimeslot

        public MarketPosition findMarketPositionByTimeslot​(int slot)
        Returns the MarketPosition associated with the given Timeslot. Result is guaranteed to be non-null.
      • getUsername

        public String getUsername()
        Returns the username for this Broker.
      • getPassword

        public String getPassword()
      • setPassword

        public void setPassword​(String newPassword)
      • isEnabled

        public boolean isEnabled()
        True just in case either the broker is logged in, or is a local wholesale broker.
      • setEnabled

        public void setEnabled​(boolean enabled)
        Enables this Broker. Of course, calling this method on a remote broker will have no effect; it must be called on the Broker instance in the server.
      • isLocal

        public boolean isLocal()
        True for a Broker that is local to the server. Affects message routing.
      • setLocal

        @StateChange
        public void setLocal​(boolean value)
        Allows subclasses to set themselves as local brokers. Local brokers must subclass this class, and implement receiveMessage() to receive messages from the server. They send messages by calling BrokerProxy.routeMessage().
      • isWholesale

        public boolean isWholesale()
        True for a broker that operates on the wholeside of the wholesale market.
      • setWholesale

        @StateChange
        public void setWholesale​(boolean value)
        Allows subclasses to make themselves wholesale brokers
      • setQueueName

        public void setQueueName​(String queueName)
        Sets the broker's queue name.
      • toQueueName

        public String toQueueName()
        Returns the broker's queue name if it's been set, otherwise the default queue name.
      • receiveMessage

        public void receiveMessage​(Object object)
        Default implementation does nothing. Broker subclasses implemented within the server can override this method to receive messages from BrokerProxy