@Singleton
public class ManagedObjectsFinalizer
extends java.lang.Object
PreDestroy
methods on all registered objects, when the service locator is shut down.
Some objects managed by Jersey are created using ServiceLocator.createAndInitialize(java.lang.Class<U>)
. This means
that such objects are created, dependencies injected and methods annotated with PostConstruct
invoked. Therefore methods annotated with PreDestroy
should be invoked on such objects too, when they are destroyed.
This service invokes PreDestroy
on all registered objects when ServiceLocator.shutdown()
is invoked
on the service locator where this service is registered. Therefore only classes with their lifecycle linked
to the service locator that created them should be registered here.Modifier and Type | Field and Description |
---|---|
private java.util.Set<java.lang.Object> |
managedObjects |
private org.glassfish.hk2.api.ServiceLocator |
serviceLocator |
Constructor and Description |
---|
ManagedObjectsFinalizer() |
Modifier and Type | Method and Description |
---|---|
void |
preDestroy() |
void |
registerForPreDestroyCall(java.lang.Object object)
Register an object for invocation of its
PreDestroy method. |
@Inject private org.glassfish.hk2.api.ServiceLocator serviceLocator
private final java.util.Set<java.lang.Object> managedObjects
public void registerForPreDestroyCall(java.lang.Object object)
PreDestroy
method.
It will be invoked when the service locator is shut down.object
- an object to be registered.@PreDestroy public void preDestroy()