Package org.jvnet.hk2.internal
Class ServiceHandleImpl<T>
- java.lang.Object
-
- org.jvnet.hk2.internal.ServiceHandleImpl<T>
-
- Type Parameters:
T
- The type of service to create
- All Implemented Interfaces:
ServiceHandle<T>
public class ServiceHandleImpl<T> extends java.lang.Object implements ServiceHandle<T>
This handle does the underlying work of getting the service. Only at the time that the getService call is made is the service gotten from the context. Once a service has been gotten, it is not looked up again.
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.LinkedList<Injectee>
injectees
private ServiceLocatorImpl
locator
private java.lang.Object
lock
private ActiveDescriptor<T>
root
private T
service
private java.lang.Object
serviceData
private boolean
serviceDestroyed
private boolean
serviceSet
private java.util.LinkedList<ServiceHandleImpl<?>>
subHandles
-
Constructor Summary
Constructors Constructor Description ServiceHandleImpl(ServiceLocatorImpl locator, ActiveDescriptor<T> root, Injectee injectee)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addSubHandle(ServiceHandleImpl<?> subHandle)
Add a sub handle to this for proper destructionvoid
destroy()
Will destroy this object and all PerLookup instances created because of this serviceActiveDescriptor<T>
getActiveDescriptor()
Returns the ActiveDescriptor associated with this service handleprivate Injectee
getLastInjectee()
Injectee
getOriginalRequest()
T
getService()
Gets the underlying service object(package private) T
getService(ServiceHandle<T> handle)
java.lang.Object
getServiceData()
Service data can be set on a service handle.java.util.List<ServiceHandle<?>>
getSubHandles()
Returns a list of subordinate subhandles to this root handleboolean
isActive()
This returns true if the underlying service has already been createdvoid
popInjectee()
void
pushInjectee(Injectee push)
void
setServiceData(java.lang.Object serviceData)
Service data can be set on a service handle.java.lang.String
toString()
-
-
-
Field Detail
-
root
private ActiveDescriptor<T> root
-
locator
private final ServiceLocatorImpl locator
-
injectees
private final java.util.LinkedList<Injectee> injectees
-
lock
private final java.lang.Object lock
-
serviceDestroyed
private boolean serviceDestroyed
-
serviceSet
private boolean serviceSet
-
service
private T service
-
serviceData
private java.lang.Object serviceData
-
subHandles
private final java.util.LinkedList<ServiceHandleImpl<?>> subHandles
-
-
Constructor Detail
-
ServiceHandleImpl
ServiceHandleImpl(ServiceLocatorImpl locator, ActiveDescriptor<T> root, Injectee injectee)
-
-
Method Detail
-
getService
public T getService()
Description copied from interface:ServiceHandle
Gets the underlying service object- Specified by:
getService
in interfaceServiceHandle<T>
- Returns:
- May return null (if the backing ActiveDescriptor returned null)
-
getLastInjectee
private Injectee getLastInjectee()
-
getService
T getService(ServiceHandle<T> handle)
-
getActiveDescriptor
public ActiveDescriptor<T> getActiveDescriptor()
Description copied from interface:ServiceHandle
Returns the ActiveDescriptor associated with this service handle- Specified by:
getActiveDescriptor
in interfaceServiceHandle<T>
- Returns:
- The ActiveDescriptor associated with this handle. Can return null in cases where the Handle describes a service not associated with an hk2 service, such as a constant service
-
isActive
public boolean isActive()
Description copied from interface:ServiceHandle
This returns true if the underlying service has already been created- Specified by:
isActive
in interfaceServiceHandle<T>
- Returns:
- true if the underlying service has been created
-
destroy
public void destroy()
Description copied from interface:ServiceHandle
Will destroy this object and all PerLookup instances created because of this service- Specified by:
destroy
in interfaceServiceHandle<T>
-
setServiceData
public void setServiceData(java.lang.Object serviceData)
Description copied from interface:ServiceHandle
Service data can be set on a service handle. If the service data is set prior to the services associated Context has created an instance then this service data can be used to influence the context's creation of the service. The service data is associated with a handle, not with the service itself- Specified by:
setServiceData
in interfaceServiceHandle<T>
- Parameters:
serviceData
- Sets the serviceData for the handle (may be null)
-
getServiceData
public java.lang.Object getServiceData()
Description copied from interface:ServiceHandle
Service data can be set on a service handle. If the service data is set prior to the services associated Context has created an instance then this service data can be used to influence the context's creation of the service. The service data is associated with a handle, not with the service itself- Specified by:
getServiceData
in interfaceServiceHandle<T>
- Returns:
- The service data for this service handle (may return null)
-
getSubHandles
public java.util.List<ServiceHandle<?>> getSubHandles()
Description copied from interface:ServiceHandle
Returns a list of subordinate subhandles to this root handle- Specified by:
getSubHandles
in interfaceServiceHandle<T>
- Returns:
- A non-null but possibly empty list of subhandles subordinate to this root
-
pushInjectee
public void pushInjectee(Injectee push)
-
popInjectee
public void popInjectee()
-
addSubHandle
public void addSubHandle(ServiceHandleImpl<?> subHandle)
Add a sub handle to this for proper destruction- Parameters:
subHandle
- A handle to add for proper destruction
-
getOriginalRequest
public Injectee getOriginalRequest()
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-