You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by js...@apache.org on 2008/08/14 16:09:54 UTC
svn commit: r685904 [1/2] - in
/activemq/camel/trunk/components/camel-jmxconnect: ./ src/ src/main/
src/main/java/ src/main/java/org/ src/main/java/org/apache/
src/main/java/org/apache/camel/ src/main/java/org/apache/camel/jmxconnect/
src/main/java/org...
Author: jstrachan
Date: Thu Aug 14 07:09:52 2008
New Revision: 685904
URL: http://svn.apache.org/viewvc?rev=685904&view=rev
Log:
added an initial cut of a remote JMX provider for ActiveMQ or for other Camel transports
Added:
activemq/camel/trunk/components/camel-jmxconnect/
activemq/camel/trunk/components/camel-jmxconnect/pom.xml (with props)
activemq/camel/trunk/components/camel-jmxconnect/src/
activemq/camel/trunk/components/camel-jmxconnect/src/main/
activemq/camel/trunk/components/camel-jmxconnect/src/main/java/
activemq/camel/trunk/components/camel-jmxconnect/src/main/java/org/
activemq/camel/trunk/components/camel-jmxconnect/src/main/java/org/apache/
activemq/camel/trunk/components/camel-jmxconnect/src/main/java/org/apache/camel/
activemq/camel/trunk/components/camel-jmxconnect/src/main/java/org/apache/camel/jmxconnect/
activemq/camel/trunk/components/camel-jmxconnect/src/main/java/org/apache/camel/jmxconnect/CamelJmxConnector.java (with props)
activemq/camel/trunk/components/camel-jmxconnect/src/main/java/org/apache/camel/jmxconnect/CamelJmxConnectorServer.java (with props)
activemq/camel/trunk/components/camel-jmxconnect/src/main/java/org/apache/camel/jmxconnect/CamelJmxConnectorSupport.java (with props)
activemq/camel/trunk/components/camel-jmxconnect/src/main/java/org/apache/camel/jmxconnect/ListenerInfo.java (with props)
activemq/camel/trunk/components/camel-jmxconnect/src/main/java/org/apache/camel/jmxconnect/MBeanCamelServerConnection.java (with props)
activemq/camel/trunk/components/camel-jmxconnect/src/main/java/org/apache/camel/jmxconnect/MBeanCamelServerConnectionClient.java (with props)
activemq/camel/trunk/components/camel-jmxconnect/src/main/java/org/apache/camel/jmxconnect/MBeanCamelServerConnectionImpl.java (with props)
activemq/camel/trunk/components/camel-jmxconnect/src/main/java/org/apache/camel/jmxconnect/MBeanServerConnectionDelegate.java (with props)
activemq/camel/trunk/components/camel-jmxconnect/src/main/java/org/apache/camel/jmxconnect/ServerListenerInfo.java (with props)
activemq/camel/trunk/components/camel-jmxconnect/src/main/java/org/apache/camel/jmxconnect/provider/
activemq/camel/trunk/components/camel-jmxconnect/src/main/java/org/apache/camel/jmxconnect/provider/activemq/
activemq/camel/trunk/components/camel-jmxconnect/src/main/java/org/apache/camel/jmxconnect/provider/activemq/ActiveMQHelper.java (with props)
activemq/camel/trunk/components/camel-jmxconnect/src/main/java/org/apache/camel/jmxconnect/provider/activemq/ClientProvider.java (with props)
activemq/camel/trunk/components/camel-jmxconnect/src/main/java/org/apache/camel/jmxconnect/provider/activemq/ServerProvider.java (with props)
activemq/camel/trunk/components/camel-jmxconnect/src/main/java/org/apache/camel/jmxconnect/provider/camel/
activemq/camel/trunk/components/camel-jmxconnect/src/main/java/org/apache/camel/jmxconnect/provider/camel/ClientProvider.java (with props)
activemq/camel/trunk/components/camel-jmxconnect/src/main/java/org/apache/camel/jmxconnect/provider/camel/ServerProvider.java (with props)
activemq/camel/trunk/components/camel-jmxconnect/src/main/java/org/apache/camel/jmxconnect/provider/jms/
activemq/camel/trunk/components/camel-jmxconnect/src/main/resources/
activemq/camel/trunk/components/camel-jmxconnect/src/main/resources/META-INF/
activemq/camel/trunk/components/camel-jmxconnect/src/test/
activemq/camel/trunk/components/camel-jmxconnect/src/test/java/
activemq/camel/trunk/components/camel-jmxconnect/src/test/java/org/
activemq/camel/trunk/components/camel-jmxconnect/src/test/java/org/apache/
activemq/camel/trunk/components/camel-jmxconnect/src/test/java/org/apache/camel/
activemq/camel/trunk/components/camel-jmxconnect/src/test/java/org/apache/camel/jmxconnect/
activemq/camel/trunk/components/camel-jmxconnect/src/test/java/org/apache/camel/jmxconnect/JmxActiveMQRemoteTest.java (with props)
activemq/camel/trunk/components/camel-jmxconnect/src/test/java/org/apache/camel/jmxconnect/JmxRemoteTest.java (with props)
activemq/camel/trunk/components/camel-jmxconnect/src/test/java/org/apache/camel/jmxconnect/SimpleService.java (with props)
activemq/camel/trunk/components/camel-jmxconnect/src/test/java/org/apache/camel/jmxconnect/SimpleServiceMBean.java (with props)
activemq/camel/trunk/components/camel-jmxconnect/src/test/resources/
activemq/camel/trunk/components/camel-jmxconnect/src/test/resources/log4j.properties (with props)
Added: activemq/camel/trunk/components/camel-jmxconnect/pom.xml
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-jmxconnect/pom.xml?rev=685904&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-jmxconnect/pom.xml (added)
+++ activemq/camel/trunk/components/camel-jmxconnect/pom.xml Thu Aug 14 07:09:52 2008
@@ -0,0 +1,137 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+ 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.
+-->
+
+<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0">
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-parent</artifactId>
+ <version>1.5-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>camel-jmxconnect</artifactId>
+ <packaging>bundle</packaging>
+ <name>Camel :: JMX Connector</name>
+ <description>Camel JMX Connector</description>
+
+ <properties>
+ <camel.osgi.export.pkg>org.apache.camel.jmxconnect.*</camel.osgi.export.pkg>
+ </properties>
+
+ <dependencies>
+
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-spring</artifactId>
+ </dependency>
+
+ <!-- TODO only used for the activemq provider - move to ActiveMQ trunk ASAP! -->
+ <dependency>
+ <groupId>org.apache.activemq</groupId>
+ <artifactId>activemq-camel</artifactId>
+ <!-- TODO move to 5.2 ASAP -->
+ <version>5.2-SNAPSHOT</version>
+ <optional>true</optional>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-jms</artifactId>
+ <optional>true</optional>
+ </dependency>
+
+
+ <!-- testing -->
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-test</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.activemq</groupId>
+ <artifactId>activemq-core</artifactId>
+ <!-- TODO move to 5.2 ASAP -->
+ <version>5.2-SNAPSHOT</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.xbean</groupId>
+ <artifactId>xbean-spring</artifactId>
+ <exclusions>
+ <exclusion>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring</artifactId>
+ </exclusion>
+ </exclusions>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>commons-logging</groupId>
+ <artifactId>commons-logging</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>log4j</groupId>
+ <artifactId>log4j</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+
+ <build>
+ <plugins>
+
+ <plugin>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <childDelegation>false</childDelegation>
+ <useFile>true</useFile>
+ <forkMode>pertest</forkMode>
+ <excludes>
+ <!--<exclude>**/SendMessageWithForeignReplyToRouteTest.*</exclude>-->
+ </excludes>
+ </configuration>
+ </plugin>
+
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-clean-plugin</artifactId>
+ <configuration>
+ <filesets>
+ <fileset>
+ <directory>${basedir}/activemq-data</directory>
+ </fileset>
+ </filesets>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
Propchange: activemq/camel/trunk/components/camel-jmxconnect/pom.xml
------------------------------------------------------------------------------
svn:eol-style = native
Added: activemq/camel/trunk/components/camel-jmxconnect/src/main/java/org/apache/camel/jmxconnect/CamelJmxConnector.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-jmxconnect/src/main/java/org/apache/camel/jmxconnect/CamelJmxConnector.java?rev=685904&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-jmxconnect/src/main/java/org/apache/camel/jmxconnect/CamelJmxConnector.java (added)
+++ activemq/camel/trunk/components/camel-jmxconnect/src/main/java/org/apache/camel/jmxconnect/CamelJmxConnector.java Thu Aug 14 07:09:52 2008
@@ -0,0 +1,332 @@
+/**
+ *
+ * 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.jmxconnect;
+
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.CamelContextAware;
+import org.apache.camel.impl.DefaultCamelContext;
+import org.apache.camel.spring.remoting.CamelProxyFactoryBean;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import javax.management.*;
+import javax.management.remote.*;
+import javax.security.auth.Subject;
+import java.io.IOException;
+import java.util.Map;
+import java.util.concurrent.atomic.AtomicLong;
+
+/**
+ * <p>
+ * The client end of a JMX API connector. An object of this type can be used to establish a connection to a connector
+ * server.
+ * </p>
+ * <p/>
+ * <p>
+ * A newly-created object of this type is unconnected. Its {@link #connect()} method must be called before it can
+ * be used. However, objects created by {@link JMXConnectorFactory#connect(JMXServiceURL, Map)
+ * JMXConnectorFactory.connect} are already connected.
+ * </p>
+ *
+ * @version $Revision: 1.1 $
+ */
+public class CamelJmxConnector implements JMXConnector, CamelContextAware {
+ private static final Log log = LogFactory.getLog(JMXConnector.class);
+ private NotificationBroadcasterSupport connectionNotifier = new NotificationBroadcasterSupport();
+ private AtomicLong notificationNumber = new AtomicLong();
+ private Map env;
+ private String endpointUri;
+ private CamelProxyFactoryBean proxy;
+ private MBeanCamelServerConnectionClient client;
+ private boolean connected;
+ private CamelContext camelContext;
+ private String connectionId;
+
+ public CamelJmxConnector(Map env, String endpointUri) {
+ this.env = env;
+ this.endpointUri = endpointUri;
+ }
+
+ public CamelJmxConnector(Map env, JMXServiceURL url) throws IOException {
+ this(env, CamelJmxConnectorSupport.getEndpointUri(url, "camel"));
+ // set any props in the url
+ // TODO
+ // populateProperties(this, endpointUri);
+ }
+
+ /**
+ * <p>
+ * Establishes the connection to the connector server. This method is equivalent to {@link #connect(Map)
+ * connect(null)}.
+ * </p>
+ *
+ * @throws IOException if the connection could not be made because of a communication problem.
+ * @throws SecurityException if the connection could not be made for security reasons.
+ */
+ public void connect() throws IOException {
+ connect(this.env);
+ }
+
+ /**
+ * <p>
+ * Establishes the connection to the connector server.
+ * </p>
+ * <p/>
+ * <p>
+ * If <code>connect</code> has already been called successfully on this object, calling it again has no effect.
+ * If, however, {@link #close} was called after <code>connect</code>, the new <code>connect</code> will throw
+ * an <code>IOException</code>.
+ * <p>
+ * <p/>
+ * <p>
+ * Otherwise, either <code>connect</code> has never been called on this object, or it has been called but produced
+ * an exception. Then calling <code>connect</code> will attempt to establish a connection to the connector server.
+ * </p>
+ *
+ * @param env the properties of the connection. Properties in this map override properties in the map specified when
+ * the <code>JMXConnector</code> was created, if any. This parameter can be null, which is equivalent
+ * to an empty map.
+ * @throws IOException if the connection could not be made because of a communication problem.
+ * @throws SecurityException if the connection could not be made for security reasons.
+ */
+ public void connect(Map env) throws IOException {
+ if (!connected) {
+ try {
+ proxy = new CamelProxyFactoryBean();
+ proxy.setCamelContext(getCamelContext());
+ proxy.setServiceInterface(javax.management.MBeanServerConnection.class);
+ proxy.setServiceInterface(MBeanCamelServerConnection.class);
+ proxy.setServiceUrl(endpointUri);
+ proxy.afterPropertiesSet();
+
+ client = new MBeanCamelServerConnectionClient((MBeanCamelServerConnection) proxy.getObject() /* TODO */);
+ connectionId = client.generateId();
+
+ // TODO we need to establish a replyToEndpoint and inform the server!
+
+ sendConnectionNotificationOpened();
+ } catch (Exception e) {
+ log.error("Failed to connect: " + e, e);
+ IOException ioe = new IOException(e.getMessage());
+ throw ioe;
+ }
+ connected = true;
+ }
+ }
+
+ /**
+ * <p>
+ * Returns an <code>MBeanServerConnection</code> object representing a remote MBean server. For a given
+ * <code>JMXConnector</code>, two successful calls to this method will usually return the same
+ * <code>MBeanServerConnection</code> object, though this is not required.
+ * </p>
+ * <p/>
+ * <p>
+ * For each method in the returned <code>MBeanServerConnection</code>, calling the method causes the
+ * corresponding method to be called in the remote MBean server. The value returned by the MBean server method is
+ * the value returned to the client. If the MBean server method produces an <code>Exception</code>, the same
+ * <code>Exception</code> is seen by the client. If the MBean server method, or the attempt to call it, produces
+ * an <code>Error</code>, the <code>Error</code> is wrapped in a {@link JMXServerErrorException}, which is
+ * seen by the client.
+ * </p>
+ * <p/>
+ * <p>
+ * Calling this method is equivalent to calling
+ * {@link #getMBeanServerConnection(Subject) getMBeanServerConnection(null)} meaning that no delegation subject is
+ * specified and that all the operations called on the <code>MBeanServerConnection</code> must use the
+ * authenticated subject, if any.
+ * </p>
+ *
+ * @return an object that implements the <code>MBeanServerConnection</code> interface by forwarding its methods to
+ * the remote MBean server.
+ */
+ public MBeanServerConnection getMBeanServerConnection() {
+ return client;
+ }
+
+ /**
+ * <p>
+ * Returns an <code>MBeanServerConnection</code> object representing a remote MBean server on which operations are
+ * performed on behalf of the supplied delegation subject. For a given <code>JMXConnector</code> and
+ * <code>Subject</code>, two successful calls to this method will usually return the same
+ * <code>MBeanServerConnection</code> object, though this is not required.
+ * </p>
+ * <p/>
+ * <p>
+ * For each method in the returned <code>MBeanServerConnection</code>, calling the method causes the
+ * corresponding method to be called in the remote MBean server on behalf of the given delegation subject instead of
+ * the authenticated subject. The value returned by the MBean server method is the value returned to the client. If
+ * the MBean server method produces an <code>Exception</code>, the same <code>Exception</code> is seen by the
+ * client. If the MBean server method, or the attempt to call it, produces an <code>Error</code>, the
+ * <code>Error</code> is wrapped in a {@link JMXServerErrorException}, which is seen by the client.
+ * </p>
+ *
+ * @param delegationSubject the <code>Subject</code> on behalf of which requests will be performed. Can be null, in which case
+ * requests will be performed on behalf of the authenticated Subject, if any.
+ * @return an object that implements the <code>MBeanServerConnection</code> interface by forwarding its methods to
+ * the remote MBean server on behalf of a given delegation subject.
+ */
+ public MBeanServerConnection getMBeanServerConnection(Subject delegationSubject) {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * <p>
+ * Closes the client connection to its server. Any ongoing or new request using the MBeanServerConnection returned
+ * by {@link #getMBeanServerConnection()} will get an <code>IOException</code>.
+ * </p>
+ * <p/>
+ * <p>
+ * If <code>close</code> has already been called successfully on this object, calling it again has no effect. If
+ * <code>close</code> has never been called, or if it was called but produced an exception, an attempt will be
+ * made to close the connection. This attempt can succeed, in which case <code>close</code> will return normally,
+ * or it can generate an exception.
+ * </p>
+ * <p/>
+ * <p>
+ * Closing a connection is a potentially slow operation. For example, if the server has crashed, the close operation
+ * might have to wait for a network protocol timeout. Callers that do not want to block in a close operation should
+ * do it in a separate thread.
+ * </p>
+ *
+ * @throws IOException if the connection cannot be closed cleanly. If this exception is thrown, it is not known whether
+ * the server end of the connection has been cleanly closed.
+ */
+ public void close() throws IOException {
+ if (connected) {
+ connected = false;
+ try {
+ sendConnectionNotificationClosed();
+ proxy.destroy();
+ } catch (Exception e) {
+ log.error("Failed to destroy proxy: " + e, e);
+ throw new IOException(e.getMessage());
+ }
+ }
+ }
+
+ /**
+ * <p>
+ * Adds a listener to be informed of changes in connection status. The listener will receive notifications of type
+ * {@link JMXConnectionNotification}. An implementation can send other types of notifications too.
+ * </p>
+ * <p/>
+ * <p>
+ * Any number of listeners can be added with this method. The same listener can be added more than once with the
+ * same or different values for the filter and handback. There is no special treatment of a duplicate entry. For
+ * example, if a listener is registered twice with no filter, then its <code>handleNotification</code> method will
+ * be called twice for each notification.
+ * </p>
+ *
+ * @param listener a listener to receive connection status notifications.
+ * @param filter a filter to select which notifications are to be delivered to the listener, or null if all
+ * notifications are to be delivered.
+ * @param handback an object to be given to the listener along with each notification. Can be null.
+ * @throws NullPointerException if <code>listener</code> is null.
+ * @see #removeConnectionNotificationListener
+ * @see NotificationBroadcaster#addNotificationListener
+ */
+ public void addConnectionNotificationListener(NotificationListener listener, NotificationFilter filter,
+ Object handback) {
+ connectionNotifier.addNotificationListener(listener, filter, handback);
+ }
+
+ /**
+ * <p>
+ * Removes a listener from the list to be informed of changes in status. The listener must previously have been
+ * added. If there is more than one matching listener, all are removed.
+ * </p>
+ *
+ * @param listener a listener to receive connection status notifications.
+ * @throws NullPointerException if <code>listener</code> is null.
+ * @throws ListenerNotFoundException if the listener is not registered with this <code>JMXConnector</code>.
+ * @see #removeConnectionNotificationListener(NotificationListener, NotificationFilter, Object)
+ * @see #addConnectionNotificationListener
+ * @see NotificationEmitter#removeNotificationListener
+ */
+ public void removeConnectionNotificationListener(NotificationListener listener) throws ListenerNotFoundException {
+ connectionNotifier.removeNotificationListener(listener);
+ }
+
+ /**
+ * <p>
+ * Removes a listener from the list to be informed of changes in status. The listener must previously have been
+ * added with the same three parameters. If there is more than one matching listener, only one is removed.
+ * </p>
+ *
+ * @param l a listener to receive connection status notifications.
+ * @param f a filter to select which notifications are to be delivered to the listener. Can be null.
+ * @param handback an object to be given to the listener along with each notification. Can be null.
+ * @throws ListenerNotFoundException if the listener is not registered with this <code>JMXConnector</code>, or is not registered
+ * with the given filter and handback.
+ * @see #removeConnectionNotificationListener(NotificationListener)
+ * @see #addConnectionNotificationListener
+ * @see NotificationEmitter#removeNotificationListener
+ */
+ public void removeConnectionNotificationListener(NotificationListener l, NotificationFilter f, Object handback)
+ throws ListenerNotFoundException {
+ connectionNotifier.removeNotificationListener(l, f, handback);
+ }
+
+
+ /**
+ * <p>
+ * Gets this connection's ID from the connector server. For a given connector server, every connection will have a
+ * unique id which does not change during the lifetime of the connection.
+ * </p>
+ *
+ * @return the unique ID of this connection. This is the same as the ID that the connector server includes in its
+ * {@link JMXConnectionNotification}s. The {@link javax.management.remote package description} describes the
+ * conventions for connection IDs.
+ */
+ public String getConnectionId() {
+ return connectionId;
+ }
+
+ public CamelContext getCamelContext() {
+ if (camelContext == null) {
+ log.warn("No CamelContext injected so creating a default implementation");
+ // TODO should we barf or create a default one?
+ camelContext = new DefaultCamelContext();
+ }
+ return camelContext;
+ }
+
+ public void setCamelContext(CamelContext camelContext) {
+ this.camelContext = camelContext;
+ }
+
+ private void sendConnectionNotificationOpened() {
+ JMXConnectionNotification notification = new JMXConnectionNotification(JMXConnectionNotification.OPENED, this,
+ getConnectionId(), notificationNumber.incrementAndGet(), "Connection opened", null);
+ connectionNotifier.sendNotification(notification);
+ }
+
+ private void sendConnectionNotificationClosed() {
+ JMXConnectionNotification notification = new JMXConnectionNotification(JMXConnectionNotification.CLOSED, this,
+ getConnectionId(), notificationNumber.incrementAndGet(), "Connection closed", null);
+ connectionNotifier.sendNotification(notification);
+ }
+
+ private void sendConnectionNotificationFailed(String message) {
+ JMXConnectionNotification notification = new JMXConnectionNotification(JMXConnectionNotification.FAILED, this,
+ getConnectionId(), notificationNumber.incrementAndGet(), message, null);
+ connectionNotifier.sendNotification(notification);
+ }
+}
\ No newline at end of file
Propchange: activemq/camel/trunk/components/camel-jmxconnect/src/main/java/org/apache/camel/jmxconnect/CamelJmxConnector.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: activemq/camel/trunk/components/camel-jmxconnect/src/main/java/org/apache/camel/jmxconnect/CamelJmxConnectorServer.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-jmxconnect/src/main/java/org/apache/camel/jmxconnect/CamelJmxConnectorServer.java?rev=685904&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-jmxconnect/src/main/java/org/apache/camel/jmxconnect/CamelJmxConnectorServer.java (added)
+++ activemq/camel/trunk/components/camel-jmxconnect/src/main/java/org/apache/camel/jmxconnect/CamelJmxConnectorServer.java Thu Aug 14 07:09:52 2008
@@ -0,0 +1,140 @@
+/**
+ *
+ * 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.jmxconnect;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.CamelContextAware;
+import org.apache.camel.impl.DefaultCamelContext;
+import org.apache.camel.spring.remoting.CamelServiceExporter;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import javax.management.MBeanServer;
+import javax.management.remote.JMXConnectorFactory;
+import javax.management.remote.JMXConnectorServer;
+import javax.management.remote.JMXServiceURL;
+import java.io.IOException;
+import java.util.Collections;
+import java.util.Map;
+
+/**
+ * <p>The client end of a JMX API connector. An object of this type can
+ * be used to establish a connection to a connector server.</p>
+ * <p/>
+ * <p>A newly-created object of this type is unconnected. Its {@link#connect}
+ * method must be called before it can be used.
+ * However, objects created by {@link
+ * JMXConnectorFactory#connect(JMXServiceURL, Map)
+ * JMXConnectorFactory.connect} are already connected.</p>
+ *
+ * @version $Revision: 1.1 $
+ */
+public class CamelJmxConnectorServer extends JMXConnectorServer implements CamelContextAware {
+
+ private static final Log log = LogFactory.getLog(CamelJmxConnectorServer.class);
+ private JMXServiceURL url;
+ private final Map env;
+ private volatile boolean stopped = true;
+ private CamelServiceExporter service;
+ private MBeanCamelServerConnectionImpl serverConnection;
+ private String endpointUri;
+ private CamelContext camelContext;
+
+
+ public CamelJmxConnectorServer(JMXServiceURL url, String endpointUri, Map environment, MBeanServer server) throws IOException {
+ super(server);
+ this.url = url;
+ this.env = environment;
+ this.endpointUri = endpointUri;
+ }
+
+ public CamelJmxConnectorServer(JMXServiceURL url, Map environment, MBeanServer server) throws IOException {
+ this(url, CamelJmxConnectorSupport.getEndpointUri(url, "camel"), environment, server);
+ //set any props in the url
+ // TODO
+ // populateProperties(this, endpointUri);
+ }
+
+ /**
+ * start the connector
+ *
+ * @throws IOException
+ */
+ public void start() throws IOException {
+ try {
+ service = new CamelServiceExporter();
+ service.setCamelContext(getCamelContext());
+ service.setServiceInterface(MBeanCamelServerConnection.class);
+ service.setUri(endpointUri);
+
+ this.serverConnection = new MBeanCamelServerConnectionImpl(getMBeanServer(), /* TODO */ null);
+ service.setService(serverConnection);
+
+ service.afterPropertiesSet();
+ stopped = false;
+ } catch (Exception e) {
+ log.error("Failed to start ", e);
+ throw new IOException(e.toString());
+ }
+
+ }
+
+ /**
+ * stop the connector
+ *
+ * @throws IOException
+ */
+ public void stop() throws IOException {
+ try {
+ if (!stopped) {
+ stopped = true;
+ service.destroy();
+ }
+ } catch (Exception e) {
+ log.error("Failed to stop ", e);
+ throw new IOException(e.toString());
+ }
+
+ }
+
+ public boolean isActive() {
+ return !stopped;
+ }
+
+ public JMXServiceURL getAddress() {
+ return url;
+ }
+
+ public Map getAttributes() {
+ return Collections.unmodifiableMap(env);
+ }
+
+
+ public CamelContext getCamelContext() {
+ if (camelContext == null) {
+ log.warn("No CamelContext injected so creating a default implementation");
+ // TODO should we barf or create a default one?
+ camelContext = new DefaultCamelContext();
+ }
+ return camelContext;
+ }
+
+ public void setCamelContext(CamelContext camelContext) {
+ this.camelContext = camelContext;
+ }
+}
\ No newline at end of file
Propchange: activemq/camel/trunk/components/camel-jmxconnect/src/main/java/org/apache/camel/jmxconnect/CamelJmxConnectorServer.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: activemq/camel/trunk/components/camel-jmxconnect/src/main/java/org/apache/camel/jmxconnect/CamelJmxConnectorSupport.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-jmxconnect/src/main/java/org/apache/camel/jmxconnect/CamelJmxConnectorSupport.java?rev=685904&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-jmxconnect/src/main/java/org/apache/camel/jmxconnect/CamelJmxConnectorSupport.java (added)
+++ activemq/camel/trunk/components/camel-jmxconnect/src/main/java/org/apache/camel/jmxconnect/CamelJmxConnectorSupport.java Thu Aug 14 07:09:52 2008
@@ -0,0 +1,45 @@
+/**
+ *
+ * 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.jmxconnect;
+
+
+import javax.management.remote.JMXServiceURL;
+import java.io.IOException;
+import java.net.MalformedURLException;
+
+/**
+ * @version $Revision: 1.1 $
+ */
+public class CamelJmxConnectorSupport {
+ public static final String DEFAULT_DESTINATION_PREFIX = "org.apache.camel.jmxconnect.";
+ public static final String MBEAN_SERVER_NAME = "*";
+ public static final String MBEAN_GROUP_NAME = "*";
+
+ public static String getEndpointUri(JMXServiceURL serviceURL, String expectedProtocol) throws IOException {
+ String protocol = serviceURL.getProtocol();
+ if (!expectedProtocol.equals(protocol)) {
+ throw new MalformedURLException("Wrong protocol " + protocol + " expecting " + expectedProtocol);
+ }
+ String path = serviceURL.getURLPath();
+ while (path.startsWith("/")) {
+ path = path.substring(1);
+ }
+ return path;
+ }
+
+}
\ No newline at end of file
Propchange: activemq/camel/trunk/components/camel-jmxconnect/src/main/java/org/apache/camel/jmxconnect/CamelJmxConnectorSupport.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: activemq/camel/trunk/components/camel-jmxconnect/src/main/java/org/apache/camel/jmxconnect/ListenerInfo.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-jmxconnect/src/main/java/org/apache/camel/jmxconnect/ListenerInfo.java?rev=685904&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-jmxconnect/src/main/java/org/apache/camel/jmxconnect/ListenerInfo.java (added)
+++ activemq/camel/trunk/components/camel-jmxconnect/src/main/java/org/apache/camel/jmxconnect/ListenerInfo.java Thu Aug 14 07:09:52 2008
@@ -0,0 +1,108 @@
+/**
+ *
+ * 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.jmxconnect;
+
+import javax.management.NotificationFilter;
+import javax.management.NotificationListener;
+
+/**
+ * @version $Revision: 1.1 $
+ */
+class ListenerInfo {
+ private String id;
+ private NotificationListener listener;
+ private NotificationFilter filter;
+ private Object handback;
+
+
+ public ListenerInfo(String id, NotificationListener listener, NotificationFilter filter, Object handback) {
+ this.id = id;
+ this.listener = listener;
+ this.filter = filter;
+ this.handback = handback;
+ }
+
+ /**
+ * Is this info a match ?
+ *
+ * @param l
+ * @param f
+ * @param handback
+ * @return true if a match
+ */
+ public boolean isMatch(NotificationListener l, NotificationFilter f, Object handback) {
+ return listener == listener && filter == filter && handback == handback;
+ }
+
+ /**
+ * @return Returns the filter.
+ */
+ public NotificationFilter getFilter() {
+ return filter;
+ }
+
+ /**
+ * @param filter The filter to set.
+ */
+ public void setFilter(NotificationFilter filter) {
+ this.filter = filter;
+ }
+
+ /**
+ * @return Returns the handback.
+ */
+ public Object getHandback() {
+ return handback;
+ }
+
+ /**
+ * @param handback The handback to set.
+ */
+ public void setHandback(Object handback) {
+ this.handback = handback;
+ }
+
+ /**
+ * @return Returns the id.
+ */
+ public String getId() {
+ return id;
+ }
+
+ /**
+ * @param id The id to set.
+ */
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ /**
+ * @return Returns the listener.
+ */
+ public NotificationListener getListener() {
+ return listener;
+ }
+
+ /**
+ * @param listener The listener to set.
+ */
+ public void setListener(NotificationListener listener) {
+ this.listener = listener;
+ }
+
+}
\ No newline at end of file
Propchange: activemq/camel/trunk/components/camel-jmxconnect/src/main/java/org/apache/camel/jmxconnect/ListenerInfo.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: activemq/camel/trunk/components/camel-jmxconnect/src/main/java/org/apache/camel/jmxconnect/MBeanCamelServerConnection.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-jmxconnect/src/main/java/org/apache/camel/jmxconnect/MBeanCamelServerConnection.java?rev=685904&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-jmxconnect/src/main/java/org/apache/camel/jmxconnect/MBeanCamelServerConnection.java (added)
+++ activemq/camel/trunk/components/camel-jmxconnect/src/main/java/org/apache/camel/jmxconnect/MBeanCamelServerConnection.java Thu Aug 14 07:09:52 2008
@@ -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.jmxconnect;
+
+import org.apache.camel.Endpoint;
+
+import javax.management.MBeanServerConnection;
+import javax.management.ObjectName;
+
+/**
+ * @version $Revision: 1.1 $
+ */
+public interface MBeanCamelServerConnection extends MBeanServerConnection {
+
+ /**
+ * Add a Notification listener
+ *
+ * @param listenerId
+ * @param name
+ * @param replyToEndpoint
+ */
+ public void addNotificationListener(String listenerId, ObjectName name, Endpoint replyToEndpoint);
+
+ /**
+ * Remove a Notification listener
+ *
+ * @param listenerId
+ */
+ public void removeNotificationListener(String listenerId);
+
+}
\ No newline at end of file
Propchange: activemq/camel/trunk/components/camel-jmxconnect/src/main/java/org/apache/camel/jmxconnect/MBeanCamelServerConnection.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: activemq/camel/trunk/components/camel-jmxconnect/src/main/java/org/apache/camel/jmxconnect/MBeanCamelServerConnectionClient.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-jmxconnect/src/main/java/org/apache/camel/jmxconnect/MBeanCamelServerConnectionClient.java?rev=685904&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-jmxconnect/src/main/java/org/apache/camel/jmxconnect/MBeanCamelServerConnectionClient.java (added)
+++ activemq/camel/trunk/components/camel-jmxconnect/src/main/java/org/apache/camel/jmxconnect/MBeanCamelServerConnectionClient.java Thu Aug 14 07:09:52 2008
@@ -0,0 +1,109 @@
+/**
+ *
+ * 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.jmxconnect;
+
+import org.apache.camel.Endpoint;
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.util.UuidGenerator;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import javax.management.*;
+import java.util.Iterator;
+import java.util.List;
+import java.util.concurrent.CopyOnWriteArrayList;
+
+/**
+ * @version $Revision: 1.1 $
+ */
+public class MBeanCamelServerConnectionClient extends MBeanServerConnectionDelegate implements Processor {
+ private static final Log log = LogFactory.getLog(MBeanCamelServerConnectionClient.class);
+ private MBeanCamelServerConnection serverConnection;
+ private Endpoint replyToEndpoint;
+ private List listeners = new CopyOnWriteArrayList();
+ private UuidGenerator idGenerator = new UuidGenerator();
+ private NotificationBroadcasterSupport localNotifier = new NotificationBroadcasterSupport();
+
+ public MBeanCamelServerConnectionClient(MBeanCamelServerConnection serverConnection) {
+ super(serverConnection);
+ this.serverConnection = serverConnection;
+ }
+
+ /**
+ * Add a notification listener
+ */
+ public void addNotificationListener(ObjectName name, NotificationListener listener, NotificationFilter filter,
+ Object handback) {
+ String id = generateId();
+ ListenerInfo info = new ListenerInfo(id, listener, filter, handback);
+ listeners.add(info);
+ localNotifier.addNotificationListener(listener, filter, handback);
+
+ // TODO need to create an endpoint for replies!!!
+ if (replyToEndpoint == null) {
+ log.error("no replyToDestination for replies to be received!");
+ }
+ serverConnection.addNotificationListener(id, name, replyToEndpoint);
+ }
+
+ public String generateId() {
+ return idGenerator.generateId();
+ }
+
+ /**
+ * Remove a Notification Listener
+ */
+ public void removeNotificationListener(ObjectName name, NotificationListener listener)
+ throws ListenerNotFoundException {
+ for (Iterator i = listeners.iterator(); i.hasNext();) {
+ ListenerInfo li = (ListenerInfo) i.next();
+ if (li.getListener() == listener) {
+ listeners.remove(i);
+ serverConnection.removeNotificationListener(li.getId());
+ break;
+ }
+ }
+ localNotifier.removeNotificationListener(listener);
+ }
+
+ /**
+ * Remove a Notification Listener
+ */
+ public void removeNotificationListener(ObjectName name, NotificationListener listener, NotificationFilter filter,
+ Object handback) throws ListenerNotFoundException {
+ for (Iterator i = listeners.iterator(); i.hasNext();) {
+ ListenerInfo li = (ListenerInfo) i.next();
+ if (li.getListener() == listener && li.getFilter() == filter && li.getHandback() == handback) {
+ listeners.remove(i);
+ serverConnection.removeNotificationListener(li.getId());
+ }
+ }
+ localNotifier.removeNotificationListener(listener, filter, handback);
+ }
+
+
+ public void process(Exchange exchange) throws Exception {
+ Notification notification = exchange.getIn().getBody(Notification.class);
+ if (notification != null) {
+ localNotifier.sendNotification(notification);
+ } else {
+ log.warn("Received message which is not a Notification: " + exchange);
+ }
+ }
+}
\ No newline at end of file
Propchange: activemq/camel/trunk/components/camel-jmxconnect/src/main/java/org/apache/camel/jmxconnect/MBeanCamelServerConnectionClient.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: activemq/camel/trunk/components/camel-jmxconnect/src/main/java/org/apache/camel/jmxconnect/MBeanCamelServerConnectionImpl.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-jmxconnect/src/main/java/org/apache/camel/jmxconnect/MBeanCamelServerConnectionImpl.java?rev=685904&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-jmxconnect/src/main/java/org/apache/camel/jmxconnect/MBeanCamelServerConnectionImpl.java (added)
+++ activemq/camel/trunk/components/camel-jmxconnect/src/main/java/org/apache/camel/jmxconnect/MBeanCamelServerConnectionImpl.java Thu Aug 14 07:09:52 2008
@@ -0,0 +1,73 @@
+/**
+ *
+ * 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.jmxconnect;
+
+import org.apache.camel.Endpoint;
+import org.apache.camel.ProducerTemplate;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import javax.management.MBeanServerConnection;
+import javax.management.ObjectName;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * @version $Revision: 1.1 $
+ */
+public class MBeanCamelServerConnectionImpl extends MBeanServerConnectionDelegate implements MBeanCamelServerConnection {
+ private static final Log log = LogFactory.getLog(MBeanCamelServerConnectionImpl.class);
+ private Map notificationListeners = new ConcurrentHashMap();
+ private final ProducerTemplate template;
+
+ public MBeanCamelServerConnectionImpl(MBeanServerConnection connection, ProducerTemplate template) {
+ super(connection);
+ this.template = template;
+ }
+
+ /**
+ * Add a Notification listener
+ *
+ * @param listenerId
+ * @param name
+ * @param replyToEndpoint
+ */
+ public void addNotificationListener(String listenerId, ObjectName name, Endpoint replyToEndpoint) {
+ try {
+ ServerListenerInfo info = new ServerListenerInfo(listenerId, notificationListeners, template, replyToEndpoint);
+ notificationListeners.put(listenerId, info);
+ connection.addNotificationListener(name, info, null, null);
+ } catch (Exception e) {
+ log.error("Failed to addNotificationListener ", e);
+ }
+
+ }
+
+ /**
+ * Remove a Notification listener
+ *
+ * @param listenerId
+ */
+ public void removeNotificationListener(String listenerId) {
+ ServerListenerInfo info = (ServerListenerInfo) notificationListeners.remove(listenerId);
+ if (info != null) {
+ info.close();
+ }
+ }
+
+}
\ No newline at end of file
Propchange: activemq/camel/trunk/components/camel-jmxconnect/src/main/java/org/apache/camel/jmxconnect/MBeanCamelServerConnectionImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: activemq/camel/trunk/components/camel-jmxconnect/src/main/java/org/apache/camel/jmxconnect/MBeanServerConnectionDelegate.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-jmxconnect/src/main/java/org/apache/camel/jmxconnect/MBeanServerConnectionDelegate.java?rev=685904&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-jmxconnect/src/main/java/org/apache/camel/jmxconnect/MBeanServerConnectionDelegate.java (added)
+++ activemq/camel/trunk/components/camel-jmxconnect/src/main/java/org/apache/camel/jmxconnect/MBeanServerConnectionDelegate.java Thu Aug 14 07:09:52 2008
@@ -0,0 +1,148 @@
+/**
+ *
+ * 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.jmxconnect;
+
+import javax.management.*;
+import java.io.IOException;
+import java.util.Set;
+
+/**
+ * Acts as a delegate for the MBeanServerConnection
+ *
+ * @version $Revision: 1.1 $
+ */
+public class MBeanServerConnectionDelegate implements MBeanServerConnection {
+
+ protected MBeanServerConnection connection;
+
+ public MBeanServerConnectionDelegate(MBeanServerConnection connection) {
+ this.connection = connection;
+
+ }
+
+ public ObjectInstance createMBean(String className, ObjectName name) throws ReflectionException, InstanceAlreadyExistsException, MBeanRegistrationException, MBeanException, NotCompliantMBeanException, IOException {
+ return connection.createMBean(className, name);
+ }
+
+ public ObjectInstance createMBean(String className, ObjectName name, ObjectName loaderName) throws ReflectionException, InstanceAlreadyExistsException, MBeanRegistrationException, MBeanException, NotCompliantMBeanException, InstanceNotFoundException, IOException {
+ return connection.createMBean(className, name, loaderName);
+ }
+
+ public ObjectInstance createMBean(String className, ObjectName name, Object[] params, String[] signature) throws ReflectionException, InstanceAlreadyExistsException, MBeanRegistrationException, MBeanException, NotCompliantMBeanException, IOException {
+ return connection.createMBean(className, name, params, signature);
+ }
+
+
+ public ObjectInstance createMBean(String className, ObjectName name, ObjectName loaderName, Object[] params, String[] signature) throws ReflectionException, InstanceAlreadyExistsException, MBeanRegistrationException, MBeanException, NotCompliantMBeanException, InstanceNotFoundException, IOException {
+ return connection.createMBean(className, name, loaderName, params, signature);
+ }
+
+ public void unregisterMBean(ObjectName name) throws InstanceNotFoundException, MBeanRegistrationException, IOException {
+ connection.unregisterMBean(name);
+
+ }
+
+ public ObjectInstance getObjectInstance(ObjectName name) throws InstanceNotFoundException, IOException {
+ return connection.getObjectInstance(name);
+ }
+
+ public Set queryMBeans(ObjectName name, QueryExp query) throws IOException {
+ return connection.queryMBeans(name, query);
+ }
+
+ public Set queryNames(ObjectName name, QueryExp query) throws IOException {
+ return connection.queryNames(name, query);
+ }
+
+ public boolean isRegistered(ObjectName name) throws IOException {
+ return connection.isRegistered(name);
+ }
+
+ public Integer getMBeanCount() throws IOException {
+ return connection.getMBeanCount();
+ }
+
+ public Object getAttribute(ObjectName name, String attribute) throws MBeanException, AttributeNotFoundException, InstanceNotFoundException, ReflectionException, IOException {
+ return connection.getAttribute(name, attribute);
+ }
+
+ public AttributeList getAttributes(ObjectName name, String[] attributes) throws InstanceNotFoundException, ReflectionException, IOException {
+ return connection.getAttributes(name, attributes);
+ }
+
+ public void setAttribute(ObjectName name, Attribute attribute) throws InstanceNotFoundException, AttributeNotFoundException, InvalidAttributeValueException, MBeanException, ReflectionException, IOException {
+ connection.setAttribute(name, attribute);
+
+ }
+
+ public AttributeList setAttributes(ObjectName name, AttributeList attributes) throws InstanceNotFoundException, ReflectionException, IOException {
+ return connection.setAttributes(name, attributes);
+ }
+
+ public Object invoke(ObjectName name, String operationName, Object[] params, String[] signature) throws InstanceNotFoundException, MBeanException, ReflectionException, IOException {
+ return connection.invoke(name, operationName, params, signature);
+ }
+
+ public String getDefaultDomain() throws IOException {
+ return connection.getDefaultDomain();
+ }
+
+ public String[] getDomains() throws IOException {
+ return connection.getDomains();
+ }
+
+ public void addNotificationListener(ObjectName name, NotificationListener listener, NotificationFilter filter, Object handback) throws InstanceNotFoundException, IOException {
+ connection.addNotificationListener(name, listener, filter, handback);
+
+ }
+
+ public void addNotificationListener(ObjectName name, ObjectName listener, NotificationFilter filter, Object handback) throws InstanceNotFoundException, IOException {
+ connection.addNotificationListener(name, listener, filter, handback);
+
+ }
+
+ public void removeNotificationListener(ObjectName name, ObjectName listener) throws InstanceNotFoundException, ListenerNotFoundException, IOException {
+ connection.removeNotificationListener(name, listener);
+
+ }
+
+ public void removeNotificationListener(ObjectName name, ObjectName listener, NotificationFilter filter, Object handback) throws InstanceNotFoundException, ListenerNotFoundException, IOException {
+ connection.removeNotificationListener(name, listener, filter, handback);
+
+ }
+
+ public void removeNotificationListener(ObjectName name, NotificationListener listener) throws InstanceNotFoundException, ListenerNotFoundException, IOException {
+ connection.removeNotificationListener(name, listener);
+
+ }
+
+ public void removeNotificationListener(ObjectName name, NotificationListener listener, NotificationFilter filter, Object handback) throws InstanceNotFoundException, ListenerNotFoundException, IOException {
+ connection.removeNotificationListener(name, listener, filter, handback);
+
+ }
+
+ public MBeanInfo getMBeanInfo(ObjectName name) throws InstanceNotFoundException, IntrospectionException, ReflectionException, IOException {
+ return connection.getMBeanInfo(name);
+ }
+
+ public boolean isInstanceOf(ObjectName name, String className) throws InstanceNotFoundException, IOException {
+ return connection.isInstanceOf(name, className);
+ }
+
+
+}
\ No newline at end of file
Propchange: activemq/camel/trunk/components/camel-jmxconnect/src/main/java/org/apache/camel/jmxconnect/MBeanServerConnectionDelegate.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: activemq/camel/trunk/components/camel-jmxconnect/src/main/java/org/apache/camel/jmxconnect/ServerListenerInfo.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-jmxconnect/src/main/java/org/apache/camel/jmxconnect/ServerListenerInfo.java?rev=685904&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-jmxconnect/src/main/java/org/apache/camel/jmxconnect/ServerListenerInfo.java (added)
+++ activemq/camel/trunk/components/camel-jmxconnect/src/main/java/org/apache/camel/jmxconnect/ServerListenerInfo.java Thu Aug 14 07:09:52 2008
@@ -0,0 +1,86 @@
+/**
+ *
+ * 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.jmxconnect;
+
+
+import org.apache.camel.Endpoint;
+import org.apache.camel.ProducerTemplate;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import javax.management.Notification;
+import javax.management.NotificationListener;
+import java.util.Map;
+
+/**
+ * @version $Revision: 1.1 $
+ */
+class ServerListenerInfo implements NotificationListener {
+ private static final Log log = LogFactory.getLog(ServerListenerInfo.class);
+ private final String id;
+ private final Map holder;
+ private final ProducerTemplate template;
+ private final Endpoint replyToEndpoint;
+
+ ServerListenerInfo(String id, Map holder, ProducerTemplate template, Endpoint replyToEndpoint) {
+ this.id = id;
+ this.holder = holder;
+ this.template = template;
+ this.replyToEndpoint = replyToEndpoint;
+ }
+
+ /**
+ * NotificationListener implementation
+ *
+ * @param notification
+ * @param handback
+ */
+ public void handleNotification(Notification notification, Object handback) {
+ System.out.println("Should be sending notification: " + notification);
+ if (replyToEndpoint == null) {
+ log.warn("No replyToDestination for replies to be received so cannot send notification: " + notification);
+ } else {
+ template.sendBody(replyToEndpoint, notification);
+ }
+ }
+
+ /**
+ * close the info if the connection times out
+ * <p/>
+ * TODO we should auto-detect that id has timed out and then remove this subscription
+ */
+ public void close() {
+ holder.remove(id);
+ }
+
+ /**
+ * @return Returns the holder.
+ */
+ public Map getHolder() {
+ return holder;
+ }
+
+
+ /**
+ * @return Returns the id.
+ */
+ public String getId() {
+ return id;
+ }
+
+}
\ No newline at end of file
Propchange: activemq/camel/trunk/components/camel-jmxconnect/src/main/java/org/apache/camel/jmxconnect/ServerListenerInfo.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: activemq/camel/trunk/components/camel-jmxconnect/src/main/java/org/apache/camel/jmxconnect/provider/activemq/ActiveMQHelper.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-jmxconnect/src/main/java/org/apache/camel/jmxconnect/provider/activemq/ActiveMQHelper.java?rev=685904&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-jmxconnect/src/main/java/org/apache/camel/jmxconnect/provider/activemq/ActiveMQHelper.java (added)
+++ activemq/camel/trunk/components/camel-jmxconnect/src/main/java/org/apache/camel/jmxconnect/provider/activemq/ActiveMQHelper.java Thu Aug 14 07:09:52 2008
@@ -0,0 +1,36 @@
+/**
+ *
+ * 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.jmxconnect.provider.activemq;
+
+import org.apache.camel.jmxconnect.CamelJmxConnectorSupport;
+import org.apache.camel.CamelContext;
+import org.apache.activemq.camel.component.ActiveMQComponent;
+
+/**
+ * @version $Revision: 1.1 $
+ */
+public class ActiveMQHelper {
+ public static String getDefaultEndpointUri() {
+ return "activemq:" + CamelJmxConnectorSupport.DEFAULT_DESTINATION_PREFIX;
+ }
+
+ public static void configureActiveMQComponent(CamelContext camelContext, String brokerUrl) {
+ ActiveMQComponent activemqComponent = camelContext.getComponent("activemq", ActiveMQComponent.class);
+ activemqComponent.setBrokerURL(brokerUrl);
+ }
+}
Propchange: activemq/camel/trunk/components/camel-jmxconnect/src/main/java/org/apache/camel/jmxconnect/provider/activemq/ActiveMQHelper.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: activemq/camel/trunk/components/camel-jmxconnect/src/main/java/org/apache/camel/jmxconnect/provider/activemq/ClientProvider.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-jmxconnect/src/main/java/org/apache/camel/jmxconnect/provider/activemq/ClientProvider.java?rev=685904&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-jmxconnect/src/main/java/org/apache/camel/jmxconnect/provider/activemq/ClientProvider.java (added)
+++ activemq/camel/trunk/components/camel-jmxconnect/src/main/java/org/apache/camel/jmxconnect/provider/activemq/ClientProvider.java Thu Aug 14 07:09:52 2008
@@ -0,0 +1,45 @@
+/**
+ *
+ * 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.jmxconnect.provider.activemq;
+
+import org.apache.camel.jmxconnect.CamelJmxConnector;
+import org.apache.camel.jmxconnect.CamelJmxConnectorSupport;
+import org.apache.camel.CamelContext;
+
+import javax.management.remote.JMXConnector;
+import javax.management.remote.JMXConnectorProvider;
+import javax.management.remote.JMXServiceURL;
+import java.io.IOException;
+import java.util.Map;
+
+/**
+ * @version $Revision: 1.1 $
+ */
+public class ClientProvider implements JMXConnectorProvider {
+ public JMXConnector newJMXConnector(JMXServiceURL url, Map environment) throws IOException {
+ // use the remaining url as the ActiveMQ broker URI
+ String brokerUrl = CamelJmxConnectorSupport.getEndpointUri(url, "activemq");
+ CamelJmxConnector answer = new CamelJmxConnector(environment, ActiveMQHelper.getDefaultEndpointUri());
+
+ // now lets configure the ActiveMQ component
+ CamelContext camelContext = answer.getCamelContext();
+ ActiveMQHelper.configureActiveMQComponent(camelContext, brokerUrl);
+ return answer;
+ }
+
+}
\ No newline at end of file
Propchange: activemq/camel/trunk/components/camel-jmxconnect/src/main/java/org/apache/camel/jmxconnect/provider/activemq/ClientProvider.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: activemq/camel/trunk/components/camel-jmxconnect/src/main/java/org/apache/camel/jmxconnect/provider/activemq/ServerProvider.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-jmxconnect/src/main/java/org/apache/camel/jmxconnect/provider/activemq/ServerProvider.java?rev=685904&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-jmxconnect/src/main/java/org/apache/camel/jmxconnect/provider/activemq/ServerProvider.java (added)
+++ activemq/camel/trunk/components/camel-jmxconnect/src/main/java/org/apache/camel/jmxconnect/provider/activemq/ServerProvider.java Thu Aug 14 07:09:52 2008
@@ -0,0 +1,47 @@
+/**
+ *
+ * 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.jmxconnect.provider.activemq;
+
+
+import org.apache.camel.jmxconnect.CamelJmxConnectorServer;
+import org.apache.camel.jmxconnect.CamelJmxConnectorSupport;
+import org.apache.camel.CamelContext;
+
+import javax.management.MBeanServer;
+import javax.management.remote.JMXConnectorServer;
+import javax.management.remote.JMXConnectorServerProvider;
+import javax.management.remote.JMXServiceURL;
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.util.Map;
+
+/**
+ * @version $Revision: 1.1 $
+ */
+public class ServerProvider implements JMXConnectorServerProvider {
+
+ public JMXConnectorServer newJMXConnectorServer(JMXServiceURL url, Map environment, MBeanServer server) throws IOException {
+ String brokerUrl = CamelJmxConnectorSupport.getEndpointUri(url, "activemq");
+ CamelJmxConnectorServer answer = new CamelJmxConnectorServer(url, ActiveMQHelper.getDefaultEndpointUri(), environment, server);
+
+ // now lets configure the ActiveMQ component
+ CamelContext camelContext = answer.getCamelContext();
+ ActiveMQHelper.configureActiveMQComponent(camelContext, brokerUrl);
+ return answer;
+ }
+}
\ No newline at end of file
Propchange: activemq/camel/trunk/components/camel-jmxconnect/src/main/java/org/apache/camel/jmxconnect/provider/activemq/ServerProvider.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: activemq/camel/trunk/components/camel-jmxconnect/src/main/java/org/apache/camel/jmxconnect/provider/camel/ClientProvider.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-jmxconnect/src/main/java/org/apache/camel/jmxconnect/provider/camel/ClientProvider.java?rev=685904&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-jmxconnect/src/main/java/org/apache/camel/jmxconnect/provider/camel/ClientProvider.java (added)
+++ activemq/camel/trunk/components/camel-jmxconnect/src/main/java/org/apache/camel/jmxconnect/provider/camel/ClientProvider.java Thu Aug 14 07:09:52 2008
@@ -0,0 +1,36 @@
+/**
+ *
+ * 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.jmxconnect.provider.camel;
+
+import org.apache.camel.jmxconnect.CamelJmxConnector;
+
+import javax.management.remote.JMXConnector;
+import javax.management.remote.JMXConnectorProvider;
+import javax.management.remote.JMXServiceURL;
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.util.Map;
+
+/**
+ * @version $Revision: 1.1 $
+ */
+public class ClientProvider implements JMXConnectorProvider {
+ public JMXConnector newJMXConnector(JMXServiceURL url, Map environment) throws IOException {
+ return new CamelJmxConnector(environment, url);
+ }
+}
Propchange: activemq/camel/trunk/components/camel-jmxconnect/src/main/java/org/apache/camel/jmxconnect/provider/camel/ClientProvider.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: activemq/camel/trunk/components/camel-jmxconnect/src/main/java/org/apache/camel/jmxconnect/provider/camel/ServerProvider.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-jmxconnect/src/main/java/org/apache/camel/jmxconnect/provider/camel/ServerProvider.java?rev=685904&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-jmxconnect/src/main/java/org/apache/camel/jmxconnect/provider/camel/ServerProvider.java (added)
+++ activemq/camel/trunk/components/camel-jmxconnect/src/main/java/org/apache/camel/jmxconnect/provider/camel/ServerProvider.java Thu Aug 14 07:09:52 2008
@@ -0,0 +1,39 @@
+/**
+ *
+ * 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.jmxconnect.provider.camel;
+
+
+import org.apache.camel.jmxconnect.CamelJmxConnectorServer;
+
+import javax.management.MBeanServer;
+import javax.management.remote.JMXConnectorServer;
+import javax.management.remote.JMXConnectorServerProvider;
+import javax.management.remote.JMXServiceURL;
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.util.Map;
+
+/**
+ * @version $Revision: 1.1 $
+ */
+public class ServerProvider implements JMXConnectorServerProvider {
+
+ public JMXConnectorServer newJMXConnectorServer(JMXServiceURL url, Map environment, MBeanServer server) throws IOException {
+ return new CamelJmxConnectorServer(url, environment, server);
+ }
+}
\ No newline at end of file
Propchange: activemq/camel/trunk/components/camel-jmxconnect/src/main/java/org/apache/camel/jmxconnect/provider/camel/ServerProvider.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: activemq/camel/trunk/components/camel-jmxconnect/src/test/java/org/apache/camel/jmxconnect/JmxActiveMQRemoteTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-jmxconnect/src/test/java/org/apache/camel/jmxconnect/JmxActiveMQRemoteTest.java?rev=685904&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-jmxconnect/src/test/java/org/apache/camel/jmxconnect/JmxActiveMQRemoteTest.java (added)
+++ activemq/camel/trunk/components/camel-jmxconnect/src/test/java/org/apache/camel/jmxconnect/JmxActiveMQRemoteTest.java Thu Aug 14 07:09:52 2008
@@ -0,0 +1,34 @@
+/**
+ *
+ * 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.jmxconnect;
+
+/**
+ * @version $Revision: 1.1 $
+ */
+public class JmxActiveMQRemoteTest extends JmxRemoteTest {
+
+ @Override
+ protected void setUp() throws Exception {
+ brokerUrl = "broker:(tcp://localhost:6000)/localhost?persistent=false";
+
+ clientServiceUrl = "service:jmx:activemq:///tcp://localhost:6000";
+ serverServiceUrl = clientServiceUrl;
+
+ super.setUp();
+ }
+}
Propchange: activemq/camel/trunk/components/camel-jmxconnect/src/test/java/org/apache/camel/jmxconnect/JmxActiveMQRemoteTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: activemq/camel/trunk/components/camel-jmxconnect/src/test/java/org/apache/camel/jmxconnect/JmxRemoteTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-jmxconnect/src/test/java/org/apache/camel/jmxconnect/JmxRemoteTest.java?rev=685904&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-jmxconnect/src/test/java/org/apache/camel/jmxconnect/JmxRemoteTest.java (added)
+++ activemq/camel/trunk/components/camel-jmxconnect/src/test/java/org/apache/camel/jmxconnect/JmxRemoteTest.java Thu Aug 14 07:09:52 2008
@@ -0,0 +1,158 @@
+/**
+ *
+ * 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.jmxconnect;
+
+
+import junit.framework.TestCase;
+import org.apache.activemq.broker.BrokerFactory;
+import org.apache.activemq.broker.BrokerService;
+
+import javax.management.*;
+import javax.management.monitor.GaugeMonitor;
+import javax.management.remote.*;
+import java.net.URI;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Arrays;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+/**
+ * @version $Revision: 1.1 $
+ */
+public class JmxRemoteTest extends TestCase {
+ private MBeanServer server;
+ private BrokerService broker;
+ private JMXConnectorServer connectorServer;
+ private JMXConnector connector;
+ private ObjectName serviceName;
+ private SimpleService service;
+ protected String serverServiceUrl = "service:jmx:camel:///activemq:foo";
+ protected String clientServiceUrl = "service:jmx:camel:///activemq:foo";
+ protected String brokerUrl = "broker:(tcp://localhost:61616)/localhost?persistent=false";
+
+ protected void setUp() throws Exception {
+ broker = BrokerFactory.createBroker(new URI(brokerUrl));
+ broker.start();
+
+ server = MBeanServerFactory.createMBeanServer();
+ //register a service
+ service = new SimpleService();
+
+ serviceName = new ObjectName("examples", "mbean", "simple");
+ server.registerMBean(service, serviceName);
+ // start the connector server
+
+ //START SNIPPET: serverJMX
+ //The url to the JMS service
+ JMXServiceURL serverURL = new JMXServiceURL(serverServiceUrl);
+ Map serverEnv = new HashMap();
+ serverEnv.put("jmx.remote.protocol.provider.pkgs", "org.apache.camel.jmxconnect.provider");
+ connectorServer = JMXConnectorServerFactory.newJMXConnectorServer(serverURL, serverEnv, server);
+ connectorServer.start();
+ //END SNIPPET: serverJMX
+
+ //START SNIPPET: clientJMX
+ //Now connect the client-side
+ //The URL to the JMS service
+ JMXServiceURL clientURL = new JMXServiceURL(clientServiceUrl);
+ Map clientEnv = new HashMap();
+ clientEnv.put("jmx.remote.protocol.provider.pkgs", "org.apache.camel.jmxconnect.provider");
+ JMXConnector clientConnector = JMXConnectorFactory.connect(clientURL, clientEnv);
+ // Connect a JSR 160 JMXConnector to the server side
+ connector = JMXConnectorFactory.connect(clientURL, clientEnv);
+ //now test the Connection
+ MBeanServerConnection connection = connector.getMBeanServerConnection();
+ //END SNIPPET: clientJMX
+
+ }
+
+ protected void tearDown() throws Exception {
+ connector.close();
+ connectorServer.stop();
+ broker.stop();
+ }
+
+
+ public void testSimpleRemoteJmx() throws Exception {
+ // Retrieve an MBeanServerConnection that represent the MBeanServer the remote
+ // connector server is bound to
+ MBeanServerConnection connection = connector.getMBeanServerConnection();
+ ObjectName queryName = new ObjectName("*:*");
+ java.util.Set names = connection.queryNames(queryName, null);
+ for (Iterator iter = names.iterator(); iter.hasNext();) {
+ ObjectName name = (ObjectName) iter.next();
+ MBeanInfo beanInfo = connection.getMBeanInfo(name);
+ System.out.println("bean info = " + beanInfo.getDescription());
+ System.out.println("attrs = " + Arrays.asList(beanInfo.getAttributes()));
+ }
+ Object value = connection.getAttribute(serviceName, "SimpleValue");
+ System.out.println("SimpleValue = " + value);
+ Attribute attr = new Attribute("SimpleValue", new Integer(10));
+ connection.setAttribute(serviceName, attr);
+ value = connection.getAttribute(serviceName, "SimpleValue");
+ assertEquals("SimpleValue", value, 10);
+ System.out.println("now SimpleValue = " + value);
+ }
+
+ // TODO not implemented yet!
+ // need server side push, the client needs to register with a replyToEndpoint
+ public void DISABLED_testNotificationsJmx() throws Exception {
+
+ // Now let's register a Monitor
+ // We would like to know if we have peaks in activity, so we can use JMX's
+ // GaugeMonitor
+ GaugeMonitor monitorMBean = new GaugeMonitor();
+ ObjectName monitorName = new ObjectName("examples", "monitor", "gauge");
+ server.registerMBean(monitorMBean, monitorName);
+ // Setup the monitor: we want to be notified if we have too many clients or too less
+ monitorMBean.setThresholds(new Integer(8), new Integer(4));
+ // Setup the monitor: we want to know if a threshold is exceeded
+ monitorMBean.setNotifyHigh(true);
+ monitorMBean.setNotifyLow(true);
+
+ monitorMBean.setDifferenceMode(false);
+ // Setup the monitor: link to the service MBean
+ monitorMBean.addObservedObject(serviceName);
+ monitorMBean.setObservedAttribute("SimpleCounter");
+ // Setup the monitor: a short granularity period
+ monitorMBean.setGranularityPeriod(50L);
+ // Setup the monitor: register a listener
+ MBeanServerConnection connection = connector.getMBeanServerConnection();
+ final AtomicBoolean notificationSet = new AtomicBoolean(false);
+ //Add a notification listener to the connection - to
+ //test for notifications across camel
+ connection.addNotificationListener(monitorName, new NotificationListener() {
+ public void handleNotification(Notification notification, Object handback) {
+ System.out.println("Notification = " + notification);
+ synchronized (notificationSet) {
+ notificationSet.set(true);
+ notificationSet.notify();
+ }
+ }
+ }, null, null);
+ service.start();
+ monitorMBean.start();
+ synchronized (notificationSet) {
+ if (!notificationSet.get()) {
+ notificationSet.wait(5000);
+ }
+ }
+ assertTrue(notificationSet.get());
+ }
+}
\ No newline at end of file
Propchange: activemq/camel/trunk/components/camel-jmxconnect/src/test/java/org/apache/camel/jmxconnect/JmxRemoteTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: activemq/camel/trunk/components/camel-jmxconnect/src/test/java/org/apache/camel/jmxconnect/SimpleService.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-jmxconnect/src/test/java/org/apache/camel/jmxconnect/SimpleService.java?rev=685904&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-jmxconnect/src/test/java/org/apache/camel/jmxconnect/SimpleService.java (added)
+++ activemq/camel/trunk/components/camel-jmxconnect/src/test/java/org/apache/camel/jmxconnect/SimpleService.java Thu Aug 14 07:09:52 2008
@@ -0,0 +1,85 @@
+/**
+ *
+ * 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.jmxconnect;
+
+/**
+ * This is based heavily on the DynamicService example from the mx4j project
+ *
+ * @version $Revision: 1.1 $
+ */
+public class SimpleService implements Runnable, SimpleServiceMBean {
+ private boolean running;
+ private int simpleCounter = 0;
+ private int simpleValue = 0;
+
+ public void start() {
+ if (!running) {
+ running = true;
+ Thread thread = new Thread(this);
+ thread.start();
+ }
+ }
+
+ public void stop() {
+ running = false;
+ }
+
+ public void run() {
+ while (running) {
+ simpleCounter++;
+ try {
+ Thread.sleep(250);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
+ public void setSimpleCounter(int simpleCounter) {
+ this.simpleCounter = simpleCounter;
+ }
+
+ public int getSimpleCounter() {
+ return simpleCounter;
+ }
+
+ public int getSimpleValue() {
+ return simpleValue;
+ }
+
+ public void setSimpleValue(int simpleValue) {
+ this.simpleValue = simpleValue;
+ }
+/*
+
+ protected MBeanAttributeInfo[] createMBeanAttributeInfo(){
+ return new MBeanAttributeInfo[] {
+ new MBeanAttributeInfo("SimpleCounter","int","test simpleCounter",true,false,false),
+ new MBeanAttributeInfo("SimpleValue","int","test simpleValue",true,true,false) };
+ }
+
+ protected MBeanOperationInfo[] createMBeanOperationInfo(){
+ return new MBeanOperationInfo[] {
+ new MBeanOperationInfo("start","Starts the SimpleService",new MBeanParameterInfo[0],"void",
+ MBeanOperationInfo.ACTION),
+ new MBeanOperationInfo("stop","Stops the SimpleService",new MBeanParameterInfo[0],"void",
+ MBeanOperationInfo.ACTION) };
+ }*/
+
+
+}
Propchange: activemq/camel/trunk/components/camel-jmxconnect/src/test/java/org/apache/camel/jmxconnect/SimpleService.java
------------------------------------------------------------------------------
svn:eol-style = native