|
||||||||||
| 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 | |
|---|---|
String |
DEFAULT_NAME
Name to use to programmatically store default instances of a particular service. |
static 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
|
ScopeInstance |
singletonScope
|
| Constructor Summary | |
|---|---|
Habitat()
|
|
Habitat(Services parent,
String name)
|
|
| 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,
Set<String> typeNames)
|
|
void |
addHabitatListener(HabitatListener listener,
String... typeNames)
Add a habitat listener with contract-level filtering. |
|
void |
addIndex(Inhabitant<?> i,
String index,
String name)
Adds a new index to look up the given inhabitant. |
|
protected void |
addIndex(Inhabitant<?> i,
String index,
String name,
boolean notify)
|
|
DynamicBinderFactory |
bindDynamically()
|
|
|
byType(Class<U> type)
|
|
ServiceLocator<?> |
byType(String typeName)
|
|
|
forContract(Class<U> contract)
|
|
ContractLocator<?> |
forContract(String contractName)
|
|
|
forContract(TypeLiteral<U> typeLiteral)
|
|
|
getAllByContract(Class<T> contractType)
Gets all the inhabitants registered under the given Contract. |
|
|
getAllByContract(String contractType)
|
|
|
getAllByType(Class<T> implType)
Gets the object of the given type. |
|
Iterator<String> |
getAllContracts()
|
|
Iterator<String> |
getAllTypes()
|
|
Collection<Binding<?>> |
getBindings()
|
|
Collection<Binding<?>> |
getBindings(Descriptor descriptor)
|
|
|
getByContract(Class<T> contractType)
Gets the object that has the given contract. |
|
|
getByType(Class<T> implType)
Gets the object of the given type. |
|
|
getByType(String implType)
Gets the object of the given type. |
|
|
getComponent(Class<T> clazz)
Obtains a reference to the component inside the manager. |
|
|
getComponent(Class<T> contract,
String name)
Loads a component that implements the given contract and has the given name. |
|
|
getComponent(String fullQualifiedName,
String name)
Analogous to the following: |
|
Collection<Binding<?>> |
getDeclaredBindings()
|
|
Collection<Binding<?>> |
getDeclaredBindings(Descriptor descriptor)
|
|
Services |
getDefault()
|
|
|
getInhabitant(Class<T> contract,
String name)
Gets a lazy reference to the component. |
|
|
getInhabitant(Type type,
String name)
|
|
Inhabitant<?> |
getInhabitantByAnnotation(Class<? extends Annotation> contract,
String name)
Gets the inhabitant that has the given contract annotation and the given name. |
|
Inhabitant<?> |
getInhabitantByContract(String typeName)
Get the first inhabitant by contract |
|
Inhabitant |
getInhabitantByContract(String fullyQualifiedName,
String name)
|
|
|
getInhabitantByType(Class<T> implType)
Gets a lazy reference to the component. |
|
Inhabitant<?> |
getInhabitantByType(String fullyQualifiedClassName)
|
|
|
getInhabitantByType(Type implType)
|
|
|
getInhabitants(Class<T> type)
Gets all the inhabitants for a spcial contract. |
|
|
getInhabitants(Class<T> contract,
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. |
|
Iterable<Inhabitant<?>> |
getInhabitantsByAnnotation(Class<? extends Annotation> contract,
String name)
Gets all the inhabitants that has the given contract annotation and the given name. |
|
Collection<Inhabitant<?>> |
getInhabitantsByContract(String fullyQualifiedClassName)
|
|
|
getInhabitantsByContract(Type contract)
Gets all the inhabitants that has the given contract. |
|
|
getInhabitantsByType(Class<T> implType)
Gets all the inhabitants that has the given implementation type. |
|
Collection<Inhabitant<?>> |
getInhabitantsByType(String fullyQualifiedClassName)
Gets all the inhabitants that has the given implementation type name. |
|
|
getProvider(String fullQualifiedName,
String name)
|
|
|
getProvider(Type type,
String name)
Gets an inhabitant from its type and optionally name |
|
protected static Long |
getServiceRanking(Inhabitant<?> i,
boolean wantNonNull)
|
|
Services |
getServices(String moduleName)
|
|
void |
initialized()
FOR INTERNAL USE ONLY |
|
|
inject(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(Class<?> type)
Checks if the given type is a contract interface that has some implementations in this Habitat. |
|
boolean |
isContract(String fullyQualifiedClassName)
|
|
boolean |
isContract(Type type)
|
|
boolean |
isContractExt(Type type)
A weaker test than isContract(Type). |
|
boolean |
isInitialized()
|
|
protected boolean |
matches(Inhabitant<?> inhabitant,
Object serviceOrInhabitant)
|
|
protected void |
notify(Habitat.NotifyCall innerCall,
Inhabitant<?> inhabitant,
HabitatListener.EventType event,
String index,
Inhabitant<HabitatListener> extraListenerToBeNotified)
|
|
protected void |
notify(Inhabitant<?> inhabitant,
HabitatListener.EventType event,
String index,
Inhabitant<HabitatListener> extraListenerToBeNotified)
|
|
protected void |
notify(Inhabitant<?> inhabitant,
HabitatListener.EventType event,
String index,
String name,
Object service,
Inhabitant<HabitatListener> extraListenerToBeNotified)
|
|
void |
notifyInhabitantChanged(Inhabitant<?> inhabitant,
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(Class<?> type)
Removes all inhabitants for a particular type |
|
boolean |
removeHabitatListener(HabitatListener listener)
Remove a habitat listener. |
|
boolean |
removeIndex(String index,
Object serviceOrInhabitant)
Removes a Contracted service |
|
boolean |
removeIndex(String index,
String name)
Removes a NamedInhabitant for a specific contract |
|
protected Object |
service(Object serviceOrInhabitant)
|
|
InhabitantTracker |
track(InhabitantTrackerContext itc,
InhabitantTracker.Callback callback)
Registers a dependency on the inhabitant with the given tracker context. |
|
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 String DEFAULT_NAME
public static final String HK2_CONCURRENCY_CONTROLS
public final ScopeInstance singletonScope
public static final boolean MANAGED_INJECTION_POINTS_ENABLED
| Constructor Detail |
|---|
public Habitat()
public Habitat(Services parent,
String name)
| Method Detail |
|---|
public Services getDefault()
getDefault in interface Servicespublic Services getServices(String moduleName)
getServices in interface Servicespublic Collection<Binding<?>> getDeclaredBindings()
getDeclaredBindings in interface Servicespublic Collection<Binding<?>> getDeclaredBindings(Descriptor descriptor)
getDeclaredBindings in interface Servicespublic Collection<Binding<?>> getBindings()
getBindings in interface Servicespublic Collection<Binding<?>> getBindings(Descriptor descriptor)
getBindings in interface Servicespublic DynamicBinderFactory bindDynamically()
bindDynamically in interface Servicespublic <U> ContractLocator<U> forContract(Class<U> contract)
forContract in interface Locatorpublic ContractLocator<?> forContract(String contractName)
forContract in interface Locatorpublic <U> ContractLocator<U> forContract(TypeLiteral<U> typeLiteral)
forContract in interface Locatorpublic <U> ServiceLocator<U> byType(Class<U> type)
byType in interface Locatorpublic ServiceLocator<?> byType(String typeName)
byType in interface 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,
String... typeNames)
listener - The habitat Listener to be addedtypeNames - The contracts to filter on; this should be non-null
protected void addHabitatListener(HabitatListener listener,
Set<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 Future<InhabitantTracker> trackFuture(InhabitantTrackerContext itc)
throws ComponentException
itc - The tracking criteria.
ComponentExceptionpublic boolean removeAllByType(Class<?> type)
type - of the component
public void add(Inhabitant<?> i)
Inhabitants for typical ways to create Inhabitants.
public void addIndex(Inhabitant<?> i,
String index,
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,
String index,
String name,
boolean notify)
protected static Long getServiceRanking(Inhabitant<?> i,
boolean wantNonNull)
public boolean remove(Inhabitant<?> inhabitant)
inhabitant - inhabitant to be removed
public boolean removeIndex(String index,
String name)
index - contract namename - instance name
public boolean removeIndex(String index,
Object serviceOrInhabitant)
index - the contract nameserviceOrInhabitant - the service instance, or an Inhabitant instance
protected boolean matches(Inhabitant<?> inhabitant,
Object serviceOrInhabitant)
protected Object service(Object serviceOrInhabitant)
public void notifyInhabitantChanged(Inhabitant<?> inhabitant,
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,
String index,
Inhabitant<HabitatListener> extraListenerToBeNotified)
protected void notify(Inhabitant<?> inhabitant,
HabitatListener.EventType event,
String index,
String name,
Object service,
Inhabitant<HabitatListener> extraListenerToBeNotified)
protected void notify(Habitat.NotifyCall innerCall,
Inhabitant<?> inhabitant,
HabitatListener.EventType event,
String index,
Inhabitant<HabitatListener> extraListenerToBeNotified)
public boolean isContract(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(Type type)
public boolean isContract(String fullyQualifiedClassName)
public boolean isContractExt(Type type)
isContract(Type).
This will return true if either the type argument
is annotated with Contract or if the
isContract(Type) returns true.
public <T> Collection<T> getAllByContract(Class<T> contractType)
Contract.
This is an example of heterogeneous type-safe container.
public <T> Collection<T> getAllByContract(String contractType)
public <T> Collection<T> getAllByType(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(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(Class<T> contract,
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> Inhabitant<T> getProvider(String fullQualifiedName,
String name)
getProvider in interface SimpleServiceLocator
public <T> T getComponent(String fullQualifiedName,
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(Class<T> contract,
String name)
throws ComponentException
Inhabitant.get() is invoked.
ComponentException
public <T> Inhabitant<T> getInhabitant(Type type,
String name)
public <T> Inhabitant<T> getInhabitantByType(Class<T> implType)
Inhabitant.get() is invoked.
public <T> Inhabitant<T> getInhabitantByType(Type implType)
public Inhabitant<?> getInhabitantByType(String fullyQualifiedClassName)
public Inhabitant<?> getInhabitantByAnnotation(Class<? extends Annotation> contract,
String name)
throws ComponentException
Inhabitant.get() is invoked.
ComponentExceptionpublic <T> Collection<Inhabitant<? extends T>> getInhabitants(Class<T> type)
T - the parameterized typetype - the contract type
public <T> Collection<Inhabitant<T>> getInhabitantsByContract(Type contract)
throws ComponentException
getInhabitantsByContract in interface SimpleServiceLocatorComponentExceptionpublic <T> T inject(T object)
inject in interface Injectorpublic <T> T inject(Class<T> type)
Inject
annotated fields and methods
inject in interface InjectorT - type of the requested instancetype - class of the requested instance
public <T> Collection<Inhabitant<T>> getInhabitantsByType(Class<T> implType)
throws ComponentException
getInhabitantsByType in interface SimpleServiceLocatorComponentExceptionpublic Collection<Inhabitant<?>> getInhabitantsByType(String fullyQualifiedClassName)
getInhabitantsByType in interface SimpleServiceLocatorpublic Inhabitant<?> getInhabitantByContract(String typeName)
typeName - fullyQualifiedClassName
public Collection<Inhabitant<?>> getInhabitantsByContract(String fullyQualifiedClassName)
getInhabitantsByContract in interface SimpleServiceLocatorpublic Iterator<String> getAllContracts()
public Iterator<String> getAllTypes()
public Inhabitant getInhabitantByContract(String fullyQualifiedName,
String name)
public <T> Iterable<Inhabitant<? extends T>> getInhabitants(Class<T> contract,
String name)
throws ComponentException
Inhabitant.get() is invoked.
ComponentException
public Iterable<Inhabitant<?>> getInhabitantsByAnnotation(Class<? extends Annotation> contract,
String name)
throws ComponentException
Inhabitant.get() is invoked.
ComponentExceptionpublic <T> T getByType(Class<T> implType)
SimpleServiceLocator
getByType in interface SimpleServiceLocatorpublic <T> T getByType(String implType)
SimpleServiceLocator
getByType in interface SimpleServiceLocator
public <T> Inhabitant<T> getProvider(Type type,
String name)
SimpleServiceLocator
getProvider in interface SimpleServiceLocatortype - requested inhabitant typename - optional namepublic <T> T getByContract(Class<T> contractType)
public void release()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||