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 Summary
Constructors Constructor Description MessageDispatcher() -
Method Summary
Modifier and Type Method Description voidafterPropertiesSet()static Objectdispatch(Object target, String methodName, Object... args)Dispatches a call to methodName inside target based on the type of message.voidhandleNewObject(Object obj)voidreceiveMessage(Object message)voidregisterAllHandlers()
-
Constructor Details
-
MessageDispatcher
public MessageDispatcher()
-
-
Method Details
-
afterPropertiesSet
- Throws:
Exception
-
receiveMessage
- Specified by:
receiveMessagein interfaceVisualizerMessageListener
-
handleNewObject
- Specified by:
handleNewObjectin interfaceNewObjectListener
-
dispatch
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()
-