|
copyright The Portico Project 2008. | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.lbf.commons.messaging.AbstractMessageHandler
org.portico.lrc.handlers.LRCMessageHandler
public abstract class LRCMessageHandler
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.
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 |
---|
protected LRC lrc
protected LRCState state
protected org.apache.log4j.Logger logger
protected LRCInstanceRepository repository
protected LRCInterestManager interests
protected LRCRegionStore regions
Constructor Detail |
---|
protected LRCMessageHandler()
protected LRCMessageHandler(String name)
Method Detail |
---|
public abstract void processMessage(com.lbf.commons.messaging.MessageContext context) throws Exception
processMessage
in interface com.lbf.commons.messaging.IMessageHandler
processMessage
in class com.lbf.commons.messaging.AbstractMessageHandler
Exception
public void initialize(com.lbf.commons.utils.Bag<String,?> properties) throws com.lbf.commons.config.ConfigurationException
initialize
in interface com.lbf.commons.messaging.IMessageHandler
initialize
in class com.lbf.commons.messaging.AbstractMessageHandler
com.lbf.commons.config.ConfigurationException
protected LRCConnection getConnection()
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.
protected ObjectModel getFOM() throws JRTIinternalError
FOM
. If the FOM is
null, a JRTIinternalError
will be thrown.
JRTIinternalError
protected void sendMessage(com.lbf.commons.messaging.MessageContext context) throws Exception
LRCConnection
in a manner that is safe. After this call, the
response portion of the context should be filled out.
context
- The context to send to the RTI
Exception
- If the sending process causes an exception it is just passed onprotected void success(com.lbf.commons.messaging.MessageContext context)
SuccessMessage
(see the commons) in the context.
protected void success(com.lbf.commons.messaging.MessageContext context, com.lbf.commons.utils.Bag<String,Object> properties)
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)
SuccessMessage
(see the commons) in the context and binds the given
object to the "result"
key in the properties.
protected void error(com.lbf.commons.messaging.MessageContext context, String message)
protected void error(com.lbf.commons.messaging.MessageContext context, Throwable cause)
|
copyright The Portico Project 2008. | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |