Class ComponentCollector<F extends ComponentFactory>
- Type Parameters:
F- the component factory type
- All Implemented Interfaces:
Iterable<ComponentType>,Channel,ComponentType,Eligible,Manager,ServiceTrackerCustomizer<F,F>
ComponentFactory
specified when creating the collector.The collector uses each service
found to create one or more Components that are then attached
to the component collector instance.
Effectively, the component collector leverages OSGi’s service layer to modify the component tree at run-time.
This class uses ComponentProvider.setFactories(ComponentFactory...)
and ComponentProvider.setPinned(List) for its implementation.
As it inherits from ComponentProvider, it automatically
supports the provisioning of additional components through
ConfigurationUpdate events. If this is not desired, invoke
ComponentProvider.setComponentsEntry(String) with null as
argument.
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.jgrapes.core.Channel
Channel.Default -
Field Summary
Fields inherited from class org.jgrapes.util.ComponentProvider
COMPONENT_NAME, COMPONENT_TYPE -
Constructor Summary
ConstructorsConstructorDescriptionComponentCollector(Channel componentChannel, BundleContext context, Class<F> factoryClass) Utility constructor that uses each factory to create a single instance, using an empty map as properties.ComponentCollector(Channel componentChannel, BundleContext context, Class<F> factoryCls, Function<String, List<Map<Object, Object>>> configurator) Creates a collector component that uses aServiceTrackerto monitor the addition and removal of component factories. -
Method Summary
Modifier and TypeMethodDescriptionaddingService(ServiceReference<F> reference) Whenever a new factory is added, it is used to create component instances with this component’s channel.voidmodifiedService(ServiceReference<F> reference, F service) voidremovedService(ServiceReference<F> reference, F service) Deletes all child components with the type produced by the factory that is removed.Methods inherited from class org.jgrapes.util.ComponentProvider
componentConfigurations, factories, onConfigurationUpdate, pinned, providerConfiguration, setComponentsEntry, setFactories, setPinnedMethods inherited from class org.jgrapes.core.Component
channel, component, defaultCriterion, isEligibleFor, setNameMethods inherited from class org.jgrapes.core.internal.ComponentVertex
activeEventPipeline, addHandler, attach, channelReplacements, children, componentPath, componentVertex, detach, fire, initComponentsHandlers, iterator, name, newEventPipeline, newEventPipeline, parent, registerAsGenerator, root, toString, unregisterAsGeneratorMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
ComponentCollector
public ComponentCollector(Channel componentChannel, BundleContext context, Class<F> factoryCls, Function<String, List<Map<Object, Object>>> configurator) Creates a collector component that uses aServiceTrackerto monitor the addition and removal of component factories.- Parameters:
componentChannel- this component’s channelcontext- the OSGiBundleContextfactoryCls- the factory classconfigurator- the function that provides the pinned configurations- See Also:
-
ComponentCollector
Utility constructor that uses each factory to create a single instance, using an empty map as properties.- Parameters:
componentChannel- this component’s channelcontext- the bundle contextfactoryClass- the factory class
-
-
Method Details
-
addingService
Whenever a new factory is added, it is used to create component instances with this component’s channel.First, the
configuratorpassed to the constructor is invoked with the name of the class of the component to be created as argument. The list of maps returned is then added to the pinned components (seeComponentProvider.setPinned(List)).The map return from the
configuratoris automatically augmented with an entry with keyBundleContext.class and the bundle context passed to the constructor.- Specified by:
addingServicein interfaceServiceTrackerCustomizer<F extends ComponentFactory,F extends ComponentFactory> - See Also:
-
modifiedService
- Specified by:
modifiedServicein interfaceServiceTrackerCustomizer<F extends ComponentFactory,F extends ComponentFactory>
-
removedService
Deletes all child components with the type produced by the factory that is removed.A (possibly) final
Stopevent is send to the detached subtrees which may be used to deactivate bundles.- Specified by:
removedServicein interfaceServiceTrackerCustomizer<F extends ComponentFactory,F extends ComponentFactory> - See Also:
-