[CVS nano] update
Paul Hammant <paul-yCVjj/[email protected]> Mon, 17 Nov 2003 15:02:00 -0600
| Newsgroups | gmane.comp.java.nanocontainer.cvs |
|---|---|
| Message-ID | <[email protected]> |
Commit in nano/jmx/src/java/org/picoextras/jmx on MAIN
NanoMBean.java +27 added 1.1
NanoMXComponentAdapter.java +92 added 1.1
NanoMXComponentAdapterFactory.java +25 added 1.1
NanoMXContainer.java +84 added 1.1
NanoMXInitializationException.java +36 added 1.1
NanoMXRegistrationException.java +39 added 1.1
+303
6 added files
update
----------
nano /jmx /src /java /org /picoextras /jmx
NanoMBean.java added at 1.1
diff -N NanoMBean.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ NanoMBean.java 17 Nov 2003 21:01:59 -0000 1.1
@@ -0,0 +1,27 @@
+/*****************************************************************************
+ * Copyright (C) NanoContainer Organization. All rights reserved. *
+ * ------------------------------------------------------------------------- *
+ * The software in this package is published under the terms of the BSD *
+ * style license a copy of which has been included with this distribution in *
+ * the LICENSE.txt file. *
+ * *
+ * Original code by James Strachan *
+ *****************************************************************************/
+package org.picoextras.jmx;
+
+import mx4j.AbstractDynamicMBean;
+
+/**
+ * @author James Strachan
+ * @version $Revision: 1.1 $
+ */
+public class NanoMBean extends AbstractDynamicMBean {
+
+ public NanoMBean(Object component) {
+ setResource(component);
+ }
+ /* Method of the second group that is overridden */
+ protected String getMBeanDescription() {
+ return "A simple DynamicMBean";
+ }
+}
----------
nano /jmx /src /java /org /picoextras /jmx
NanoMXComponentAdapter.java added at 1.1
diff -N NanoMXComponentAdapter.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ NanoMXComponentAdapter.java 17 Nov 2003 21:01:59 -0000 1.1
@@ -0,0 +1,92 @@
+/*****************************************************************************
+ * Copyright (C) NanoContainer Organization. All rights reserved. *
+ * ------------------------------------------------------------------------- *
+ * The software in this package is published under the terms of the BSD *
+ * style license a copy of which has been included with this distribution in *
+ * the LICENSE.txt file. *
+ * *
+ * Original code by James Strachan and Mauro Talevi *
+ *****************************************************************************/
+package org.picoextras.jmx;
+
+import org.picocontainer.extras.DecoratingComponentAdapter;
+import org.picocontainer.ComponentAdapter;
+import org.picocontainer.defaults.AssignabilityRegistrationException;
+import org.picocontainer.defaults.NotConcreteRegistrationException;
+import org.picocontainer.PicoInitializationException;
+import org.picocontainer.PicoIntrospectionException;
+import org.picocontainer.MutablePicoContainer;
+
+import javax.management.*;
+
+/**
+ * @author James Strachan
+ * @author Mauro Talevi
+ * @author Jeppe Cramon
+ * @version $Revision: 1.1 $
+ */
+public class NanoMXComponentAdapter extends DecoratingComponentAdapter {
+
+ private final MBeanServer mbeanServer;
+ private Object componentInstance;
+
+ /**
+ * @param mbeanServer
+ */
+ public NanoMXComponentAdapter(MBeanServer mbeanServer, ComponentAdapter delegate) {
+ super(delegate);
+ this.mbeanServer = mbeanServer;
+ }
+
+ public Object getComponentInstance(MutablePicoContainer picoContainer) throws PicoInitializationException, PicoIntrospectionException, AssignabilityRegistrationException, NotConcreteRegistrationException {
+ if (componentInstance == null) {
+ componentInstance = super.getComponentInstance(picoContainer);
+
+ ObjectName name = null;
+ try {
+ name = asObjectName(getComponentKey());
+ Object mbean = asMBean(componentInstance);
+ mbeanServer.registerMBean(mbean, name);
+ } catch (MalformedObjectNameException e) {
+ throw new NanoMXInitializationException("Failed to register MBean '" + name + "' for component '" + getComponentKey() + "', due to " + e.getMessage(), e);
+ } catch (MBeanRegistrationException e) {
+ throw new NanoMXInitializationException("Failed to register MBean '" + name + "' for component '" + getComponentKey() + "', due to " + e.getMessage(), e);
+ } catch (NotCompliantMBeanException e) {
+ throw new NanoMXInitializationException("Failed to register MBean '" + name + "' for component '" + getComponentKey() + "', due to " + e.getMessage(), e);
+ } catch (InstanceAlreadyExistsException e) {
+ throw new NanoMXInitializationException("Failed to register MBean '" + name + "' for component '" + getComponentKey() + "', due to " + e.getMessage(), e);
+ }
+ return componentInstance;
+ }
+ return componentInstance;
+ }
+
+ public static Object asMBean(Object component) {
+ return new NanoMBean(component);
+ }
+
+ /**
+ * Ensures that the given key is converted to a JMX ObjectName
+ * @param key
+ * @return an ObjectName based on the given key
+ */
+ public static ObjectName asObjectName(Object key) throws MalformedObjectNameException {
+ if (key == null) {
+ throw new NullPointerException("key cannot be null");
+ }
+ if (key instanceof ObjectName) {
+ return (ObjectName) key;
+ }
+ if (key instanceof Class) {
+ Class clazz = (Class) key;
+ return new ObjectName("nanomx:type=" + clazz.getName());
+ } else {
+ String text = key.toString();
+ // Fix, so it works under WebSphere ver. 5
+ if (text.indexOf(':') == -1) {
+ text = "nanomx:type=" + text;
+ }
+ return new ObjectName(text);
+ }
+ }
+}
----------
nano /jmx /src /java /org /picoextras /jmx
NanoMXComponentAdapterFactory.java added at 1.1
diff -N NanoMXComponentAdapterFactory.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ NanoMXComponentAdapterFactory.java 17 Nov 2003 21:01:59 -0000 1.1
@@ -0,0 +1,25 @@
+package org.picoextras.jmx;
+
+import org.picocontainer.defaults.ComponentAdapterFactory;
+import org.picocontainer.ComponentAdapter;
+import org.picocontainer.defaults.AssignabilityRegistrationException;
+import org.picocontainer.defaults.NotConcreteRegistrationException;
+import org.picocontainer.Parameter;
+import org.picocontainer.PicoIntrospectionException;
+
+import javax.management.MBeanServer;
+import java.io.Serializable;
+
+public class NanoMXComponentAdapterFactory implements ComponentAdapterFactory, Serializable {
+ private MBeanServer mbeanServer;
+ private ComponentAdapterFactory delegate;
+
+ public NanoMXComponentAdapterFactory(MBeanServer mbeanServer, ComponentAdapterFactory componentAdapterFactory) {
+ this.mbeanServer = mbeanServer;
+ delegate = componentAdapterFactory;
+ }
+
+ public ComponentAdapter createComponentAdapter(Object componentKey, Class componentImplementation, Parameter[] parameters) throws PicoIntrospectionException, AssignabilityRegistrationException, NotConcreteRegistrationException {
+ return new NanoMXComponentAdapter(mbeanServer, delegate.createComponentAdapter(componentKey, componentImplementation, parameters));
+ }
+}
----------
nano /jmx /src /java /org /picoextras /jmx
NanoMXContainer.java added at 1.1
diff -N NanoMXContainer.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ NanoMXContainer.java 17 Nov 2003 21:01:59 -0000 1.1
@@ -0,0 +1,84 @@
+/*****************************************************************************
+ * Copyright (C) NanoContainer Organization. All rights reserved. *
+ * ------------------------------------------------------------------------- *
+ * The software in this package is published under the terms of the BSD *
+ * style license a copy of which has been included with this distribution in *
+ * the LICENSE.txt file. *
+ * *
+ * Original code by James Strachan and Mauro Talevi *
+ *****************************************************************************/
+
+package org.picoextras.jmx;
+
+import org.picocontainer.PicoRegistrationException;
+import org.picocontainer.defaults.*;
+import org.picocontainer.defaults.ComponentAdapterFactory;
+
+import javax.management.*;
+import java.io.Serializable;
+
+/**
+ * A simple PicoContainer which allow multiple implementations of the same interface
+ * and any component registered with the internals is also registered into JMX
+ * for viewing in a JMX management console.
+ *
+ * @author James Strachan
+ * @author Mauro Talevi
+ * @author Aslak Hellesøy
+ * @author Jeppe Cramon
+ * @version $Revision: 1.1 $
+ */
+public class NanoMXContainer extends DefaultPicoContainer implements Serializable {
+
+ private MBeanServer mbeanServer;
+
+ public NanoMXContainer(MBeanServer mbeanServer, ComponentAdapterFactory componentAdapterFactory) {
+ super(new NanoMXComponentAdapterFactory(mbeanServer, componentAdapterFactory));
+ this.mbeanServer = mbeanServer;
+ }
+
+ public NanoMXContainer(MBeanServer mbeanServer) {
+ this(mbeanServer, new DefaultComponentAdapterFactory());
+ }
+
+ public NanoMXContainer() {
+ this(MBeanServerFactory.newMBeanServer());
+ MBeanServerFactory.createMBeanServer();
+ }
+
+ public MBeanServer getMBeanServer() {
+ return mbeanServer;
+ }
+
+ /**
+ * Registers a new constructed component with the given key
+ *
+ * @param key is the key (or name) used to lookup the component in the future
+ * @param component is the component to be registered
+ * @throws PicoRegistrationException
+ */
+ public synchronized Object registerComponentInstance(Object key, Object component)
+ throws PicoRegistrationException {
+ ObjectName name = null;
+ try {
+ name = NanoMXComponentAdapter.asObjectName(key);
+ Object result = super.registerComponentInstance(key, component);
+
+ Object mbean = NanoMXComponentAdapter.asMBean(component);
+ mbeanServer.registerMBean(mbean, name);
+
+ return result;
+ } catch (InstanceAlreadyExistsException e) {
+ throw new NanoMXRegistrationException("Failed to register MBean '" + name + "' for component '" + key + "', due to " + e.getMessage(), e);
+ } catch (MBeanRegistrationException e) {
+ throw new NanoMXRegistrationException("Failed to register MBean '" + name + "' for component '" + key + "', due to " + e.getMessage(), e);
+ } catch (NotCompliantMBeanException e) {
+ throw new NanoMXRegistrationException("Failed to register MBean '" + name + "' for component '" + key + "', due to " + e.getMessage(), e);
+ } catch (MalformedObjectNameException e) {
+ throw new NanoMXRegistrationException("Failed to register MBean '" + name + "' for component '" + key + "', due to " + e.getMessage(), e);
+ } catch (PicoRegistrationException e) {
+ throw new NanoMXRegistrationException("Failed to register MBean '" + name + "' for component '" + key + "', due to " + e.getMessage(), e);
+ }
+ }
+
+}
----------
nano /jmx /src /java /org /picoextras /jmx
NanoMXInitializationException.java added at 1.1
diff -N NanoMXInitializationException.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ NanoMXInitializationException.java 17 Nov 2003 21:01:59 -0000 1.1
@@ -0,0 +1,36 @@
+/*****************************************************************************
+ * Copyright (C) NanoContainer Organization. All rights reserved. *
+ * ------------------------------------------------------------------------- *
+ * The software in this package is published under the terms of the BSD *
+ * style license a copy of which has been included with this distribution in *
+ * the LICENSE.txt file. *
+ * *
+ * Original code by James Strachan and Mauro Talevi *
+ *****************************************************************************/
+package org.picoextras.jmx;
+
+import org.picocontainer.PicoInitializationException;
+
+/**
+ * A registration exception caused trying to register the component with JMX
+ *
+ * @author James Strachan
+ * @author Mauro Talevi
+ * @version $Revision: 1.1 $
+ */
+public class NanoMXInitializationException extends PicoInitializationException {
+ public NanoMXInitializationException() {
+ }
+
+ public NanoMXInitializationException(String message) {
+ super(message);
+ }
+
+ public NanoMXInitializationException(Throwable cause) {
+ super(cause);
+ }
+
+ public NanoMXInitializationException(String message, Throwable cause) {
+ super(message, cause);
+ }
+}
----------
nano /jmx /src /java /org /picoextras /jmx
NanoMXRegistrationException.java added at 1.1
diff -N NanoMXRegistrationException.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ NanoMXRegistrationException.java 17 Nov 2003 21:01:59 -0000 1.1
@@ -0,0 +1,39 @@
+/*****************************************************************************
+ * Copyright (C) NanoContainer Organization. All rights reserved. *
+ * ------------------------------------------------------------------------- *
+ * The software in this package is published under the terms of the BSD *
+ * style license a copy of which has been included with this distribution in *
+ * the LICENSE.txt file. *
+ * *
+ * Original code by James Strachan and Mauro Talevi *
+ *****************************************************************************/
+package org.picoextras.jmx;
+
+import org.picocontainer.PicoRegistrationException;
+
+/**
+ * A registration exception caused trying to register the component with JMX
+ *
+ * @author James Strachan
+ * @author Mauro Talevi
+ * @author Jeppe Cramon
+ * @version $Revision: 1.1 $
+ */
+public class NanoMXRegistrationException extends PicoRegistrationException {
+ public NanoMXRegistrationException() {
+ super();
+ }
+
+ public NanoMXRegistrationException(String message) {
+ super(message);
+ }
+
+
+ public NanoMXRegistrationException(String message, Exception cause) {
+ super(message, cause);
+ }
+
+ public NanoMXRegistrationException(Throwable cause) {
+ super(cause);
+ }
+}