js.ea
Class EventAgentImpl

java.lang.Object
  extended by java.rmi.server.RemoteObject
      extended by java.rmi.server.RemoteServer
          extended by java.rmi.server.UnicastRemoteObject
              extended by js.ea.EventAgentImpl
All Implemented Interfaces:
java.io.Serializable, java.rmi.Remote, AdminEA, EventAgent, EventMonitorInterface

public class EventAgentImpl
extends java.rmi.server.UnicastRemoteObject
implements EventAgent, EventMonitorInterface

The EventAgent manages the event mechanism of JavaSymphony (event registering and production).

Author:
Johannes Testori
See Also:
Serialized Form

Field Summary
 
Fields inherited from class java.rmi.server.RemoteObject
ref
 
Method Summary
static EventAgentImpl create(java.lang.String hostname, int port, NetworkAgentImpl na)
          Creates an instance of EventAgentImpl.
 boolean equals(EventAgent ea)
           
static EventAgent getInstance()
           
 java.util.Properties getProperties()
           
 java.lang.String getUrl()
           
 void globalRegister(JSConsumerEvent event)
          Used to register an event on the EventAgent where the event will be produced.
 void globalUnregister(JSConsumerEvent event)
          Used to unregister an event on the EventAgent where the event will be produced.
 void informAddedNA(NetworkAgent na, boolean propagate)
          Informs about the adding of a network agent to the physical architecture.
 void informRemovedAll()
          Informs about the removal of all network agents of the physical architecture.
 void informRemovedNA(NetworkAgent na, boolean propagate)
          Informs aboout the removal of a network agent from the physical architecture.
 void produceEvent(JSProducerEvent event, java.lang.Object[] args)
          Produces the specified event.
 void receiveEvent(JSProducerEvent event, java.lang.Object[] args, java.lang.Class[] paramTypes)
          Receives events from the EventAgent that produced the event.
 void registerConsumerEvent(JSConsumerEvent event)
          Registers the specified event.
 void remoteInit(java.util.HashSet eaList, EventAgent parent)
          When a new network agent has been added to the physical architecture, the event agent of the parent NA calls this method of the event agent of the new NA.
 void remoteRegisterConsumer(EventAgent ea, JSConsumerEvent event)
          Invokes globalRegister for the specified EventAgent.
 void remoteUnregisterConsumer(EventAgent ea, JSConsumerEvent event)
          Invokes globalUnregister for the specified EventAgent.
 void sendEvent(EventAgent ea, JSProducerEvent event, java.util.HashSet destEAs, java.lang.Object[] args, java.lang.Class[] paramTypes)
          Sends an event to the specified EventAgent.
 void setProperties(java.util.Properties props, boolean propagate)
          Sets the properties that store which event types are enabled/disabled.
 void setPubOA(PubOA pubOA)
          Sets the PubOA of the NetworkAgent where the EventAgent is located.
 java.lang.String toString()
           
 void unregisterConsumerEvent(JSConsumerEvent event)
          Removes the specified event from the registeredEvents-list and calls remoteUnregisterConsumer to unregister the event at the EventAgents where the VAs are located that produce the desired event.
 
Methods inherited from class java.rmi.server.UnicastRemoteObject
clone, exportObject, exportObject, exportObject, unexportObject
 
Methods inherited from class java.rmi.server.RemoteServer
getClientHost, getLog, setLog
 
Methods inherited from class java.rmi.server.RemoteObject
equals, getRef, hashCode, toStub
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Method Detail

create

public static EventAgentImpl create(java.lang.String hostname,
                                    int port,
                                    NetworkAgentImpl na)
                             throws java.rmi.RemoteException
Creates an instance of EventAgentImpl.

Parameters:
hostname - name of local host
port - port of NetworkAgent and PubOA, EventAgent will be bound to this port
na - NetworkAgent that creates the EventAgent
Throws:
java.rmi.RemoteException

equals

public boolean equals(EventAgent ea)
               throws java.rmi.RemoteException
Specified by:
equals in interface EventAgent
Parameters:
ea - js.ea.EventAgent
Returns:
true if the specified EventAgent equals this EventAgent
Throws:
java.rmi.RemoteException

getInstance

public static EventAgent getInstance()
Returns:
the instance of the EventAgent (if called from the main application, the EventAgent from the node where the application is registered will be returned)

getProperties

public java.util.Properties getProperties()
                                   throws java.rmi.RemoteException
Specified by:
getProperties in interface EventMonitorInterface
Returns:
properties that store which event types are enabled/disabled
Throws:
java.rmi.RemoteException

getUrl

public java.lang.String getUrl()
                        throws java.rmi.RemoteException
Specified by:
getUrl in interface EventAgent
Returns:
the URL of the EventAgent
Throws:
java.rmi.RemoteException

globalRegister

public void globalRegister(JSConsumerEvent event)
                    throws java.rmi.RemoteException
Used to register an event on the EventAgent where the event will be produced. Stores the event in the consumerEvents-list.

Specified by:
globalRegister in interface EventAgent
Parameters:
event - the event to be registered
Throws:
java.rmi.RemoteException

globalUnregister

public void globalUnregister(JSConsumerEvent event)
                      throws java.rmi.RemoteException
Used to unregister an event on the EventAgent where the event will be produced. Removes the event from the consumerEvents-list.

Specified by:
globalUnregister in interface EventAgent
Parameters:
event - the event to be unregistered
Throws:
java.rmi.RemoteException

informAddedNA

public void informAddedNA(NetworkAgent na,
                          boolean propagate)
                   throws java.rmi.RemoteException
Informs about the adding of a network agent to the physical architecture. Adds the NetworkAgent's EventAgent to the EventAgents-list and registered all events of type C_ALL_EVENTS.

Specified by:
informAddedNA in interface AdminEA
Parameters:
na - the network agent that has been added
propagate - true, if the information shall be propagated to other event agents
Throws:
java.rmi.RemoteException

informRemovedAll

public void informRemovedAll()
                      throws java.rmi.RemoteException
Informs about the removal of all network agents of the physical architecture. Clears the EventAgents-list

Specified by:
informRemovedAll in interface AdminEA
Throws:
java.rmi.RemoteException

informRemovedNA

public void informRemovedNA(NetworkAgent na,
                            boolean propagate)
                     throws java.rmi.RemoteException
Informs aboout the removal of a network agent from the physical architecture. Removes the NetworkAgent's EventAgent from the EventAgents-list.

Specified by:
informRemovedNA in interface AdminEA
Parameters:
na - the network agent that has been removed
propagate - true, if the information shall be propagated to other event agents
Throws:
java.rmi.RemoteException

produceEvent

public void produceEvent(JSProducerEvent event,
                         java.lang.Object[] args)
                  throws java.rmi.RemoteException
Produces the specified event. Searches the registeredEvents-list and invokes sendEvent for matching consumer.

Specified by:
produceEvent in interface EventAgent
Parameters:
event - the event to be produced
args - the arguments of the method that handles the event
Throws:
java.rmi.RemoteException

receiveEvent

public void receiveEvent(JSProducerEvent event,
                         java.lang.Object[] args,
                         java.lang.Class[] paramTypes)
                  throws java.rmi.RemoteException
Receives events from the EventAgent that produced the event. Searches the registeredEvents-list and calls invokeMethod for matching consumers.

Specified by:
receiveEvent in interface EventAgent
Parameters:
event - produced event
arguments - for the method that handles the event
paramTypes - signature of the method
Throws:
java.rmi.RemoteException

registerConsumerEvent

public void registerConsumerEvent(JSConsumerEvent event)
                           throws java.rmi.RemoteException
Registers the specified event. Adds the event to the registeredEvents-list and registers it (using remoteRegisterConsumer at the EventAgents where the VAs are located that produce the desired event.

Specified by:
registerConsumerEvent in interface EventAgent
Parameters:
event - event to register
Throws:
java.rmi.RemoteException

remoteInit

public void remoteInit(java.util.HashSet eaList,
                       EventAgent parent)
When a new network agent has been added to the physical architecture, the event agent of the parent NA calls this method of the event agent of the new NA.

Specified by:
remoteInit in interface AdminEA
Parameters:
eaList - list of all NAs in the physical architecture
parent - event agent of the parent NA

remoteRegisterConsumer

public void remoteRegisterConsumer(EventAgent ea,
                                   JSConsumerEvent event)
                            throws java.rmi.RemoteException
Invokes globalRegister for the specified EventAgent.

Specified by:
remoteRegisterConsumer in interface EventAgent
Parameters:
ea - EventAgent where the event should be registered
event - evtnt to be registered
Throws:
java.rmi.RemoteException

remoteUnregisterConsumer

public void remoteUnregisterConsumer(EventAgent ea,
                                     JSConsumerEvent event)
                              throws java.rmi.RemoteException
Invokes globalUnregister for the specified EventAgent.

Specified by:
remoteUnregisterConsumer in interface EventAgent
Parameters:
ea - EventAgent where the event should be unregistered
event - event to be unregistered
Throws:
java.rmi.RemoteException

sendEvent

public void sendEvent(EventAgent ea,
                      JSProducerEvent event,
                      java.util.HashSet destEAs,
                      java.lang.Object[] args,
                      java.lang.Class[] paramTypes)
               throws java.rmi.RemoteException
Sends an event to the specified EventAgent.

Specified by:
sendEvent in interface EventAgent
Parameters:
ea - EventAgent where the event should be sent to
event - the event to be sent further
destEAs - stores EventAgent where the event has been sent to to avoid sending events to the same EventAgent twice
args - arguments for the method that handles the event
paramTypes - signature of the method
Throws:
java.rmi.RemoteException

setProperties

public void setProperties(java.util.Properties props,
                          boolean propagate)
                   throws java.rmi.RemoteException
Sets the properties that store which event types are enabled/disabled.

Specified by:
setProperties in interface EventMonitorInterface
Parameters:
props - new properties for EventAgent
propagate - true if the properties should be propagated to other EventAgents
Throws:
java.rmi.RemoteException

setPubOA

public void setPubOA(PubOA pubOA)
Sets the PubOA of the NetworkAgent where the EventAgent is located.

Specified by:
setPubOA in interface EventAgent
Parameters:
pubOA - reference to the pubOA of the NetworkAgent

toString

public java.lang.String toString()
Overrides:
toString in class java.rmi.server.RemoteObject
Returns:
a textual description of the Eventagent

unregisterConsumerEvent

public void unregisterConsumerEvent(JSConsumerEvent event)
                             throws java.rmi.RemoteException
Removes the specified event from the registeredEvents-list and calls remoteUnregisterConsumer to unregister the event at the EventAgents where the VAs are located that produce the desired event.

Specified by:
unregisterConsumerEvent in interface EventAgent
Parameters:
event - event to unregister
Throws:
java.rmi.RemoteException