|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object cz.cuni.amis.pogamut.base.factory.guice.AbstractGuiceAgentFactory cz.cuni.amis.pogamut.base.factory.guice.GuiceAgentFactory<AGENT,PARAMS>
AGENT
- PARAMS
- public class GuiceAgentFactory<AGENT extends IAgent,PARAMS extends IAgentParameters>
Guice-based IAgent
factory that instantiates the agent according to the bindigs that are found inside
the GuiceAgentModule
, which is provided during the construction.
Additionally to the classic Injector.getInstance(Class)
method, the class offers a place where to
slip runtime dependencies. I.e., if you are unable to specify some dependencies during class coding, you need
to create Provider
s for the runtime dependency (such as desired IAgentId
for the IAgent
).
These dependencies are injected into the module via the method configureModule(IAgentParameters)
that is called before the new instance is created.
Additionally, the factory method newAgent(IAgentParameters)
clears the agent scope
that is defined by the GuiceAgentModule
.
NOTE: if you are going to extend the implementation, than the only place that should suffice you for hacking is
configureModule(IAgentParameters)
where you slip runtime dependencies that the base GuiceAgentFactory
is unaware of, taking these dependencies from your custom IAgentParameters
implementation.
NOTE: you might not need to override the configureModule(IAgentParameters)
as the
module configuration might be also done inside GuiceAgentModule.prepareNewAgent(IAgentParameters)
which
is implicitly called from the configureModule(IAgentParameters)
.
THREAD-SAFE
Constructor Summary | |
---|---|
GuiceAgentFactory(GuiceAgentModule module)
Creates a Guice-based factory that will use Injector created using the 'module'. |
Method Summary | |
---|---|
protected void |
configureModule(PARAMS agentParameters)
Called from within the newAgent(IAgentParameters) to configure the AbstractGuiceAgentFactory.getAgentModule()
with variables from 'agentParams'. |
AGENT |
newAgent(PARAMS agentParameters)
Creates a new instance of the IAgent interface that is cast to AGENT parameter. |
Methods inherited from class cz.cuni.amis.pogamut.base.factory.guice.AbstractGuiceAgentFactory |
---|
getAgentModule, getInjector, setAgentModule |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public GuiceAgentFactory(GuiceAgentModule module)
Injector
created using the 'module'.
The module MUST specify bindings for the IAgent
interface as that is what's going to be
instantiated using the injector from AbstractGuiceAgentFactory.getInjector()
.
module
- module that configures bindings between classes, may be null (specify module later using AbstractGuiceAgentFactory.setAgentModule(GuiceAgentModule)
)Method Detail |
---|
protected void configureModule(PARAMS agentParameters)
newAgent(IAgentParameters)
to configure the AbstractGuiceAgentFactory.getAgentModule()
with variables from 'agentParams'.
Just calls GuiceAgentModule.prepareNewAgent(IAgentParameters)
.
NOTE: You will probably need to override this method in subclasses. If you do - do not forget to call super.configureModule(agentParameters) first! So other runtime-dependencies can be set too.
agentParameters
- public AGENT newAgent(PARAMS agentParameters) throws PogamutException
IAgent
interface that is cast to AGENT parameter.
Firstly, it calls configureModule(IAgentParameters)
to configure run-time
dependencies of the module and prepare it for the new agent instance, secondly,
it instantiates a new IAgent
instance.
NOTE: that the GuiceAgentFactory
must be correctly instantiated, i.e.,
the module passed into the constructor must bind IAgent
interface to the
AGENT (or descendant) class, otherwise you may experience ClassCastException
.
newAgent
in interface IAgentFactory<AGENT extends IAgent,PARAMS extends IAgentParameters>
agentParameters
-
PogamutException
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |