Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PAXCDI-196 - It does not work to intercept the events start and stop the bundles. #21

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,17 @@ public class BeanBundleImpl {
@Inject
private ServiceEventBridge serviceEventBridge;

@Inject
private BundleEventBridge bundleEventBridge;

/**
* Register OSGi services when the bean is initialized
*/
public void onInitialized(@Observes ContainerInitialized event) {
log.debug("onInitialized {}", bundleContext.getBundle());
serviceEventBridge.start();
componentLifecycleManager.start();
bundleEventBridge.start();
}

/**
Expand All @@ -68,5 +72,6 @@ public void onDestroy() {
log.debug("onDestroy {}", bundleContext.getBundle());
componentLifecycleManager.stop();
serviceEventBridge.stop();
bundleEventBridge.stop();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public Void addingBundle(Bundle bundle, BundleEvent bundleEvent) {
return null;
}
log.debug("adding bundle {} {}", bundle);
Event<BundleCdiEvent> childEvent = select(bundleEvent);
Event<BundleCdiEvent> childEvent = select(bundle, bundleEvent);
childEvent.fire(new BundleCdiEvent(bundle, bundleEvent));
return null;
}
Expand All @@ -85,14 +85,16 @@ public Void addingBundle(Bundle bundle, BundleEvent bundleEvent) {
* @return
*/
@SuppressWarnings("serial")
private Event<BundleCdiEvent> select(BundleEvent bundleEvent) {
private Event<BundleCdiEvent> select(Bundle bundle, BundleEvent bundleEvent) {
if (bundleEvent != null) {
switch (bundleEvent.getType()) {
case BundleEvent.STARTED:
case BundleEvent.STARTING:
// case BundleEvent.STARTED:
return event.select(new AnnotationLiteral<BundleStarted>() {
});

case BundleEvent.STOPPED:
// case BundleEvent.STOPPED:
case BundleEvent.STOPPING:
return event.select(new AnnotationLiteral<BundleStopped>() {
});

Expand All @@ -101,19 +103,31 @@ private Event<BundleCdiEvent> select(BundleEvent bundleEvent) {
}
}
else {
return event;
switch (bundle.getState()) {
case Bundle.ACTIVE:
return event.select(new AnnotationLiteral<BundleStarted>() {
});

case Bundle.RESOLVED:
return event.select(new AnnotationLiteral<BundleStopped>() {
});

default:
return event;
}

}
}

@Override
public void modifiedBundle(Bundle bundle, BundleEvent bundleEvent, Void object) {
Event<BundleCdiEvent> childEvent = select(bundleEvent);
Event<BundleCdiEvent> childEvent = select(bundle, bundleEvent);
childEvent.fire(new BundleCdiEvent(bundle, bundleEvent));
}

@Override
public void removedBundle(Bundle bundle, BundleEvent bundleEvent, Void object) {
Event<BundleCdiEvent> childEvent = select(bundleEvent);
Event<BundleCdiEvent> childEvent = select(bundle, bundleEvent);
childEvent.fire(new BundleCdiEvent(bundle, bundleEvent));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,18 @@ public void serviceChanged(ServiceEvent serviceEvent) {
createServiceObjectsWrapper(bundleContext, serviceReference);
Object service = serviceObjects.getService();

try {
Class klass = service.getClass();
event.select(klass, qualifier).fire(service);

TypeLiteral literal = new ParameterizedTypeLiteral(ServiceCdiEvent.class, klass);
ServiceCdiEvent cdiEvent = new ServiceCdiEvent(serviceReference, service);
event.select(literal, qualifier).fire(cdiEvent);
}
finally {
serviceObjects.ungetService(service);
if (service != null) {
try {
Class klass = service.getClass();
event.select(klass, qualifier).fire(service);

TypeLiteral literal = new ParameterizedTypeLiteral(ServiceCdiEvent.class, klass);
ServiceCdiEvent cdiEvent = new ServiceCdiEvent(serviceReference, service);
event.select(literal, qualifier).fire(cdiEvent);
}
finally {
serviceObjects.ungetService(service);
}
}
}

Expand Down