springs.context
Class Context

java.lang.Object
  |
  +--springs.context.Context
All Implemented Interfaces:
ConfigurationParameters, ContextInterfaceForAgents, Debug
Direct Known Subclasses:
Context_RMIImpl

public abstract class Context
extends java.lang.Object
implements ContextInterfaceForAgents, ConfigurationParameters

A context. An implementation should follow the singleton pattern: only a context is allowed in a given JVM.

Author:
Sergio Ilarri Artigas

Field Summary
protected  springs.access.AccessService _accessService
          A reference to the access service.
protected  springs.context.AgentInfos _agentInfos
          Information kept for the agents that execute in the context.
protected static springs.context.Context _context
          Singleton pattern.
protected  springs.context.ContextAddress _contextAddress
          The address of the context.
private  java.util.Hashtable _contexts
          Table with the contexts in the system, consisting of pairs .
private  java.io.BufferedWriter _logFile
          The log file.
private static int _PORT_FOR_CLASS_SERVER
           
static springs.context.ContextAddress CONTEXT_ADDRESS_REGION_NAME_SERVER
          The address of the Region Name Server.
static java.lang.String CONTEXT_LOG_FILENAME
          For logs.
static java.lang.String LOCALHOST
           
static java.lang.String LOCALHOST_IP
           
static boolean START_CLASS_SERVER
          Set it to true to enable the remote loading of classes.
 
Fields inherited from interface springs.common.ConfigurationParameters
_persistence, ACTIVATE_AUTOMATIC_REFERENCES_UPDATES, ACTIVATE_NAMING_SERVICE, AGENT_REFERENCES_UPDATER_NAME, BACKLOG, BLOCK_UNTIL_REFERENCE_UPDATED_IF_NEEDED, COLLECT_LOGS_CALLS, CONTEXT_MANAGER_NAME, CONTEXT_WATCHING_PERIOD, CRASH_WHEN_NOT_ENOUGH_MEMORY, CREATE_AGENTS_IN_BACKGROUND, DEFAULT_PORT_NUMBER_FOR_CONTEXTS, DELAY_DEPARTURES_IF_NEEDED, DISABLE_LOGGER, EXPORT_RETRIAL, FORCE_REMOVALS, HYBRID_STRATEGY_PROXY_UPDATE, INITIAL_SEPARATOR_URL, LAZY_UPDATE_AGENT_OBJECT, LEASE_VALUE, MAX_MILLIS_TO_WAIT_FOR_ARU, MAX_MILLIS_TO_WAIT_FOR_UPDATE_REFERENCE, MAX_TRIES_ASSIGNING_THREAD_TO_AGENT, MAXIMUM_NUMBER_OF_CONSECUTIVE_FAILED_PINGS, MILLIS_TO_KEEP_MARKED_TO_REMOVE_REFERENCES, MILLIS_TO_KEEP_UNUSED_LOCAL_REFERENCES, MILLIS_TO_WAIT_FOR_CLASS_SERVER_READY, MILLIS_TO_WAIT_FOR_RMI_REGISTRY_CREATION, MINIMUM_MILLIS_STAY_AT_CONTEXT, NUM_STAYS_TO_COMPUTE_AVERAGE_STAY, PERIOD_LARC, REBIND_RETRIAL, REGION_NAME_SERVER_NAME, RETRYING_STRATEGY_FOR_AGENT_SEARCHING, RETRYING_STRATEGY_FOR_CREATIONS, RETRYING_STRATEGY_FOR_INVOKATIONS, RETRYING_STRATEGY_FOR_REMOTE_REFERENCE_UPDATING, RETURN_CALL_RESULTS_WITH_STATISTICS, RMI_PROTOCOL, SECURITY_POLICY, TIME_BETWEEN_TRIES_ASSIGNING_THREAD_TO_AGENT, TIMEOUT_CONNECTION_RMI, TIMEOUT_RMI, TRACE_RMI_SERVERS, TRACKING_FACTOR, UPDATE_REFERENCES_IN_BACKGROUND, UPDATE_REFERENCES_WITH_AUXILIARY_THREAD, USE_CACHE_OF_CLASSES, USE_SOCKETS_COUNTING_BYTES, USE_SPECIFIC_SOCKET_FACTORY, WAIT_UNTIL_REFERENCES_UPDATED, WRITE_CONTEXT_LOGS_IN_STDOUT
 
Fields inherited from interface springs.common.Debug
DEBUG_ACCESS_SERVICE, DEBUG_BASIC, DEBUG_CLASS_LOADING, DEBUG_CONTEXT_MANAGER, DEBUG_CONTEXT_STATUS_WHEN_MEMORY_ERROR, DEBUG_CREATION, DEBUG_DELETING, DEBUG_NAMING_SERVICE, DEBUG_PROBLEMS_WITH_RMI_CLASS_LOADING, DEBUG_REFERENCE_UPDATER, DEBUG_REMOVAL, DEBUG_RMI, DEBUG_RMI_FAILURES, DEBUG_RNS, DEBUG_SEARCHING, DEBUG_SENDING, DEBUG_TIMES, LOG_CONTEXT_INFO, PRINT_EXCEPTION_FAILED_REMOTE_CALLS, PRINT_FAILED_MOVEMENTS, PRINT_FAILED_REMOTE_CALLS, PRINT_FAILED_REMOTE_REFERENCE_UPDATING, PRINT_FAILED_SEARCHINGS, PRINT_RETRYING_TASK_FAILURES, PROXY_QUEUE
 
Constructor Summary
Context()
           
 
Method Summary
 void addAgentInfo(springs.agent.SpringsAgent agent)
          Adds information about the given agent.
 void addContext(springs.context.ContextAddress context)
          Adds a context to the list of contexts in the system.
 void createAgent(java.lang.String targetContext, springs.agent.SpringsAgent agent, java.lang.String agentName)
          Creates an agent.
private  springs.access.AgentReference createAgentReference(springs.agent.SpringsAgent agent)
          Creates an agent reference.
protected  void ensureMinimumStayTime(java.lang.String agentName)
          Ensures that the agent will stay in the context at least the minimum amount of time required, delaying the call otherwise.
 springs.access.AccessService getAccessService()
          Gets a reference to the access service.
 springs.agent.SpringsAgent getAgent(java.lang.String agentName)
          Obtains the local agent.
 springs.context.ContextAddress getContextAddress()
          Gets the context address.
 springs.context.ContextAddress getContextAddress(java.lang.String contextName)
          Obtains the address of the given context.
abstract  springs.context.ContextManager getContextManager(springs.context.ContextAddress contextAddress)
          Obtains the context manager at a certain address.
 java.util.Collection getContexts()
          Returns the information about the contexts in the system.
 java.lang.String getContextStatus()
          Gets a string with information about the context.
 java.util.Vector getLocationServers(java.lang.String agentName)
           
protected  long getMillisStay(java.lang.String agentName)
          Gets the number of milliseconds that the given agent has stayed so far in the current context.
 java.lang.String getName()
          Obtains the name of the context.
 int getNumAgents()
          Gets the number of agents executing in the context.
 int getNumContexts()
          Returns the number of contexts in the system.
 int getNumLocationServers(java.lang.String agentName)
           
 int getNumObservers(java.lang.String agentName)
           
 int getNumTrackedAndObservedAgents()
          Obtains the number of tracked agents.
 java.util.Vector getObservers(java.lang.String agentName)
           
static int getPortClassServer()
          Gets the port for the class server.
 springs.access.AgentReference getReferenceToLocalAgent(java.lang.String agentName, boolean addAsObserver)
          Gets a reference to an agent that it is executing locally.
protected  java.lang.String getStringForReferenceUpdates(java.util.Vector referenceUpdates)
          Obtains a string with the reference updates.
static void initializeLocalIP()
          Initializes the local IP address.
protected static boolean isLocalContext(springs.context.ContextAddress addr)
          Checks if the given address refers to the local context.
 void logContextInfo()
          Logs information about contexts.
 void recordStartStay(java.lang.String agentName)
          Records the current as the time instant when the agent starts its stay in the current context.
 void referenceUsed(java.lang.String agentName)
          Notifies the context that a reference to the given agent has been used.
abstract  void releaseReference(java.lang.String agentName)
          Releases a reference to the given agent, so that it must not be automatically updated anymore
abstract  void removeAgent(springs.agent.SpringsAgent agent, boolean isMoving)
          Removes an agent.
 void removeAgentInfo(java.lang.String agentName, int seqNumber)
          Removes the information for the given agent.
 void removeContext(java.lang.String cn)
          Removes a context from the list of contexts in the system.
 void setContexts(java.util.Hashtable contexts)
          Records the information about the contexts in the system.
static void setPortClassServer(int port)
          Sets the port for the class server.
protected abstract  void start(java.lang.String addressRNS)
          Starts a context.
protected abstract  void start(java.lang.String addressRNS, int portClassServer)
          Starts a context.
 void stop()
          Stops the context.
abstract  void updateRemoteReferences(java.util.Hashtable contextsToReferences)
          Updates the remote references to local agents.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface springs.context.ContextInterfaceForAgents
callAgentMethod, callAgentMethod, callAgentMethod, callAgentMethod, callAgentMethodAsynchronously, callAgentMethodAsynchronously, callAgentMethodAsynchronously, callAgentMethodAsynchronously, checkpoint, createAgent, deleteAgent, isSuspended, moveAgent, sendAgent, sendAsynchronousMessage, sendMessage, sendMessage, suspend
 

Field Detail

CONTEXT_LOG_FILENAME

public static java.lang.String CONTEXT_LOG_FILENAME
For logs.


START_CLASS_SERVER

public static boolean START_CLASS_SERVER
Set it to true to enable the remote loading of classes.


_PORT_FOR_CLASS_SERVER

private static int _PORT_FOR_CLASS_SERVER

LOCALHOST

public static java.lang.String LOCALHOST

LOCALHOST_IP

public static java.lang.String LOCALHOST_IP

CONTEXT_ADDRESS_REGION_NAME_SERVER

public static springs.context.ContextAddress CONTEXT_ADDRESS_REGION_NAME_SERVER
The address of the Region Name Server.


_context

protected static springs.context.Context _context
Singleton pattern.

See Also:
Context

_agentInfos

protected springs.context.AgentInfos _agentInfos
Information kept for the agents that execute in the context.

See Also:
AgentInfos

_accessService

protected springs.access.AccessService _accessService
A reference to the access service.

See Also:
AccessService

_contextAddress

protected springs.context.ContextAddress _contextAddress
The address of the context.

See Also:
ContextAddress

_contexts

private java.util.Hashtable _contexts
Table with the contexts in the system, consisting of pairs .

See Also:
Hashtable

_logFile

private java.io.BufferedWriter _logFile
The log file.

See Also:
BufferedWriter
Constructor Detail

Context

public Context()
Method Detail

setPortClassServer

public static void setPortClassServer(int port)
Sets the port for the class server.

Parameters:
port - the port.

getPortClassServer

public static int getPortClassServer()
Gets the port for the class server.

Returns:
the port.

initializeLocalIP

public static void initializeLocalIP()
Initializes the local IP address.


getObservers

public java.util.Vector getObservers(java.lang.String agentName)

getNumObservers

public int getNumObservers(java.lang.String agentName)

getLocationServers

public java.util.Vector getLocationServers(java.lang.String agentName)

getNumLocationServers

public int getNumLocationServers(java.lang.String agentName)

logContextInfo

public void logContextInfo()
Logs information about contexts.


getContextStatus

public java.lang.String getContextStatus()
Gets a string with information about the context.

Returns:
a string with information about the context.
See Also:
String

addAgentInfo

public void addAgentInfo(springs.agent.SpringsAgent agent)
Adds information about the given agent.

Parameters:
agent - the agent name.
See Also:
SpringsAgent

recordStartStay

public void recordStartStay(java.lang.String agentName)
Records the current as the time instant when the agent starts its stay in the current context.

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

getMillisStay

protected long getMillisStay(java.lang.String agentName)
Gets the number of milliseconds that the given agent has stayed so far in the current context.

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

ensureMinimumStayTime

protected void ensureMinimumStayTime(java.lang.String agentName)
Ensures that the agent will stay in the context at least the minimum amount of time required, delaying the call otherwise.

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

removeAgentInfo

public void removeAgentInfo(java.lang.String agentName,
                            int seqNumber)
Removes the information for the given agent.

Parameters:
agentName - the name of the agent.
seqNumber - the sequence number for this delete.
See Also:
String

getAgent

public springs.agent.SpringsAgent getAgent(java.lang.String agentName)
Obtains the local agent.

Parameters:
agentName - the name of the agent.
Returns:
the agent.
See Also:
SpringsAgent

getNumTrackedAndObservedAgents

public int getNumTrackedAndObservedAgents()
Obtains the number of tracked agents.

Returns:
the number of tracked agents.

getNumAgents

public int getNumAgents()
Gets the number of agents executing in the context.

Returns:
the number of agents.

getReferenceToLocalAgent

public springs.access.AgentReference getReferenceToLocalAgent(java.lang.String agentName,
                                                              boolean addAsObserver)
Gets a reference to an agent that it is executing locally.

Parameters:
agentName - the name of the agent.
addAsObserver - a boolean indicating whether the requester should add itself as an observer.
Returns:
the reference; null if the agent is not executing locally anymore or has began to move.
Throws:
AgentReferenceException - if error.
See Also:
AgentReference, String, AgentReferenceException

createAgentReference

private springs.access.AgentReference createAgentReference(springs.agent.SpringsAgent agent)
Creates an agent reference.

Parameters:
agent - the agent.
Returns:
the reference.
See Also:
AgentReference, SpringsAgent

getNumContexts

public int getNumContexts()
Returns the number of contexts in the system.

Returns:
the number of contexts.

setContexts

public void setContexts(java.util.Hashtable contexts)
Records the information about the contexts in the system.

Parameters:
contexts - a table consisting of pairs .
See Also:
Hashtable

getContexts

public java.util.Collection getContexts()
Returns the information about the contexts in the system.

Returns:
the pairs .
See Also:
Collection

addContext

public void addContext(springs.context.ContextAddress context)
Adds a context to the list of contexts in the system.

Parameters:
context - the context.
See Also:
ContextAddress

removeContext

public void removeContext(java.lang.String cn)
Removes a context from the list of contexts in the system.

Parameters:
cn - the name of the context.
See Also:
String, RemoteException

getContextAddress

public springs.context.ContextAddress getContextAddress(java.lang.String contextName)
Obtains the address of the given context.

Returns:
the address, or null if unknown.
See Also:
ContextAddress, String

getName

public java.lang.String getName()
Obtains the name of the context.

Returns:
the name.
See Also:
String

getContextAddress

public springs.context.ContextAddress getContextAddress()
Gets the context address.

Specified by:
getContextAddress in interface ContextInterfaceForAgents
Returns:
the context address.
See Also:
ContextAddress

getAccessService

public springs.access.AccessService getAccessService()
Gets a reference to the access service.

Returns:
a reference to the access service.
See Also:
AccessService

isLocalContext

protected static boolean isLocalContext(springs.context.ContextAddress addr)
Checks if the given address refers to the local context.

Parameters:
addr - the address.
Returns:
a boolean indicating that.
See Also:
ContextAddress

referenceUsed

public void referenceUsed(java.lang.String agentName)
Notifies the context that a reference to the given agent has been used.

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

stop

public void stop()
          throws ContextStoppingException
Stops the context.

Throws:
ContextStoppingException - if the context cannot be stopped.
See Also:
ContextStoppingException

createAgent

public void createAgent(java.lang.String targetContext,
                        springs.agent.SpringsAgent agent,
                        java.lang.String agentName)
                 throws CreationException
Creates an agent.

Parameters:
targetContext - the name of the target context.
agent - the agent.
agentName - the name of the agent.
Throws:
CreationException - if error.
See Also:
CreationException

getContextManager

public abstract springs.context.ContextManager getContextManager(springs.context.ContextAddress contextAddress)
                                                          throws CommunicationException
Obtains the context manager at a certain address.

Parameters:
contextAddress - the context address.
Returns:
the context manager.
Throws:
CommunicationException - if error.
See Also:
ContextAddress, ContextManager, CommunicationException

start

protected abstract void start(java.lang.String addressRNS)
                       throws ContextStartingException
Starts a context.

Parameters:
addressRNS - the address of the Region Name Server. If any, pass null.
Throws:
ContextStartingException - if the context cannot be started.
See Also:
String, ContextStartingException

start

protected abstract void start(java.lang.String addressRNS,
                              int portClassServer)
                       throws ContextStartingException
Starts a context.

Parameters:
addressRNS - the address of the Region Name Server. If any, pass null.
portClassServer - the port where to launch the class server.
Throws:
ContextStartingException - if the context cannot be started.
See Also:
String, ContextStartingException

updateRemoteReferences

public abstract void updateRemoteReferences(java.util.Hashtable contextsToReferences)
                                     throws CommunicationException
Updates the remote references to local agents.

Parameters:
contextsToReferences - a table that maps from contexts to information about how to update the references.
Throws:
CommunicationException - if error.
See Also:
Hashtable, CommunicationException

releaseReference

public abstract void releaseReference(java.lang.String agentName)
                               throws ContextException
Releases a reference to the given agent, so that it must not be automatically updated anymore

Parameters:
agentName - the name of the agent.
Throws:
ContextException - if error.
See Also:
AgentReference, String, ContextException

removeAgent

public abstract void removeAgent(springs.agent.SpringsAgent agent,
                                 boolean isMoving)
                          throws RemovalException
Removes an agent.

Parameters:
agent - the agent.
isMoving - a boolean indicating if the agent is sent because of a movement from another context.
Throws:
throws - RemovalException if error.
RemovalException
See Also:
SpringsAgent, RemovalException

getStringForReferenceUpdates

protected java.lang.String getStringForReferenceUpdates(java.util.Vector referenceUpdates)
Obtains a string with the reference updates.

Parameters:
referenceUpdates - the updates.
Returns:
the string.
See Also:
String, Vector