From c195d9ed1c5bb2a5c8d684eecab3585bacb0146e Mon Sep 17 00:00:00 2001 From: Mark Fisher Date: Fri, 12 Mar 2010 05:42:00 +0000 Subject: [PATCH] INT-212 Added sendSuccessCount and sendErrorCount to the AbstractMessageChannel --- .../channel/AbstractMessageChannel.java | 33 +++++++++++++++++-- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/org.springframework.integration/src/main/java/org/springframework/integration/channel/AbstractMessageChannel.java b/org.springframework.integration/src/main/java/org/springframework/integration/channel/AbstractMessageChannel.java index f536a808b1..f025020d17 100644 --- a/org.springframework.integration/src/main/java/org/springframework/integration/channel/AbstractMessageChannel.java +++ b/org.springframework.integration/src/main/java/org/springframework/integration/channel/AbstractMessageChannel.java @@ -18,6 +18,7 @@ package org.springframework.integration.channel; import java.util.List; import java.util.concurrent.CopyOnWriteArrayList; +import java.util.concurrent.atomic.AtomicLong; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -45,6 +46,10 @@ public abstract class AbstractMessageChannel extends IntegrationObjectSupport im private final Log logger = LogFactory.getLog(this.getClass()); + private final AtomicLong sendSuccessCount = new AtomicLong(); + + private final AtomicLong sendErrorCount = new AtomicLong(); + private volatile Class[] datatypes = new Class[] { Object.class }; private final ChannelInterceptorList interceptors = new ChannelInterceptorList(); @@ -57,6 +62,24 @@ public abstract class AbstractMessageChannel extends IntegrationObjectSupport im return this.getBeanName(); } + /** + * Return the current count of Messages that have been sent + * to this channel successfully. + */ + public long getSendSuccessCount() { + return this.sendSuccessCount.get(); + } + + /** + * Return the current count of errors that have occurred while + * attempting to send a Message to this channel. This value is + * incremented whenever an Exception is thrown from one of the + * send() methods. + */ + public long getSendErrorCount() { + return this.sendErrorCount.get(); + } + /** * Specify the Message payload datatype(s) supported by this channel. If a * payload type does not match directly, but the 'conversionService' is @@ -151,13 +174,17 @@ public abstract class AbstractMessageChannel extends IntegrationObjectSupport im } try { boolean sent = this.doSend(message, timeout); + if (sent) { + this.sendSuccessCount.incrementAndGet(); + } this.interceptors.postSend(message, this, sent); return sent; } - catch (MessagingException e) { - throw e; - } catch (Exception e) { + this.sendErrorCount.incrementAndGet(); + if (e instanceof MessagingException) { + throw (MessagingException) e; + } throw new MessageDeliveryException(message, "failed to send Message to channel '" + this.getName() + "'", e); }