@Override public void activate(ComponentContext context) { service = new EventServiceImpl(); }
protected void handleTxCommited() { CompositeEventBundle b = threadBundles.get(); threadBundles.remove(); // notify post commit event listeners for (EventBundle bundle : b.byRepository.values()) { try { fireEventBundle(bundle); } catch (NuxeoException e) { log.error("Error while processing " + bundle, e); } } }
@Override public void afterCompletion(int status) { if (status == Status.STATUS_COMMITTED) { handleTxCommited(); } else if (status == Status.STATUS_ROLLEDBACK) { handleTxRollbacked(); } else { log.error("Unexpected afterCompletion status: " + status); } }
@Override public void registerContribution(Object contribution, String extensionPoint, ComponentInstance contributor) { if (EVENT_LISTENER_XP.equals(extensionPoint)) { EventListenerDescriptor descriptor = (EventListenerDescriptor) contribution; descriptor.setRuntimeContext(contributor.getRuntimeContext()); try { service.addEventListener(descriptor); } catch (RuntimeException e) { String msg = "Failed to register event listener in component '" + contributor.getName() + "': error initializing event listener '" + descriptor.getName() + "' (" + e.toString() + ')'; Framework.getRuntime().getMessageHandler().addError(msg); } } else if (EVENT_PIPE_XP.equals(extensionPoint)) { EventPipeDescriptor descriptor = (EventPipeDescriptor) contribution; service.addEventPipe(descriptor); } else if (EVENT_DISPATCHER_XP.equals(extensionPoint)) { EventDispatcherDescriptor descriptor = (EventDispatcherDescriptor) contribution; service.addEventDispatcher(descriptor); } }
EventBundleImpl b = new EventBundleImpl(); b.push(shallowEvent); fireEventBundle(b); } else { recordEvent(shallowEvent);
@Override public void applicationStarted(ComponentContext context) { service.init(); }
@Override public void fireEvent(String name, EventContext context) { fireEvent(new EventImpl(name, context)); }
protected void recordEvent(Event event) { CompositeEventBundle b = threadBundles.get(); b.push(event); if (TransactionHelper.isTransactionActive()) { if (!b.registeredSynchronization) { // register as synchronization try { TransactionHelper.lookupTransactionManager().getTransaction().registerSynchronization(this); } catch (NamingException | SystemException | RollbackException e) { throw new RuntimeException("Cannot register Synchronization", e); } b.registeredSynchronization = true; } } else if (event.isCommitEvent()) { handleTxCommited(); } }