/** * Returns a Message with the view into a {@link RedisStore} identified * by {@link #keyExpression} */ @Override protected RedisStore doReceive() { String key = this.keyExpression.getValue(this.evaluationContext, String.class); Assert.hasText(key, "Failed to determine the key for the collection"); RedisStore store = this.createStoreView(key); Object holder = TransactionSynchronizationManager.getResource(this); if (holder != null) { Assert.isInstanceOf(IntegrationResourceHolder.class, holder); ((IntegrationResourceHolder) holder).addAttribute("store", store); } if (store instanceof Collection<?> && ((Collection<?>) store).size() < 1) { return null; } else { return store; } }
holder.setMessage(message);
private void doProcess(IntegrationResourceHolder holder, Expression expression, MessageChannel messageChannel, String expressionType) { Message<?> message = holder.getMessage(); if (message != null) { if (expression != null) {
DefaultTransactionalResourceSynchronization(Object resourceKey) { super(new IntegrationResourceHolder(), resourceKey); }
/** * If we don't need variables (i.e., resource is null) * we can use a singleton context; otherwise we need a new one each time. * @param resource The resource * @return The context. */ private EvaluationContext prepareEvaluationContextToUse(Object resource) { if (resource != null) { EvaluationContext evaluationContextWithVariables = createEvaluationContext(); if (resource instanceof IntegrationResourceHolder) { IntegrationResourceHolder holder = (IntegrationResourceHolder) resource; for (Entry<String, Object> entry : holder.getAttributes().entrySet()) { String key = entry.getKey(); evaluationContextWithVariables.setVariable(key, entry.getValue()); } } return evaluationContextWithVariables; } else { return this.evaluationContext; } }
@Override public TransactionSynchronization create(Object key) { Assert.notNull(key, "'key' must not be null"); return new IntegrationResourceHolderSynchronization(new IntegrationResourceHolder(), key); }
/** * If we don't need variables (i.e., resource is null) * we can use a singleton context; otherwise we need a new one each time. * @param resource The resource * @return The context. */ private EvaluationContext prepareEvaluationContextToUse(Object resource) { if (resource != null) { EvaluationContext evaluationContextWithVariables = createEvaluationContext(); if (resource instanceof IntegrationResourceHolder) { IntegrationResourceHolder holder = (IntegrationResourceHolder) resource; for (Entry<String, Object> entry : holder.getAttributes().entrySet()) { String key = entry.getKey(); evaluationContextWithVariables.setVariable(key, entry.getValue()); } } return evaluationContextWithVariables; } else { return this.evaluationContext; } }
@Override public Message<String> receive() { GenericMessage<String> message = new GenericMessage<String>("foo"); IntegrationResourceHolder holder = (IntegrationResourceHolder) TransactionSynchronizationManager.getResource(this); holder.addAttribute("baz", "qux"); holder.addAttribute("bix", "qox"); return message; } });
private Runnable prepareSendingTask(Object mailMessage) { return () -> { @SuppressWarnings("unchecked") org.springframework.messaging.Message<?> message = mailMessage instanceof Message ? getMessageBuilderFactory().withPayload(mailMessage).build() : (org.springframework.messaging.Message<Object>) mailMessage; if (TransactionSynchronizationManager.isActualTransactionActive() && this.transactionSynchronizationFactory != null) { TransactionSynchronization synchronization = this.transactionSynchronizationFactory.create(this); if (synchronization != null) { TransactionSynchronizationManager.registerSynchronization(synchronization); if (synchronization instanceof IntegrationResourceHolderSynchronization && !TransactionSynchronizationManager.hasResource(this)) { TransactionSynchronizationManager.bindResource(this, ((IntegrationResourceHolderSynchronization) synchronization).getResourceHolder()); } Object resourceHolder = TransactionSynchronizationManager.getResource(this); if (resourceHolder instanceof IntegrationResourceHolder) { ((IntegrationResourceHolder) resourceHolder).setMessage(message); } } } sendMessage(message); }; }
private Message<?> pollForMessage() { try { return this.pollingTask.call(); } catch (Exception e) { if (e instanceof MessagingException) { throw (MessagingException) e; } else { Message<?> failedMessage = null; if (this.transactionSynchronizationFactory != null) { Object resource = TransactionSynchronizationManager.getResource(getResourceToBind()); if (resource instanceof IntegrationResourceHolder) { failedMessage = ((IntegrationResourceHolder) resource).getMessage(); } } throw new MessagingException(failedMessage, e); // NOSONAR (null failedMessage) } } finally { if (this.transactionSynchronizationFactory != null) { Object resource = getResourceToBind(); if (TransactionSynchronizationManager.hasResource(resource)) { TransactionSynchronizationManager.unbindResource(resource); } } } }
DefaultTransactionalResourceSynchronization(Object resourceKey) { super(new IntegrationResourceHolder(), resourceKey); }
@Override public Message<String> receive() { GenericMessage<String> message = new GenericMessage<String>("foo"); IntegrationResourceHolder holder = (IntegrationResourceHolder) TransactionSynchronizationManager.getResource(this); holder.addAttribute("baz", "qux"); holder.addAttribute("bix", "qox"); return message; } });
@Override public void processAfterCommit(IntegrationResourceHolder holder) { String remoteDir = (String) holder.getMessage().getHeaders().get(FileHeaders.REMOTE_DIRECTORY); String remoteFile = (String) holder.getMessage().getHeaders().get(FileHeaders.REMOTE_FILE); this.template.remove(remoteDir + this.remoteFileSeparator + remoteFile); }
@Override public TransactionSynchronization create(Object key) { Assert.notNull(key, "'key' must not be null"); return new IntegrationResourceHolderSynchronization(new IntegrationResourceHolder(), key); }
if (holder != null) { Assert.isInstanceOf(IntegrationResourceHolder.class, holder); ((IntegrationResourceHolder) holder).addAttribute("mongoTemplate", this.mongoTemplate);
TransactionSynchronizationManager.getResource(ImapIdleChannelAdapter.this); if (resourceHolder instanceof IntegrationResourceHolder) { ((IntegrationResourceHolder) resourceHolder).setMessage(message);
private void doProcess(IntegrationResourceHolder holder, Expression expression, MessageChannel messageChannel, String expressionType) { Message<?> message = holder.getMessage(); if (message != null) { if (expression != null) {
@Override public Message<String> receive() { GenericMessage<String> message = new GenericMessage<String>("foo"); ((IntegrationResourceHolder) TransactionSynchronizationManager.getResource(this)) .addAttribute("baz", testMessage); return message; } });
private Message<?> pollForMessage() { try { return this.pollingTask.call(); } catch (Exception e) { if (e instanceof MessagingException) { throw (MessagingException) e; } else { Message<?> failedMessage = null; if (this.transactionSynchronizationFactory != null) { Object resource = TransactionSynchronizationManager.getResource(getResourceToBind()); if (resource instanceof IntegrationResourceHolder) { failedMessage = ((IntegrationResourceHolder) resource).getMessage(); } } throw new MessagingException(failedMessage, e); // NOSONAR (null failedMessage) } } finally { if (this.transactionSynchronizationFactory != null) { Object resource = getResourceToBind(); if (TransactionSynchronizationManager.hasResource(resource)) { TransactionSynchronizationManager.unbindResource(resource); } } } }