| Method from net.hivecell.hive.agent.EventSendingHelper Detail: |
public void addListener(EventReceivingAgent newListener) {
addListener( newListener, HiveEvent.ALL_EVENTS );
}
Add a listener to the list. EventSendingAgents can delegate to
this method to us. |
public void addListener(EventReceivingAgent newListener,
long eventMask) {
// log the message.
myCell.noteAgentMessage( agent, "addListener", newListener, agent );
// hmm - this doesn't seem right -- do we need the EventMaskWrapper?
EventReceivingAgent newListenerReference = (EventReceivingAgent)myCell.getLocalReference( newListener );
if( newListenerReference == null ) newListenerReference = newListener;
EventMaskWrapper emw = new EventMaskWrapper( newListenerReference, eventMask );
agentsToEventMaskWrappers.put( newListenerReference, emw );
// note the connection
myCell.noteAgentConnect( agent, newListener, agent );
}
Add a listener to ourselves, but only send them events that
correspond to a certain event mask |
public void asyncFinished(AsyncResult ar) {
if( ar.wasException() )
((EventSendingErrorListener)agent).eventSendingError( ar.getReceiver(), (Exception)ar.getResult() );
}
Used for async error listening |
public void broadcastEvent(Object data) {
if( data instanceof HiveEvent )
broadcastEvent( (HiveEvent)data );
else
broadcastEvent( data, HiveEvent.ALL_EVENTS );
}
|
public void broadcastEvent(HiveEvent he) {
broadcastEvent( he, HiveEvent.ALL_EVENTS );
}
|
public void broadcastEvent(Object data,
long eventMask) {
if( data instanceof HiveEvent )
broadcastEvent( (HiveEvent)data, eventMask );
else
broadcastEvent( new HiveEvent( remoteAgent, count++, data ), eventMask );
}
|
public void broadcastEvent(HiveEvent he,
long eventMask) {
EventMaskWrapper[] masks = null;
synchronized( agentsToEventMaskWrappers ) {
masks = new EventMaskWrapper[agentsToEventMaskWrappers.size()];
Enumeration e = agentsToEventMaskWrappers.elements();
int count = 0;
while( e.hasMoreElements() )
masks[count++] = (EventMaskWrapper)e.nextElement();
}
broadcastEventTo( he, eventMask, null, masks );
}
|
public void broadcastEventTo(Object data,
EventReceivingAgent agent) {
if( data instanceof HiveEvent )
broadcastEventTo( (HiveEvent)data, agent );
else {
EventReceivingAgent[] destinationAgent = { agent };
broadcastEventTo( data, destinationAgent, null );
}
}
|
public void broadcastEventTo(HiveEvent he,
EventReceivingAgent agent) {
EventReceivingAgent[] destinationAgent = { agent };
broadcastEventTo( he, destinationAgent, null );
}
|
public void broadcastEventTo(Object data,
EventReceivingAgent[] agents,
EventMaskWrapper[] masks) {
if( data instanceof HiveEvent )
broadcastEventTo( (HiveEvent)data, agents, masks );
else
broadcastEventTo( data, HiveEvent.ALL_EVENTS, agents, masks );
}
|
public void broadcastEventTo(HiveEvent he,
EventReceivingAgent[] agents,
EventMaskWrapper[] masks) {
broadcastEventTo( he, HiveEvent.ALL_EVENTS, agents, masks );
}
|
public void broadcastEventTo(Object data,
long eventMask,
EventReceivingAgent[] agents,
EventMaskWrapper[] masks) {
if( data instanceof HiveEvent )
broadcastEventTo( (HiveEvent)data, eventMask, agents, masks );
else
broadcastEventTo( new HiveEvent( remoteAgent, count++, data ), eventMask, agents, masks );
}
|
public void broadcastEventTo(HiveEvent he,
long eventMask,
EventReceivingAgent[] agents,
EventMaskWrapper[] masks) {
Vector destinationAgentsVector = new Vector();
Vector destinationCellAddressVector = new Vector();
if( masks != null )
for( int count=0;count < masks.length;count++ )
if( ( masks[count].getEventMask() & eventMask ) != 0 ) {
try {
CellAddress destinationAddress = masks[count].getAgent().getCell().getAddress();
destinationAgentsVector.addElement( masks[count].getAgent() );
destinationCellAddressVector.addElement( destinationAddress );
} catch( RemoteException error ) {
Debug.error( "cannot figure out what is the cell address of " + masks[count].getAgent() );
removeListener( masks[count].getAgent() );
}
}
if( agents != null )
for( int count=0;count < agents.length;count++ )
try {
CellAddress destinationAddress = agents[count].getCell().getAddress();
destinationAgentsVector.addElement( agents[count] );
destinationCellAddressVector.addElement( destinationAddress );
} catch( RemoteException error ) {
Debug.error( "cannot figure out what is the cell address of " + masks[count].getAgent() );
removeListener( masks[count].getAgent() );
}
EventReceivingAgent[] destinationAgents = new EventReceivingAgent[destinationAgentsVector.size()];
CellAddress[] destinationCellAddresses = new CellAddress[destinationAgents.length];
destinationAgentsVector.copyInto( destinationAgents );
destinationCellAddressVector.copyInto( destinationCellAddresses );
AsyncResult ar = agentMessagingShadow.sendEvent( destinationAgents, destinationCellAddresses, he );
if( agent instanceof EventSendingErrorListener )
// we're only registering ourselves as an error listener
ar.addExceptionOnlyListener( (AsyncResultListener)this );
}
|
public int getEventCount(Agent sender) {
// rk -- why is this commented out?
// myCell.noteAgentMessage( agent, "getEventCount", sender, agent );
// myCell.noteAgentMessage( agent, "getEventCount reply", agent, sender ); // reply
// the count is not guaranteed to be an exact count -- it is
// simply guaranteed to be increasing. this is incremented
// here so people when querying how many events were sent out
// so they can appropriately set the event in their custom
// HiveEvents, the count remains increasing
return count++;
}
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. |
public Vector getListeners() {
Vector listeners = new Vector();
synchronized( agentsToEventMaskWrappers ) {
Enumeration e = agentsToEventMaskWrappers.keys();
while( e.hasMoreElements() )
listeners.addElement( e.nextElement() );
}
return listeners;
}
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!!!! |
public EventReceivingAgent[] getLocalListeners() {
Vector allListeners = getListeners();
Vector localListeners = new Vector( allListeners.size() );
Enumeration e = allListeners.elements();
while( e.hasMoreElements() ) {
EventReceivingAgent candidateAgent = (EventReceivingAgent)e.nextElement();
if( myCell.isAgentLocal( candidateAgent ) )
localListeners.addElement( candidateAgent );
}
EventReceivingAgent[] returning = new EventReceivingAgent[localListeners.size()];
localListeners.copyInto( returning );
return returning;
}
return a list of all the listeners which are local to this agent |
public void removeListener(EventReceivingAgent sender) {
myCell.noteAgentMessage( agent, "removeListener", sender, agent );
EventMaskWrapper emw = (EventMaskWrapper)agentsToEventMaskWrappers.remove( sender );
if( emw != null )
myCell.noteAgentDisconnect( agent, sender, agent );
else
Debug.warning( "Was asked to remove listener " + Global.shortString( sender ) + " but I don't have it on my list." );
}
Remove a listener from the event queue. EventSendingAgents can
delegate to this method to us |