de.fhg.igd.atlas.core
Class AgentTracerImpl

java.lang.Object
  extended byde.fhg.igd.semoa.service.AbstractService
      extended byde.fhg.igd.atlas.core.AgentTracerImpl
All Implemented Interfaces:
AgentTracer, Runnable, Service

public class AgentTracerImpl
extends AbstractService
implements AgentTracer, Runnable

Provides the function of an Agent Tracer, which tracks the current location of agents, making use of a locally installed LSClientService interface. Agents can be added and removed to a watch list. In certain update intervals the update daemon initiates lookups to resolve the current contact addresses of all agents in the watch list. The corresponding (implicit name, contact address) correlations can be requested as SortedMap.

Version:
"$Id: AgentTracerImpl.java 1913 2007-08-08 02:41:53Z jpeters $"
Author:
Jan Peters
See Also:
LSClientService, AgentTracerGui

Field Summary
protected  LSClientService clientService_
          The reference to a locally installed LSClientService which is used to lookup the agent's contact addresses.
private  Object datalock_
          The internal lock object used for synchronisation of watchList respectively tracedAgents_ modifications.
private static String[] DEPEND_
          The dependencies to other objects in the global Environment.
protected  EventReflector eventReflector_
          The event reflector which is notified, every time a refresh request has been executed successfully.
private  Object lock_
          The internal lock object used for the tracerThread_.
 int LOOKUP_ATTEMPTS
          The number of allowed unsuccessful lookups for an agent contact address, before the agent will be removed from the watch list.
protected  Signals signals_
          Used for for signaling between database and tracerThread.
protected  SortedMap tracedAgents_
          The current contact addresses of all agents in the watch list are stored in this map.
protected  Thread tracerThread_
          Thread that provides the functionality of the update daemon.
protected  long updateTime_
          Update time for the update daemon.
protected  SortedMap watchList_
          Represents the watch list, which stores the implicit names of the agents and the number of unsuccessful lookups.
 
Fields inherited from class de.fhg.igd.semoa.service.AbstractService
REV_POSTFIX, REV_PREFIX
 
Fields inherited from interface de.fhg.igd.atlas.core.AgentTracer
WHATIS
 
Constructor Summary
AgentTracerImpl()
          Creates a new instance of the agent tracer with the a update time of 1000ms for its update daemon.
AgentTracerImpl(long updateTime)
          Creates a new instance of the agent tracer with the given updateTime for its update daemon.
 
Method Summary
 void addAgentToWatchList(AgentCard card)
          Adds an agent to the agent tracer's watch list.
 void addAgentToWatchList(byte[] implicitName)
          Adds an agent to the agent tracer's watch list.
 TrustedListener addListener(Listener listener)
          Adds a Listener.
 String author()
          Returns the String with the author's name.
 String[] dependencies()
          Returns the dependencies of this service as described in Service.
 long getUpdateTime()
          Returns the update interval of the agent tracer.
 String info()
          Returns the String with the service's short description.
 SortedMap list()
          Returns a copy of the internally used map which holds the (implicit name, contact address) correlations of the last update.
 String printTracedAgents()
          Returns the string representation of the stored (implicit name, contact address) correlations.
 void refresh()
          Initiates a contact address update for all agents in the agent tracer's watch list.
 void removeAgentFromWatchList(AgentCard card)
          Removes an agent from the agent tracer's watch list.
 void removeAgentFromWatchList(byte[] implicitName)
          Removes an agent from the agent tracer's watch list.
 String revision()
          Returns the revision number of this class as a string.
 void run()
          This method represents the functionality of the update daemon.
 void setUpdateTime(long updateTime)
          Sets the update interval of the agent tracer.
private  void stop()
          Stops the tracerThread_.
 String toString()
           
 
Methods inherited from class de.fhg.igd.semoa.service.AbstractService
checkDependencies, docs, doPrivileged, doPrivileged, getACC, getEnvironment, majorVersion, minorVersion
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DEPEND_

private static final String[] DEPEND_
The dependencies to other objects in the global Environment.


LOOKUP_ATTEMPTS

public final int LOOKUP_ATTEMPTS
The number of allowed unsuccessful lookups for an agent contact address, before the agent will be removed from the watch list.

See Also:
Constant Field Values

clientService_

protected LSClientService clientService_
The reference to a locally installed LSClientService which is used to lookup the agent's contact addresses.


eventReflector_

protected EventReflector eventReflector_
The event reflector which is notified, every time a refresh request has been executed successfully.


updateTime_

protected long updateTime_
Update time for the update daemon.


watchList_

protected SortedMap watchList_
Represents the watch list, which stores the implicit names of the agents and the number of unsuccessful lookups.


tracedAgents_

protected SortedMap tracedAgents_
The current contact addresses of all agents in the watch list are stored in this map. They are sorted over the corresponding implicit names.


tracerThread_

protected Thread tracerThread_
Thread that provides the functionality of the update daemon.


signals_

protected Signals signals_
Used for for signaling between database and tracerThread.


lock_

private Object lock_
The internal lock object used for the tracerThread_.


datalock_

private Object datalock_
The internal lock object used for synchronisation of watchList respectively tracedAgents_ modifications.

Constructor Detail

AgentTracerImpl

public AgentTracerImpl()
Creates a new instance of the agent tracer with the a update time of 1000ms for its update daemon.


AgentTracerImpl

public AgentTracerImpl(long updateTime)
Creates a new instance of the agent tracer with the given updateTime for its update daemon.

Parameters:
updateTime - The update time in milli seconds.
Method Detail

info

public String info()
Returns the String with the service's short description.

Specified by:
info in interface Service
Specified by:
info in class AbstractService
Returns:
The String with the service's short description.

author

public String author()
Returns the String with the author's name.

Specified by:
author in interface Service
Specified by:
author in class AbstractService
Returns:
The String with the author's name.

revision

public String revision()
Returns the revision number of this class as a string.

Specified by:
revision in class AbstractService
Returns:
The revision number of this class as a string.

dependencies

public String[] dependencies()
Returns the dependencies of this service as described in Service.

Specified by:
dependencies in interface Service
Overrides:
dependencies in class AbstractService
Returns:
The array of dependencies.

toString

public String toString()
Overrides:
toString in class AbstractService
Returns:
The string representation of this instance.

addAgentToWatchList

public void addAgentToWatchList(AgentCard card)
Adds an agent to the agent tracer's watch list. The agent identified by the given agentCard will be registered within the agent tracer and lookups will be initiated in certain update intervals to resolve its current contact address. If the contact address of an agent in the watch list could not be resolved for a certain number of update cycles, it is automatically removed from the list, again. Theadded to the watch list if not already

Specified by:
addAgentToWatchList in interface AgentTracer
Parameters:
card - The agent card of the agent.

addAgentToWatchList

public void addAgentToWatchList(byte[] implicitName)
Adds an agent to the agent tracer's watch list. The agent identified by the given implicitName will be registered within the agent tracer and lookups will be initiated in certain update intervals to resolve its current contact address. If the contact address of an agent in the watch list could not be resolved for a certain number of update cycles, it is automatically removed from the list, again. Theadded to the watch list if not already

Specified by:
addAgentToWatchList in interface AgentTracer

removeAgentFromWatchList

public void removeAgentFromWatchList(AgentCard card)
Removes an agent from the agent tracer's watch list. If the agent identified by the given agentCard can be found in the watch list, it is removed immediately.

Specified by:
removeAgentFromWatchList in interface AgentTracer

removeAgentFromWatchList

public void removeAgentFromWatchList(byte[] implicitName)
Removes an agent from the agent tracer's watch list. If the agent identified by the given implicitName can be found in the watch list, it is removed immediately.

Specified by:
removeAgentFromWatchList in interface AgentTracer
Parameters:
implicitName - The implicit name of the agent.

addListener

public TrustedListener addListener(Listener listener)
Adds a Listener. The Listener will receive events of the type String every time an update has been initiated by the agent tracer's update daemon respectively by a call of refresh. Listener instances passed to this method shall be wrapped in a TrustedListener which is then returned.

Specified by:
addListener in interface AgentTracer
Parameters:
listener - The Listener to be registered.
Returns:
The TrustedListener that wraps around the given Listener.
Throws:
NullPointerException - if listener is null.

list

public SortedMap list()
Returns a copy of the internally used map which holds the (implicit name, contact address) correlations of the last update. The entries of the type Map.Entry consist of the implicit name of the agent (byte[]) as key and the contact address (URL) as corresponding value. If the contact address of an agent could not be resolved the nth time, a URL of following format is returned:
error://unknown/n

Specified by:
list in interface AgentTracer
Returns:
The sorted map of (implicit name, contact address) correlations.

refresh

public void refresh()
Initiates a contact address update for all agents in the agent tracer's watch list. This method can be used to refresh the (implicit name, contact address) correlations, even if the update mechanism is deactivated.

Specified by:
refresh in interface AgentTracer

getUpdateTime

public long getUpdateTime()
Returns the update interval of the agent tracer.

Specified by:
getUpdateTime in interface AgentTracer
Returns:
The update time of the agent tracer or 0 if the update mechanism is deactivated.

setUpdateTime

public void setUpdateTime(long updateTime)
Sets the update interval of the agent tracer. The given value determines the interval in which the agent tracer updates the contact addresses of the agents in its watch list. An updateTime of 0 deactivates the update mechanism.

Specified by:
setUpdateTime in interface AgentTracer

run

public void run()
This method represents the functionality of the update daemon.

Specified by:
run in interface Runnable

stop

private void stop()
Stops the tracerThread_.


printTracedAgents

public String printTracedAgents()
Returns the string representation of the stored (implicit name, contact address) correlations.

Returns:
The string representation.


Copyright © Fraunhofer Gesellschaft. All Rights Reserved.