springs.access
Class LocalAgentReferences

java.lang.Object
  |
  +--springs.access.LocalAgentReferences

public class LocalAgentReferences
extends java.lang.Object

Stores local references to agents.

Author:
Sergio Ilarri Artigas

Field Summary
private  java.util.Hashtable _agentReferences
           
private  java.util.Hashtable _timesToDelete
           
 
Constructor Summary
LocalAgentReferences()
          Constructor.
 
Method Summary
 springs.access.AgentReference getReference(java.lang.String agentName)
          Obtains a reference to an agent, null if any reference is available.
 int releaseAndRemoveOldReferences()
          Release local references that are out-of-date and references that have been marked to be removed.
 void removeReference(java.lang.String agentName)
          Removes a reference to an agent.
 springs.access.AgentReference removeReferenceImmediately(java.lang.String agentName)
          Removes a reference immediately, without waiting for possible later updates.
 int size()
          Obtains the number of references.
 void updateReference(springs.access.AgentReference newReference)
          Updates the given reference.
 void updateReferenceImmediately(springs.agent.SpringsAgent agent, java.lang.String localContextName)
          Updates a reference immediately.
 void updateTimeToDelete(java.lang.String agentName, long millisToKeep)
          Updates the time to delete the local reference to a certain agent, by considering that the reference has been used again just now.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_timesToDelete

private java.util.Hashtable _timesToDelete

_agentReferences

private java.util.Hashtable _agentReferences
Constructor Detail

LocalAgentReferences

public LocalAgentReferences()
Constructor.

Method Detail

updateReference

public void updateReference(springs.access.AgentReference newReference)
Updates the given reference.

Parameters:
newReference - the agent reference.
See Also:
AgentReference

getReference

public springs.access.AgentReference getReference(java.lang.String agentName)
Obtains a reference to an agent, null if any reference is available.

Parameters:
agentName - the name of the agent.
Returns:
a reference.
See Also:
AgentReference

removeReference

public void removeReference(java.lang.String agentName)
Removes a reference to an agent. Instead of removing it immediately, the reference is marked as removable and used now. So it will be removed next time references are cleaned (we assume that it won't be used in the meanwhile!). This will avoid conflicts in case a delayed previous update of the reference to the agent arrives in the meantime.

Parameters:
agentName - the name of the agent.
See Also:
String

removeReferenceImmediately

public springs.access.AgentReference removeReferenceImmediately(java.lang.String agentName)
Removes a reference immediately, without waiting for possible later updates.

Parameters:
agentName - the name of the agent.
Returns:
the agent reference.
See Also:
AgentReference, String

updateReferenceImmediately

public void updateReferenceImmediately(springs.agent.SpringsAgent agent,
                                       java.lang.String localContextName)
Updates a reference immediately.

Parameters:
agent - the agent.
localContextName - the local context name.
See Also:
SpringsAgent, String

updateTimeToDelete

public void updateTimeToDelete(java.lang.String agentName,
                               long millisToKeep)
Updates the time to delete the local reference to a certain agent, by considering that the reference has been used again just now.

Parameters:
agentName - the name of the agent.
millisToKeep - the number of milliseconds to keep the reference.
See Also:
String

releaseAndRemoveOldReferences

public int releaseAndRemoveOldReferences()
                                  throws ContextException
Release local references that are out-of-date and references that have been marked to be removed.

Returns:
the number of released references.
Throws:
ContextException - if there is a context exception.
See Also:
ContextException

size

public int size()
Obtains the number of references.

Returns:
the number of references.