Package org.eclipse.sisu.inject
Class DefaultBeanLocator
- java.lang.Object
-
- org.eclipse.sisu.inject.DefaultBeanLocator
-
- All Implemented Interfaces:
BeanLocator
,MutableBeanLocator
public final class DefaultBeanLocator extends java.lang.Object implements MutableBeanLocator
DefaultMutableBeanLocator
that locates qualified beans across a dynamic group ofBindingPublisher
s.
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.concurrent.ConcurrentMap<java.lang.Long,RankedBindings>
cachedBindings
private java.util.Map<WatchedBeans,java.lang.Object>
cachedWatchers
private ImplicitBindings
implicitBindings
private RankedSequence<BindingPublisher>
publishers
private java.lang.Long[]
typeIdHolder
-
Constructor Summary
Constructors Constructor Description DefaultBeanLocator()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
add(com.google.inject.Injector injector, int rank)
Adds the given rankedInjector
and distributes itsBinding
s.boolean
add(BindingPublisher publisher)
Adds the given rankedBindingPublisher
and distributes itsBinding
s.(package private) void
autoPublish(com.google.inject.Injector injector)
Automatically publishes anyInjector
that contains a binding to thisBeanLocator
.void
clear()
Removes all knownBindingPublisher
s and theirBinding
s.private RankedBindings
fetchBindings(com.google.inject.TypeLiteral type, java.lang.Long[] idReturn)
Fetches any bindings currently associated with the given type.java.lang.Iterable<BeanEntry>
locate(com.google.inject.Key key)
Finds bean implementations that match the given qualified bindingKey
.java.lang.Iterable<BindingPublisher>
publishers()
Snapshot of currently registeredBindingPublisher
s.void
remove(com.google.inject.Injector injector)
Removes the givenInjector
and itsBinding
s.boolean
remove(BindingPublisher publisher)
Removes the givenBindingPublisher
and itsBinding
s.(package private) static void
staticAutoPublish(MutableBeanLocator locator, com.google.inject.Injector injector)
void
watch(com.google.inject.Key key, Mediator mediator, java.lang.Object watcher)
Tracks bean implementations that match the given qualified bindingKey
.
-
-
-
Field Detail
-
publishers
private final RankedSequence<BindingPublisher> publishers
-
cachedBindings
private final java.util.concurrent.ConcurrentMap<java.lang.Long,RankedBindings> cachedBindings
-
cachedWatchers
private final java.util.Map<WatchedBeans,java.lang.Object> cachedWatchers
-
implicitBindings
private final ImplicitBindings implicitBindings
-
typeIdHolder
private final java.lang.Long[] typeIdHolder
-
-
Method Detail
-
locate
public java.lang.Iterable<BeanEntry> locate(com.google.inject.Key key)
Description copied from interface:BeanLocator
Finds bean implementations that match the given qualified bindingKey
.- Specified by:
locate
in interfaceBeanLocator
- Parameters:
key
- The qualified key- Returns:
- Sequence of bean entries that match the given key
-
watch
public void watch(com.google.inject.Key key, Mediator mediator, java.lang.Object watcher)
Description copied from interface:BeanLocator
Tracks bean implementations that match the given qualified bindingKey
.Uses the
Mediator
pattern to send events to an arbitrary watcher object.- Specified by:
watch
in interfaceBeanLocator
- Parameters:
key
- The qualified keymediator
- The event mediatorwatcher
- The bean watcher
-
add
public boolean add(BindingPublisher publisher)
Description copied from interface:MutableBeanLocator
Adds the given rankedBindingPublisher
and distributes itsBinding
s.- Specified by:
add
in interfaceMutableBeanLocator
- Parameters:
publisher
- The new publisher- Returns:
true
if the publisher was added; otherwisefalse
-
remove
public boolean remove(BindingPublisher publisher)
Description copied from interface:MutableBeanLocator
Removes the givenBindingPublisher
and itsBinding
s.- Specified by:
remove
in interfaceMutableBeanLocator
- Parameters:
publisher
- The old publisher- Returns:
true
if the publisher was removed; otherwisefalse
-
publishers
public java.lang.Iterable<BindingPublisher> publishers()
Description copied from interface:MutableBeanLocator
Snapshot of currently registeredBindingPublisher
s.- Specified by:
publishers
in interfaceMutableBeanLocator
- Returns:
- The registered
BindingPublisher
s
-
clear
public void clear()
Description copied from interface:MutableBeanLocator
Removes all knownBindingPublisher
s and theirBinding
s.- Specified by:
clear
in interfaceMutableBeanLocator
-
add
public void add(com.google.inject.Injector injector, int rank)
Description copied from interface:MutableBeanLocator
Adds the given rankedInjector
and distributes itsBinding
s. Marked as deprecated because most clients should not call this method; any injector with an instance binding to aBeanLocator
is automatically added to that locator as part of the bootstrapping process.- Specified by:
add
in interfaceMutableBeanLocator
- Parameters:
injector
- The new injectorrank
- The assigned rank; should reflect the injector'sRankingFunction.maxRank()
-
remove
public void remove(com.google.inject.Injector injector)
Description copied from interface:MutableBeanLocator
Removes the givenInjector
and itsBinding
s.- Specified by:
remove
in interfaceMutableBeanLocator
- Parameters:
injector
- The old injector
-
fetchBindings
private RankedBindings fetchBindings(com.google.inject.TypeLiteral type, java.lang.Long[] idReturn)
Fetches any bindings currently associated with the given type.- Parameters:
type
- The generic typeidReturn
- Optional holder, returns the assigned type id- Returns:
- Associated bindings;
null
if this is a new type
-
autoPublish
@Inject void autoPublish(com.google.inject.Injector injector)
Automatically publishes anyInjector
that contains a binding to thisBeanLocator
.- Parameters:
injector
- The injector
-
staticAutoPublish
@Inject static void staticAutoPublish(MutableBeanLocator locator, com.google.inject.Injector injector)
-
-