com.sun.hk2.component
Class ExistingSingletonInhabitant<T>

java.lang.Object
  extended by org.glassfish.hk2.utilities.DescriptorImpl
      extended by com.sun.hk2.component.AbstractInhabitantImpl<T>
          extended by com.sun.hk2.component.ExistingSingletonInhabitant<T>
All Implemented Interfaces:
Holder<T>, Serializable, ActiveDescriptor<T>, Descriptor, SingleCache<T>, Binding<T>, Factory<T>, ManagedComponentProvider<T>, Provider<T>, Releasable, Inhabitant<T>

Deprecated.

@Deprecated
public class ExistingSingletonInhabitant<T>
extends AbstractInhabitantImpl<T>
implements ActiveDescriptor<T>

Inhabitant built around an object that already exists.

Author:
Kohsuke Kawaguchi
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from interface com.sun.hk2.component.Holder
Holder.Impl<T>
 
Field Summary
 
Fields inherited from class com.sun.hk2.component.AbstractInhabitantImpl
descriptor, logger
 
Constructor Summary
ExistingSingletonInhabitant(Class<T> type, T object)
          Deprecated.  
ExistingSingletonInhabitant(Class<T> type, T object, Map<String,List<String>> metadata)
          Deprecated.  
ExistingSingletonInhabitant(T object)
          Deprecated.  
 
Method Summary
 T create(ServiceHandle<?> root)
          Deprecated. Creates an instance of the ActiveDescriptor.
 void dispose(T instance)
          Deprecated. Disposes this instance.
 T get(Inhabitant onBehalfOf)
          Deprecated. Returns the instance of this inhabitant.
 T getCache()
          Deprecated. This can be used for scopes that will only every be created once.
 Set<Type> getContractTypes()
          Deprecated. The set of types that this ActiveDescriptor must produce.
 Long getFactoryLocatorId()
          Deprecated. If this ActiveDescriptor has DescriptorType of PROVIDE_METHOD then this field will return the ServiceId of its associated Factory service.
 Long getFactoryServiceId()
          Deprecated. If this ActiveDescriptor has DescriptorType of PROVIDE_METHOD then this field will return the ServiceId of its associated Factory service.
 Class<?> getImplementationClass()
          Deprecated. The implementation class that should be used to generate new instances of this descriptor.
 List<Injectee> getInjectees()
          Deprecated. Returns the full list of Injectees this class has.
 Set<Annotation> getQualifierAnnotations()
          Deprecated. The full set of qualifiers that this ActiveDescriptor provides
 Class<? extends Annotation> getScopeAnnotation()
          Deprecated. Returns the scope that this ActiveDescriptor belongs to
 boolean isActive()
          Deprecated. Returns true if the component has been instantiated.
 boolean isCacheSet()
          Deprecated. Returns true if this cache has been set
 boolean isReified()
          Deprecated. This method returns true if this descriptor has been reified (class loaded).
 Map<String,List<String>> metadata()
          Deprecated. Gets the metadata associated with this inhabitant.
 void release()
          Deprecated. Called to orderly shutdown ServiceLocator.
 void releaseCache()
          Deprecated. Removes the cached value and makes it such that this cache has not been set
 void setCache(T cacheMe)
          Deprecated. Sets the value into the cache
 String toString()
          Deprecated.  
 Class<T> type()
          Deprecated. Type of the inhabitant.
 String typeName()
          Deprecated. The short-cut for type().getName() but this allows us to defer loading the actual types.
 
Methods inherited from class com.sun.hk2.component.AbstractInhabitantImpl
companions, get, getAnnotation, getAnnotation, getAnnotations, getByType, getDescriptor, getDescriptorFor, getProvider, getProvider, getSerializedMetadata, getSerializedMetadata, lead, matches, setCompanions
 
Methods inherited from class org.glassfish.hk2.utilities.DescriptorImpl
addAdvertisedContract, addMetadata, addQualifier, equals, getAdvertisedContracts, getBaseDescriptor, getDescriptorType, getImplementation, getLoader, getLocatorId, getMetadata, getName, getQualifiers, getRanking, getScope, getServiceId, hashCode, pretty, readObject, removeAdvertisedContract, removeAllMetadata, removeMetadata, removeQualifier, setBaseDescriptor, setDescriptorType, setImplementation, setLoader, setLocatorId, setName, setRanking, setScope, setServiceId, writeObject
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.glassfish.hk2.api.Descriptor
getAdvertisedContracts, getBaseDescriptor, getDescriptorType, getImplementation, getLoader, getLocatorId, getMetadata, getName, getQualifiers, getRanking, getScope, getServiceId, setRanking
 

Constructor Detail

ExistingSingletonInhabitant

public ExistingSingletonInhabitant(T object)
Deprecated. 

ExistingSingletonInhabitant

public ExistingSingletonInhabitant(Class<T> type,
                                   T object)
Deprecated. 

ExistingSingletonInhabitant

public ExistingSingletonInhabitant(Class<T> type,
                                   T object,
                                   Map<String,List<String>> metadata)
Deprecated. 
Method Detail

toString

public String toString()
Deprecated. 
Overrides:
toString in class AbstractInhabitantImpl<T>

typeName

public String typeName()
Deprecated. 
Description copied from interface: Inhabitant
The short-cut for type().getName() but this allows us to defer loading the actual types.

Specified by:
typeName in interface Inhabitant<T>

type

public Class<T> type()
Deprecated. 
Description copied from interface: Inhabitant
Type of the inhabitant.

The only binding contract that needs to be honored is that the Inhabitant.get() method returns an instance assignable to this type. That is, get().getClass()==type() doesn't necessarily have to hold, but type().isInstance(get()) must.

This is particularly true when Factory is involved, as in such case HK2 has no way of knowing the actual type. That said, this method is not designed for the semantics of contract/implementation split --- implementations of a contract should return the concrete type from this method, and use habitat index to support look-up by contract.

Specified by:
type in interface Provider<T>
Specified by:
type in interface Inhabitant<T>
Returns:
Always non-null, same value.

metadata

public Map<String,List<String>> metadata()
Deprecated. 
Description copied from interface: Inhabitant
Gets the metadata associated with this inhabitant.

This data is usually used by a sub-system of HK2, and not really meant to be used by applications. (At least for now.) The main benefit of metadata is that it's available right away as soon as the ServiceLocator is properly initialized, even before component classes are loaded. In contrast, accessing annotations would require classes to be loaded and resolved.

Specified by:
metadata in interface Inhabitant<T>
Returns:
can be empty but never null. The values are read-only.
See Also:
Service.metadata()

get

public T get(Inhabitant onBehalfOf)
      throws ComponentException
Deprecated. 
Description copied from interface: Inhabitant
Returns the instance of this inhabitant.

THIS METHOD SHOULD BE ONLY USED BY HK2 IMPLEMENTATION.

Inhabitants are often used with the decorator pattern (see AbstractCreatorInhabitantImpl for example), yet during the object initializtion inside the Inhabitant.get() method, we often need the reference to the outer-most Inhabitant registered to the ServiceLocator (for example so that we can request the injection of {link Inhabita} that represents itself, or to inject companions.)

So this overloaded version of the get method takes the outer-most Inhabitant. This method is only invoked from within HK2 where the decorator pattern is used.

Specified by:
get in interface Inhabitant<T>
Throws:
ComponentException

isActive

public boolean isActive()
Deprecated. 
Description copied from interface: Provider
Returns true if the component has been instantiated.

Specified by:
isActive in interface Provider<T>
Returns:
true if the component is active.

release

public void release()
Deprecated. 
Description copied from interface: Inhabitant
Called to orderly shutdown ServiceLocator.

The expected behavior is for objects to get its PreDestroy callback invoked, and its reference released. For singleton objects, this method is expected to dispose that object.

For scoped objects, those are released when ScopeInstance.release() is invoked.

Specified by:
release in interface Releasable
Specified by:
release in interface Inhabitant<T>

getCache

public T getCache()
Deprecated. 
Description copied from interface: SingleCache
This can be used for scopes that will only every be created once. The returned value must have been set previously with setCache. If this is called when isCacheSet is false will result in a RuntimeException

Specified by:
getCache in interface SingleCache<T>
Returns:
A value cached with this ActiveDescriptor

isCacheSet

public boolean isCacheSet()
Deprecated. 
Description copied from interface: SingleCache
Returns true if this cache has been set

Specified by:
isCacheSet in interface SingleCache<T>
Returns:
true if there is a currently cached value, false otherwise

setCache

public void setCache(T cacheMe)
Deprecated. 
Description copied from interface: SingleCache
Sets the value into the cache

Specified by:
setCache in interface SingleCache<T>
Parameters:
cacheMe - A single value that can be cached in this active descriptor

releaseCache

public void releaseCache()
Deprecated. 
Description copied from interface: SingleCache
Removes the cached value and makes it such that this cache has not been set

Specified by:
releaseCache in interface SingleCache<T>

isReified

public boolean isReified()
Deprecated. 
Description copied from interface: ActiveDescriptor
This method returns true if this descriptor has been reified (class loaded). If this method returns false then the other methods in this interface will throw an IllegalStateException. Once this method returns true it may be

Specified by:
isReified in interface ActiveDescriptor<T>
Returns:
true if this descriptor has been reified, false otherwise

getImplementationClass

public Class<?> getImplementationClass()
Deprecated. 
Description copied from interface: ActiveDescriptor
The implementation class that should be used to generate new instances of this descriptor.

If the class returned is a Factory, then the factory is used to create instances. In this case the system will get an instance of the factory and use it to create the instances

Specified by:
getImplementationClass in interface ActiveDescriptor<T>
Returns:
The class that directly implements the contract types, or the class that is the factory for an object that implements the contract types

getContractTypes

public Set<Type> getContractTypes()
Deprecated. 
Description copied from interface: ActiveDescriptor
The set of types that this ActiveDescriptor must produce. These types may be Classes or ParameterizedTypes, and may be no other subclass of Type

Specified by:
getContractTypes in interface ActiveDescriptor<T>
Returns:
the set of types this ActiveDescriptor must implement or extend

getScopeAnnotation

public Class<? extends Annotation> getScopeAnnotation()
Deprecated. 
Description copied from interface: ActiveDescriptor
Returns the scope that this ActiveDescriptor belongs to

Specified by:
getScopeAnnotation in interface ActiveDescriptor<T>
Returns:
The scope of this ActiveDescriptor

getQualifierAnnotations

public Set<Annotation> getQualifierAnnotations()
Deprecated. 
Description copied from interface: ActiveDescriptor
The full set of qualifiers that this ActiveDescriptor provides

Specified by:
getQualifierAnnotations in interface ActiveDescriptor<T>
Returns:
The set of annotations that this ActiveDescriptor provides

getFactoryServiceId

public Long getFactoryServiceId()
Deprecated. 
Description copied from interface: ActiveDescriptor
If this ActiveDescriptor has DescriptorType of PROVIDE_METHOD then this field will return the ServiceId of its associated Factory service. Otherwise this method should return null

Specified by:
getFactoryServiceId in interface ActiveDescriptor<T>
Returns:
The service ID of the associated factory service

getFactoryLocatorId

public Long getFactoryLocatorId()
Deprecated. 
Description copied from interface: ActiveDescriptor
If this ActiveDescriptor has DescriptorType of PROVIDE_METHOD then this field will return the ServiceId of its associated Factory service. Otherwise this method should return null

Specified by:
getFactoryLocatorId in interface ActiveDescriptor<T>
Returns:
The locator ID of the associated factory service

getInjectees

public List<Injectee> getInjectees()
Deprecated. 
Description copied from interface: ActiveDescriptor
Returns the full list of Injectees this class has. These references will be resolved prior to the class being constructed, even if these injectees are field or method injectees.

If this descriptor is describing a factory created type then this list must have zero length

Specified by:
getInjectees in interface ActiveDescriptor<T>
Returns:
Will not return null, but may return an empty list. The set of Injectees that must be resolved before this ActiveDescriptor can be constructed

create

public T create(ServiceHandle<?> root)
Deprecated. 
Description copied from interface: ActiveDescriptor
Creates an instance of the ActiveDescriptor. All of the Injectee's must be created prior to instantiation, and associated with the ExtendedProvider so that they can be destroyed properly

Specified by:
create in interface ActiveDescriptor<T>
Parameters:
root - The root service handle, which can be used to associated all the PerLookup objects with this creation
Returns:
An instance of this ActiveDescriptor

dispose

public void dispose(T instance)
Deprecated. 
Description copied from interface: ActiveDescriptor
Disposes this instance. All the PerLookup objects that were created for this instance will be destroyed after this object has been destroyed

Specified by:
dispose in interface ActiveDescriptor<T>
Overrides:
dispose in class AbstractInhabitantImpl<T>
Parameters:
instance - The instance to destroy


Copyright © 2013 Oracle Corporation. All Rights Reserved.