[jboss-svn-commits] JBL Code SVN: r29646 - in labs/jbossesb/trunk/product/tools/jonplugin/src/main: resources/META-INF and 1 other directory.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Sun Oct 18 22:08:26 EDT 2009
Author: tcunning
Date: 2009-10-18 22:08:25 -0400 (Sun, 18 Oct 2009)
New Revision: 29646
Added:
labs/jbossesb/trunk/product/tools/jonplugin/src/main/java/org/jbosson/plugins/jbossesb/ESBMessageEventPoller.java
Modified:
labs/jbossesb/trunk/product/tools/jonplugin/src/main/java/org/jbosson/plugins/jbossesb/ServiceComponent.java
labs/jbossesb/trunk/product/tools/jonplugin/src/main/resources/META-INF/rhq-plugin.xml
Log:
JBESB-2585
Add an event poller.
Added: labs/jbossesb/trunk/product/tools/jonplugin/src/main/java/org/jbosson/plugins/jbossesb/ESBMessageEventPoller.java
===================================================================
--- labs/jbossesb/trunk/product/tools/jonplugin/src/main/java/org/jbosson/plugins/jbossesb/ESBMessageEventPoller.java (rev 0)
+++ labs/jbossesb/trunk/product/tools/jonplugin/src/main/java/org/jbosson/plugins/jbossesb/ESBMessageEventPoller.java 2009-10-19 02:08:25 UTC (rev 29646)
@@ -0,0 +1,146 @@
+/*
+ * 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.jbosson.plugins.jbossesb;
+
+import org.rhq.core.domain.event.Event;
+import org.rhq.core.domain.event.EventSeverity;
+import org.rhq.core.pluginapi.event.EventPoller;
+
+import javax.management.*;
+import javax.management.remote.*;
+import java.util.Iterator;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.Hashtable;
+import java.util.List;
+import java.util.Set;
+import java.util.Vector;
+
+import org.rhq.core.domain.event.Event;
+import org.rhq.core.domain.event.EventSeverity;
+
+import org.rhq.core.pluginapi.event.EventPoller;
+import org.rhq.core.pluginapi.inventory.ResourceDiscoveryComponent;
+import org.rhq.core.pluginapi.inventory.ResourceDiscoveryContext;
+
+import org.rhq.core.pluginapi.inventory.ResourceContext;
+
+import org.mc4j.ems.connection.EmsConnection;
+import org.mc4j.ems.connection.support.classloader.ClassLoaderFactory;
+import org.mc4j.ems.connection.bean.EmsBean;
+import org.mc4j.ems.connection.bean.attribute.EmsAttribute;
+import org.mc4j.ems.connection.bean.notification.EmsNotification;
+import org.mc4j.ems.connection.bean.notification.EmsNotificationEvent;
+import org.mc4j.ems.connection.bean.notification.EmsNotificationListener;
+import org.mc4j.ems.connection.bean.operation.EmsOperation;
+
+/**
+ * Message event poller. Grabs notifications from the MessageAlerts MBean and
+ * converts them into Events. Clears the MessageAlerts ArrayList after collecting
+ * the notifications.
+ *
+ * A better implementation of this would use EmsNotification, but EmsNotifications do
+ * not seem to add a listener and collect Notifications properly.
+ *
+ * @author <a href="mailto:tcunning at redhat.com">tcunning at redhat.com</a>
+ */
+public class ESBMessageEventPoller implements EventPoller {
+ 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 MESSAGE_ALERTS_BEAN = "jboss.esb:service=MessageAlerts";
+ public static final String ALERTS_ATTRIBUTE = "Alerts";
+ public static final String CLEAR_ALERT_OPERATION = "clearAlerts";
+
+ 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 final Set<Event> events = new HashSet<Event>();
+ private String eventType;
+ private EmsBean emsbean;
+ private EmsConnection connection;
+
+ /**
+ * Constructor
+ * @param eventType
+ */
+ public ESBMessageEventPoller(String eventType) {
+ this.eventType = eventType;
+ emsbean = null;
+ connection = null;
+ }
+
+ /**
+ * Set the Ems connection and grab the emsbean.
+ * @param connection
+ */
+ public void setConnection(EmsConnection connection) {
+ this.connection = connection;
+ this.emsbean = connection.getBean(MESSAGE_ALERTS_BEAN);
+ }
+
+ /** Return the type of events we handle
+ * @see org.rhq.core.pluginapi.event.EventPoller#getEventType()
+ */
+ public String getEventType() {
+ return eventType;
+ }
+
+ /** Return collected events
+ * @see org.rhq.core.pluginapi.event.EventPoller#poll()
+ */
+ public Set<Event> poll() {
+ synchronized(emsbean) {
+ if (emsbean != null) {
+ try {
+ EmsAttribute alertAttribute = emsbean.getAttribute(ALERTS_ATTRIBUTE);
+ if (alertAttribute != null) {
+ List<Hashtable> notifList = null;
+ notifList = (ArrayList<Hashtable>) alertAttribute.refresh();
+ for (Hashtable notifHash : notifList) {
+ long timestamp = (new Long ((String) notifHash.get(NOTIFICATION_TIMESTAMP_LONG))).longValue();
+
+ Event event = new Event(getEventType(),
+ ((String)notifHash.get(NOTIFICATION_TYPE)),
+ timestamp,
+ EventSeverity.WARN,
+ ((String)notifHash.get(NOTIFICATION_MESSAGE)));
+ EmsOperation clear = emsbean.getOperation(CLEAR_ALERT_OPERATION);
+ clear.invoke();
+ events.add(event);
+ }
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ return events;
+ }
+}
Modified: labs/jbossesb/trunk/product/tools/jonplugin/src/main/java/org/jbosson/plugins/jbossesb/ServiceComponent.java
===================================================================
--- labs/jbossesb/trunk/product/tools/jonplugin/src/main/java/org/jbosson/plugins/jbossesb/ServiceComponent.java 2009-10-18 07:41:48 UTC (rev 29645)
+++ labs/jbossesb/trunk/product/tools/jonplugin/src/main/java/org/jbosson/plugins/jbossesb/ServiceComponent.java 2009-10-19 02:08:25 UTC (rev 29646)
@@ -59,19 +59,18 @@
private static final String OVERALL_MINUTE_METRIC_NAME = "overallMessageCountByMinute";
EventContext eventContext;
- public static final String NOTIFICATION_TYPE = "org.jboss.esb.message.alert";
+ public static final String ESB_MESSAGE_EVENT = "ESBMessageAlert";
@Override
public void start(ResourceContext<MBeanResourceComponent> context) {
super.start(context);
this.context = context;
- /*
eventContext = context.getEventContext();
- ESBMessageEventPoller ep = new ESBMessageEventPoller(NOTIFICATION_TYPE);
- ep.setEmsBean(getEmsBean());
+
+ ESBMessageEventPoller ep = new ESBMessageEventPoller(ESB_MESSAGE_EVENT);
+ ep.setConnection(getEmsConnection());
eventContext.registerEventPoller(ep, 53);
- */
}
@Override
Modified: labs/jbossesb/trunk/product/tools/jonplugin/src/main/resources/META-INF/rhq-plugin.xml
===================================================================
--- labs/jbossesb/trunk/product/tools/jonplugin/src/main/resources/META-INF/rhq-plugin.xml 2009-10-18 07:41:48 UTC (rev 29645)
+++ labs/jbossesb/trunk/product/tools/jonplugin/src/main/resources/META-INF/rhq-plugin.xml 2009-10-19 02:08:25 UTC (rev 29646)
@@ -11,7 +11,7 @@
<depends plugin="JMX" />
<depends plugin="JBossAS" useClasses="true"/>
-
+
<service name="ESB"
discovery="org.jbosson.plugins.jbossesb.ESBDiscoveryComponent"
class="org.jbosson.plugins.jbossesb.ESBComponent"
@@ -115,14 +115,16 @@
<c:simple-property name="serviceName" type="string" description="the JBoss ESB service name"/>
<c:simple-property name="categoryName" type="string" description="the JBoss ESB service category name"/>
</plugin-configuration>
+
<operation name="resetCounter" displayName="Reset the message counter" description="Reset the message counter"/>
<metric displayName="Message Count" property="overallMessageCount" category="utilization" displayType="summary" measurementType="dynamic" description="Message Count"/>
- <metric displayName="Message Count (avg)" property="overallMessageCountByMinute" category="utilization" displayType="summary" measurementType="trendsup" description="Message Count (avg)"/>
- <metric displayName="Overall Bytes" property="overallBytes" units="bytes" category="utilization" displayType="summary"
+ <metric displayName="Message Count (avg)" property="overallMessageCountByMinute" category="utilization" displayType="summary" measurementType="trendsup" description="Message Count (avg)"/>
+ <metric displayName="Overall Bytes" property="overallBytes" units="bytes" category="utilization" displayType="summary"
defaultOn="true" measurementType="dynamic" description="Overall Bytes"/>
- <metric displayName="Overall Bytes Processed" property="bytesProcessed" units="bytes" category="utilization" displayType="summary" defaultOn="true" measurementType="dynamic" description="Overall Bytes Processed"/>
- <metric displayName="Overall Bytes Failed" property="bytesFailed" units="bytes" category="utilization" displayType="summary" defaultOn="true" measurementType="dynamic" description="Overall Bytes Failed"/>
- <metric displayName="Overall Service Time Processed" property="overallTimeProcessed" units="milliseconds" category="utilization" displayType="summary" defaultOn="true" measurementType="dynamic" description="Overall Service Time Processed"/>
+ <metric displayName="Overall Bytes Processed" property="bytesProcessed" units="bytes" category="utilization" displayType="summary" defaultOn="true" measurementType="dynamic" description="Overall Bytes Processed"/>
+ <metric displayName="Overall Bytes Failed" property="bytesFailed" units="bytes" category="utilization" displayType="summary" defaultOn="true" measurementType="dynamic" description="Overall Bytes Failed"/>
+ <metric displayName="Overall Service Time Processed" property="overallTimeProcessed" units="milliseconds" category="utilization" displayType="summary" defaultOn="true" measurementType="dynamic" description="Overall Service Time Processed"/>
+ <event name="ESBMessageAlert"/>
<help>
<![CDATA[
JBoss ESB Services are the services available within a deployment.
More information about the jboss-svn-commits
mailing list