leafchat.core.api
Class BasicMsgOwner

java.lang.Object
  extended by leafchat.core.api.BasicMsgOwner
All Implemented Interfaces:
MsgOwner

public abstract class BasicMsgOwner
extends java.lang.Object
implements MsgOwner

Utility class that implements most of MsgOwner (assuming you are going to let the system handle target registration).


Constructor Summary
BasicMsgOwner()
           
 
Method Summary
 boolean allowExternalDispatch(Msg m)
          Called if somebody tries to dispatch a message other than via the MessageDispatch class
 MessageDispatch getDispatch()
           
 void init(MessageDispatch md)
          Called once the dispatcher is registered.
 void manualDispatch(Msg m)
          Called when the dispatcher should handle manual dispatch of a message (to all targets for which it returned false in registerTarget).
 boolean registerTarget(java.lang.Object target, java.lang.Class<? extends Msg> message, MessageFilter mf, int requestID, int priority)
          Called when a new target registers to receive messages from this class.
 void unregisterTarget(java.lang.Object target, int requestID)
          Called when a target unregisters.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface leafchat.core.api.MsgOwner
getFriendlyName, getMessageClass
 

Constructor Detail

BasicMsgOwner

public BasicMsgOwner()
Method Detail

getDispatch

public MessageDispatch getDispatch()
Returns:
The MessageDispatch object used to send messages

allowExternalDispatch

public boolean allowExternalDispatch(Msg m)
Description copied from interface: MsgOwner
Called if somebody tries to dispatch a message other than via the MessageDispatch class

Specified by:
allowExternalDispatch in interface MsgOwner
Parameters:
m - Message for dispatch
Returns:
True to permit dispatch, false to prohibit

init

public void init(MessageDispatch md)
Description copied from interface: MsgOwner
Called once the dispatcher is registered.

Specified by:
init in interface MsgOwner
Parameters:
md - Provided by the system to handle message dispatch from this dispatcher

manualDispatch

public void manualDispatch(Msg m)
Description copied from interface: MsgOwner
Called when the dispatcher should handle manual dispatch of a message (to all targets for which it returned false in registerTarget). Manual dispatch happens *before* any automatic dispatching.

It is up to the message owner to handle 'stopped' messages (m.isStopped) and not pass them on to further targets.

Specified by:
manualDispatch in interface MsgOwner
Parameters:
m - Message being sent

registerTarget

public boolean registerTarget(java.lang.Object target,
                              java.lang.Class<? extends Msg> message,
                              MessageFilter mf,
                              int requestID,
                              int priority)
Description copied from interface: MsgOwner
Called when a new target registers to receive messages from this class.

Specified by:
registerTarget in interface MsgOwner
Parameters:
target - Target
message - Class of desired message (null = all)
mf - Filter (may be null)
requestID - ID associated with this request (used in unregister)
priority - Priority for message
Returns:
True if the system should automatically dispatch messages to this target; false if this MessageOwner will dispatch messages itself

unregisterTarget

public void unregisterTarget(java.lang.Object target,
                             int requestID)
Description copied from interface: MsgOwner
Called when a target unregisters.

Specified by:
unregisterTarget in interface MsgOwner
Parameters:
target - Target
requestID - Identifier of the request to be removed


Copyright © 2011 Samuel Marshall. All rights reserved.