SeamFramework.orgCommunity Documentation
Weld-OSGi provides numerous events about OSGi events and bean bundle lifecycle events. It also allows decoupled bean bundle communication.
All these features uses CDI events mechanisms:
These events may be listened with a Observes
annotated parameter
method
public void bindBundle(@Observes AbstractBundleEvent event) { }
These events may be fired with the regular CDI mechanisms
BeanManager beanManager; ... beanManager.fireEvent(new BundleContainerEvents.BundleContainerInitialized(bundle.getBundleContext()));
Event<Object> event; ... event.select(AbstractBundleEvent.class).fire(new BundleInstalled(bundle));
Weld-OSGi provides a CDI event notification for bean bundle about bean bundle CDI container lifecycle events:
A BundleContainerInitialized
event is fired every time a bean bundle CDI container
is initialized
A BundleContainerShutdown
event is fired every time a bean bundle CDI container is
shutdown
Weld-OSGi provides a CDI event notification for bean bundle about bundle lifecycle events:
Such an event is fired every time the correspondent OSGi bundle event is fired
All bundle lifecycle events may be listened using the AbstractBundleEvent
event
Specific bundle lifecycle events are: BundleInstalled
,
BundleUninstalled
, BundleLazyActivation
, BundleResolved
,
BundleUnresolved
, BundleUpdated
, BundleStarted
,
BundleStarting
, BundleStopped
and BundleStopping
It is possible to filter the listened source bundle by bundle symbolic name and version (optional)
public void bindBundle(@Observes @BundleName("com.sample.gui") @BundleVersion("4.2.1") AbstractBundleEvent event) { } public void bindBundle(@Observes @BundleName("com.sample.gui") BundleInstalled event) { }
Only the events from the corresponding bundle are listened.
If a BundleVersion
annotation is provided without a BundleName
annotation
Weld-OSGi detects the problem and treats it as an error.
Weld-OSGi provides a CDI event notification for bean bundle about service lifecycle events:
Such an event is fired every time the correspondent OSGi service event is fired
All service lifecycle events may be listen using the AbstractServiceEvent
event
Specific bundle lifecycle events are: ServiceArrival
, ServiceDeparture
and ServiceChanged
It is possible to filter the listened source service by specification and or OSGi LDAP properties and filter
public void bindService(@Observes @Specification(MyService.class) AbstractServiceEvent event) { } public void bindService(@Observes @AnyQualifier ServiceArrival event) { } public void bindService(@Observes @Specification(MyService.class) @Filter("(&(lang=EN)(country=US))") ServiceChanged event) { }
Only the corresponding service events are listened.
Weld-OSGi provides a CDI event notification for bean bundle about bean bundle required service dependency validation:
A Valid
event is fired every time a bean bundle got all its required service
dependency validated
A Invalid
event is fired every time a bean bundle got one of its required service
dependency invalidated
Weld-OSGi provides a way to communicate within and between bean bundles:
A InterBundleEvent
is fired by a bean
bundle
@Inject Event<InterBundleEvent> event; MyMessage myMessage = new MyMessage(); event.fire(new InterBundleEvent(myMessage));
A InterBundleEvent
may be listened by every active bean bundle
It is possible to filter the listened source message by message type and ignoring the events from the current bundle
public void listenAllEventsFromOtherBundles(@Observes @Sent InterBundleEvent event) { } public void listenMyMessageEvents(@Observes @Specification(MyMessage.class) InterBundleEvent event) { } public void listenMyMessageEventsFromOtherBundles(@Observes @Sent @Specification(MyMessage.class) InterBundleEvent event) { }
Only the corresponding events are listened.