|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.sun.hk2.component.AbstractInhabitantImpl<T>
com.sun.hk2.component.ScopedInhabitant<T>
public class ScopedInhabitant<T>
| Nested Class Summary |
|---|
| Nested classes/interfaces inherited from interface com.sun.hk2.component.Holder |
|---|
Holder.Impl<T> |
| Field Summary | |
|---|---|
protected Creator<T> |
creator
|
| Fields inherited from class com.sun.hk2.component.AbstractInhabitantImpl |
|---|
descriptor, logger |
| Constructor Summary | |
|---|---|
ScopedInhabitant(Creator<T> creator,
Scope scope)
|
|
| Method Summary | |
|---|---|
T |
get(Inhabitant onBehalfOf)
Returns the instance of this inhabitant. |
Scope |
getScope()
|
boolean |
isActive()
|
MultiMap<String,String> |
metadata()
Gets the metadata associated with this inhabitant. |
void |
release()
Called to orderly shutdown Habitat. |
Class<? extends T> |
type()
Type of the inhabitant. |
String |
typeName()
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, dispose, get, getAnnotation, getAnnotation, getAnnotations, 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 |
| Field Detail |
|---|
protected final Creator<T> creator
| Constructor Detail |
|---|
public ScopedInhabitant(Creator<T> creator,
Scope scope)
| Method Detail |
|---|
public Scope getScope()
public T get(Inhabitant onBehalfOf)
InhabitantTHIS 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.
public boolean isActive()
public void release()
InhabitantHabitat.
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.
public final String typeName()
Inhabitanttype().getName()
but this allows us to defer loading the actual types.
public final Class<? extends T> type()
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.
public MultiMap<String,String> metadata()
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 Habitat is properly initialized, even before
component classes are loaded. In contrast, accessing annotations would require
classes to be loaded and resolved.
Service.metadata()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||