Author: ningjiang
Date: Mon May 12 20:10:59 2008
New Revision: 655720
URL: http://svn.apache.org/viewvc?rev=655720&view=rev
Log:
CAMEL-508 patch applied with thanks to William, also fixed some CS errors in
camel-core
Added:
activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/management/JmxInstrumentationUsingPlatformMBSTest.java
(with props)
Modified:
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/NoTypeConversionAvailableException.java
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultComponent.java
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultEndpoint.java
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/management/InstrumentationAgentImpl.java
activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/impl/DefaultComponentTest.java
activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/management/JmxInstrumentationUsingPropertiesTest.java
Modified:
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/NoTypeConversionAvailableException.java
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/NoTypeConversionAvailableException.java?rev=655720&r1=655719&r2=655720&view=diff
==============================================================================
---
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/NoTypeConversionAvailableException.java
(original)
+++
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/NoTypeConversionAvailableException.java
Mon May 12 20:10:59 2008
@@ -18,7 +18,7 @@
/**
* An exception thrown if a value could not be converted to the required type
- *
+ *
* @version $Revision$
*/
public class NoTypeConversionAvailableException extends RuntimeCamelException {
@@ -26,8 +26,8 @@
private final Class type;
public NoTypeConversionAvailableException(Object value, Class type) {
- super("No type converter available to convert from type: " + (value !=
null ? value.getClass() : null) +
- " to the required type " + type.getName() + " with value " +
value);
+ super("No type converter available to convert from type: " + (value !=
null ? value.getClass() : null)
+ + " to the required type " + type.getName() + " with value " +
value);
this.value = value;
this.type = type;
}
Modified:
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultComponent.java
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultComponent.java?rev=655720&r1=655719&r2=655720&view=diff
==============================================================================
---
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultComponent.java
(original)
+++
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultComponent.java
Mon May 12 20:10:59 2008
@@ -91,10 +91,10 @@
// fail if there are parameters that could not be set, then they
are probably miss spelt or not supported at all
if (parameters.size() > 0) {
- throw new ResolveEndpointFailedException(uri, "There are " +
parameters.size() +
- " parameters that couldn't be set on the endpoint." +
- " Check the uri if the parameters are spelt correctly and
that they are properties of the endpoint." +
- " Unknown parameters=[" + parameters + "]");
+ throw new ResolveEndpointFailedException(uri, "There are " +
parameters.size()
+ + " parameters that couldn't be set on the endpoint."
+ + " Check the uri if the parameters are spelt correctly
and that they are properties of the endpoint."
+ + " Unknown parameters=[" + parameters + "]");
}
}
Modified:
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultEndpoint.java
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultEndpoint.java?rev=655720&r1=655719&r2=655720&view=diff
==============================================================================
---
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultEndpoint.java
(original)
+++
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultEndpoint.java
Mon May 12 20:10:59 2008
@@ -23,12 +23,12 @@
import java.util.concurrent.ScheduledThreadPoolExecutor;
import org.apache.camel.CamelContext;
+import org.apache.camel.CamelContextAware;
import org.apache.camel.Component;
import org.apache.camel.Endpoint;
import org.apache.camel.Exchange;
import org.apache.camel.ExchangePattern;
import org.apache.camel.PollingConsumer;
-import org.apache.camel.CamelContextAware;
import org.apache.camel.util.ObjectHelper;
/**
Modified:
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/management/InstrumentationAgentImpl.java
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/management/InstrumentationAgentImpl.java?rev=655720&r1=655719&r2=655720&view=diff
==============================================================================
---
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/management/InstrumentationAgentImpl.java
(original)
+++
activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/management/InstrumentationAgentImpl.java
Mon May 12 20:10:59 2008
@@ -54,6 +54,7 @@
public class InstrumentationAgentImpl extends ServiceSupport implements
InstrumentationAgent,
CamelContextAware {
public static final String SYSTEM_PROPERTY_JMX = "org.apache.camel.jmx";
+ public static final String SYSTEM_PROPERTY_JMX_USE_PLATFORM_MBS =
SYSTEM_PROPERTY_JMX + ".usePlatformMBeanServer";
public static final String DEFAULT_DOMAIN = "org.apache.camel";
public static final String DEFAULT_HOST = "localhost";
public static final int DEFAULT_PORT = 1099;
@@ -93,7 +94,8 @@
public MBeanServer getMBeanServer() {
if (server == null) {
- server = ManagementFactory.getPlatformMBeanServer();
+ // The MBeanServer was not injected
+ createMBeanServer();
}
return server;
}
@@ -138,8 +140,8 @@
ObjectHelper.notNull(context, "camelContext");
if (getMBeanServer() == null) {
- // The MBeanServer was not injected
- createMBeanServer();
+ // No mbean server or jmx not enabled
+ return;
}
if (jmxDomainName == null) {
@@ -161,7 +163,7 @@
}
protected void doStop() throws Exception {
- // close JMX Connector
+ // close JMX Connector
if (cs != null) {
try {
cs.stop();
@@ -170,7 +172,7 @@
}
cs = null;
}
-
+
// Using the array to hold the busMBeans to avoid the
// CurrentModificationException
Object[] mBeans = mbeans.toArray();
@@ -278,13 +280,17 @@
}
// jmx is enabled but there's no MBeanServer, so create one
- List servers = MBeanServerFactory.findMBeanServer(jmxDomainName);
- if (servers.size() == 0) {
- server = MBeanServerFactory.createMBeanServer(jmxDomainName);
+ if (Boolean.getBoolean(SYSTEM_PROPERTY_JMX_USE_PLATFORM_MBS)) {
+ server = ManagementFactory.getPlatformMBeanServer();
} else {
- server = (MBeanServer)servers.get(0);
+ // jmx is enabled but there's no MBeanServer, so create one
+ List servers = MBeanServerFactory.findMBeanServer(jmxDomainName);
+ if (servers.size() == 0) {
+ server = MBeanServerFactory.createMBeanServer(jmxDomainName);
+ } else {
+ server = (MBeanServer)servers.get(0);
+ }
}
-
// we need a connector too
try {
createJmxConnector(hostName);
Modified:
activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/impl/DefaultComponentTest.java
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/impl/DefaultComponentTest.java?rev=655720&r1=655719&r2=655720&view=diff
==============================================================================
---
activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/impl/DefaultComponentTest.java
(original)
+++
activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/impl/DefaultComponentTest.java
Mon May 12 20:10:59 2008
@@ -28,7 +28,7 @@
*/
public class DefaultComponentTest extends ContextTestSupport {
- private class MyComponent extends DefaultComponent<DefaultExchange> {
+ private final class MyComponent extends DefaultComponent<DefaultExchange> {
private MyComponent(CamelContext context) {
super(context);
Added:
activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/management/JmxInstrumentationUsingPlatformMBSTest.java
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/management/JmxInstrumentationUsingPlatformMBSTest.java?rev=655720&view=auto
==============================================================================
---
activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/management/JmxInstrumentationUsingPlatformMBSTest.java
(added)
+++
activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/management/JmxInstrumentationUsingPlatformMBSTest.java
Mon May 12 20:10:59 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.management;
+
+import javax.management.ObjectName;
+
+/**
+ * @version $Revision$
+ */
+public class JmxInstrumentationUsingPlatformMBSTest extends
JmxInstrumentationUsingPropertiesTest {
+
+ @Override
+ protected void setUp() throws Exception {
+
System.setProperty(InstrumentationAgentImpl.SYSTEM_PROPERTY_JMX_USE_PLATFORM_MBS,
"True");
+ super.setUp();
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ // restore environment to original state
+
System.setProperty(InstrumentationAgentImpl.SYSTEM_PROPERTY_JMX_USE_PLATFORM_MBS,
"");
+ super.tearDown();
+ }
+
+ @Override
+ public void testMBeanServerType() throws Exception {
+ assertNotNull(iAgent.getMBeanServer().getMBeanInfo(
+ new ObjectName("java.lang:type=OperatingSystem")));
+ }
+
+}
Propchange:
activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/management/JmxInstrumentationUsingPlatformMBSTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/management/JmxInstrumentationUsingPlatformMBSTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified:
activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/management/JmxInstrumentationUsingPropertiesTest.java
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/management/JmxInstrumentationUsingPropertiesTest.java?rev=655720&r1=655719&r2=655720&view=diff
==============================================================================
---
activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/management/JmxInstrumentationUsingPropertiesTest.java
(original)
+++
activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/management/JmxInstrumentationUsingPropertiesTest.java
Mon May 12 20:10:59 2008
@@ -16,6 +16,9 @@
*/
package org.apache.camel.management;
+import javax.management.InstanceNotFoundException;
+import javax.management.ObjectName;
+
public class JmxInstrumentationUsingPropertiesTest extends
JmxInstrumentationUsingDefaultsTest {
@@ -41,4 +44,14 @@
protected void enableJmx() {
// do not enable here, System properties should do the job
}
+
+ public void testMBeanServerType() throws Exception {
+ try {
+ iAgent.getMBeanServer().getMBeanInfo(new
ObjectName("java.lang:type=OperatingSystem"));
+ assertTrue(false); // should not get here
+ } catch (InstanceNotFoundException e) {
+ // expect exception since this is not a platform mbean server
+ }
+ }
+
}