@Override public void trigger(Message<?> message) { Object key = this.correlationStrategy.getCorrelationKey(message); if (key == null) { throw new MessagingException(message, "Correlation Strategy returned null"); } SynchronousQueue<Message<?>> syncQueue = createOrObtainQueue(key); try { if (!syncQueue.offer(message, this.timeout, TimeUnit.MILLISECONDS)) { this.logger.error("Suspending thread timed out or did not arrive within timeout for: " + message); this.suspensions.remove(key); if (getDiscardChannel() != null) { this.messagingTemplate.send(getDiscardChannel(), message); } } } catch (InterruptedException e) { Thread.currentThread().interrupt(); this.logger.error("Interrupted while waiting for the suspending thread for: " + message); this.suspensions.remove(key); } }
@Override protected Object handleRequestMessage(Message<?> requestMessage) { Object key = this.correlationStrategy.getCorrelationKey(requestMessage); if (key == null) { throw new MessagingException(requestMessage, "Correlation Strategy returned null"); } Thread existing = this.inProcess.putIfAbsent(key, Thread.currentThread()); if (existing != null) { throw new MessagingException(requestMessage, "Correlation key (" + key + ") is already in use by " + existing.getName()); } SynchronousQueue<Message<?>> syncQueue = createOrObtainQueue(key); try { Message<?> releaseMessage = syncQueue.poll(this.timeout, TimeUnit.MILLISECONDS); if (releaseMessage != null) { return processRelease(key, requestMessage, releaseMessage); } } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new MessageHandlingException(requestMessage, "Interrupted while waiting for release", e); } finally { this.inProcess.remove(key); this.suspensions.remove(key); } return null; }
@Override public void trigger(Message<?> message) { Object key = this.correlationStrategy.getCorrelationKey(message); if (key == null) { throw new MessagingException(message, "Correlation Strategy returned null"); } SynchronousQueue<Message<?>> syncQueue = createOrObtainQueue(key); try { if (!syncQueue.offer(message, this.timeout, TimeUnit.MILLISECONDS)) { this.logger.error("Suspending thread timed out or did not arrive within timeout for: " + message); this.suspensions.remove(key); if (getDiscardChannel() != null) { this.messagingTemplate.send(getDiscardChannel(), message); } } } catch (InterruptedException e) { Thread.currentThread().interrupt(); this.logger.error("Interrupted while waiting for the suspending thread for: " + message); this.suspensions.remove(key); } }
@Override protected Object handleRequestMessage(Message<?> requestMessage) { Object key = this.correlationStrategy.getCorrelationKey(requestMessage); if (key == null) { throw new MessagingException(requestMessage, "Correlation Strategy returned null"); } Thread existing = this.inProcess.putIfAbsent(key, Thread.currentThread()); if (existing != null) { throw new MessagingException(requestMessage, "Correlation key (" + key + ") is already in use by " + existing.getName()); } SynchronousQueue<Message<?>> syncQueue = createOrObtainQueue(key); try { Message<?> releaseMessage = syncQueue.poll(this.timeout, TimeUnit.MILLISECONDS); if (releaseMessage != null) { return processRelease(key, requestMessage, releaseMessage); } } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new MessageHandlingException(requestMessage, "Interrupted while waiting for release", e); } finally { this.inProcess.remove(key); this.suspensions.remove(key); } return null; }