@Override public int getActiveThreadsCount() { return asyncExec.getActiveCount(); }
@Override public int getEventsInQueueCount() { return asyncExec.getUnfinishedCount(); }
public boolean waitForCompletion(long timeoutMillis) throws InterruptedException { WorkManager workManager = getWorkManager(); if (workManager == null) { return false; } return workManager.awaitCompletion(timeoutMillis, TimeUnit.MILLISECONDS); }
@Override public boolean waitForCompletion(long timeoutMillis) throws InterruptedException { return asyncExec.waitForCompletion(timeoutMillis); } }
@Override protected boolean processEventBundles(List<EventBundle> bundles) { EventServiceAdmin eventService = Framework.getService(EventServiceAdmin.class);// EventListenerList listeners = eventService.getListenerList(); List<EventListenerDescriptor> postCommitAsync = listeners.getEnabledAsyncPostCommitListenersDescriptors(); // could introduce bulk mode for EventListeners for (EventBundle eventBundle : bundles) { asyncExec.run(postCommitAsync, eventBundle); } return true; }
@Override public void initConsumer(String name, Map<String, String> params) { super.initConsumer(name, params); asyncExec = new AsyncEventExecutor(); if (Framework.getRuntime() == null) { throw new RuntimeException("Nuxeo Runtime not initialized"); } }
public void shutdown(long timeoutMillis) throws InterruptedException { postCommitExec.shutdown(timeoutMillis); Set<AsyncWaitHook> notTerminated = asyncWaitHooks.stream().filter(hook -> !hook.shutdown()).collect( Collectors.toSet()); if (!notTerminated.isEmpty()) { throw new RuntimeException("Asynch services are still running : " + notTerminated); } if (!asyncExec.shutdown(timeoutMillis)) { throw new RuntimeException("Async executor is still running, timeout expired"); } if (pipeDispatcher != null) { pipeDispatcher.shutdown(); } }
public void init() { asyncExec.init(); EventDispatcherDescriptor dispatcherDescriptor = dispatchers.getDispatcherDescriptor(); if (dispatcherDescriptor != null) { List<EventPipeDescriptor> pipes = registeredPipes.getPipes(); if (!pipes.isEmpty()) { pipeDispatcher = dispatcherDescriptor.getInstance(); pipeDispatcher.init(pipes, dispatcherDescriptor.getParameters()); } } }
public void run(final List<EventListenerDescriptor> listeners, EventBundle bundle) { // EventBundle that have gone through bus have been serialized // we need to reconnect them before filtering // this means we need a valid transaction ! if (!(bundle instanceof ReconnectedEventBundleImpl)) { scheduleListeners(listeners, bundle); } else { final EventBundle tmpBundle = bundle; TransactionHelper.runInTransaction(() -> { EventBundle connectedBundle = new EventBundleImpl(); Map<String, CoreSession> sessions = new HashMap<>(); List<Event> events = ((ReconnectedEventBundleImpl)tmpBundle).getReconnectedEvents(); for (Event event : events) { connectedBundle.push(event); CoreSession session = event.getContext().getCoreSession(); if (!(sessions.keySet().contains(session.getRepositoryName()))) { sessions.put(session.getRepositoryName(), session); } } for (CoreSession session : sessions.values()) { ((CloseableCoreSession) session).close(); } scheduleListeners(listeners, connectedBundle); }); } }
@Override public void waitForAsyncCompletion(long timeout) { Set<AsyncWaitHook> notCompleted = asyncWaitHooks.stream() .filter(hook -> !hook.waitForAsyncCompletion()) .collect(Collectors.toSet()); if (!notCompleted.isEmpty()) { throw new RuntimeException("Async tasks are still running : " + notCompleted); } try { if (!asyncExec.waitForCompletion(timeout)) { throw new RuntimeException("Async event listeners thread pool is not terminated"); } } catch (InterruptedException e) { Thread.currentThread().interrupt(); // TODO change signature throw new RuntimeException(e); } if (pipeDispatcher != null) { try { pipeDispatcher.waitForCompletion(timeout); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new RuntimeException(e); } } }
asyncExec.run(postCommitAsync, event); } else {
public EventServiceImpl() { listenerDescriptors = new EventListenerList(); postCommitExec = new PostCommitEventExecutor(); asyncExec = new AsyncEventExecutor(); }
public void init() { WorkManager workManager = getWorkManager(); if (workManager != null) { workManager.init(); } }
public boolean shutdown(long timeoutMillis) throws InterruptedException { WorkManager workManager = getWorkManager(); if (workManager == null) { return true; } return workManager.shutdown(timeoutMillis, TimeUnit.MILLISECONDS); }
public int getActiveCount() { WorkManager workManager = getWorkManager(); int n = 0; for (String queueId : workManager.getWorkQueueIds()) { n += workManager.getQueueSize(queueId, State.RUNNING); } return n; }
public int getUnfinishedCount() { WorkManager workManager = getWorkManager(); int n = 0; for (String queueId : workManager.getWorkQueueIds()) { n += workManager.getQueueSize(queueId, State.SCHEDULED) + workManager.getQueueSize(queueId, State.RUNNING); } return n; }
private void scheduleListeners(final List<EventListenerDescriptor> listeners, EventBundle bundle) { for (EventListenerDescriptor listener : listeners) { EventBundle filtered = listener.filterBundle(bundle); if (filtered.isEmpty()) { continue; } // This may be called in a transaction if event.isCommitEvent() is true or at transaction commit // in other cases. If the transaction has been marked rollback-only, then scheduling must discard // so we schedule "after commit" getWorkManager().schedule(new ListenerWork(listener, filtered), true); } }