copyright The Portico Project 2008.

org.portico.lrc.handlers
Class LRCMessageHandler

java.lang.Object
  extended by com.lbf.commons.messaging.AbstractMessageHandler
      extended by org.portico.lrc.handlers.LRCMessageHandler
All Implemented Interfaces:
com.lbf.commons.messaging.IMessageHandler
Direct Known Subclasses:
CLB_CallbackHandler, CLB_CallbackHandler, CLB_Java1CallbackHandler, CLB_Terminator, REQ_AssociateRegionHandler, REQ_CreateRegionHandler, REQ_DeleteObjectHandler, REQ_DeleteRegionHandler, REQ_InteractionHandler, REQ_JoinFederationHandler, REQ_LocalDeleteHandler, REQ_ModifyRegionHandler, REQ_PublishInteractionHandler, REQ_PublishObjectHandler, REQ_RegisterObjectHandler, REQ_RequestClassUpdateHandler, REQ_RequestUpdateHandler, REQ_ResignHandler, REQ_SubscribeInteractionHandler, REQ_SubscribeObjectHandler, REQ_SyncPointHandler, REQ_TimeAdvanceHandler, REQ_UpdateAttributeHandler

public abstract class LRCMessageHandler
extends com.lbf.commons.messaging.AbstractMessageHandler

This class should be the parent of all LRC message handlers. It provides a number of helper methods and pre-fetches the LRC, LRCState, LRCInstanceRepository and LRCInterestManager, storing them in local variables (marked as protected, so they can be accessed from child classes). It also stores a link to the LRC logger in the same way.

IMPORTANT IMPLEMENTATION NOTE: If you override the initialize(Bag) method in your subclass, it is of vital importance that you first call to the parent class method (via super.initialize(properties)) so that the implementation in this handler can execute. The implementation here extracts all the information that is used to populate the local variables that are inherited, so it needs to run or else they will be null and useless to any handler that wants to make use of them.

ANOTHER IMPORTANT IMPLEMENTATION NOTE: The LRCConnection instance should NEVER be prefetched. It is only available once a federate joins the federate, and that is not the case when the handlers are first initialized. Thus, if you prefetch the connection, you will just end up with NullPointerExceptions any time you try to send a message to the RTI. Use the inherited getConnection() method instead (or grab the connection directly from the LRC).


Field Summary
protected  LRCInterestManager interests
           
protected  org.apache.log4j.Logger logger
           
protected  LRC lrc
           
protected  LRCRegionStore regions
           
protected  LRCInstanceRepository repository
           
protected  LRCState state
           
 
Fields inherited from class com.lbf.commons.messaging.AbstractMessageHandler
augmentable, name
 
Constructor Summary
protected LRCMessageHandler()
           
protected LRCMessageHandler(String name)
           
 
Method Summary
protected  void error(com.lbf.commons.messaging.MessageContext context, String message)
          Sets an error response for the context with the given message.
protected  void error(com.lbf.commons.messaging.MessageContext context, Throwable cause)
          Sets an error response for the context embedding the given cause
protected  LRCConnection getConnection()
          Fetch the LRCConnection associated with the federate.
protected  ObjectModel getFOM()
          This method provides quick and easy access to the FOM.
 void initialize(com.lbf.commons.utils.Bag<String,?> properties)
          Prefetch a number of useful LRC entities.
abstract  void processMessage(com.lbf.commons.messaging.MessageContext context)
           
protected  void sendMessage(com.lbf.commons.messaging.MessageContext context)
          This method will take the given context and send it to the RTI.
protected  void success(com.lbf.commons.messaging.MessageContext context)
          Puts a SuccessMessage (see the commons) in the context.
protected  void success(com.lbf.commons.messaging.MessageContext context, com.lbf.commons.utils.Bag<String,Object> properties)
          Puts a SuccessMessage (see the commons) in the context and puts the given properties in it.
protected  void success(com.lbf.commons.messaging.MessageContext context, Object result)
          Puts a SuccessMessage (see the commons) in the context and binds the given object to the "result" key in the properties.
 
Methods inherited from class com.lbf.commons.messaging.AbstractMessageHandler
getName, isAugmentable, setAugmentable, setName
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

lrc

protected LRC lrc

state

protected LRCState state

logger

protected org.apache.log4j.Logger logger

repository

protected LRCInstanceRepository repository

interests

protected LRCInterestManager interests

regions

protected LRCRegionStore regions
Constructor Detail

LRCMessageHandler

protected LRCMessageHandler()

LRCMessageHandler

protected LRCMessageHandler(String name)
Method Detail

processMessage

public abstract void processMessage(com.lbf.commons.messaging.MessageContext context)
                             throws Exception
Specified by:
processMessage in interface com.lbf.commons.messaging.IMessageHandler
Specified by:
processMessage in class com.lbf.commons.messaging.AbstractMessageHandler
Throws:
Exception

initialize

public void initialize(com.lbf.commons.utils.Bag<String,?> properties)
                throws com.lbf.commons.config.ConfigurationException
Prefetch a number of useful LRC entities. WARNING: if you override this method in your child class, you MUST call up the inheritance tree to this method first. Otherwise, the various local variables will not be initialized properly.

Specified by:
initialize in interface com.lbf.commons.messaging.IMessageHandler
Overrides:
initialize in class com.lbf.commons.messaging.AbstractMessageHandler
Throws:
com.lbf.commons.config.ConfigurationException

getConnection

protected LRCConnection getConnection()
Fetch the LRCConnection associated with the federate. As the connection is not present until the federate joins a federation, it cannot be pre-fetched. This method ensures that it is fetched in a safe manner.


getFOM

protected ObjectModel getFOM()
                      throws JRTIinternalError
This method provides quick and easy access to the FOM. If the FOM is null, a JRTIinternalError will be thrown.

Throws:
JRTIinternalError

sendMessage

protected void sendMessage(com.lbf.commons.messaging.MessageContext context)
                    throws Exception
This method will take the given context and send it to the RTI. It will gain access to the LRCConnection in a manner that is safe. After this call, the response portion of the context should be filled out.

Parameters:
context - The context to send to the RTI
Throws:
Exception - If the sending process causes an exception it is just passed on

success

protected void success(com.lbf.commons.messaging.MessageContext context)
Puts a SuccessMessage (see the commons) in the context.


success

protected void success(com.lbf.commons.messaging.MessageContext context,
                       com.lbf.commons.utils.Bag<String,Object> properties)
Puts a SuccessMessage (see the commons) in the context and puts the given properties in it.


success

protected void success(com.lbf.commons.messaging.MessageContext context,
                       Object result)
Puts a SuccessMessage (see the commons) in the context and binds the given object to the "result" key in the properties.


error

protected void error(com.lbf.commons.messaging.MessageContext context,
                     String message)
Sets an error response for the context with the given message. The message is wrapped up in an RTIinternalError.


error

protected void error(com.lbf.commons.messaging.MessageContext context,
                     Throwable cause)
Sets an error response for the context embedding the given cause


copyright The Portico Project 2008.