@Override public void afterCompletion(final int status) { // after the transaction rolled back, // execute this job exception handler object as a command with // the command service so that this gets done in a separate transaction LOG.severe("starting new transaction for handling job exception"); final String processUUID = commandService.execute(this); LOG.severe("completed transaction for handling job exception"); commandService.execute(new Command<Void>() { @Override public Void execute(Environment environment) throws Exception { EnvTool.getEventExecutor().getJobExecutor().notifyThreadFinished(processUUID); return null; } }); }
@Override public void run() { try { eventExecutor.getCommandService().execute(cmd); } catch (final Throwable e) { LOG.severe("Exception in event block: " + Misc.getStackTraceFrom(e)); } }
protected void storeJobs(final Set<EventCoupleId> eventCoupleIds) { final int batchSize = 50; if (eventCoupleIds.size() <= batchSize) { getCommandService().execute(new CreateJobs(eventCoupleIds)); } else { //build slices final Set<EventCoupleId> eventCoupleIdsToProcessInThisLoop = new HashSet<EventCoupleId>(); final Iterator<EventCoupleId> it = eventCoupleIds.iterator(); while (it.hasNext()) { eventCoupleIdsToProcessInThisLoop.clear(); while (it.hasNext() && eventCoupleIdsToProcessInThisLoop.size() < batchSize) { eventCoupleIdsToProcessInThisLoop.add(it.next()); } getCommandService().execute(new CreateJobs(eventCoupleIdsToProcessInThisLoop)); } } }
public <T> T execute(Command<T> command) { Environment environment = environmentFactory.openEnvironment(); try { return next.execute(command); } finally { environment.close(); } }
public long getNewProcessInstanceNb(ProcessDefinitionUUID processUUID) { long newProcessInstanceNb; synchronized (getMutex(processUUID)) { newProcessInstanceNb = EnvTool.getCommandService().execute(new StoreMetaDataCommand(processUUID)); } if (LOG.isLoggable(Level.FINE)) { LOG.fine("Creating a new ProcessInstance with nb: " + newProcessInstanceNb); } return newProcessInstanceNb; }
@Override protected void execute() throws InterruptedException { getCommandService().execute(new CleanExpiredWebTokens()); }
@Override public void afterCompletion(final int transactionStatus) { if (this.transactionStatus == transactionStatus) { EnvTool.getCommandService().execute(new MarkActivityAsFailed(activityInstUUID)); } }
@Override protected Long getNextDueDate() { return getCommandService().execute(new GetNextExpressionEventDueDate()); }
@Override protected void execute() { getCommandService().execute(new RemoveOverdueEvents()); Set<EventCoupleId> coupleIds; do { if (LOG.isLoggable(Level.FINE)) { LOG.fine("Getting couples..."); } coupleIds = getCommandService().execute(new GetEventCouples(maxCouples)); if (LOG.isLoggable(Level.FINE)) { LOG.fine(this.getClass().getSimpleName() + " on node " + System.getProperty("bonita.node.name") + " has got " + coupleIds.size() + " couples"); } if (LOG.isLoggable(Level.FINE)) { LOG.fine("Creating jobs..."); } storeJobs(coupleIds); if (LOG.isLoggable(Level.FINE)) { LOG.fine("Jobs created."); } if (LOG.isLoggable(Level.FINE)) { LOG.fine("All couples handled, looping..."); } } while (coupleIds.size() == maxCouples); if (matchingConditionEnable) { final Set<EventCoupleId> coupleIds2 = getCommandService().execute(new GetExpressionMessageEventCouples()); storeJobs(coupleIds2); } }
@Override protected Long getNextDueDate() { //DB correlation next due date final Long dueDate1 = getCommandService().execute(new GetNextEventDueDate()); if (matchingConditionEnable) { //matching condition next due date final Long dueDate2 = getCommandService().execute(new GetNextExpressionEventDueDate()); if (dueDate1 == null && dueDate2 == null) { return null; } else if (dueDate1 != null && dueDate2 == null) { return dueDate1; } else if (dueDate2 != null && dueDate1 == null) { return dueDate2; } else { return Math.min(dueDate1, dueDate2); } } else { return dueDate1; } }
@Override protected void execute() { final Set<EventCoupleId> coupleIds = getCommandService().execute(new GetExpressionMessageEventCouples()); storeJobs(coupleIds); }
@Override public void afterCompletion(final int status) { if (status == Status.STATUS_COMMITTED) { EnvTool.getCommandService().execute(new DeleteExecutionCommand(child.getId())); } } });
@Override protected Long getNextDueDate() { return getCommandService().execute(new GetNextJobDueDate(getProcessUUIDsToExclude())); }
cleanLockedProcessUUIDs(); final List<String> nonLockedProcessUUIDs = getCommandService().execute( getNonlockedProcessUUIDsCommand(getProcessUUIDsToExclude())); if (LOG.isLoggable(Level.FINE)) {
public <T> T execute(Command<T> command) { int attempt = 1; long sleepTime = delay; while (attempt <= retries) { if (attempt > 1) { if (LOG.isLoggable(Level.INFO)) { LOG.info("retrying..."); } } try { return next.execute(command); } catch (StaleStateException e) { manageException(attempt, sleepTime, e); } catch (AssertionFailure e) { manageException(attempt, sleepTime, e); } catch (LockAcquisitionException e) { manageException(attempt, sleepTime, e); } } if (LOG.isLoggable(Level.INFO)) { LOG.info("gave up after "+attempt+" attempts"); } String message = ExceptionManager.getInstance().getFullMessage("bp_RI_1", attempt); throw new BonitaRuntimeException(message); }
private static void updateJobsAndJobLocks(final String domain) throws Exception { final EnvironmentFactory envFactory = GlobalEnvironmentFactory.getEnvironmentFactory(domain); final Environment environment = envFactory.openEnvironment(); try { DomainOwner.setDomain(domain); final CommandService commandService = envFactory.get(CommandService.class); //create job locks for process definition and root process instances final UpdateJobLocksCommand creteJobLockscommand = new UpdateJobLocksCommand(); commandService.execute(creteJobLockscommand); //update jobs by setting the procesUUID where it's currently null final UpdateJobsCommand updateJobsCommand = new UpdateJobsCommand(); commandService.execute(updateJobsCommand); } finally { DomainOwner.setDomain(null); environment.close(); } }
public synchronized void start() { domain = commandService.execute(new GetDomainCommand()); name = EventExecutor.class.getSimpleName() + "-" + Misc.getHostName() + "-" + domain; if (isActive) {
@Override public Object invoke(final Object proxy, final Method method, final Object[] args) throws Throwable { if (Environment.getCurrent() != null) { return new RESTServerAPIInterceptorCommand(method, args, api) .execute(Environment.getCurrent()); } // If no environment: use directly the command Service with interceptors final EnvironmentFactory envFactory = GlobalEnvironmentFactory .getEnvironmentFactory(DomainOwner.getDomain()); try { return envFactory.get(CommandService.class).execute( new RESTServerAPIInterceptorCommand(method, args, api)); } catch (final BonitaWrapperException e) { throw e.getCause(); } catch (final BonitaRuntimeException e) { if (DefaultCommandService.class.getName().equals(e.getWrappedBy()) || UnRollbackableException.class.getName().equals(e.getWrappedBy())) { throw e.getCause(); } else { throw e; } } }
@Override public long getNewProcessInstanceNb(final ProcessDefinitionUUID processUUID) { final String metaName = getMetadataName(processUUID); // look for sequence object final Sequence sequence = getSequence(processUUID); long processInstanceNb; // noinspection SynchronizationOnLocalVariableOrMethodParameter synchronized (sequence) { if (sequence.shouldReset()) { final long nextHi = EnvTool.getCommandService().execute(new Command<Long>() { private static final long serialVersionUID = 1L; @Override public Long execute(final Environment environment) throws Exception { final Journal journal = EnvTool.getJournal(); journal.lockMetadata(metaName); long nb = journal.getLockedMetadata(metaName); nb += increment; journal.updateLockedMetadata(metaName, nb); return nb; } }); sequence.reset(nextHi, increment); } processInstanceNb = sequence.inc(); } return processInstanceNb; }
standardTransaction.begin(); try { return next.execute(command); } catch (final UnRollbackableException e) { final Throwable originalCause = e.getCause();