[jboss-svn-commits] JBL Code SVN: r12880 - labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/message.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Wed Jun 27 00:50:08 EDT 2007


Author: tcunning
Date: 2007-06-27 00:50:08 -0400 (Wed, 27 Jun 2007)
New Revision: 12880

Added:
   labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/message/DeliveryObservableLogger.java
   labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/message/MessageCounter.java
   labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/message/MessageCounterMBean.java
   labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/message/MessageStatusBean.java
Modified:
   labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/message/ActionProcessingPipeline.java
Log:
bug:JBESB-544
Commit rudimentary message counter MBean.


Modified: labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/message/ActionProcessingPipeline.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/message/ActionProcessingPipeline.java	2007-06-27 03:54:09 UTC (rev 12879)
+++ labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/message/ActionProcessingPipeline.java	2007-06-27 04:50:08 UTC (rev 12880)
@@ -228,7 +228,8 @@
 	public boolean process(final Message message)
 	{
 		final EPR faultToAddress = getFaultToAddress(message);
-
+		long start = System.currentTimeMillis();
+		
 		if (active.get())
 		{
 			if (LOGGER.isDebugEnabled())
@@ -287,6 +288,10 @@
 						faultTo(faultToAddress, Factory.createErrorMessage(Factory.UNEXPECTED_ERROR, message, ex));
 					}
 
+					long procTime = System.currentTimeMillis() - start;
+		        	DeliveryObservableLogger.getInstance().logMessage(new MessageStatusBean(procTime, message, 
+		        			MessageStatusBean.MESSAGE_FAILED));
+					
 					return false;
 				}
 			}
@@ -298,7 +303,9 @@
 			}
 
 			notifySuccess(messages);
-			
+			long procTime = System.currentTimeMillis() - start;
+        	DeliveryObservableLogger.getInstance().logMessage(new MessageStatusBean(procTime, message, 
+        			MessageStatusBean.MESSAGE_SENT));
 			return true;
 		}
 		else
@@ -306,7 +313,10 @@
 			LOGGER.debug("pipeline process disabled for message");
 
 			faultTo(faultToAddress, Factory.createErrorMessage(Factory.NOT_ENABLED, message, null));
-
+			long procTime = System.currentTimeMillis() - start;
+        	DeliveryObservableLogger.getInstance().logMessage(new MessageStatusBean(procTime, message, 
+        			MessageStatusBean.MESSAGE_FAILED));
+        	
 			return false;
 		}
 	}

Added: labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/message/DeliveryObservableLogger.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/message/DeliveryObservableLogger.java	                        (rev 0)
+++ labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/message/DeliveryObservableLogger.java	2007-06-27 04:50:08 UTC (rev 12880)
@@ -0,0 +1,57 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA  02110-1301, USA.
+ *
+ * (C) 2005-2006, JBoss Inc.
+ */
+package org.jboss.soa.esb.listeners.message;
+
+import java.util.Observable;
+
+/**
+ * DeliveryObservableLogger is an observable which reports out to Observers.
+ *
+ * @author <a href="mailto:tcunning at redhat.com">tcunning at redhat.com</a>
+ */
+public class DeliveryObservableLogger extends Observable {
+	private static DeliveryObservableLogger ref = null;
+	
+	/**
+	 * Constructor.
+	 */
+	private DeliveryObservableLogger() {
+	}
+
+	/**
+	 * Return the instance of DeliveryObservableLogger.
+	 * @return instance of DeliveryObservableLogger
+	 */
+	public static DeliveryObservableLogger getInstance() {
+		if (ref == null) {
+			ref = new DeliveryObservableLogger();
+		} 
+		return ref;
+	}
+
+	/**
+	 * Log the message to any registered observers.
+	 * @param msb message status bean
+	 */
+	public void logMessage(MessageStatusBean msb) {
+		setChanged();
+		notifyObservers(msb);
+	}	
+}

Added: labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/message/MessageCounter.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/message/MessageCounter.java	                        (rev 0)
+++ labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/message/MessageCounter.java	2007-06-27 04:50:08 UTC (rev 12880)
@@ -0,0 +1,135 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA  02110-1301, USA.
+ *
+ * (C) 2005-2006, JBoss Inc.
+ */
+
+package org.jboss.soa.esb.listeners.message;
+
+import java.sql.Timestamp;
+import java.util.Observable;
+import java.util.Observer;
+
+import org.jboss.system.ServiceMBeanSupport;
+
+/**
+ * MessageCounter is a MBean implementation which keeps track of message data and 
+ * metadata.
+ * 
+ * @author <a href="mailto:tcunning at redhat.com">tcunning at redhat.com</a> 
+ *
+ */
+public class MessageCounter extends ServiceMBeanSupport implements MessageCounterMBean, Observer {
+
+	private String lastMessageTime;
+	private int failedMessageCount;
+	private int successMessageCount;
+	private long totalProcessTime;
+	private long totalBytes;	
+	
+	/**
+	 * Constructor.
+	 */
+	public MessageCounter () {
+		DeliveryObservableLogger.getInstance().addObserver(this);
+		resetCounts();
+	}
+	
+	/**
+	 * Get the total number of failed messages.
+	 * @return total number of failed messages
+	 */
+	public int getFailedMessageCount() {
+		return failedMessageCount;
+	}
+
+	/**
+	 * Get the time the last message was processed at.
+	 * @return time the last message was processed at
+	 */
+	public String getLastMessageTime() {
+		return lastMessageTime;
+	}
+
+	/**
+	 * Get the total number of processed messages, both successful and failed.
+	 * @return total number of processed messages
+	 */
+	public int getTotalMessageCount() {
+		return (failedMessageCount + successMessageCount);
+	}
+
+	/**
+	 * Get the total number of successfully processed messages.
+	 * @return total number of successfully processed messages
+	 */
+	public int getSuccessfulMessageCount() {
+		return successMessageCount;
+	}
+
+	/**
+	 * Update the message counter based on the MessageStatusBean that is returned
+	 * from the observable.
+	 * @param Observable the observable object
+	 * @param arg the MessageStatusBean 
+	 */
+	public void update(Observable o, Object arg) {
+		MessageStatusBean msb = (MessageStatusBean) arg;
+		
+		if (msb.getMessageStatus().equals(MessageStatusBean.MESSAGE_SENT)) {
+			successMessageCount++;
+		} else if (msb.getMessageStatus().equals(MessageStatusBean.MESSAGE_FAILED)) {
+			failedMessageCount++;
+		}
+		Timestamp ts = new Timestamp(msb.getMessageTime());
+		lastMessageTime = ts.toString();
+		
+		totalProcessTime += msb.getProcessTime();
+		totalBytes += msb.getMessage().getBody().getByteArray().length;
+	}
+
+	/**
+	 * Get the average time to process a message.
+	 * @return average time to process a message 
+	 */
+	public long getAverageTime() {
+		if ((successMessageCount + failedMessageCount ) > 0) {
+			return (totalProcessTime / (successMessageCount + failedMessageCount));
+		} else {
+			return 0;
+		}
+	}
+
+	/**
+	 * Get the average bytes of the processed messages.
+	 * @return average bytes of the messages processed
+	 */
+	public long getAverageBytes() {
+		return (totalBytes / (successMessageCount + failedMessageCount));
+	}
+	
+	/**
+	 * Reset the counts - this resets the totals and the last message time. 
+	 */
+	public void resetCounts() {
+		lastMessageTime = null;
+		successMessageCount = 0;
+		failedMessageCount = 0;
+		totalProcessTime = 0;
+		totalBytes = 0;
+	}
+}

Added: labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/message/MessageCounterMBean.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/message/MessageCounterMBean.java	                        (rev 0)
+++ labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/message/MessageCounterMBean.java	2007-06-27 04:50:08 UTC (rev 12880)
@@ -0,0 +1,46 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA  02110-1301, USA.
+ *
+ * (C) 2005-2006, JBoss Inc.
+ */
+package org.jboss.soa.esb.listeners.message;
+
+import org.jboss.system.ServiceMBean;
+
+/**
+ * MBean to represent simple message counting.    Stores the number of succesful and
+ * failed messages, the last message time, total bytes and time, and has the ability
+ * to reset all counts.    
+ * 
+ * @author <a href="mailto:tcunning at redhat.com">tcunning at redhat.com</a> 
+ *
+ */
+public interface MessageCounterMBean extends ServiceMBean {
+	public int getTotalMessageCount();
+	
+	public int getSuccessfulMessageCount();
+	
+	public int getFailedMessageCount();
+	
+	public String getLastMessageTime();
+
+	public long getAverageTime();
+	
+	public long getAverageBytes();
+	
+	public void resetCounts();
+}

Added: labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/message/MessageStatusBean.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/message/MessageStatusBean.java	                        (rev 0)
+++ labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/message/MessageStatusBean.java	2007-06-27 04:50:08 UTC (rev 12880)
@@ -0,0 +1,124 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA  02110-1301, USA.
+ *
+ * (C) 2005-2006, JBoss Inc.
+ */
+package org.jboss.soa.esb.listeners.message;
+
+import org.jboss.soa.esb.message.Message;
+
+/**
+ * Bean that stores data on the message status.    Since the Observer/Observable
+ * java scheme only allows us to pass a single object, we store all the required 
+ * data and metadata for reporting here.
+ * 
+ * @author <a href="mailto:tcunning at redhat.com">tcunning at redhat.com</a> 
+ *
+ */
+public class MessageStatusBean {
+	private Message m_msg;
+	private String m_status;
+	private long m_messageTime;
+	private long m_processTime;
+	
+	public static final String MESSAGE_SENT = "SENT";
+	public static final String MESSAGE_FAILED = "FAILED";
+	
+	/**
+	 * Constructor.
+	 */
+	public MessageStatusBean() {
+	}
+	
+	/**
+	 * Constructor.
+	 * 
+	 * @param f_processTime  Time it takes to process message.
+	 * @param f_msg the message
+	 * @param f_status status 
+	 */
+	public MessageStatusBean(long f_processTime, Message f_msg, String f_status) {
+		this.m_processTime = f_processTime;
+		this.m_msg = f_msg;
+		this.m_status = f_status;
+		this.m_messageTime = System.currentTimeMillis();
+	}
+	
+	/**
+	 * Message getter.
+	 * @return the Message
+	 */
+	public Message getMessage() {
+		return m_msg;
+	}
+	
+	/**
+	 * Message mutator.
+	 * @param f_msg the Message
+	 */
+	public void setMessage(Message f_msg) {
+		this.m_msg = f_msg;
+	}
+	
+	/**
+	 * Message status getter.
+	 * @return message status
+	 */
+	public String getMessageStatus() {
+		return m_status;
+	}
+	
+	/**
+	 * Message status mutator.
+	 * @param f_status message status 
+	 */
+	public void setMessageStatus(String f_status) {
+		this.m_status = f_status;
+	}
+	
+	/**
+	 * Message time getter.
+	 * @return the time when the message was sent
+	 */
+	public long getMessageTime() {
+		return m_messageTime;
+	}
+	
+	/**
+	 * Message time mutator.
+	 * @param f_messageTime the time the message was sent 
+	 */
+	public void setMessageTime(long f_messageTime) {
+		m_messageTime = f_messageTime;
+	}
+	
+	/**
+	 * Process time getter.
+	 * @return processing time of the message
+	 */
+	public long getProcessTime() {
+		return m_processTime;
+	}
+	
+	/**
+	 * Process time mutator.
+	 * @param f_processTime processing time of the message
+	 */
+	public void setProcessTime(long f_processTime) {
+		this.m_processTime = f_processTime;
+	}
+}




More information about the jboss-svn-commits mailing list