Class MessageDispatcher

java.lang.Object
org.powertac.visualizer.service_ptac.MessageDispatcher
All Implemented Interfaces:
VisualizerMessageListener, NewObjectListener

@Service
public class MessageDispatcher
extends Object
implements VisualizerMessageListener, NewObjectListener
ADAPTED FROM broker core

Routes incoming messages to broker components, and outgoing messages to the server. Components must register for specific message types with the broker, which passes the registrations to this router. For this to work, registered components must implement a handleMessage(msg) method that takes the specified type as its single argument.

Author:
Jurica Babic, Govert Buijs, Erik Kemperman
  • Constructor Details

  • Method Details

    • afterPropertiesSet

      @PostConstruct public void afterPropertiesSet() throws Exception
      Throws:
      Exception
    • receiveMessage

      public void receiveMessage​(Object message)
      Specified by:
      receiveMessage in interface VisualizerMessageListener
    • handleNewObject

      public void handleNewObject​(Object obj)
      Specified by:
      handleNewObject in interface NewObjectListener
    • dispatch

      public static Object dispatch​(Object target, String methodName, Object... args)
      Dispatches a call to methodName inside target based on the type of message. Allows polymorphic method dispatch without the use of visitor or double dispatch schemes, which produce nasty couplings with domain types.

      Note that this scheme finds only exact matches between types of arguments and declared types of formal parameters for declared or inherited methods. So it will not call a method with formal parameter types of (Transaction, List) if the actual arguments are (Transaction, ArrayList).

    • registerAllHandlers

      public void registerAllHandlers()