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 Component
s 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
ConstructorDescriptionComponentCollector
(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 aServiceTracker
to 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.void
modifiedService
(ServiceReference<F> reference, F service) void
removedService
(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, setPinned
Methods inherited from class org.jgrapes.core.Component
channel, component, defaultCriterion, isEligibleFor, setName
Methods 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, unregisterAsGenerator
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods 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 aServiceTracker
to monitor the addition and removal of component factories.- Parameters:
componentChannel
- this component’s channelcontext
- the OSGiBundleContext
factoryCls
- 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
configurator
passed 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
configurator
is automatically augmented with an entry with keyBundleContext
.class and the bundle context passed to the constructor.- Specified by:
addingService
in interfaceServiceTrackerCustomizer<F extends ComponentFactory,
F extends ComponentFactory> - See Also:
-
modifiedService
- Specified by:
modifiedService
in 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
Stop
event is send to the detached subtrees which may be used to deactivate bundles.- Specified by:
removedService
in interfaceServiceTrackerCustomizer<F extends ComponentFactory,
F extends ComponentFactory> - See Also:
-