@Override
public void invoke(int state, InvocationContext context) {
XBundle bundle = (XBundle) context.getBundle();
XBundleRevision brev = bundle.getBundleRevision();
ContextActivator activator = brev.getAttachment(ContextActivator.class);
if (activator != null) {
switch (state) {
case Bundle.ACTIVE:
try {
injectBundleContext(activator.getContext(), bundle.getBundleContext());
if (!activator.start(4, TimeUnit.SECONDS)) {
throw new LifecycleInterceptorException(MESSAGES.startContextFailed());
}
} catch (TimeoutException ex) {
throw new LifecycleInterceptorException(ex.getMessage(), ex);
}
break;
case Bundle.RESOLVED:
activator.stop(4, TimeUnit.SECONDS);
uninjectBundleContext(activator.getContext());
break;
}
}
}