org.curjent.example.agent.factory
Class Agents
java.lang.Object
org.curjent.example.agent.factory.Agents
public class Agents
- extends Object
Example application factory methods.
Shows a pattern for creating and initializing agents for a specific
application. Among other things, most applications centralize initialization
to ensure unhandled agent exceptions are logged by default as appropriate to
each application.
This example factory is specific to curjent's agent examples. It shows a best
practice for agents: providing a handler for unhandled exceptions. Because
most agent calls run asynchronously on a background thread, there is nothing
but the curjent library to catch unexpected exceptions. Agent designers
almost always provide a handler to at least log the exception in debug and
test environments.
For the example applications, the agent factory initializes all agents to
print unhandled exceptions to the console using the example Logger agent. A
factory for your application may, for example, initialize agents to log
exceptions using log4j. Individual agent factories, such as the one for the
hello world example, can customize the agent further as needed.
The await method waits for an agent to finish processing calls. The example
programs wait for its agents to finish processing calls before exiting.
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
UNHANDLED_EXCEPTION_HANDLER
private static final ExceptionHandler UNHANDLED_EXCEPTION_HANDLER
Agents
public Agents()
newInstance
public static <T> T newInstance(Class<T> intrface,
Object task)
newInstance
public static <T> T newInstance(Class<T> intrface,
AgentTasks tasks)
initialize
private static void initialize(Object agent)
await
public static void await(Object... agents)
Copyright 2009-2011 Tom Landon
Apache License 2.0