[jboss-svn-commits] JBL Code SVN: r29647 - 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
Sun Oct 18 22:10:43 EDT 2009
Author: tcunning
Date: 2009-10-18 22:10:43 -0400 (Sun, 18 Oct 2009)
New Revision: 29647
Added:
labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/message/MessageAlerts.java
labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/message/MessageAlertsMBean.java
Modified:
labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/message/ServiceMessageCounter.java
Log:
JBESB-2585
Add MessageAlerts notification listener.
Added: labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/message/MessageAlerts.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/message/MessageAlerts.java (rev 0)
+++ labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/message/MessageAlerts.java 2009-10-19 02:10:43 UTC (rev 29647)
@@ -0,0 +1,72 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY 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 along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.soa.esb.listeners.message;
+
+import java.util.ArrayList;
+import java.util.Hashtable;
+import java.util.List;
+
+import javax.management.Notification;
+import javax.management.NotificationListener;
+
+/**
+ * MessageAlertsMBean implementation. Listens for MBean notifications from
+ * services and actions and stores them in an ArrayList.
+ *
+ * @author <a href="mailto:tcunning at redhat.com">tcunning at redhat.com</a>
+ */
+public class MessageAlerts
+ implements MessageAlertsMBean, NotificationListener {
+ private static final String NOTIFICATION_MESSAGE = "notificationMessage";
+ private static final String NOTIFICATION_SOURCE = "notificationSource";
+ private static final String NOTIFICATION_SEQUENCE_LONG = "notificationSequence";
+ private static final String NOTIFICATION_TIMESTAMP_LONG = "notificationTimestamp";
+ private static final String NOTIFICATION_TYPE = "notificationType";
+
+ private static ArrayList<Hashtable> alerts;
+
+ public MessageAlerts() {
+ alerts = new ArrayList<Hashtable>();
+ }
+
+ @Override
+ public void clearAlerts() {
+ alerts = new ArrayList<Hashtable>();
+ }
+
+ @Override
+ public ArrayList<Hashtable> getAlerts() {
+ return alerts;
+ }
+
+ @Override
+ public void handleNotification(Notification notification, Object handback) {
+ String source = notification.getSource().toString();
+ Hashtable<String,String> notifHash = new Hashtable<String, String>();
+ notifHash.put(NOTIFICATION_MESSAGE, notification.getMessage());
+ notifHash.put(NOTIFICATION_SOURCE, source);
+ notifHash.put(NOTIFICATION_SEQUENCE_LONG, new String("" + notification.getSequenceNumber()));
+ notifHash.put(NOTIFICATION_TIMESTAMP_LONG, new String("" + notification.getTimeStamp()));
+ notifHash.put(NOTIFICATION_TYPE, notification.getType());
+ alerts.add(notifHash);
+ }
+}
Added: labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/message/MessageAlertsMBean.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/message/MessageAlertsMBean.java (rev 0)
+++ labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/message/MessageAlertsMBean.java 2009-10-19 02:10:43 UTC (rev 29647)
@@ -0,0 +1,35 @@
+/*
+ * 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.ArrayList;
+import java.util.Hashtable;
+
+/**
+ * MBean to represent message alerts. Stores an array of alerts.
+ *
+ * @author <a href="mailto:tcunning at redhat.com">tcunning at redhat.com</a>
+ *
+ */
+public interface MessageAlertsMBean {
+ public ArrayList<Hashtable> getAlerts();
+
+ public void clearAlerts();
+}
Modified: labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/message/ServiceMessageCounter.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/message/ServiceMessageCounter.java 2009-10-19 02:08:25 UTC (rev 29646)
+++ labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/message/ServiceMessageCounter.java 2009-10-19 02:10:43 UTC (rev 29647)
@@ -22,6 +22,7 @@
package org.jboss.soa.esb.listeners.message;
+import java.io.Serializable;
import java.lang.reflect.Method;
import java.util.Enumeration;
import java.util.Hashtable;
@@ -37,10 +38,13 @@
import javax.management.MBeanAttributeInfo;
import javax.management.MBeanException;
import javax.management.MBeanInfo;
+import javax.management.MBeanNotificationInfo;
import javax.management.MBeanOperationInfo;
import javax.management.MBeanRegistrationException;
import javax.management.MBeanServer;
import javax.management.NotCompliantMBeanException;
+import javax.management.Notification;
+import javax.management.NotificationBroadcasterSupport;
import javax.management.ObjectName;
import javax.management.ReflectionException;
@@ -62,7 +66,8 @@
* @author <a href="mailto:tcunning at redhat.com">tcunning at redhat.com</a>
* @since Version 4.2
*/
-public class ServiceMessageCounter implements DynamicMBean {
+public class ServiceMessageCounter extends NotificationBroadcasterSupport
+ implements DynamicMBean, Serializable {
private Hashtable<String, IntHolder> actionCounterHash;
private Hashtable<String, IntHolder> actionFailedCounterHash;
private Hashtable<String, LongHolder> actionProcessTimeHash;
@@ -81,8 +86,15 @@
private long bytesOverall;
private long timeProcessed;
+ private int notificationindex;
private Long alertTime = new Long("-1");
private Long alertLength = new Long("-1");
+
+ public static final String SERVICE_LENGTH_NOTIFICATION_TYPE = "org.jboss.esb.message.service.length.alert";
+ public static final String SERVICE_TIME_NOTIFICATION_TYPE = "org.jboss.esb.message.service.time.alert";
+ public static final String ACTION_LENGTH_NOTIFICATION_TYPE = "org.jboss.esb.message.action.length.alert";
+ public static final String ACTION_TIME_NOTIFICATION_TYPE = "org.jboss.esb.message.action.time.alert";
+
public static final String RESET_COUNTER = "resetCounter";
private static final String MESSAGE_COUNTER = "messages successfully processed count";
@@ -190,6 +202,8 @@
actionLengthThresholdHash = new Hashtable<String, Long>();
actionTimeThresholdHash = new Hashtable<String, Long>();
+ notificationindex = 0;
+
if (f_config.getAttribute(ListenerTagNames.SERVICE_ALERT_LENGTH_TAG) != null) {
alertLength = new Long(f_config.getAttribute(ListenerTagNames.SERVICE_ALERT_LENGTH_TAG));
}
@@ -254,7 +268,7 @@
actionLengthThresholdHash.put(actionId, new Long(actionConfig.getAttribute(ListenerTagNames.ACTION_ALERT_LENGTH_TAG)));
}
if (actionConfig.getAttribute(ListenerTagNames.ACTION_ALERT_TIME_TAG) != null) {
- actionTimeThresholdHash.put(actionId, new Long(actionConfig.getAttribute(ListenerTagNames.ACTION_ALERT_LENGTH_TAG)));
+ actionTimeThresholdHash.put(actionId, new Long(actionConfig.getAttribute(ListenerTagNames.ACTION_ALERT_TIME_TAG)));
}
actionNames[count] = actionId ;
}
@@ -275,7 +289,7 @@
bytesFailed = 0 ;
bytesOverall = 0;
timeProcessed = 0;
-
+
for (String key : actionCounterHash.keySet()) {
actionCounterHash.put(key, new IntHolder());
}
@@ -377,13 +391,10 @@
attrs[counter] = alertTimeInfo;
counter++;
} catch (SecurityException e) {
- // TODO Auto-generated catch block
e.printStackTrace();
} catch (NoSuchMethodException e) {
- // TODO Auto-generated catch block
e.printStackTrace();
} catch (IntrospectionException e) {
- // TODO Auto-generated catch block
e.printStackTrace();
}
@@ -450,6 +461,7 @@
// TODO Auto-generated catch block
e.printStackTrace();
}
+ MBeanNotificationInfo[] notifications = getNotificationInfo();
MBeanOperationInfo[] opers = {
new MBeanOperationInfo(
@@ -458,7 +470,7 @@
};
return new MBeanInfo(
this.getClass().getName(), "Service Message Counter MBean",
- attrs, null, opers, null); // notifications
+ attrs, null, opers, notifications); // notifications
}
/* (non-Javadoc)
@@ -608,6 +620,21 @@
try {
mbeanServer.registerMBean(this, listObjectName);
+
+ MessageAlerts alerts = new MessageAlerts();
+ // Find out whether the MessageAlerts Bean has been registered
+ try {
+ ObjectName alertObjectName = new ObjectName("jboss.esb:service=MessageAlerts");
+ if (!mbeanServer.isRegistered(alertObjectName)) {
+ mbeanServer.registerMBean(alerts, alertObjectName);
+ }
+
+ if (isAlertsEnabled()) {
+ addNotificationListener(alerts, null, null);
+ }
+ } catch (Exception e) {
+ logger.warn("", e);
+ }
} catch (InstanceAlreadyExistsException e) {
logger.warn("", e);
} catch (MBeanRegistrationException e) {
@@ -648,23 +675,39 @@
public synchronized void alertService (ActionStatusBean asb) {
if (!(this.getAlertTime().longValue() < 0)) {
if ( (asb.getServiceTime() / NANOSECONDS_PER_MILLISECONDS) > this.getAlertTime().longValue()) {
- logger.warn(this.getObjectName().toString()
+ String alert = this.getObjectName().toString()
+ " service alert time " + (asb.getServiceTime() / NANOSECONDS_PER_MILLISECONDS)
+ " took longer than " + this.getAlertTime()
- + " ms");
+ + " ms";
+ logger.warn(alert);
+ Notification n = new Notification (ALERT_TIME, this,
+ notificationindex++, System.currentTimeMillis(), alert);
+ sendNotification(n);
}
}
if (!(this.getAlertLength().longValue() < 0)) {
if (asb.getBytesProcessed() > this.getAlertLength().longValue()) {
- logger.warn(this.getObjectName().toString()
+ String alert = this.getObjectName().toString()
+ " service message size " + asb.getBytesProcessed()
+ " was larger than " + this.getAlertLength()
- + " bytes");
+ + " bytes";
+ logger.warn(alert);
+ Notification n = new Notification (ALERT_LENGTH, this,
+ notificationindex++, System.currentTimeMillis(), alert);
+ sendNotification(n);
}
}
}
+ public boolean isAlertsEnabled() {
+ boolean value = ((this.getAlertLength().longValue() > 0) ||
+ (this.getAlertTime().longValue() > 0) ||
+ (this.getActionAlertLength().longValue() > 0) ||
+ (this.getActionAlertTime().longValue() > 0));
+ return value;
+ }
+
/*
* Produce alerts for actions if the length or time thresholds are met.
*/
@@ -675,10 +718,14 @@
}
if (!(actionTime < 0)) {
if ( (asb.getProcTime() / NANOSECONDS_PER_MILLISECONDS) > actionTime) {
- logger.warn(this.getObjectName().toString() + " service, " + actionName
+ String alert = this.getObjectName().toString() + " service, " + actionName
+ " action alert time " + (asb.getProcTime() / NANOSECONDS_PER_MILLISECONDS)
+ " took longer than " + actionTime
- + " ms");
+ + " ms";
+ logger.warn(alert);
+ Notification n = new Notification (ACTION_ALERT_TIME, this,
+ notificationindex++, System.currentTimeMillis(), alert);
+ sendNotification(n);
}
}
@@ -688,10 +735,14 @@
}
if (!(actionLength < 0)) {
if (asb.getBytesProcessed() > actionLength) {
- logger.warn(this.getObjectName().toString() + " service, " + actionName
+ String alert = this.getObjectName().toString() + " service, " + actionName
+ " action message size " + asb.getBytesProcessed()
+ " was larger than " + actionLength
- + " bytes");
+ + " bytes";
+ logger.warn(alert);
+ Notification n = new Notification (ACTION_ALERT_LENGTH, this,
+ notificationindex++, System.currentTimeMillis(), alert);
+ sendNotification(n);
}
}
}
@@ -740,7 +791,7 @@
}
// Very basic holder classes
- private static final class IntHolder
+ private static final class IntHolder implements Serializable
{
int value ;
@Override
@@ -749,7 +800,7 @@
}
}
- private static final class LongHolder
+ private static final class LongHolder implements Serializable
{
long value ;
@Override
@@ -758,4 +809,12 @@
}
}
+ @Override
+ public MBeanNotificationInfo[] getNotificationInfo() {
+ return new MBeanNotificationInfo[] {
+ new MBeanNotificationInfo(new String[] {SERVICE_TIME_NOTIFICATION_TYPE, SERVICE_LENGTH_NOTIFICATION_TYPE, ACTION_TIME_NOTIFICATION_TYPE, ACTION_LENGTH_NOTIFICATION_TYPE},
+ "javax.management.Notification", "JBoss ESB message alert notification")
+ };
+ }
+
}
More information about the jboss-svn-commits
mailing list