|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.jvnet.hk2.component.Habitat
public class Habitat
A set of templates that constitute a world of objects.
| Nested Class Summary | |
|---|---|
protected static interface |
Habitat.NotifyCall
|
| Field Summary | |
|---|---|
java.lang.String |
DEFAULT_NAME
Name to use to programmatically store default instances of a particular service. |
static java.lang.String |
HK2_CONCURRENCY_CONTROLS
System property tag for concurrency controls (i.e., true for multi threaded injection, inhabitant activation, etc.) |
static boolean |
MANAGED_INJECTION_POINTS_ENABLED
|
org.glassfish.hk2.ScopeInstance |
singletonScope
|
| Constructor Summary | |
|---|---|
Habitat()
|
|
| Method Summary | ||
|---|---|---|
void |
add(Inhabitant<?> i)
Adds a new inhabitant. |
|
|
addComponent(T component)
Add an already instantiated component to this manager. |
|
void |
addHabitatListener(HabitatListener listener)
Add a habitat listener with no contract-level filtering. |
|
protected void |
addHabitatListener(HabitatListener listener,
java.util.Set<java.lang.String> typeNames)
|
|
void |
addHabitatListener(HabitatListener listener,
java.lang.String... typeNames)
Add a habitat listener with contract-level filtering. |
|
void |
addIndex(Inhabitant<?> i,
java.lang.String index,
java.lang.String name)
Adds a new index to look up the given inhabitant. |
|
protected void |
addIndex(Inhabitant<?> i,
java.lang.String index,
java.lang.String name,
boolean notify)
|
|
org.glassfish.hk2.DynamicBinderFactory |
bindDynamically()
|
|
|
byType(java.lang.Class<U> type)
|
|
org.glassfish.hk2.ServiceLocator<?> |
byType(java.lang.String typeName)
|
|
|
forContract(java.lang.Class<U> contract)
|
|
org.glassfish.hk2.ContractLocator<?> |
forContract(java.lang.String contractName)
|
|
|
forContract(org.glassfish.hk2.TypeLiteral<U> typeLiteral)
|
|
|
getAllByContract(java.lang.Class<T> contractType)
Gets all the inhabitants registered under the given Contract. |
|
|
getAllByContract(java.lang.String contractType)
|
|
|
getAllByType(java.lang.Class<T> implType)
Gets the object of the given type. |
|
java.util.Iterator<java.lang.String> |
getAllContracts()
|
|
java.util.Collection<Inhabitant<?>> |
getAllInhabitantsByContract(java.lang.String contractType)
|
|
|
getAllInhabitantsByType(java.lang.Class<T> implType)
Gets all matching inhabitants given the type. |
|
java.util.Iterator<java.lang.String> |
getAllTypes()
|
|
java.util.Collection<org.glassfish.hk2.Binding<?>> |
getBindings()
|
|
java.util.Collection<org.glassfish.hk2.Binding<?>> |
getBindings(org.glassfish.hk2.Descriptor descriptor)
|
|
|
getByContract(java.lang.Class<T> contractType)
Gets the object that has the given contract. |
|
|
getByType(java.lang.Class<T> implType)
Gets the object of the given type. |
|
|
getByType(java.lang.String implType)
Gets the object of the given type. |
|
|
getComponent(java.lang.Class<T> clazz)
Obtains a reference to the component inside the manager. |
|
|
getComponent(java.lang.Class<T> contract,
java.lang.String name)
Loads a component that implements the given contract and has the given name. |
|
|
getComponent(java.lang.String fullQualifiedName,
java.lang.String name)
Analogous to the following: |
|
java.util.Collection<org.glassfish.hk2.Binding<?>> |
getDeclaredBindings()
|
|
java.util.Collection<org.glassfish.hk2.Binding<?>> |
getDeclaredBindings(org.glassfish.hk2.Descriptor descriptor)
|
|
org.glassfish.hk2.Services |
getDefault()
|
|
|
getInhabitant(java.lang.Class<T> contract,
java.lang.String name)
Gets a lazy reference to the component. |
|
|
getInhabitant(java.lang.reflect.Type type,
java.lang.String name)
|
|
Inhabitant<?> |
getInhabitantByAnnotation(java.lang.Class<? extends java.lang.annotation.Annotation> contract,
java.lang.String name)
Gets the inhabitant that has the given contract annotation and the given name. |
|
Inhabitant<?> |
getInhabitantByContract(java.lang.String typeName)
Get the first inhabitant by contract |
|
Inhabitant |
getInhabitantByContract(java.lang.String fullyQualifiedName,
java.lang.String name)
|
|
|
getInhabitantByType(java.lang.Class<T> implType)
Gets a lazy reference to the component. |
|
Inhabitant<?> |
getInhabitantByType(java.lang.String fullyQualifiedClassName)
|
|
|
getInhabitantByType(java.lang.reflect.Type implType)
|
|
|
getInhabitants(java.lang.Class<T> contract)
Gets all the inhabitants that has the given contract. |
|
|
getInhabitants(java.lang.Class<T> contract,
java.lang.String name)
Gets all the inhabitants that has the given contract and the given name This method defers the actual instantiation of the component until Inhabitant.get() is invoked. |
|
java.lang.Iterable<Inhabitant<?>> |
getInhabitantsByAnnotation(java.lang.Class<? extends java.lang.annotation.Annotation> contract,
java.lang.String name)
Gets all the inhabitants that has the given contract annotation and the given name. |
|
java.util.Collection<Inhabitant<?>> |
getInhabitantsByContract(java.lang.String fullyQualifiedClassName)
|
|
|
getInhabitantsByType(java.lang.Class<T> implType)
Gets all the inhabitants that has the given implementation type. |
|
java.util.Collection<Inhabitant<?>> |
getInhabitantsByType(java.lang.String fullyQualifiedClassName)
Gets all the inhabitants that has the given implementation type name. |
|
protected static java.lang.Long |
getServiceRanking(Inhabitant<?> i,
boolean wantNonNull)
|
|
org.glassfish.hk2.Services |
getServices(java.lang.String moduleName)
|
|
void |
initialized()
FOR INTERNAL USE ONLY |
|
|
inject(java.lang.Class<T> type)
Instantiate the passed type and injects all the Inject
annotated fields and methods |
|
|
inject(T object)
|
|
boolean |
isContextualFactoriesPresent()
FOR INTERNAL USE |
|
static boolean |
isContextualFactoriesPresentAnywhere()
FOR INTERNAL USE |
|
boolean |
isContract(java.lang.Class<?> type)
Checks if the given type is a contract interface that has some implementations in this Habitat. |
|
boolean |
isContract(java.lang.String fullyQualifiedClassName)
|
|
boolean |
isContract(java.lang.reflect.Type type)
|
|
boolean |
isInitialized()
|
|
protected boolean |
matches(Inhabitant<?> inhabitant,
java.lang.Object serviceOrInhabitant)
|
|
protected void |
notify(Habitat.NotifyCall innerCall,
Inhabitant<?> inhabitant,
HabitatListener.EventType event,
java.lang.String index,
Inhabitant<HabitatListener> extraListenerToBeNotified)
|
|
protected void |
notify(Inhabitant<?> inhabitant,
HabitatListener.EventType event,
java.lang.String index,
Inhabitant<HabitatListener> extraListenerToBeNotified)
|
|
protected void |
notify(Inhabitant<?> inhabitant,
HabitatListener.EventType event,
java.lang.String index,
java.lang.String name,
java.lang.Object service,
Inhabitant<HabitatListener> extraListenerToBeNotified)
|
|
void |
notifyInhabitantChanged(Inhabitant<?> inhabitant,
java.lang.String... contracts)
Trigger a notification that an inhabitant has changed. |
|
void |
release()
Releases all the components. |
|
boolean |
remove(Inhabitant<?> inhabitant)
Removes an inhabitant |
|
boolean |
removeAllByType(java.lang.Class<?> type)
Removes all inhabitants for a particular type |
|
boolean |
removeHabitatListener(HabitatListener listener)
Remove a habitat listener. |
|
boolean |
removeIndex(java.lang.String index,
java.lang.Object serviceOrInhabitant)
Removes a Contracted service |
|
boolean |
removeIndex(java.lang.String index,
java.lang.String name)
Removes a NamedInhabitant for a specific contract |
|
protected java.lang.Object |
service(java.lang.Object serviceOrInhabitant)
|
|
InhabitantTracker |
track(InhabitantTrackerContext itc,
InhabitantTracker.Callback callback)
Registers a dependency on the inhabitant with the given tracker context. |
|
java.util.concurrent.Future<InhabitantTracker> |
trackFuture(InhabitantTrackerContext itc)
Returns a future that can be checked asynchronously, and multiple times. |
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public final java.lang.String DEFAULT_NAME
public static final java.lang.String HK2_CONCURRENCY_CONTROLS
public final org.glassfish.hk2.ScopeInstance singletonScope
public static final boolean MANAGED_INJECTION_POINTS_ENABLED
| Constructor Detail |
|---|
public Habitat()
| Method Detail |
|---|
public org.glassfish.hk2.Services getDefault()
getDefault in interface org.glassfish.hk2.Servicespublic org.glassfish.hk2.Services getServices(java.lang.String moduleName)
getServices in interface org.glassfish.hk2.Servicespublic java.util.Collection<org.glassfish.hk2.Binding<?>> getDeclaredBindings()
getDeclaredBindings in interface org.glassfish.hk2.Servicespublic java.util.Collection<org.glassfish.hk2.Binding<?>> getDeclaredBindings(org.glassfish.hk2.Descriptor descriptor)
getDeclaredBindings in interface org.glassfish.hk2.Servicespublic java.util.Collection<org.glassfish.hk2.Binding<?>> getBindings()
getBindings in interface org.glassfish.hk2.Servicespublic java.util.Collection<org.glassfish.hk2.Binding<?>> getBindings(org.glassfish.hk2.Descriptor descriptor)
getBindings in interface org.glassfish.hk2.Servicespublic org.glassfish.hk2.DynamicBinderFactory bindDynamically()
bindDynamically in interface org.glassfish.hk2.Servicespublic <U> org.glassfish.hk2.ContractLocator<U> forContract(java.lang.Class<U> contract)
forContract in interface org.glassfish.hk2.Locatorpublic org.glassfish.hk2.ContractLocator<?> forContract(java.lang.String contractName)
forContract in interface org.glassfish.hk2.Locatorpublic <U> org.glassfish.hk2.ContractLocator<U> forContract(org.glassfish.hk2.TypeLiteral<U> typeLiteral)
forContract in interface org.glassfish.hk2.Locatorpublic <U> org.glassfish.hk2.ServiceLocator<U> byType(java.lang.Class<U> type)
byType in interface org.glassfish.hk2.Locatorpublic org.glassfish.hk2.ServiceLocator<?> byType(java.lang.String typeName)
byType in interface org.glassfish.hk2.Locatorpublic void addHabitatListener(HabitatListener listener)
listener - The habitat Listener to be added#addHabitatListener(HabitatListener, String...)} is
recommended for most cases
public void addHabitatListener(HabitatListener listener,
java.lang.String... typeNames)
listener - The habitat Listener to be addedtypeNames - The contracts to filter on; this should be non-null
protected void addHabitatListener(HabitatListener listener,
java.util.Set<java.lang.String> typeNames)
public boolean removeHabitatListener(HabitatListener listener)
listener - The habitat Listener to be removed
public InhabitantTracker track(InhabitantTrackerContext itc,
InhabitantTracker.Callback callback)
throws ComponentException
itc - The tracking criteria.callback - Optionally the callback.
ComponentException
public java.util.concurrent.Future<InhabitantTracker> trackFuture(InhabitantTrackerContext itc)
throws ComponentException
itc - The tracking criteria.
ComponentExceptionpublic boolean removeAllByType(java.lang.Class<?> type)
type - of the component
public void add(Inhabitant<?> i)
Inhabitants for typical ways to create Inhabitants.
public void addIndex(Inhabitant<?> i,
java.lang.String index,
java.lang.String name)
index - Primary index name, such as contract FQCN.name - Name that identifies the inhabitant among other inhabitants in
the same index. Can be null for unnamed inhabitants.
protected void addIndex(Inhabitant<?> i,
java.lang.String index,
java.lang.String name,
boolean notify)
protected static java.lang.Long getServiceRanking(Inhabitant<?> i,
boolean wantNonNull)
public boolean remove(Inhabitant<?> inhabitant)
inhabitant - inhabitant to be removed
public boolean removeIndex(java.lang.String index,
java.lang.String name)
index - contract namename - instance name
public boolean removeIndex(java.lang.String index,
java.lang.Object serviceOrInhabitant)
index - the contract nameserviceOrInhabitant - the service instance, or an Inhabitant instance
protected boolean matches(Inhabitant<?> inhabitant,
java.lang.Object serviceOrInhabitant)
protected java.lang.Object service(java.lang.Object serviceOrInhabitant)
public void notifyInhabitantChanged(Inhabitant<?> inhabitant,
java.lang.String... contracts)
inhabitant - the inhabitant that has changedcontracts - the contracts associated with the inhabitantpublic void initialized()
public boolean isInitialized()
public static boolean isContextualFactoriesPresentAnywhere()
public boolean isContextualFactoriesPresent()
protected void notify(Inhabitant<?> inhabitant,
HabitatListener.EventType event,
java.lang.String index,
Inhabitant<HabitatListener> extraListenerToBeNotified)
protected void notify(Inhabitant<?> inhabitant,
HabitatListener.EventType event,
java.lang.String index,
java.lang.String name,
java.lang.Object service,
Inhabitant<HabitatListener> extraListenerToBeNotified)
protected void notify(Habitat.NotifyCall innerCall,
Inhabitant<?> inhabitant,
HabitatListener.EventType event,
java.lang.String index,
Inhabitant<HabitatListener> extraListenerToBeNotified)
public boolean isContract(java.lang.Class<?> type)
Habitat.
There are two ways for a type to be marked as a contract. Either it has
Contract, or it's marked by ContractProvided from the
implementation.
Note that just having Contract is not enough to make this method
return true. It can still return false if the contract has no
implementation in this habitat.
This method is useful during the injection to determine what lookup to
perform, and it handles the case correctly when the type is marked as a
contract by ContractProvided.
public boolean isContract(java.lang.reflect.Type type)
public boolean isContract(java.lang.String fullyQualifiedClassName)
public <T> java.util.Collection<T> getAllByContract(java.lang.Class<T> contractType)
Contract.
This is an example of heterogeneous type-safe container.
public <T> java.util.Collection<T> getAllByContract(java.lang.String contractType)
public java.util.Collection<Inhabitant<?>> getAllInhabitantsByContract(java.lang.String contractType)
public <T> java.util.Collection<T> getAllByType(java.lang.Class<T> implType)
public <T> java.util.Collection<Inhabitant> getAllInhabitantsByType(java.lang.Class<T> implType)
public <T> void addComponent(T component)
throws ComponentException
component - component instance
ComponentException - if the passed object is not an HK2 component or
injection/extraction failed.
public <T> T getComponent(java.lang.Class<T> clazz)
throws ComponentException
Scope of the component, a new instance might be
created, or an existing instance might be returned.
ComponentException - If failed to obtain a requested instance. In practice,
failure only happens when we try to create a new instance of
the component.
public <T> T getComponent(java.lang.Class<T> contract,
java.lang.String name)
throws ComponentException
SimpleServiceLocator
getComponent in interface SimpleServiceLocatorname - can be null, in which case it'll only match to the unnamed
component.
ComponentException
public <T> T getComponent(java.lang.String fullQualifiedName,
java.lang.String name)
SimpleServiceLocatorgetComponent(contractClass.getName(), name);
getComponent in interface SimpleServiceLocatorfullQualifiedName - the contract class namename - can be null, in which case it'll only match to the unnamed
component.
public <T> Inhabitant<T> getInhabitant(java.lang.Class<T> contract,
java.lang.String name)
throws ComponentException
Inhabitant.get() is invoked.
ComponentException
public <T> Inhabitant<T> getInhabitant(java.lang.reflect.Type type,
java.lang.String name)
public <T> Inhabitant<T> getInhabitantByType(java.lang.Class<T> implType)
Inhabitant.get() is invoked.
public <T> Inhabitant<T> getInhabitantByType(java.lang.reflect.Type implType)
public Inhabitant<?> getInhabitantByType(java.lang.String fullyQualifiedClassName)
public Inhabitant<?> getInhabitantByAnnotation(java.lang.Class<? extends java.lang.annotation.Annotation> contract,
java.lang.String name)
throws ComponentException
Inhabitant.get() is invoked.
ComponentException
public <T> java.util.Collection<Inhabitant<? extends T>> getInhabitants(java.lang.Class<T> contract)
throws ComponentException
ComponentExceptionpublic <T> T inject(T object)
inject in interface org.glassfish.hk2.inject.Injectorpublic <T> T inject(java.lang.Class<T> type)
Inject
annotated fields and methods
inject in interface org.glassfish.hk2.inject.InjectorT - type of the requested instancetype - class of the requested instance
public <T> java.util.Collection<Inhabitant<T>> getInhabitantsByType(java.lang.Class<T> implType)
throws ComponentException
ComponentExceptionpublic java.util.Collection<Inhabitant<?>> getInhabitantsByType(java.lang.String fullyQualifiedClassName)
public Inhabitant<?> getInhabitantByContract(java.lang.String typeName)
typeName - fullyQualifiedClassName
public java.util.Collection<Inhabitant<?>> getInhabitantsByContract(java.lang.String fullyQualifiedClassName)
public java.util.Iterator<java.lang.String> getAllContracts()
public java.util.Iterator<java.lang.String> getAllTypes()
public Inhabitant getInhabitantByContract(java.lang.String fullyQualifiedName,
java.lang.String name)
public <T> java.lang.Iterable<Inhabitant<? extends T>> getInhabitants(java.lang.Class<T> contract,
java.lang.String name)
throws ComponentException
Inhabitant.get() is invoked.
ComponentException
public java.lang.Iterable<Inhabitant<?>> getInhabitantsByAnnotation(java.lang.Class<? extends java.lang.annotation.Annotation> contract,
java.lang.String name)
throws ComponentException
Inhabitant.get() is invoked.
ComponentExceptionpublic <T> T getByType(java.lang.Class<T> implType)
SimpleServiceLocator
getByType in interface SimpleServiceLocatorpublic <T> T getByType(java.lang.String implType)
SimpleServiceLocator
getByType in interface SimpleServiceLocatorpublic <T> T getByContract(java.lang.Class<T> contractType)
public void release()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||