de.fhg.igd.semoa.server
Class AgentContext

java.lang.Object
  extended byde.fhg.igd.semoa.server.AgentContext

public class AgentContext
extends Object

Is a placeholder of an agent. Instances of this class are used by the server to manage agents.

Version:
"$Id: AgentContext.java 1913 2007-08-08 02:41:53Z jpeters $"
Author:
Volker Roth, Ulrich Pinsdorf
See Also:
Lifecycle

Field Summary
private  Map fields_
          The private fields of this AgentContext.
private  Object lock_
          The lock object.
private static Logger log_
          The Logger instance for this class
private  int state_
          The state of the agent.
static String WHATIS
          The WhatIs entry key for this service.
 
Constructor Summary
AgentContext()
          Creates an instance.
AgentContext(Map map)
          Creates an instance that is backed by the given Map.
 
Method Summary
 void clearThreadLocals()
          Clears the annotations of the calling thread.
 Object doSynchronized(SyncedOperation op)
          Runs the given SyncedOperation in a synchronized block.
 Object get(FieldType field)
           
 void initThreadLocals()
          Annotates the current thread with the agent's thread local variables.
 void join()
          Waits until all threads of this agent have terminated.
 void load()
           
 void notifyListeners(String action)
          Sends out an AgentEvent with the given action.
 Object set(FieldType field, Object value)
          Sets the given field to the given value.
protected  Bootstrapper.Action sigterm(Bootstrapper bs, ErrorCode err)
           
 void start()
          Starts the agent.
 String toString()
          Prints basic information about the agent described by this context.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

log_

private static Logger log_
The Logger instance for this class


WHATIS

public static final String WHATIS
The WhatIs entry key for this service.

See Also:
Constant Field Values

fields_

private transient Map fields_
The private fields of this AgentContext. Fields are identified by FieldType instances.

See Also:
FieldType

lock_

private Object lock_
The lock object.


state_

private int state_
The state of the agent.

Constructor Detail

AgentContext

public AgentContext()
Creates an instance.


AgentContext

public AgentContext(Map map)
Creates an instance that is backed by the given Map.

Parameters:
map - The Map that is used to store the fields of this AgentContext.
Throws:
NullPointerException - if the argument is null.
Method Detail

set

public Object set(FieldType field,
                  Object value)
Sets the given field to the given value.

Parameters:
field - The FieldType of the field that is set to the given value.
value - The object that is set or null if the field shall be cleared. Be careful not to loose important objects by erroneously clearing a field. Weird errors could occur.
Returns:
The old value of the given field or null if the field wasn't initialized.
Throws:
NullPointerException - if the given field type is null.

get

public Object get(FieldType field)
Returns:
The value of the given field or null if the field is not initialized.
Throws:
NullPointerException - if the given field type is null.

doSynchronized

public Object doSynchronized(SyncedOperation op)
                      throws InvocationTargetException
Runs the given SyncedOperation in a synchronized block.

Parameters:
op - The SyncedOperation that is invoked.
Returns:
The result of the SyncedOperation.
Throws:
NullPointerException - if op is null.
InvocationTargetException - if the SyncedOperation threw an exception. The target exception is the exception that was thrown.

join

public void join()
Waits until all threads of this agent have terminated. This method can be invoked by at most one thread from the agent's thread group. Otherwise, a deadlock occurs. Threads from other thread groups can call it without risk.


load

public void load()
          throws IOException
Throws:
IOException

start

public void start()
           throws LifecycleException
Starts the agent. Most necessary objects will be created if the context is not already set up with them.

Throws:
LifecycleException - if the agent type is not supported by the installed lifecycles.

sigterm

protected Bootstrapper.Action sigterm(Bootstrapper bs,
                                      ErrorCode err)

initThreadLocals

public void initThreadLocals()
Annotates the current thread with the agent's thread local variables. This method should be called only by threads in the agent's thread group.


clearThreadLocals

public void clearThreadLocals()
Clears the annotations of the calling thread. This method should be called only by threads in the agent's thread group.


notifyListeners

public void notifyListeners(String action)
Sends out an AgentEvent with the given action.

Parameters:
action - The action string that identifies the event subtype.
Throws:
IllegalStateException - if the event dispatching failed e.g., because of a lack of permissions.

toString

public String toString()
Prints basic information about the agent described by this context.



Copyright © Fraunhofer Gesellschaft. All Rights Reserved.