activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rajdav...@apache.org
Subject svn commit: r538519 - in /activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/jmx: ./ JMXComponent.java JMXConsumer.java JMXEndpoint.java JMXExchange.java JMXMessage.java package.html
Date Wed, 16 May 2007 10:22:19 GMT
Author: rajdavies
Date: Wed May 16 03:22:09 2007
New Revision: 538519

URL: http://svn.apache.org/viewvc?view=rev&rev=538519
Log:
listen for JMX events

Added:
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/jmx/
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/jmx/JMXComponent.java
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/jmx/JMXConsumer.java
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/jmx/JMXEndpoint.java
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/jmx/JMXExchange.java
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/jmx/JMXMessage.java
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/jmx/package.html

Added: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/jmx/JMXComponent.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/jmx/JMXComponent.java?view=auto&rev=538519
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/jmx/JMXComponent.java
(added)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/jmx/JMXComponent.java
Wed May 16 03:22:09 2007
@@ -0,0 +1,59 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.jmx;
+
+import java.util.Map;
+import javax.management.MBeanServer;
+import org.apache.camel.CamelContext;
+import org.apache.camel.Endpoint;
+import org.apache.camel.impl.DefaultComponent;
+import org.apache.camel.util.IntrospectionSupport;
+
+/**
+ * The <a href="http://activemq.apache.org/camel/jmx.html">JMX Component</a>
for monitoring jmx attributes
+ *
+ * @version $Revision: 523772 $
+ */
+public class JMXComponent extends DefaultComponent <JMXExchange>{
+	private MBeanServer mbeanServer;
+	
+    public JMXComponent() {
+    }
+
+    public JMXComponent(CamelContext context) {
+        super(context);
+    }
+
+    protected Endpoint<JMXExchange> createEndpoint(String uri, String remaining, Map
parameters) throws Exception {
+       
+        JMXEndpoint result = new JMXEndpoint(remaining, this);
+        IntrospectionSupport.setProperties(result, parameters);
+        result.setMbeanServer(getMbeanServer());
+        return result;
+    }
+
+	
+    public MBeanServer getMbeanServer(){
+    	return mbeanServer;
+    }
+
+	
+    public void setMbeanServer(MBeanServer mbeanServer){
+    	this.mbeanServer=mbeanServer;
+    }
+}

Added: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/jmx/JMXConsumer.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/jmx/JMXConsumer.java?view=auto&rev=538519
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/jmx/JMXConsumer.java
(added)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/jmx/JMXConsumer.java
Wed May 16 03:22:09 2007
@@ -0,0 +1,46 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.jmx;
+
+import javax.management.Notification;
+import javax.management.NotificationListener;
+import org.apache.camel.Processor;
+import org.apache.camel.impl.DefaultConsumer;
+
+/**
+ * Generate an Exchange after getting a JMX Notification
+ * @version $Revision: 523016 $
+ */
+public class JMXConsumer extends DefaultConsumer implements
+        NotificationListener {
+
+	JMXEndpoint jmxEndpoint;
+
+	public JMXConsumer(JMXEndpoint endpoint,Processor processor){
+		super(endpoint,processor);
+		this.jmxEndpoint=endpoint;
+	}
+
+	public void handleNotification(Notification notification,Object handback){
+		try{
+			getProcessor().process(jmxEndpoint.createExchange(notification));
+		}catch(Throwable e){
+			handleException(e);
+		}
+	}
+}

Added: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/jmx/JMXEndpoint.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/jmx/JMXEndpoint.java?view=auto&rev=538519
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/jmx/JMXEndpoint.java
(added)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/jmx/JMXEndpoint.java
Wed May 16 03:22:09 2007
@@ -0,0 +1,162 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.jmx;
+
+import javax.management.MBeanServer;
+import javax.management.Notification;
+import javax.management.ObjectName;
+import javax.management.monitor.CounterMonitor;
+import org.apache.camel.Consumer;
+import org.apache.camel.Processor;
+import org.apache.camel.Producer;
+import org.apache.camel.impl.DefaultEndpoint;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * Creates a CounterMonitor for jmx attributes
+ *
+ * @version $Revision: 523016 $
+ */
+public class JMXEndpoint extends DefaultEndpoint<JMXExchange> {
+
+	private static final Log log=LogFactory.getLog(JMXEndpoint.class);
+	private String name;
+	private ObjectName ourName;
+	private String observedObjectName;
+	private String attributeName;
+	private long granularityPeriod=5000;
+	private Number threshold;
+	private Number offset;
+	private MBeanServer mbeanServer;
+	private CounterMonitor counterMonitor=new CounterMonitor();
+
+	protected JMXEndpoint(String endpointUri,JMXComponent component){
+		super(endpointUri,component);
+		observedObjectName=endpointUri;
+	}
+
+	/**
+	 * @return a Producer
+	 * @throws Exception
+	 * @see org.apache.camel.Endpoint#createProducer()
+	 */
+	public Producer<JMXExchange> createProducer() throws Exception{
+		throw new RuntimeException("Not supported");
+	}
+
+	/**
+	 * @param proc
+	 * @return a Consumer
+	 * @throws Exception
+	 * @see org.apache.camel.Endpoint#createConsumer(org.apache.camel.Processor)
+	 */
+	public Consumer<JMXExchange> createConsumer(Processor proc)
+	        throws Exception{
+		ObjectName observedName=new ObjectName(observedObjectName);
+		if(name==null){
+			String type=observedName.getKeyProperty("type");
+			type=type!=null?type:"UNKNOWN";
+			name=mbeanServer.getDefaultDomain()+":type=CounterMonitor_"+type;
+		}
+		JMXConsumer result=new JMXConsumer(this,proc);
+		ourName=new ObjectName(name);
+		counterMonitor.setNotify(true);
+		counterMonitor.addObservedObject(observedName);
+		counterMonitor.setObservedAttribute(attributeName);
+		counterMonitor.setGranularityPeriod(granularityPeriod);
+		counterMonitor.setDifferenceMode(false);
+		counterMonitor.setInitThreshold(threshold);
+		counterMonitor.setOffset(offset);
+		mbeanServer.registerMBean(counterMonitor,ourName);
+		mbeanServer.addNotificationListener(ourName,result,null,new Object());
+		return result;
+	}
+
+	public boolean isSingleton(){
+		return true;
+	}
+
+	public JMXExchange createExchange(Notification notification){
+		return new JMXExchange(getContext(),notification);
+	}
+
+	public JMXExchange createExchange(){
+		return new JMXExchange(getContext(),null);
+	}
+
+	
+    public String getAttributeName(){
+    	return attributeName;
+    }
+
+	
+    public void setAttributeName(String attributeName){
+    	this.attributeName=attributeName;
+    }
+
+	
+    public long getGranularityPeriod(){
+    	return granularityPeriod;
+    }
+
+	
+    public void setGranularityPeriod(long granularityPeriod){
+    	this.granularityPeriod=granularityPeriod;
+    }
+
+	
+    public String getName(){
+    	return name;
+    }
+
+	
+    public void setName(String name){
+    	this.name=name;
+    }
+
+	
+    public Number getOffset(){
+    	return offset;
+    }
+
+	
+    public void setOffset(Number offset){
+    	this.offset=offset;
+    }
+
+	
+    public Number getThreshold(){
+    	return threshold;
+    }
+
+	
+    public void setThreshold(Number threshold){
+    	this.threshold=threshold;
+    }
+
+	
+    public MBeanServer getMbeanServer(){
+    	return mbeanServer;
+    }
+
+	
+    public void setMbeanServer(MBeanServer mbeanServer){
+    	this.mbeanServer=mbeanServer;
+    }
+}

Added: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/jmx/JMXExchange.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/jmx/JMXExchange.java?view=auto&rev=538519
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/jmx/JMXExchange.java
(added)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/jmx/JMXExchange.java
Wed May 16 03:22:09 2007
@@ -0,0 +1,41 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.jmx;
+
+import javax.management.Notification;
+import org.apache.camel.CamelContext;
+import org.apache.camel.Exchange;
+import org.apache.camel.impl.DefaultExchange;
+
+/**
+ * A {@link Exchange} for a jmx notification
+ * 
+ * @version $Revision: 520985 $
+ */
+public class JMXExchange extends DefaultExchange {
+
+	/**
+	 * Constructor
+	 * @param camelContext
+	 * @param file
+	 */
+	public JMXExchange(CamelContext camelContext,Notification notification){
+		super(camelContext);
+		setIn(new JMXMessage(notification));
+	}
+}

Added: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/jmx/JMXMessage.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/jmx/JMXMessage.java?view=auto&rev=538519
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/jmx/JMXMessage.java
(added)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/jmx/JMXMessage.java
Wed May 16 03:22:09 2007
@@ -0,0 +1,57 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.jmx;
+
+import javax.management.Notification;
+import org.apache.camel.Exchange;
+import org.apache.camel.impl.DefaultMessage;
+
+/**
+ * A {@link Message} for a JMX Notification
+ * 
+ * @version $Revision: 520985 $
+ */
+public class JMXMessage extends DefaultMessage {
+
+	private Notification notification;
+
+	public JMXMessage() {
+        this(null);
+    }
+
+	public JMXMessage(Notification notification){
+		this.notification=notification;
+	}
+
+	@Override public String toString(){
+		return "JMXMessage: "+notification;
+	}
+
+	@Override public JMXExchange getExchange(){
+		return (JMXExchange)super.getExchange();
+	}
+
+	@Override public JMXMessage newInstance(){
+		return new JMXMessage();
+	}
+
+	
+    public Notification getNotification(){
+    	return notification;
+    }
+}

Added: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/jmx/package.html
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/jmx/package.html?view=auto&rev=538519
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/jmx/package.html
(added)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/jmx/package.html
Wed May 16 03:22:09 2007
@@ -0,0 +1,25 @@
+<!--
+    Licensed to the Apache Software Foundation (ASF) under one or more
+    contributor license agreements.  See the NOTICE file distributed with
+    this work for additional information regarding copyright ownership.
+    The ASF licenses this file to You under the Apache License, Version 2.0
+    (the "License"); you may not use this file except in compliance with
+    the License.  You may obtain a copy of the License at
+   
+    http://www.apache.org/licenses/LICENSE-2.0
+   
+    Unless required by applicable law or agreed to in writing, software
+    distributed under the License is distributed on an "AS IS" BASIS,
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    See the License for the specific language governing permissions and
+    limitations under the License.
+-->
+<html>
+<head>
+</head>
+<body>
+
+The <a href="http://activemq.apache.org/camel/jmx.html">JMX Component</a> for
monitoring JMX Attributes uisng a CounterMonitor.
+
+</body>
+</html>



Mime
View raw message