schedulerContext.get(HANDLER_INTERCEPTORS); DeadlineMessage<?> deadlineMessage = deadlineMessage(serializer, jobData); ScopeDescriptor deadlineScope = deadlineScope(serializer, jobData);
/** * Extracts a {@link DeadlineMessage} from provided {@code jobDataMap}. * * <b>Note</b> that this function is able to retrieve two different formats of DeadlineMessage. The first being * a now deprecated solution which used to serialized the entire {@link DeadlineMessage} into the * {@link JobDataMap}. This is only kept for backwards compatibility. The second is the new solution which * stores all the required deadline fields separately, only de-/serializing the payload and metadata of a * DeadlineMessage instead of the entire message. * * @param serializer the {@link Serializer} used to deserialize the contents of the given {@code} jobDataMap} * into a {@link DeadlineMessage} * @param jobDataMap the {@link JobDataMap} which should contain a {@link DeadlineMessage} * @return the {@link DeadlineMessage} pulled from the {@code jobDataMap} */ public static DeadlineMessage deadlineMessage(Serializer serializer, JobDataMap jobDataMap) { if (jobDataMap.containsKey(SERIALIZED_DEADLINE_MESSAGE)) { SimpleSerializedObject<byte[]> serializedDeadlineMessage = new SimpleSerializedObject<>( (byte[]) jobDataMap.get(SERIALIZED_DEADLINE_MESSAGE), byte[].class, (String) jobDataMap.get(SERIALIZED_DEADLINE_MESSAGE_CLASS_NAME), null ); return serializer.deserialize(serializedDeadlineMessage); } return new GenericDeadlineMessage<>((String) jobDataMap.get(DEADLINE_NAME), (String) jobDataMap.get(MESSAGE_ID), deserializeDeadlinePayload(serializer, jobDataMap), deserializeDeadlineMetaData(serializer, jobDataMap), retrieveDeadlineTimestamp(jobDataMap)); }
private JobDetail buildJobDetail(DeadlineMessage deadlineMessage, ScopeDescriptor deadlineScope, JobKey jobKey) { JobDataMap jobData = DeadlineJob.DeadlineJobDataBinder.toJobData(serializer, deadlineMessage, deadlineScope); return JobBuilder.newJob(DeadlineJob.class) .withDescription(deadlineMessage.getPayloadType().getName()) .withIdentity(jobKey) .usingJobData(jobData) .build(); }
schedulerContext.get(HANDLER_INTERCEPTORS); DeadlineMessage<?> deadlineMessage = deadlineMessage(serializer, jobData); ScopeDescriptor deadlineScope = deadlineScope(serializer, jobData);
/** * Extracts a {@link DeadlineMessage} from provided {@code jobDataMap}. * * <b>Note</b> that this function is able to retrieve two different formats of DeadlineMessage. The first being * a now deprecated solution which used to serialized the entire {@link DeadlineMessage} into the * {@link JobDataMap}. This is only kept for backwards compatibility. The second is the new solution which * stores all the required deadline fields separately, only de-/serializing the payload and metadata of a * DeadlineMessage instead of the entire message. * * @param serializer the {@link Serializer} used to deserialize the contents of the given {@code} jobDataMap} * into a {@link DeadlineMessage} * @param jobDataMap the {@link JobDataMap} which should contain a {@link DeadlineMessage} * @return the {@link DeadlineMessage} pulled from the {@code jobDataMap} */ public static DeadlineMessage deadlineMessage(Serializer serializer, JobDataMap jobDataMap) { if (jobDataMap.containsKey(SERIALIZED_DEADLINE_MESSAGE)) { SimpleSerializedObject<byte[]> serializedDeadlineMessage = new SimpleSerializedObject<>( (byte[]) jobDataMap.get(SERIALIZED_DEADLINE_MESSAGE), byte[].class, (String) jobDataMap.get(SERIALIZED_DEADLINE_MESSAGE_CLASS_NAME), null ); return serializer.deserialize(serializedDeadlineMessage); } return new GenericDeadlineMessage<>((String) jobDataMap.get(DEADLINE_NAME), (String) jobDataMap.get(MESSAGE_ID), deserializeDeadlinePayload(serializer, jobDataMap), deserializeDeadlineMetaData(serializer, jobDataMap), retrieveDeadlineTimestamp(jobDataMap)); }
/** * Extracts a {@link DeadlineMessage} from provided {@code jobDataMap}. * * <b>Note</b> that this function is able to retrieve two different formats of DeadlineMessage. The first being * a now deprecated solution which used to serialized the entire {@link DeadlineMessage} into the * {@link JobDataMap}. This is only kept for backwards compatibility. The second is the new solution which * stores all the required deadline fields separately, only de-/serializing the payload and metadata of a * DeadlineMessage instead of the entire message. * * @param serializer the {@link Serializer} used to deserialize the contents of the given {@code} jobDataMap} * into a {@link DeadlineMessage} * @param jobDataMap the {@link JobDataMap} which should contain a {@link DeadlineMessage} * @return the {@link DeadlineMessage} pulled from the {@code jobDataMap} */ public static DeadlineMessage deadlineMessage(Serializer serializer, JobDataMap jobDataMap) { if (jobDataMap.containsKey(SERIALIZED_DEADLINE_MESSAGE)) { SimpleSerializedObject<byte[]> serializedDeadlineMessage = new SimpleSerializedObject<>( (byte[]) jobDataMap.get(SERIALIZED_DEADLINE_MESSAGE), byte[].class, (String) jobDataMap.get(SERIALIZED_DEADLINE_MESSAGE_CLASS_NAME), null ); return serializer.deserialize(serializedDeadlineMessage); } return new GenericDeadlineMessage<>((String) jobDataMap.get(DEADLINE_NAME), (String) jobDataMap.get(MESSAGE_ID), deserializeDeadlinePayload(serializer, jobDataMap), deserializeDeadlineMetaData(serializer, jobDataMap), retrieveDeadlineTimestamp(jobDataMap)); }
@Override public void execute(JobExecutionContext context) throws JobExecutionException { if (LOGGER.isDebugEnabled()) { LOGGER.debug("Starting a deadline job"); } JobDetail jobDetail = context.getJobDetail(); JobDataMap jobData = jobDetail.getJobDataMap(); try { SchedulerContext schedulerContext = context.getScheduler().getContext(); Serializer serializer = (Serializer) schedulerContext.get(JOB_DATA_SERIALIZER); TransactionManager transactionManager = (TransactionManager) schedulerContext.get(TRANSACTION_MANAGER_KEY); ScopeAwareProvider scopeAwareComponents = (ScopeAwareProvider) schedulerContext.get(SCOPE_AWARE_RESOLVER); DeadlineMessage<?> deadlineMessage = deadlineMessage(serializer, jobData); ScopeDescriptor deadlineScope = deadlineScope(serializer, jobData); DefaultUnitOfWork<DeadlineMessage<?>> unitOfWork = DefaultUnitOfWork.startAndGet(deadlineMessage); unitOfWork.attachTransaction(transactionManager); unitOfWork.execute(() -> executeScheduledDeadline(scopeAwareComponents, deadlineMessage, deadlineScope)); if (LOGGER.isInfoEnabled()) { LOGGER.info("Job successfully executed. Deadline message [{}] processed.", deadlineMessage.getPayloadType().getSimpleName()); } } catch (Exception e) { LOGGER.error("Exception occurred during processing a deadline job [{}]", jobDetail.getDescription(), e); throw new JobExecutionException(e); } }
/** * Serializes the provided {@code deadlineMessage} and {@code deadlineScope} and puts them in a {@link * JobDataMap}. * * @param serializer the {@link Serializer} used to serialize the given {@code deadlineMessage} and {@code * deadlineScope} * @param deadlineMessage the {@link DeadlineMessage} to be handled * @param deadlineScope the {@link ScopeDescriptor} of the {@link org.axonframework.messaging.Scope} the * {@code deadlineMessage} should go to. * @return a {@link JobDataMap} containing the {@code deadlineMessage} and {@code deadlineScope} */ public static JobDataMap toJobData(Serializer serializer, DeadlineMessage deadlineMessage, ScopeDescriptor deadlineScope) { JobDataMap jobData = new JobDataMap(); putDeadlineMessage(jobData, deadlineMessage, serializer); putDeadlineScope(jobData, deadlineScope, serializer); return jobData; }
/** * Serializes the provided {@code deadlineMessage} and {@code deadlineScope} and puts them in a {@link * JobDataMap}. * * @param serializer the {@link Serializer} used to serialize the given {@code deadlineMessage} and {@code * deadlineScope} * @param deadlineMessage the {@link DeadlineMessage} to be handled * @param deadlineScope the {@link ScopeDescriptor} of the {@link org.axonframework.messaging.Scope} the * {@code deadlineMessage} should go to. * @return a {@link JobDataMap} containing the {@code deadlineMessage} and {@code deadlineScope} */ public static JobDataMap toJobData(Serializer serializer, DeadlineMessage deadlineMessage, ScopeDescriptor deadlineScope) { JobDataMap jobData = new JobDataMap(); putDeadlineMessage(jobData, deadlineMessage, serializer); putDeadlineScope(jobData, deadlineScope, serializer); return jobData; }
private JobDetail buildJobDetail(DeadlineMessage deadlineMessage, ScopeDescriptor deadlineScope, JobKey jobKey) { JobDataMap jobData = DeadlineJob.DeadlineJobDataBinder.toJobData(serializer, deadlineMessage, deadlineScope); return JobBuilder.newJob(DeadlineJob.class) .withDescription(deadlineMessage.getPayloadType().getName()) .withIdentity(jobKey) .usingJobData(jobData) .build(); }
private JobDetail buildJobDetail(DeadlineMessage deadlineMessage, ScopeDescriptor deadlineScope, JobKey jobKey) { JobDataMap jobData = DeadlineJob.DeadlineJobDataBinder.toJobData(serializer, deadlineMessage, deadlineScope); return JobBuilder.newJob(DeadlineJob.class) .withDescription(deadlineMessage.getPayloadType().getName()) .withIdentity(jobKey) .usingJobData(jobData) .build(); }
/** * Serializes the provided {@code deadlineMessage} and {@code deadlineScope} and puts them in a {@link * JobDataMap}. * * @param serializer the {@link Serializer} used to serialize the given {@code deadlineMessage} and {@code * deadlineScope} * @param deadlineMessage the {@link DeadlineMessage} to be handled * @param deadlineScope the {@link ScopeDescriptor} of the {@link org.axonframework.messaging.Scope} the * {@code deadlineMessage} should go to. * @return a {@link JobDataMap} containing the {@code deadlineMessage} and {@code deadlineScope} */ public static JobDataMap toJobData(Serializer serializer, DeadlineMessage deadlineMessage, ScopeDescriptor deadlineScope) { JobDataMap jobData = new JobDataMap(); putDeadlineMessage(jobData, deadlineMessage, serializer); putDeadlineScope(jobData, deadlineScope, serializer); return jobData; }