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
DefaultMutableBeanLocatorthat locates qualified beans across a dynamic group ofBindingPublishers.
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.concurrent.ConcurrentMap<java.lang.Long,RankedBindings>cachedBindingsprivate java.util.Map<WatchedBeans,java.lang.Object>cachedWatchersprivate ImplicitBindingsimplicitBindingsprivate java.util.concurrent.locks.ReentrantReadWriteLockpublisherLockprivate RankedSequence<BindingPublisher>publishersprivate 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 booleanadd(BindingPublisher publisher)Adds the given rankedBindingPublisherand distributes itsBindings.(package private) voidautoPublish(com.google.inject.Injector injector)Automatically publishes anyInjectorthat contains a binding to thisBeanLocator.
Relies on Guice's auto-injection, bind the locator with a Provider to disable this feature.(package private) static voidautoPublishChild(com.google.inject.Injector childInjector)Automatically publishes childInjectors that inherit a binding to thisBeanLocator.
Assumes module(s) used to create the child injector request static injection of this class.voidclear()Removes all knownBindingPublishers and theirBindings.private RankedBindingsfetchBindings(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 registeredBindingPublishers.booleanremove(BindingPublisher publisher)Removes the givenBindingPublisherand itsBindings.voidwatch(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
-
publisherLock
private final java.util.concurrent.locks.ReentrantReadWriteLock publisherLock
-
-
Method Detail
-
locate
public java.lang.Iterable<BeanEntry> locate(com.google.inject.Key key)
Description copied from interface:BeanLocatorFinds bean implementations that match the given qualified bindingKey.- Specified by:
locatein 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:BeanLocatorTracks bean implementations that match the given qualified bindingKey.Uses the
Mediatorpattern to send events to an arbitrary watcher object.- Specified by:
watchin interfaceBeanLocator- Parameters:
key- The qualified keymediator- The event mediatorwatcher- The bean watcher
-
add
public boolean add(BindingPublisher publisher)
Description copied from interface:MutableBeanLocatorAdds the given rankedBindingPublisherand distributes itsBindings.- Specified by:
addin interfaceMutableBeanLocator- Parameters:
publisher- The new publisher- Returns:
trueif the publisher was added; otherwisefalse
-
remove
public boolean remove(BindingPublisher publisher)
Description copied from interface:MutableBeanLocatorRemoves the givenBindingPublisherand itsBindings.- Specified by:
removein interfaceMutableBeanLocator- Parameters:
publisher- The old publisher- Returns:
trueif the publisher was removed; otherwisefalse
-
publishers
public java.lang.Iterable<BindingPublisher> publishers()
Description copied from interface:MutableBeanLocatorSnapshot of currently registeredBindingPublishers.- Specified by:
publishersin interfaceMutableBeanLocator- Returns:
- The registered
BindingPublishers
-
clear
public void clear()
Description copied from interface:MutableBeanLocatorRemoves all knownBindingPublishers and theirBindings.- Specified by:
clearin interfaceMutableBeanLocator
-
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;
nullif this is a new type
-
autoPublish
@Inject void autoPublish(com.google.inject.Injector injector)
Automatically publishes anyInjectorthat contains a binding to thisBeanLocator.
Relies on Guice's auto-injection, bind the locator with a Provider to disable this feature.- Parameters:
injector- The injector
-
autoPublishChild
@Inject static void autoPublishChild(com.google.inject.Injector childInjector)
Automatically publishes childInjectors that inherit a binding to thisBeanLocator.
Assumes module(s) used to create the child injector request static injection of this class.- Parameters:
childInjector- The child injector
-
-