public final class DefaultBeanLocator extends java.lang.Object implements MutableBeanLocator
MutableBeanLocator
that locates qualified beans across a dynamic group of BindingPublisher
s.Modifier and Type | Field and 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 and Description |
---|
DefaultBeanLocator() |
Modifier and Type | Method and Description |
---|---|
boolean |
add(BindingPublisher publisher)
Adds the given ranked
BindingPublisher and distributes its Binding s. |
void |
add(com.google.inject.Injector injector,
int rank)
Adds the given ranked
Injector and distributes its Binding s. |
(package private) void |
autoPublish(com.google.inject.Injector injector)
Automatically publishes any
Injector that contains a binding to this BeanLocator . |
void |
clear()
Removes all known
BindingPublisher s and their Binding 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 binding
Key . |
java.lang.Iterable<BindingPublisher> |
publishers()
Snapshot of currently registered
BindingPublisher s. |
boolean |
remove(BindingPublisher publisher)
Removes the given
BindingPublisher and its Binding s. |
void |
remove(com.google.inject.Injector injector)
Removes the given
Injector and its Binding 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 binding
Key . |
private final RankedSequence<BindingPublisher> publishers
private final java.util.concurrent.ConcurrentMap<java.lang.Long,RankedBindings> cachedBindings
private final java.util.Map<WatchedBeans,java.lang.Object> cachedWatchers
private final ImplicitBindings implicitBindings
private final java.lang.Long[] typeIdHolder
public java.lang.Iterable<BeanEntry> locate(com.google.inject.Key key)
BeanLocator
Key
.locate
in interface BeanLocator
key
- The qualified keypublic void watch(com.google.inject.Key key, Mediator mediator, java.lang.Object watcher)
BeanLocator
Key
.
Uses the Mediator
pattern to send events to an arbitrary watcher object.
watch
in interface BeanLocator
key
- The qualified keymediator
- The event mediatorwatcher
- The bean watcherpublic boolean add(BindingPublisher publisher)
MutableBeanLocator
BindingPublisher
and distributes its Binding
s.add
in interface MutableBeanLocator
publisher
- The new publishertrue
if the publisher was added; otherwise false
public boolean remove(BindingPublisher publisher)
MutableBeanLocator
BindingPublisher
and its Binding
s.remove
in interface MutableBeanLocator
publisher
- The old publishertrue
if the publisher was removed; otherwise false
public java.lang.Iterable<BindingPublisher> publishers()
MutableBeanLocator
BindingPublisher
s.publishers
in interface MutableBeanLocator
BindingPublisher
spublic void clear()
MutableBeanLocator
BindingPublisher
s and their Binding
s.clear
in interface MutableBeanLocator
public void add(com.google.inject.Injector injector, int rank)
MutableBeanLocator
Injector
and distributes its Binding
s. Marked as deprecated because most
clients should not call this method; any injector with an instance binding to a BeanLocator
is
automatically added to that locator as part of the bootstrapping process.add
in interface MutableBeanLocator
injector
- The new injectorrank
- The assigned rank; should reflect the injector's RankingFunction.maxRank()
public void remove(com.google.inject.Injector injector)
MutableBeanLocator
Injector
and its Binding
s.remove
in interface MutableBeanLocator
injector
- The old injectorprivate RankedBindings fetchBindings(com.google.inject.TypeLiteral type, java.lang.Long[] idReturn)
type
- The generic typeidReturn
- Optional holder, returns the assigned type idnull
if this is a new type@Inject void autoPublish(com.google.inject.Injector injector)
Injector
that contains a binding to this BeanLocator
.injector
- The injector@Inject static void staticAutoPublish(MutableBeanLocator locator, com.google.inject.Injector injector)