org.actorsguildframework
Class DefaultAgent

java.lang.Object
  extended by org.actorsguildframework.DefaultAgent
All Implemented Interfaces:
Agent

public class DefaultAgent
extends Object
implements Agent

DefaultAgent is an implementation of the Agent interface.


Nested Class Summary
static class DefaultAgent.Configuration
          Represents a configuration for an Agent.
 
Constructor Summary
DefaultAgent()
          Creates a new agent with a default configuration.
DefaultAgent(DefaultAgent.Configuration configuration)
          Creates a new agent with the given Configuration.
 
Method Summary
 void awaitAll(AsyncResult... asyncResults)
          Waits until all given AsyncResults are available.
 void awaitAllUntilError(AsyncResult... asyncResults)
          Waits until all given AsyncResults are available, and throws the WrappedException of the first AsyncResult that failed, if one failed.
 AsyncResult awaitAny(AsyncResult... asyncResults)
          Waits until one of the given AsyncResults is available.
<T> T
create(Class<T> actorOrBeanClass)
          Creates a new instance of the given Bean or Actor.
<T> T
create(Class<T> actorOrBeanClass, Props props)
          Creates a new instance of the given Bean or Actor and sets its properties.
 void shutdown()
          Tries to shut down the agent with all its threads.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultAgent

public DefaultAgent(DefaultAgent.Configuration configuration)
Creates a new agent with the given Configuration. Use create(Class) to add actors to the agent.

Parameters:
configuration - the configuration to use

DefaultAgent

public DefaultAgent()
Creates a new agent with a default configuration. Use create(Class) to add actors to the agent.

Method Detail

create

public <T> T create(Class<T> actorOrBeanClass)
Description copied from interface: Agent
Creates a new instance of the given Bean or Actor. Create supports the following annotations:
  1. Bean
  2. Prop
  3. DefaultValue

Specified by:
create in interface Agent
Type Parameters:
T - the type of the class to create
Parameters:
actorOrBeanClass - the class to create
Returns:
the new instance

create

public <T> T create(Class<T> actorOrBeanClass,
                    Props props)
Description copied from interface: Agent
Creates a new instance of the given Bean or Actor and sets its properties. Create supports the following annotations:
  1. Bean
  2. Prop
  3. DefaultValue
The second argument allows specifying values for the instance's properties. The value of the Props must be compatible with the class of the property. If the property is a primitive (like int), specify the wrapper type (Number sub-classes, for example Integer). create also supports type conversion for all numeric type, as well as between Character and Integer. For those properties that are not given, the method will take the defined DefaultValue, if specified, or the type's default value (null for references, 0 for number primitives, false for boolean).

Specified by:
create in interface Agent
Type Parameters:
T - the type of the class to create
Parameters:
actorOrBeanClass - the class to create
props - the values for the instance's properties. Null for no initial properties.
Returns:
the new instance

awaitAll

public void awaitAll(AsyncResult... asyncResults)
Description copied from interface: Agent
Waits until all given AsyncResults are available. awaitAll can be invoked from all threads, including those that do not process a message.

Specified by:
awaitAll in interface Agent
Parameters:
asyncResults - the list of AsyncResult instances to wait for
See Also:
Agent.awaitAllUntilError(AsyncResult...), Agent.awaitAny(AsyncResult...)

awaitAllUntilError

public void awaitAllUntilError(AsyncResult... asyncResults)
Description copied from interface: Agent
Waits until all given AsyncResults are available, and throws the WrappedException of the first AsyncResult that failed, if one failed. awaitAll can be invoked from all threads, including those that do not process a message.

Specified by:
awaitAllUntilError in interface Agent
Parameters:
asyncResults - the list of AsyncResult instances to wait for
See Also:
Agent.awaitAll(AsyncResult...)

awaitAny

public AsyncResult awaitAny(AsyncResult... asyncResults)
Description copied from interface: Agent
Waits until one of the given AsyncResults is available. awaitAny can be invoked from all threads, including those that do not process a message.

Specified by:
awaitAny in interface Agent
Parameters:
asyncResults - the list of AsyncResult instances to wait for
Returns:
the AsyncResult that is ready, null for empty lists
See Also:
Agent.awaitAll(AsyncResult...)

shutdown

public void shutdown()
Description copied from interface: Agent
Tries to shut down the agent with all its threads. Messages that have not been processed yet will not be processed.

This call is useful if you want to terminate your Java application. Without it, the Agent's non-daemon threads may keep the application from terminating. A safer alternative to shutdown may be calling System.exit(int), as there is no guarantee that shutdown can terminate all threads.

A agent and its actors must not be used after calling this method. The behaviour would be undefined.

Specified by:
shutdown in interface Agent