net.hivecell.hive.agent
Class EventSendingHelper

java.lang.Object
  |
  +--net.hivecell.hive.agent.EventSendingHelper

public class EventSendingHelper
extends java.lang.Object
implements AsyncResultListener

Helper class for EventSendingAgent interface; agent implementations can delegate methods to this class. This class maintains a list of listeners for events, as well as a count of events it has sent. When broadcastEvent is called by the client, the EventSendingHelper delivers the message to all current listeners. By default these messages are sent asynchronously. Please be careful if creating Hive objects to send by hand -- use the getCount() method in this object to determine the value that the count field in the HiveEvent constructor can use. This is not the recommended way to send events -- it is preferred programmers use the Object methods instead unless they need to send custom HiveEvents

See Also:
EventSendingAgent, AsyncSender

Field Summary
protected  AgentImpl agent
          Agent we're helping
protected  AgentMessagingShadow agentMessagingShadow
          The hook to the AgentMessagingShadow
protected  java.util.Hashtable agentsToEventMaskWrappers
           
protected  Cell myCell
          Cell we're on
protected  Agent remoteAgent
          The remote reference to the agent we are helping
 
Constructor Summary
EventSendingHelper(AgentImpl agentHelped, Cell server)
          Construct a helper for an event sending agent to delegate to.
 
Method Summary
 void addListener(EventReceivingAgent newListener)
          Add a listener to the list.
 void addListener(EventReceivingAgent newListener, long eventMask)
          Add a listener to ourselves, but only send them events that correspond to a certain event mask
 void asyncFinished(AsyncResult ar)
          Used for async error listening
 void broadcastEvent(HiveEvent he)
           
 void broadcastEvent(HiveEvent he, long eventMask)
           
 void broadcastEvent(java.lang.Object data)
           
 void broadcastEvent(java.lang.Object data, long eventMask)
           
 void broadcastEventTo(HiveEvent he, EventReceivingAgent agent)
           
 void broadcastEventTo(HiveEvent he, EventReceivingAgent[] agents, EventMaskWrapper[] masks)
           
 void broadcastEventTo(HiveEvent he, long eventMask, EventReceivingAgent[] agents, EventMaskWrapper[] masks)
           
 void broadcastEventTo(java.lang.Object data, EventReceivingAgent agent)
           
 void broadcastEventTo(java.lang.Object data, EventReceivingAgent[] agents, EventMaskWrapper[] masks)
           
 void broadcastEventTo(java.lang.Object data, long eventMask, EventReceivingAgent[] agents, EventMaskWrapper[] masks)
           
 int getEventCount(Agent sender)
          Get a count of how many events have fired.
 java.util.Vector getListeners()
          return a list of the agents which are subscribed to us -- we just return a vector of agents that are the keys toe the agentToEventMaskWrappers.
 EventReceivingAgent[] getLocalListeners()
          return a list of all the listeners which are local to this agent
 void removeListener(EventReceivingAgent sender)
          Remove a listener from the event queue.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

agent

protected AgentImpl agent
Agent we're helping

remoteAgent

protected Agent remoteAgent
The remote reference to the agent we are helping

myCell

protected Cell myCell
Cell we're on

agentMessagingShadow

protected AgentMessagingShadow agentMessagingShadow
The hook to the AgentMessagingShadow

agentsToEventMaskWrappers

protected java.util.Hashtable agentsToEventMaskWrappers
Constructor Detail

EventSendingHelper

public EventSendingHelper(AgentImpl agentHelped,
                          Cell server)
Construct a helper for an event sending agent to delegate to.
Parameters:
agentHelped - The agent to be helped.
server - The Cell we're on.
Method Detail

getListeners

public java.util.Vector getListeners()
return a list of the agents which are subscribed to us -- we just return a vector of agents that are the keys toe the agentToEventMaskWrappers. i want this to eventually be an array!!!!
Returns:
a vector version of the agentsToEventMaskWrappers.keys()

getLocalListeners

public EventReceivingAgent[] getLocalListeners()
return a list of all the listeners which are local to this agent
Returns:
an array of all the agents who are subscribed to us && local to us

addListener

public void addListener(EventReceivingAgent newListener)
Add a listener to the list. EventSendingAgents can delegate to this method to us.
Parameters:
newListener - the listener that we want to be subscribed to us

addListener

public void addListener(EventReceivingAgent newListener,
                        long eventMask)
Add a listener to ourselves, but only send them events that correspond to a certain event mask
Parameters:
newListener - the listener that we want subscribed to us
eventMask - the event mask that we are subscribing this agent with

removeListener

public void removeListener(EventReceivingAgent sender)
Remove a listener from the event queue. EventSendingAgents can delegate to this method to us
Parameters:
sender - the agent that we want removed from our subscriber lists

getEventCount

public int getEventCount(Agent sender)
Get a count of how many events have fired. EventSendingAgents can delegate to this method to us. This is not guaranteed to be an exact count -- only that the count is increasing.
Parameters:
agent - the agent asking for this information

broadcastEvent

public void broadcastEvent(java.lang.Object data)

broadcastEvent

public void broadcastEvent(java.lang.Object data,
                           long eventMask)

broadcastEvent

public void broadcastEvent(HiveEvent he)

broadcastEvent

public void broadcastEvent(HiveEvent he,
                           long eventMask)

broadcastEventTo

public void broadcastEventTo(java.lang.Object data,
                             EventReceivingAgent agent)

broadcastEventTo

public void broadcastEventTo(HiveEvent he,
                             EventReceivingAgent agent)

broadcastEventTo

public void broadcastEventTo(java.lang.Object data,
                             EventReceivingAgent[] agents,
                             EventMaskWrapper[] masks)

broadcastEventTo

public void broadcastEventTo(java.lang.Object data,
                             long eventMask,
                             EventReceivingAgent[] agents,
                             EventMaskWrapper[] masks)

broadcastEventTo

public void broadcastEventTo(HiveEvent he,
                             EventReceivingAgent[] agents,
                             EventMaskWrapper[] masks)

broadcastEventTo

public void broadcastEventTo(HiveEvent he,
                             long eventMask,
                             EventReceivingAgent[] agents,
                             EventMaskWrapper[] masks)

asyncFinished

public void asyncFinished(AsyncResult ar)
Used for async error listening
Specified by:
asyncFinished in interface AsyncResultListener
Parameters:
ar - the async result that we get spit back to us after our async call has completed