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

    Constructors
    Modifier
    Constructor
    Description
    protected
    AbstractMessageDelegator(Class delegateType, boolean automap)
    Creates an AbstractMessageDelegator that will forward received messages to methods of the specified delegate type.
  • Method Summary

    Modifier and Type
    Method
    Description
    protected boolean
    Returns true if the specified method name is allowed.
    protected final void
    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.
    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
    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.
    map(Class messageType, String methodName)
    Manually maps a specified method to the specified message type.
    map(String... methodNames)
    Specifically maps the specified methods names, autowiring the parameters.
    protected void
    map(Set<String> constraints)
    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().

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • AbstractMessageDelegator

      protected AbstractMessageDelegator(Class delegateType, boolean automap)
      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

      public Class[] getMessageTypes()
      Returns the array of messages known to be handled by this message delegator.
    • isValidMethod

      protected boolean isValidMethod(Method m, Class messageType)
      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

      protected Class getMessageType(Method m)
      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

      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.
    • allowName

      protected boolean allowName(String name)
      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

      public AbstractMessageDelegator<S> map(String... methodNames)
      Specifically maps the specified methods names, autowiring the parameters.
    • map

      protected void map(Set<String> constraints)
      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

      public AbstractMessageDelegator<S> map(Class messageType, String methodName)
      Manually maps a specified method to the specified message type.
    • getMethod

      protected Method getMethod(Class c)
      Returns the mapped method for the specified message type.
    • getSourceDelegate

      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.
    • messageReceived

      public 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().
      Specified by:
      messageReceived in interface MessageListener<S extends MessageConnection>