@SuppressWarnings("unchecked") @Override public void run() { EventMessage<?> eventMessage = createMessage(); if (logger.isDebugEnabled()) { logger.debug("Triggered the publication of event [{}]", eventMessage.getPayloadType().getSimpleName()); } try { UnitOfWork<EventMessage<?>> unitOfWork = new DefaultUnitOfWork<>(null); unitOfWork.attachTransaction(transactionManager); unitOfWork.execute(() -> eventBus.publish(eventMessage)); } finally { tokens.remove(tokenId); } }
/** * Performs the actual handling logic. * * @param command The actual command to handle * @param handler The handler that must be invoked for this command * @param callback The callback to notify of the result * @param <C> The type of payload of the command * @param <R> The type of result expected from the command handler */ @SuppressWarnings({"unchecked"}) protected <C, R> void handle(CommandMessage<C> command, MessageHandler<? super CommandMessage<?>> handler, CommandCallback<? super C, ? super R> callback) { if (logger.isDebugEnabled()) { logger.debug("Handling command [{}]", command.getCommandName()); } UnitOfWork<CommandMessage<?>> unitOfWork = DefaultUnitOfWork.startAndGet(command); unitOfWork.attachTransaction(transactionManager); InterceptorChain chain = new DefaultInterceptorChain<>(unitOfWork, handlerInterceptors, handler); CommandResultMessage<R> resultMessage = asCommandResultMessage(unitOfWork.executeWithResult(chain::proceed, rollbackConfiguration)); callback.onResult(command, resultMessage); }
@Override public void run() { if (logger.isDebugEnabled()) { logger.debug("Triggered deadline"); } try { Instant triggerInstant = GenericEventMessage.clock.instant(); UnitOfWork<DeadlineMessage<?>> unitOfWork = new DefaultUnitOfWork<>( new GenericDeadlineMessage<>(deadlineName, deadlineMessage, () -> triggerInstant)); unitOfWork.attachTransaction(transactionManager); InterceptorChain chain = new DefaultInterceptorChain<>(unitOfWork, handlerInterceptors(), deadlineMessage -> { executeScheduledDeadline(deadlineMessage, deadlineScope); return null; }); ResultMessage<?> resultMessage = unitOfWork.executeWithResult(chain::proceed); if (resultMessage.isExceptional()) { Throwable e = resultMessage.exceptionResult(); throw new DeadlineException(format("An error occurred while triggering the deadline %s %s", deadlineName, deadlineId), e); } } finally { scheduledTasks.remove(new DeadlineId(deadlineName, deadlineId)); } }
@Override public void execute(JobExecutionContext context) throws JobExecutionException { logger.debug("Starting job to publish a scheduled event"); JobDetail jobDetail = context.getJobDetail(); JobDataMap jobData = jobDetail.getJobDataMap(); try { SchedulerContext schedulerContext = context.getScheduler().getContext(); EventJobDataBinder jobDataBinder = (EventJobDataBinder) schedulerContext.get(EVENT_JOB_DATA_BINDER_KEY); Object event = jobDataBinder.fromJobData(jobData); EventMessage<?> eventMessage = createMessage(event); EventBus eventBus = (EventBus) context.getScheduler().getContext().get(EVENT_BUS_KEY); TransactionManager txManager = (TransactionManager) context.getScheduler().getContext().get(TRANSACTION_MANAGER_KEY); UnitOfWork<EventMessage<?>> unitOfWork = DefaultUnitOfWork.startAndGet(null); if (txManager != null) { unitOfWork.attachTransaction(txManager); } unitOfWork.execute(() -> eventBus.publish(eventMessage)); if (logger.isInfoEnabled()) { logger.info("Job successfully executed. Scheduled Event [{}] has been published.", eventMessage.getPayloadType().getSimpleName()); } } catch (Exception e) { logger.error("Exception occurred while publishing scheduled event [{}]", jobDetail.getDescription(), e); throw new JobExecutionException(e); } }
unitOfWork.attachTransaction(transactionManager); unitOfWork.resources().put(segmentIdResourceKey, segment.getSegmentId()); unitOfWork.resources().put(lastTokenResourceKey, finalLastToken);
@SuppressWarnings("unchecked") @Override public void run() { EventMessage<?> eventMessage = createMessage(); if (logger.isDebugEnabled()) { logger.debug("Triggered the publication of event [{}]", eventMessage.getPayloadType().getSimpleName()); } try { UnitOfWork<EventMessage<?>> unitOfWork = new DefaultUnitOfWork<>(null); unitOfWork.attachTransaction(transactionManager); unitOfWork.execute(() -> eventBus.publish(eventMessage)); } finally { tokens.remove(tokenId); } }
@SuppressWarnings("unchecked") @Override public void run() { EventMessage<?> eventMessage = createMessage(); if (logger.isDebugEnabled()) { logger.debug("Triggered the publication of event [{}]", eventMessage.getPayloadType().getSimpleName()); } try { UnitOfWork<EventMessage<?>> unitOfWork = new DefaultUnitOfWork<>(null); unitOfWork.attachTransaction(transactionManager); unitOfWork.execute(() -> eventBus.publish(eventMessage)); } finally { tokens.remove(tokenId); } }
@Override public void run() { Instant triggerInstant = GenericEventMessage.clock.instant(); DeadlineMessage<?> deadlineMessage = new GenericDeadlineMessage<>( deadlineName, new GenericMessage<>(messageOrPayload), () -> triggerInstant ); if (logger.isDebugEnabled()) { logger.debug("Triggered deadline"); } try { UnitOfWork<DeadlineMessage<?>> unitOfWork = new DefaultUnitOfWork<>(deadlineMessage); unitOfWork.attachTransaction(transactionManager); unitOfWork.execute(() -> executeScheduledDeadline(deadlineMessage, deadlineScope)); } finally { scheduledTasks.remove(new DeadlineId(deadlineName, deadlineId)); } }
/** * Performs the actual handling logic. * * @param command The actual command to handle * @param handler The handler that must be invoked for this command * @param callback The callback to notify of the result * @param <C> The type of payload of the command * @param <R> The type of result expected from the command handler */ @SuppressWarnings({"unchecked"}) protected <C, R> void handle(CommandMessage<C> command, MessageHandler<? super CommandMessage<?>> handler, CommandCallback<? super C, R> callback) { if (logger.isDebugEnabled()) { logger.debug("Handling command [{}]", command.getCommandName()); } try { UnitOfWork<CommandMessage<?>> unitOfWork = DefaultUnitOfWork.startAndGet(command); unitOfWork.attachTransaction(transactionManager); InterceptorChain chain = new DefaultInterceptorChain<>(unitOfWork, handlerInterceptors, handler); R result = (R) unitOfWork.executeWithResult(chain::proceed, rollbackConfiguration); callback.onSuccess(command, result); } catch (Exception e) { callback.onFailure(command, e); } }
/** * Performs the actual handling logic. * * @param command The actual command to handle * @param handler The handler that must be invoked for this command * @param callback The callback to notify of the result * @param <C> The type of payload of the command * @param <R> The type of result expected from the command handler */ @SuppressWarnings({"unchecked"}) protected <C, R> void handle(CommandMessage<C> command, MessageHandler<? super CommandMessage<?>> handler, CommandCallback<? super C, ? super R> callback) { if (logger.isDebugEnabled()) { logger.debug("Handling command [{}]", command.getCommandName()); } UnitOfWork<CommandMessage<?>> unitOfWork = DefaultUnitOfWork.startAndGet(command); unitOfWork.attachTransaction(transactionManager); InterceptorChain chain = new DefaultInterceptorChain<>(unitOfWork, handlerInterceptors, handler); CommandResultMessage<R> resultMessage = asCommandResultMessage(unitOfWork.executeWithResult(chain::proceed, rollbackConfiguration)); callback.onResult(command, resultMessage); }
@Override public void execute(JobExecutionContext context) throws JobExecutionException { logger.debug("Starting job to publish a scheduled event"); JobDetail jobDetail = context.getJobDetail(); JobDataMap jobData = jobDetail.getJobDataMap(); try { SchedulerContext schedulerContext = context.getScheduler().getContext(); EventJobDataBinder jobDataBinder = (EventJobDataBinder) schedulerContext.get(EVENT_JOB_DATA_BINDER_KEY); Object event = jobDataBinder.fromJobData(jobData); EventMessage<?> eventMessage = createMessage(event); EventBus eventBus = (EventBus) context.getScheduler().getContext().get(EVENT_BUS_KEY); TransactionManager txManager = (TransactionManager) context.getScheduler().getContext().get(TRANSACTION_MANAGER_KEY); UnitOfWork<EventMessage<?>> unitOfWork = DefaultUnitOfWork.startAndGet(null); if (txManager != null) { unitOfWork.attachTransaction(txManager); } unitOfWork.execute(() -> eventBus.publish(eventMessage)); if (logger.isInfoEnabled()) { logger.info("Job successfully executed. Scheduled Event [{}] has been published.", eventMessage.getPayloadType().getSimpleName()); } } catch (Exception e) { logger.error("Exception occurred while publishing scheduled event [{}]", jobDetail.getDescription(), e); throw new JobExecutionException(e); } }
@Override public void execute(JobExecutionContext context) throws JobExecutionException { logger.debug("Starting job to publish a scheduled event"); JobDetail jobDetail = context.getJobDetail(); JobDataMap jobData = jobDetail.getJobDataMap(); try { SchedulerContext schedulerContext = context.getScheduler().getContext(); EventJobDataBinder jobDataBinder = (EventJobDataBinder) schedulerContext.get(EVENT_JOB_DATA_BINDER_KEY); Object event = jobDataBinder.fromJobData(jobData); EventMessage<?> eventMessage = createMessage(event); EventBus eventBus = (EventBus) context.getScheduler().getContext().get(EVENT_BUS_KEY); TransactionManager txManager = (TransactionManager) context.getScheduler().getContext().get(TRANSACTION_MANAGER_KEY); UnitOfWork<EventMessage<?>> unitOfWork = DefaultUnitOfWork.startAndGet(null); if (txManager != null) { unitOfWork.attachTransaction(txManager); } unitOfWork.execute(() -> eventBus.publish(eventMessage)); if (logger.isInfoEnabled()) { logger.info("Job successfully executed. Scheduled Event [{}] has been published.", eventMessage.getPayloadType().getSimpleName()); } } catch (Exception e) { logger.error("Exception occurred while publishing scheduled event [{}]", jobDetail.getDescription(), e); throw new JobExecutionException(e); } }
@Override public void run() { if (logger.isDebugEnabled()) { logger.debug("Triggered deadline"); } try { Instant triggerInstant = GenericEventMessage.clock.instant(); UnitOfWork<DeadlineMessage<?>> unitOfWork = new DefaultUnitOfWork<>( new GenericDeadlineMessage<>(deadlineName, deadlineMessage, () -> triggerInstant)); unitOfWork.attachTransaction(transactionManager); InterceptorChain chain = new DefaultInterceptorChain<>(unitOfWork, handlerInterceptors(), deadlineMessage -> { executeScheduledDeadline(deadlineMessage, deadlineScope); return null; }); ResultMessage<?> resultMessage = unitOfWork.executeWithResult(chain::proceed); if (resultMessage.isExceptional()) { Throwable e = resultMessage.exceptionResult(); throw new DeadlineException(format("An error occurred while triggering the deadline %s %s", deadlineName, deadlineId), e); } } finally { scheduledTasks.remove(new DeadlineId(deadlineName, deadlineId)); } }
unitOfWork.attachTransaction(transactionManager); unitOfWork.resources().put(segmentIdResourceKey, segment.getSegmentId()); unitOfWork.resources().put(lastTokenResourceKey, finalLastToken);
unitOfWork.attachTransaction(transactionManager); unitOfWork.resources().put(segmentIdResourceKey, segment.getSegmentId()); unitOfWork.resources().put(lastTokenResourceKey, finalLastToken);