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

java.lang.Object
  extended by com.sun.hk2.component.AbstractInhabitantImpl<T>
      extended by com.sun.hk2.component.AbstractCreatorInhabitantImpl<T>
          extended by com.sun.hk2.component.SingletonInhabitant<T>
All Implemented Interfaces:
Holder<T>, Binding<T>, Factory<T>, ManagedComponentProvider<T>, Provider<T>, Releasable, Inhabitant<T>

public class SingletonInhabitant<T>
extends AbstractCreatorInhabitantImpl<T>

Specialized implementation of ScopedInhabitant for Singleton.

Author:
Kohsuke Kawaguchi

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.AbstractCreatorInhabitantImpl
creator
 
Fields inherited from class com.sun.hk2.component.AbstractInhabitantImpl
descriptor, logger
 
Constructor Summary
SingletonInhabitant(Creator<T> creator)
           
 
Method Summary
 T get(Inhabitant onBehalfOf)
          Returns the instance of this inhabitant.
 boolean isActive()
           
 void release()
          Called to orderly shutdown Habitat.
 
Methods inherited from class com.sun.hk2.component.AbstractCreatorInhabitantImpl
getCreator, metadata, type, typeName
 
Methods inherited from class com.sun.hk2.component.AbstractInhabitantImpl
companions, dispose, get, getAnnotation, getAnnotation, getAnnotations, getByType, getDescriptor, getDescriptorFor, getProvider, getProvider, getSerializedMetadata, getSerializedMetadata, lead, matches, setCompanions, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SingletonInhabitant

public SingletonInhabitant(Creator<T> creator)
Method Detail

get

public T get(Inhabitant onBehalfOf)
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 Habitat (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.


release

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

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.


isActive

public boolean isActive()


Copyright © 2012 Oracle Corporation. All Rights Reserved.