copyright The Portico Project 2008.

org.portico.lrc.handlers
Class REQ_SubscribeObjectHandler

java.lang.Object
  extended by com.lbf.commons.messaging.AbstractMessageHandler
      extended by org.portico.lrc.handlers.LRCMessageHandler
          extended by org.portico.lrc.handlers.REQ_SubscribeObjectHandler
All Implemented Interfaces:
com.lbf.commons.messaging.IMessageHandler

public class REQ_SubscribeObjectHandler
extends LRCMessageHandler

This handler manages object attribute subscribe/unsubscribe requests. It will make all the appropriate checks before sending the request on to the RTI, and it will store the relevant information once it has been returned from the RTI.

Before *ANY* request is processed, the processMessage() method will check to make sure the federate is an execution member and that a save or restore is not currently in progress.


Field Summary
 
Fields inherited from class org.portico.lrc.handlers.LRCMessageHandler
interests, logger, lrc, regions, repository, state
 
Fields inherited from class com.lbf.commons.messaging.AbstractMessageHandler
augmentable, name
 
Constructor Summary
REQ_SubscribeObjectHandler()
           
 
Method Summary
 void processMessage(com.lbf.commons.messaging.MessageContext context)
          Processes an incoming message and depending on the type, delegates it to the appropriate private handling method.
private  void subscribe(com.lbf.commons.messaging.MessageContext context)
          Handle a request to subscribe to a set of attributes for a specific object class.
private  void subscribeWithDDM(com.lbf.commons.messaging.MessageContext context, RTI_SubscribeObjectClass request)
          This method handles subscription requests that include DDM information.
private  void unsubscribe(com.lbf.commons.messaging.MessageContext context)
          This method handles requests to remove a subscription for a specific object class (or a subset of attributes within that class).
private  void unsubscribeDDM(com.lbf.commons.messaging.MessageContext context, RTI_UnsubscribeObjectClass request)
          This method handles an unsubscribe request when DDM information is used.
private  void unsubscribeImplicit(com.lbf.commons.messaging.MessageContext context, int classHandle, String target)
          This method converts a previous subscription request that contained 0-attributes into an unsubscribe request (RTI_UnsubscribeObjectClass) for the identified class.
private  void unsubscribeImplicitDDM(com.lbf.commons.messaging.MessageContext context, int classHandle, String target, int regionToken)
          Same as unsubscribeImplicit(MessageContext, int, String) except that it can include region data.
private  void validateDDM(int classHandle, int regionToken, Set<Integer> attributes)
          This method will validate the DDM related parts of a subscription request.
private  void validateHandles(int classHandle, Set<Integer> attributes)
          This method will verify that the object class exists in the FOM, and that each of the attribute handles represents an attribute that exists for the object class.
private  void validateRegion(int regionToken)
          Makes sure the region is valid (that we know about it).
private  void validateSubscribed(int classHandle)
          Validates that the given object class is subscribed by this federate
 
Methods inherited from class org.portico.lrc.handlers.LRCMessageHandler
error, error, getConnection, getFOM, initialize, sendMessage, success, success, success
 
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
 

Constructor Detail

REQ_SubscribeObjectHandler

public REQ_SubscribeObjectHandler()
Method Detail

processMessage

public void processMessage(com.lbf.commons.messaging.MessageContext context)
                    throws Exception
Processes an incoming message and depending on the type, delegates it to the appropriate private handling method.

Specified by:
processMessage in interface com.lbf.commons.messaging.IMessageHandler
Specified by:
processMessage in class LRCMessageHandler
Throws:
Exception

subscribe

private void subscribe(com.lbf.commons.messaging.MessageContext context)
                throws Exception
Handle a request to subscribe to a set of attributes for a specific object class. This method will first validate that each of the attribute handles exists in the FOM and then it will send the request on to the RTI. If the RTI returns a success response, the new subscription interest will be recorded in the LRCInterestManager.

If the provided set of attribute handles is empty, the request is taken to be an implicit unpublication request for all attributes of the object class. In that case, processing is turned over to #unsubscribeOCImplicit(MessageContext, int, String).

Throws:
Exception

subscribeWithDDM

private void subscribeWithDDM(com.lbf.commons.messaging.MessageContext context,
                              RTI_SubscribeObjectClass request)
                       throws Exception
This method handles subscription requests that include DDM information. Although these requests only need to be handled a little bit differently, they do need this handling to occur in a few places. Rather than just littering the original subscription process with a bunch of "if(usesDDM)" blocks, it's probably just cleaner to split this processing off into a separate method.

Throws:
Exception

unsubscribeImplicit

private void unsubscribeImplicit(com.lbf.commons.messaging.MessageContext context,
                                 int classHandle,
                                 String target)
                          throws Exception
This method converts a previous subscription request that contained 0-attributes into an unsubscribe request (RTI_UnsubscribeObjectClass) for the identified class. It then passes this request to the #unsubscribeOC(MessageContext) method for processing.

Throws:
Exception

unsubscribeImplicitDDM

private void unsubscribeImplicitDDM(com.lbf.commons.messaging.MessageContext context,
                                    int classHandle,
                                    String target,
                                    int regionToken)
                             throws Exception
Same as unsubscribeImplicit(MessageContext, int, String) except that it can include region data. If you don't want to include a region, either call the other method or pass PorticoConstants.NULL_HANDLE as the regionToken.

Throws:
Exception

unsubscribe

private void unsubscribe(com.lbf.commons.messaging.MessageContext context)
                  throws Exception
This method handles requests to remove a subscription for a specific object class (or a subset of attributes within that class). The method will first valudate that the object class handle exists in the FOM before confirming that the class is currently subscribed to by the federate. If everything is in order, the request is sent to the RTI where it will be processed. Assuming that the RTI responds with a success message, this method will then remove any subscription interest from the LRCInterestManager

If the unsubscription request includes a specific set of attributes that should be unsubscribed (rather than the entire class), the method will validate that each of the attribute handles exists in the FOM before allowing the message to travel to the RTI.

Throws:
Exception

unsubscribeDDM

private void unsubscribeDDM(com.lbf.commons.messaging.MessageContext context,
                            RTI_UnsubscribeObjectClass request)
                     throws Exception
This method handles an unsubscribe request when DDM information is used. The process varies from the standard unsubscribe in a small ways, but in a number of places. Rather than litter the standard unsubscribe handler with "if(usesDDM)" statements, it is cleaner to just factor this process out into a separate method.

Throws:
Exception

validateHandles

private void validateHandles(int classHandle,
                             Set<Integer> attributes)
                      throws JObjectClassNotDefined,
                             JAttributeNotDefined,
                             JRTIinternalError
This method will verify that the object class exists in the FOM, and that each of the attribute handles represents an attribute that exists for the object class.

Throws:
JObjectClassNotDefined - If the classHandle doesn't represent a class in the FOM
JAttributeNotDefined - If an attribute handle doesn't represent an attribute in the defined object class
JRTIinternalError - If there is a problem locating the FOM

validateSubscribed

private void validateSubscribed(int classHandle)
                         throws JObjectClassNotSubscribed
Validates that the given object class is subscribed by this federate

Throws:
JObjectClassNotSubscribed - If the object class is not currently subscribed to

validateDDM

private void validateDDM(int classHandle,
                         int regionToken,
                         Set<Integer> attributes)
                  throws JRegionNotKnown,
                         JInvalidRegionContext,
                         JRTIinternalError
This method will validate the DDM related parts of a subscription request. It will make sure that the federate knows about the region provided with the request and that the region is valid for all the identified attributes in the request (i.e. that the FOM specifies the appropriate space).

Throws:
JRegionNotKnown
JInvalidRegionContext
JRTIinternalError

validateRegion

private void validateRegion(int regionToken)
                     throws JRegionNotKnown
Makes sure the region is valid (that we know about it). If it isn't, throws an exception

Throws:
JRegionNotKnown

copyright The Portico Project 2008.