Top Description Methods
org.glassfish.hk2.api

public Interface ServiceHandle<T>

extends Closeable
Type Parameters
<T>
The type of the service that can be returned
Imports
java.io.Closeable, java.util.List

This service handle can be used to get a specific instance of a service, and can be used to destroy that service as well
Author
jwells

Method Summary

Modifier and TypeMethod and Description
public default void
close()

Implements java.io.Closeable.close.

Will destroy this object and all PerLookup instances created because of this service

public default void
destroy()
Deprecated since 2.6. Use close instead

Will destroy this object and all PerLookup instances created because of this service

public ActiveDescriptor<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
getActiveDescriptor
()

Returns the ActiveDescriptor associated with this service handle

public T

Returns:

May return null (if the backing ActiveDescriptor returned null)
getService
()

Gets the underlying service object

public Object

Returns:

The service data for this service handle (may return null)
getServiceData
()

Service data can be set on a service handle.

public List<ServiceHandle<?>>

Returns:

A non-null but possibly empty list of subhandles subordinate to this root
getSubHandles
()

Returns a list of subordinate subhandles to this root handle

public boolean

Returns:

true if the underlying service has been created
isActive
()

This returns true if the underlying service has already been created

public void
setServiceData(Object
Sets the serviceData for the handle (may be null)
serviceData
)

Service data can be set on a service handle.

Method Detail

closeback to summary
public default void close()

Implements java.io.Closeable.close.

Will destroy this object and all PerLookup instances created because of this service

Annotations
@Override
destroyback to summary
public default void destroy()

Deprecated

since 2.6. Use close instead

Will destroy this object and all PerLookup instances created because of this service

Annotations
@Deprecated
getActiveDescriptorback to summary
public ActiveDescriptor<T> getActiveDescriptor()

Returns the ActiveDescriptor associated with this service handle

Returns:ActiveDescriptor<T>

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

getServiceback to summary
public T getService()

Gets the underlying service object

Returns:T

May return null (if the backing ActiveDescriptor returned null)

Exceptions
MultiException:
if there was an error creating the service
IllegalStateException:
if the handle was previously destroyed
getServiceDataback to summary
public Object getServiceData()

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

Returns:Object

The service data for this service handle (may return null)

getSubHandlesback to summary
public List<ServiceHandle<?>> getSubHandles()

Returns a list of subordinate subhandles to this root handle

Returns:List<ServiceHandle<?>>

A non-null but possibly empty list of subhandles subordinate to this root

isActiveback to summary
public boolean isActive()

This returns true if the underlying service has already been created

Returns:boolean

true if the underlying service has been created

setServiceDataback to summary
public void setServiceData(Object serviceData)

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

Parameters
serviceData:Object

Sets the serviceData for the handle (may be null)