|
||||||||||
| 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. |
ScopeInstance |
singletonScope
|
| Constructor Summary | |
|---|---|
Habitat()
|
|
| Method Summary | ||
|---|---|---|
void |
add(Inhabitant<?> i)
Adds a new inhabitant. |
|
|
addComponent(java.lang.String name,
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)
|
|
|
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)
|
|
java.util.Iterator<java.lang.String> |
getAllTypes()
|
|
|
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. |
|
|
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. |
|
java.lang.Object |
getComponent(java.lang.String fullQualifiedName,
java.lang.String name)
|
|
|
getInhabitant(java.lang.Class<T> contract,
java.lang.String name)
Gets a lazy reference to the component. |
|
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)
|
|
|
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 |
|
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)
|
|
void |
initialized()
FOR INTERNAL USE ONLY |
|
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 |
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 final ScopeInstance singletonScope
| Constructor Detail |
|---|
public Habitat()
| Method Detail |
|---|
public 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 removedtypeNames - The contracts to filter on
public InhabitantTracker track(InhabitantTrackerContext itc,
InhabitantTracker.Callback callback)
throws ComponentException
Once the criteria is met, any callback provided is called. This callback may occur asynchronously from the thread initiating the event.
itc - The tracking criteria.callback - Optionally the callback.
ComponentException
public java.util.concurrent.Future<InhabitantTracker> trackFuture(InhabitantTrackerContext itc)
throws ComponentException
Implementation Note: The Future that is returned does not behave in the traditional sense in that it is NOT directly submitted to an ExecutorService. Each call to get() or get(timeout) may result in a [re]submission to an internally held executor. This means that a call to get(...) may return a tracker, and a subsequent call to get(...) may return null, or vice versa. This is true until the underlying tracker is released at which point a tracker is no longer usable.
itc - The tracking criteria.
ComponentExceptionpublic boolean removeAllByType(java.lang.Class<?> type)
type - of the component
public void add(Inhabitant<?> i)
See 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()
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.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> void addComponent(java.lang.String name,
T component)
throws ComponentException
name - name of the component, could be default namecomponent - 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
This is the "new Foo()" equivalent in the IoC world.
Depending on the 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
name - can be null, in which case it'll only match to the unnamed component.
ComponentException
public java.lang.Object getComponent(java.lang.String fullQualifiedName,
java.lang.String name)
public <T> Inhabitant<T> getInhabitant(java.lang.Class<T> contract,
java.lang.String name)
throws ComponentException
This method defers the actual instantiation of the component
until Inhabitant.get() is invoked.
ComponentExceptionpublic <T> Inhabitant<T> getInhabitantByType(java.lang.Class<T> implType)
This method defers the actual instantiation of the component
until Inhabitant.get() is invoked.
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
This method defers the actual instantiation of the component
until Inhabitant.get() is invoked.
ComponentException
public <T> java.util.Collection<Inhabitant<? extends T>> getInhabitants(java.lang.Class<T> contract)
throws ComponentException
ComponentException
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)
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
This method defers the actual instantiation of the component
until 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
This method defers the actual instantiation of the component
until Inhabitant.get() is invoked.
ComponentExceptionpublic <T> T getByType(java.lang.Class<T> implType)
public <T> T getByContract(java.lang.Class<T> contractType)
If there are more than one of them, this method arbitrarily return one of them.
public void release()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||