scorej.external.grid
Class GridHelper

java.lang.Object
  |
  +--scorej.external.CommProtocol
        |
        +--scorej.external.grid.GridHelper
All Implemented Interfaces:
java.util.EventListener, com.globalinfotek.coabsgrid.MessageListener, net.jini.lookup.ServiceDiscoveryListener

public class GridHelper
extends CommProtocol
implements com.globalinfotek.coabsgrid.MessageListener, net.jini.lookup.ServiceDiscoveryListener

Protocol that facilitates communication with the CoABS Grid. The ScoreJ Node itself can be registered with the Grid, so that different ScoreJ nodes can send signals back and forth using the grid. Agents can be registered with the Grid also, so that they can send/receive messages from other agents on the Grid.


Field Summary
 boolean registered
           
 
Fields inherited from class scorej.external.CommProtocol
_props
 
Constructor Summary
GridHelper()
          Exists for the purposes of S framework instantiation.
GridHelper(java.lang.String id)
          GridHelper constructor.
 
Method Summary
 void addNodeListener(RemoteNodeListener l)
           
 void broadcastSignal(Signal sig)
          Broadcast a signal to all nodes.
 void changeFilters(java.util.Vector newFilters)
          Changes the signal filters associated with the node to the new set specified in the arguments.
 void changeFilters(java.util.Vector newFilters, Node n)
          Changes the signal filters associated with the node to the new set specified in the arguments.
 void closeProtocol()
          Extends CommProtocol.closeProtocol.
static Signal convertMessageToSignal(com.globalinfotek.coabsgrid.Message msg)
          Convert a Grid Message object to a ScoreJ signal
 com.globalinfotek.coabsgrid.Message convertSignalToMessage(Signal sig, boolean raw)
          Convert a scoreJ Signal into a Grid Message.
 java.util.Vector findAllAgents(AgentID template)
          Find as many agents as possible that matches the template.
 java.util.Vector findAllAgentsOnGrid(JiniAgentEntry searchTemplate)
          Grid lookup.
 com.globalinfotek.coabsgrid.AgentRep findKnownAgentRep(ID idTemplate)
          Find an AgentRep that this node already knows about from an ID.
 void findOmarNodes()
          Find every "agent" registered with a ScoreJiniEntry on the Grid.
 AgentID findSingleAgent(AgentID template)
          Find one agent that matches the template.
 java.util.Properties getDefaultProperties()
          Implements CommProtocol.getDefaultProperties
 com.globalinfotek.coabsgrid.Directory getDirectory()
           
 net.jini.core.entry.Entry[] getEntries()
          Get entries advertised with the Grid
static GridNode getGridNode()
          Returns the GridNode used for this node.
 java.lang.String getId()
           
 Node getLocalNode()
          Gets a reference to the local Node object.
 java.util.Vector getNodes()
          Return a list of discovered Nodes Required by CommProtocol
protected  GridHelper initializeGrid()
           
protected  GridHelper initializeGrid(java.lang.String nodeID)
           
 void initializeProtocol(java.util.Properties props)
          Implements CommProtocol.initializeProtocol(Properties)
 boolean isRegistered()
           
 void messageAdded(com.globalinfotek.coabsgrid.Message msg)
          Message added function is the Grid callback that gets invoked whenever a incoming message gets added to this message queue.
 void registerAgent(AgentID agent)
          Register an agent with the Grid.
 void registerAgent(AgentID agent, boolean independentAgent)
           
 void registerAgent(java.lang.String name, net.jini.core.entry.Entry[] attributes)
          Register an agent on the Grid as a independent Agent (not part of this ScoreJ Node).
 void registerFilter(Filter f)
          Add a new signal filter to the local node.
 void registerFilter(Filter f, Node n)
          Add a new signal filter to a node.
protected  void registerWithGrid()
           
 void sendSignal(Node node, Signal sig)
          Send a signal to a Node by invoking sendSignal on that node.
 void serviceAdded(net.jini.lookup.ServiceDiscoveryEvent event)
          Received a notification event from the grid that some node or agent has registered.
 void serviceChanged(net.jini.lookup.ServiceDiscoveryEvent event)
          Received a serviceChanged event.
 void serviceRemoved(net.jini.lookup.ServiceDiscoveryEvent event)
           
 void shutdownHandler()
          Shutdown handler will be called when the JVM exits
 void startProtocol()
          Implements CommProtocol.startProtocol(Properties)
 boolean unregisterAgent(AgentID agent)
          Remove a AgentID from the registered agent list
 void unregisterAllAgents()
          Clean out the registered agent list
 void update()
          Required by CommProtocol
 void updateEntry(net.jini.core.entry.Entry newEntry)
          Update the Grid Advertisement for this node by adding a new Entry to it
 
Methods inherited from class scorej.external.CommProtocol
getProperties, isEnabledRegisterAgent, isEnabledRegisterFilter, setEnabledRegisterAgent, setEnabledRegisterFilter, setProperties
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

registered

public boolean registered
Constructor Detail

GridHelper

public GridHelper()
Exists for the purposes of S framework instantiation. Should not be invoked directly.


GridHelper

public GridHelper(java.lang.String id)
GridHelper constructor.

Method Detail

initializeProtocol

public void initializeProtocol(java.util.Properties props)
Implements CommProtocol.initializeProtocol(Properties)

Specified by:
initializeProtocol in class CommProtocol
Parameters:
props - protocol properties, can be null or empty.

startProtocol

public void startProtocol()
Implements CommProtocol.startProtocol(Properties)

Specified by:
startProtocol in class CommProtocol

getDefaultProperties

public java.util.Properties getDefaultProperties()
Implements CommProtocol.getDefaultProperties

Specified by:
getDefaultProperties in class CommProtocol
Returns:
default protocol properties

getGridNode

public static GridNode getGridNode()
Returns the GridNode used for this node.


getDirectory

public com.globalinfotek.coabsgrid.Directory getDirectory()

getId

public java.lang.String getId()

initializeGrid

protected GridHelper initializeGrid()

initializeGrid

protected GridHelper initializeGrid(java.lang.String nodeID)

registerWithGrid

protected void registerWithGrid()

convertMessageToSignal

public static Signal convertMessageToSignal(com.globalinfotek.coabsgrid.Message msg)
Convert a Grid Message object to a ScoreJ signal


convertSignalToMessage

public com.globalinfotek.coabsgrid.Message convertSignalToMessage(Signal sig,
                                                                  boolean raw)
Convert a scoreJ Signal into a Grid Message. If the raw flag is set to true, just encapsulate the Signal object as the Data member of a DataMessage. If raw is false, stringify the Signal args, and create a BasicMessage.

Parameters:
sig - is the Signal object to be converted
raw - boolean determining whether the Signal is stringified or sent as an object.
Returns:
Message object, either a DataMessage or a BasicMessage.

messageAdded

public void messageAdded(com.globalinfotek.coabsgrid.Message msg)
Message added function is the Grid callback that gets invoked whenever a incoming message gets added to this message queue.

Specified by:
messageAdded in interface com.globalinfotek.coabsgrid.MessageListener

findOmarNodes

public void findOmarNodes()
Find every "agent" registered with a ScoreJiniEntry on the Grid.


addNodeListener

public void addNodeListener(RemoteNodeListener l)

serviceAdded

public void serviceAdded(net.jini.lookup.ServiceDiscoveryEvent event)
Received a notification event from the grid that some node or agent has registered.

Specified by:
serviceAdded in interface net.jini.lookup.ServiceDiscoveryListener

serviceRemoved

public void serviceRemoved(net.jini.lookup.ServiceDiscoveryEvent event)
Specified by:
serviceRemoved in interface net.jini.lookup.ServiceDiscoveryListener

serviceChanged

public void serviceChanged(net.jini.lookup.ServiceDiscoveryEvent event)
Received a serviceChanged event. Update the attributes of the node or agent.

Specified by:
serviceChanged in interface net.jini.lookup.ServiceDiscoveryListener

getNodes

public java.util.Vector getNodes()
Return a list of discovered Nodes Required by CommProtocol

Specified by:
getNodes in class CommProtocol
Returns:
a list of Node objects.

getLocalNode

public Node getLocalNode()
Gets a reference to the local Node object.

Specified by:
getLocalNode in class CommProtocol
Returns:
a name of reference to the local Node object.

registerFilter

public void registerFilter(Filter f)
Add a new signal filter to the local node. This method is a a No-op if filter registration is disabled.

Specified by:
registerFilter in class CommProtocol

registerFilter

public void registerFilter(Filter f,
                           Node n)
Add a new signal filter to a node. This method is a a No-op if filter registration is disabled. Required by CommProtocol

Specified by:
registerFilter in class CommProtocol
Parameters:
f - The Filter object to be registered.
n - The Node to associate the filter with.

changeFilters

public void changeFilters(java.util.Vector newFilters)
Changes the signal filters associated with the node to the new set specified in the arguments. This method is a a No-op if filter registration is disabled.

Specified by:
changeFilters in class CommProtocol
Parameters:
newFilters - A Vector of new Filter Objects.

changeFilters

public void changeFilters(java.util.Vector newFilters,
                          Node n)
Changes the signal filters associated with the node to the new set specified in the arguments. This method is a a No-op if filter registration is disabled.

Specified by:
changeFilters in class CommProtocol
Parameters:
newFilters - A Vector of new Filter Objects.
n - Reference to the Node object.

updateEntry

public void updateEntry(net.jini.core.entry.Entry newEntry)
Update the Grid Advertisement for this node by adding a new Entry to it


getEntries

public net.jini.core.entry.Entry[] getEntries()
Get entries advertised with the Grid


sendSignal

public void sendSignal(Node node,
                       Signal sig)
Send a signal to a Node by invoking sendSignal on that node. If something fails, remove the Node from our list of existing nodes

Overrides:
sendSignal in class CommProtocol
Parameters:
node - The node the signal is sent to.
sig - The siganl object to be sent.

broadcastSignal

public void broadcastSignal(Signal sig)
Broadcast a signal to all nodes. No longer used.


isRegistered

public boolean isRegistered()

closeProtocol

public void closeProtocol()
Extends CommProtocol.closeProtocol. Closes this service by deregistering with Jini

Specified by:
closeProtocol in class CommProtocol

registerAgent

public void registerAgent(AgentID agent)
Register an agent with the Grid. This will add the JiniAgentEntry to the attribute list of the JiniScoreEntry (this node's entry). This method is a No-op if agent registration is disabled.

Specified by:
registerAgent in class CommProtocol

registerAgent

public void registerAgent(AgentID agent,
                          boolean independentAgent)

registerAgent

public void registerAgent(java.lang.String name,
                          net.jini.core.entry.Entry[] attributes)
Register an agent on the Grid as a independent Agent (not part of this ScoreJ Node). This means that the agent will have its own MessageQueue. This method is a No-op if agent registration is disabled.

Parameters:
name - String name of the agent

unregisterAgent

public boolean unregisterAgent(AgentID agent)
Description copied from class: CommProtocol
Remove a AgentID from the registered agent list

Specified by:
unregisterAgent in class CommProtocol

unregisterAllAgents

public void unregisterAllAgents()
Description copied from class: CommProtocol
Clean out the registered agent list

Specified by:
unregisterAllAgents in class CommProtocol

findSingleAgent

public AgentID findSingleAgent(AgentID template)
Find one agent that matches the template. First look at local agents that this node registered with the Grid. Then look for agents that have been located before using Grid Lookups. Then check remote scoreJ nodes. Finally, issue a grid search. This method returns null if agent registration is disbaled.

Specified by:
findSingleAgent in class CommProtocol
Returns:
AgentID matching the template

findAllAgents

public java.util.Vector findAllAgents(AgentID template)
Find as many agents as possible that matches the template. First look at local agents that this node registered with the Grid. Then look for agents that have been located before using Grid Lookups. Then check remote scoreJ nodes. This functions does NOT issue a general grid search. You'll need to do that manually (by calling the next function down) if you want.

Specified by:
findAllAgents in class CommProtocol
Returns:
Vector of AgentIDs that match the template

findAllAgentsOnGrid

public java.util.Vector findAllAgentsOnGrid(JiniAgentEntry searchTemplate)
Grid lookup. Search the Grid for as many agents as possible that match the passed in template. Returns a Vector of AgentIDs.


findKnownAgentRep

public com.globalinfotek.coabsgrid.AgentRep findKnownAgentRep(ID idTemplate)
Find an AgentRep that this node already knows about from an ID. This searches only the local agents, foundScorejAgents, and foundNonScorejAgents. It does not do a grid search. This method returns a null if agent registration is disabled.


shutdownHandler

public void shutdownHandler()
Shutdown handler will be called when the JVM exits

Overrides:
shutdownHandler in class CommProtocol

update

public void update()
Required by CommProtocol

Specified by:
update in class CommProtocol