public class HandlerContainerImpl extends Object implements HandlerContainer
HandlerContainer
. Inherit from this class if
you want subclasses that can contain handlers.
Classes inheriting from HandlerContainerImpl
and that participate in dependency
injection with Guice/GIN can use the automatic binding mechanism. See
HandlerContainerImpl()
and HandlerContainerImpl(boolean)
for more details.Constructor and Description |
---|
HandlerContainerImpl()
Creates a handler container class with automatic binding, unless
AutobindDisable is used to globally disable automatic
binding. |
HandlerContainerImpl(boolean autoBind)
Creates a handler container class with or without automatic binding.
|
Modifier and Type | Method and Description |
---|---|
void |
bind()
Call this method after the object is constructed in order to bind all its
handlers.
|
boolean |
isBound()
Returns true if the
HandlerContainer is currently bound. |
protected void |
onBind()
Lifecycle method called when binding the object.
|
protected void |
onUnbind()
Lifecycle method called when unbinding the object.
|
protected void |
registerHandler(HandlerRegistration handlerRegistration)
Registers a handler so that it is automatically removed when
unbind() is called. |
void |
unbind()
Call this method when you want to release the object and its handlers are
not needed anymore.
|
@Inject public HandlerContainerImpl()
AutobindDisable
is used to globally disable automatic
binding.
Autobinding requires the class to be instantiated by Guice/GIN.
If you are instantiating HandlerContainerImpl
with new
,
autobinding will not work. It is recommended you document it by
using #HandlerContainerImpl(boolean) with false
as a parameter.public HandlerContainerImpl(boolean autoBind)
bind()
method will be called
automatically after the class is instantiated through Guice/GIN dependency
injection mechanism, unless AutobindDisable
is used to globally
disable automatic binding. Otherwise, the user is responsible for calling
bind()
.
Autobinding requires the class to be instantiated by Guice/GIN.
If you are instantiating HandlerContainerImpl
with new
,
autobinding will not work. It is recommended you document it by
passing false
to the autoBind
parameter.autoBind
- true
to request automatic binding, false
otherwise.HandlerContainerImpl()
public void bind()
HandlerContainer
HandlerContainer.bind()
from the constructor
of a non-leaf class since it is meant to be called after the object has
been entirely constructed.
When automatic binding is used (see HandlerContainerImpl
), this will
be called immediately after the object is constructed through Guice/GIN dependency
injection mechanism.
If you are not using automatic binding, or if you later call
HandlerContainer.unbind()
on this object, you will have to call HandlerContainer.bind()
manually.
Multiple call to bind will not fail, the class will be bound once.bind
in interface HandlerContainer
public final boolean isBound()
HandlerContainer
HandlerContainer
is currently bound.
That is, the HandlerContainer.bind()
method has completed and HandlerContainer.unbind()
has not
been called.isBound
in interface HandlerContainer
true
if bound, false
otherwise.public void unbind()
HandlerContainer
HandlerContainer.bind()
again manually
if you ever want to reuse the object.unbind
in interface HandlerContainer
protected void onBind()
onBind()
. Also, do
not call directly, call bind()
instead.
Any event handler should be
initialised here rather than in the constructor. Also, it is good practice to
perform any costly initialisation here.
Handlers registered by calling
registerHandler(HandlerRegistration)
will be removed
when unbinding. Any other initialisation that takes place here (or as a
side-effect of what is done here) should be taken down in onUnbind()
.
This method will never be invoked more then once, or if it is, the second
time will necessarily be preceded by an invocation of onUnbind()
.protected void onUnbind()
onUnbind()
.
Also, do not call directly, call unbind()
instead.
Any handler registration recorded with (HandlerRegistration)
will have
already been removed at this point. You should override this method to
take down any other initialisation that took place in onBind()
.
This method will never be invoked more then once, or if it is, the second
time will necessarily be preceded by an invocation of onBind()
.protected void registerHandler(HandlerRegistration handlerRegistration)
unbind()
is called. This provides an easy way to track event
handler registrations.handlerRegistration
- The registration of handler to track.Copyright © 2010–2014 Arcbees. All rights reserved.