Package com.jme3.network.util
Class AbstractMessageDelegator<S extends MessageConnection>
java.lang.Object
com.jme3.network.util.AbstractMessageDelegator<S>
- All Implemented Interfaces:
MessageListener<S>
- Direct Known Subclasses:
ObjectMessageDelegator
,SessionDataDelegator
public abstract class AbstractMessageDelegator<S extends MessageConnection>
extends Object
implements MessageListener<S>
A MessageListener implementation that will forward messages to methods
of a delegate object. These methods can be automapped or manually
specified. Subclasses provide specific implementations for how to
find the actual delegate object.
-
Constructor Summary
ModifierConstructorDescriptionprotected
AbstractMessageDelegator
(Class delegateType, boolean automap) Creates an AbstractMessageDelegator that will forward received messages to methods of the specified delegate type. -
Method Summary
Modifier and TypeMethodDescriptionprotected boolean
Returns true if the specified method name is allowed.protected final void
automap()
Calls the map(Set) method with a null argument causing all available matching methods to mapped to message types.protected Method
findDelegate
(String name, Class messageType) Goes through all of the delegate type's methods to find a method of the specified name that may take the specified message type.protected Class
Convenience method that returns the message type as reflectively determined for a particular method.Class[]
Returns the array of messages known to be handled by this message delegator.protected Method
Returns the mapped method for the specified message type.protected abstract Object
getSourceDelegate
(S source) Implemented by subclasses to provide the actual delegate object against which the mapped message type methods will be called.protected boolean
isValidMethod
(Method m, Class messageType) Returns true if the specified method is valid for the specified message type.Manually maps a specified method to the specified message type.Specifically maps the specified methods names, autowiring the parameters.protected void
Goes through all of the delegate type's declared methods mapping methods that match the current constraints.void
messageReceived
(S source, Message msg) Implementation of the MessageListener's messageReceived() method that will use the current message type mapping to find an appropriate message handling method and call it on the delegate returned by getSourceDelegate().
-
Constructor Details
-
AbstractMessageDelegator
Creates an AbstractMessageDelegator that will forward received messages to methods of the specified delegate type. If automap is true then reflection is used to lookup probably message handling methods.
-
-
Method Details
-
getMessageTypes
Returns the array of messages known to be handled by this message delegator. -
isValidMethod
Returns true if the specified method is valid for the specified message type. This is used internally during automapping to provide implementation specific filtering of methods. This implementation checks for methods that take either the connection and message type arguments (in that order) or just the message type. -
getMessageType
Convenience method that returns the message type as reflectively determined for a particular method. This only works with methods that actually have arguments. This implementation returns the last element of the method's getParameterTypes() array, thus supporting both method(connection, messageType) and method(messageType) calling forms. -
findDelegate
Goes through all of the delegate type's methods to find a method of the specified name that may take the specified message type. -
allowName
Returns true if the specified method name is allowed. This is used by automapping to determine if a method should be rejected purely on name. Default implementation always returns true. -
automap
protected final void automap()Calls the map(Set) method with a null argument causing all available matching methods to mapped to message types. -
map
Specifically maps the specified methods names, autowiring the parameters. -
map
Goes through all of the delegate type's declared methods mapping methods that match the current constraints. If the constraints set is null then allowName() is checked for names otherwise only names in the constraints set are allowed. For each candidate method that passes the above checks, isValidMethod() is called with a null message type argument. All methods are made accessible thus supporting non-public methods as well as public methods. -
map
Manually maps a specified method to the specified message type. -
getMethod
Returns the mapped method for the specified message type. -
getSourceDelegate
Implemented by subclasses to provide the actual delegate object against which the mapped message type methods will be called. -
messageReceived
Implementation of the MessageListener's messageReceived() method that will use the current message type mapping to find an appropriate message handling method and call it on the delegate returned by getSourceDelegate().- Specified by:
messageReceived
in interfaceMessageListener<S extends MessageConnection>
-