[jboss-cvs] JBossAS SVN: r86472 - in projects/jbossmx/trunk: mbeanserver and 7 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Mon Mar 30 10:10:52 EDT 2009
Author: adrian at jboss.org
Date: 2009-03-30 10:10:52 -0400 (Mon, 30 Mar 2009)
New Revision: 86472
Added:
projects/jbossmx/trunk/mbeanserver/
projects/jbossmx/trunk/mbeanserver/.classpath
projects/jbossmx/trunk/mbeanserver/.project
projects/jbossmx/trunk/mbeanserver/.settings/
projects/jbossmx/trunk/mbeanserver/.settings/org.eclipse.jdt.core.prefs
projects/jbossmx/trunk/mbeanserver/pom.xml
projects/jbossmx/trunk/mbeanserver/src/
projects/jbossmx/trunk/mbeanserver/src/main/
projects/jbossmx/trunk/mbeanserver/src/main/org/
projects/jbossmx/trunk/mbeanserver/src/main/org/jboss/
projects/jbossmx/trunk/mbeanserver/src/main/org/jboss/jmx/
projects/jbossmx/trunk/mbeanserver/src/main/org/jboss/jmx/mbeanserver/
projects/jbossmx/trunk/mbeanserver/src/main/org/jboss/jmx/mbeanserver/DelegateMBeanServer.java
projects/jbossmx/trunk/mbeanserver/src/main/org/jboss/jmx/mbeanserver/DelegateState.java
projects/jbossmx/trunk/mbeanserver/src/main/org/jboss/jmx/mbeanserver/JBossMBeanRegistry.java
projects/jbossmx/trunk/mbeanserver/src/main/org/jboss/jmx/mbeanserver/JBossMBeanServer.java
projects/jbossmx/trunk/mbeanserver/src/main/org/jboss/jmx/mbeanserver/JBossMBeanServerBuilder.java
projects/jbossmx/trunk/mbeanserver/src/main/org/jboss/jmx/mbeanserver/MBeanServerChain.java
projects/jbossmx/trunk/mbeanserver/src/main/org/jboss/jmx/mbeanserver/RegistryEntry.java
projects/jbossmx/trunk/mbeanserver/src/main/org/jboss/jmx/mbeanserver/SecurityActions.java
Modified:
projects/jbossmx/trunk/pom.xml
Log:
[JBMX-11] - Initial version of MBeanServerChain to add JBossMX features to the JDK MBeanServer
Added: projects/jbossmx/trunk/mbeanserver/.classpath
===================================================================
--- projects/jbossmx/trunk/mbeanserver/.classpath (rev 0)
+++ projects/jbossmx/trunk/mbeanserver/.classpath 2009-03-30 14:10:52 UTC (rev 86472)
@@ -0,0 +1,5 @@
+<classpath>
+ <classpathentry kind="src" path="src/main"/>
+ <classpathentry kind="output" path="target/classes"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+</classpath>
\ No newline at end of file
Added: projects/jbossmx/trunk/mbeanserver/.project
===================================================================
--- projects/jbossmx/trunk/mbeanserver/.project (rev 0)
+++ projects/jbossmx/trunk/mbeanserver/.project 2009-03-30 14:10:52 UTC (rev 86472)
@@ -0,0 +1,13 @@
+<projectDescription>
+ <name>jboss-mbeanserver</name>
+ <comment>JBossMX (mbeanserver module)</comment>
+ <projects/>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
\ No newline at end of file
Added: projects/jbossmx/trunk/mbeanserver/.settings/org.eclipse.jdt.core.prefs
===================================================================
--- projects/jbossmx/trunk/mbeanserver/.settings/org.eclipse.jdt.core.prefs (rev 0)
+++ projects/jbossmx/trunk/mbeanserver/.settings/org.eclipse.jdt.core.prefs 2009-03-30 14:10:52 UTC (rev 86472)
@@ -0,0 +1,5 @@
+#Mon Mar 30 15:03:58 CEST 2009
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.source=1.5
+org.eclipse.jdt.core.compiler.compliance=1.5
Added: projects/jbossmx/trunk/mbeanserver/pom.xml
===================================================================
--- projects/jbossmx/trunk/mbeanserver/pom.xml (rev 0)
+++ projects/jbossmx/trunk/mbeanserver/pom.xml 2009-03-30 14:10:52 UTC (rev 86472)
@@ -0,0 +1,28 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <parent>
+ <groupId>org.jboss.mx</groupId>
+ <artifactId>jboss-mx</artifactId>
+ <version>6.0.0-SNAPSHOT</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.jboss.mx</groupId>
+ <artifactId>jboss-mbeanserver</artifactId>
+ <packaging>jar</packaging>
+ <name>JBossMX MBeanServer</name>
+ <url>http://www.jboss.org/jbossmx</url>
+ <description>JBossMX (mbeanserver module)</description>
+ <build>
+ <sourceDirectory>src/main</sourceDirectory>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <version>2.3</version>
+ <configuration>
+ <skip>true</skip>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
Added: projects/jbossmx/trunk/mbeanserver/src/main/org/jboss/jmx/mbeanserver/DelegateMBeanServer.java
===================================================================
--- projects/jbossmx/trunk/mbeanserver/src/main/org/jboss/jmx/mbeanserver/DelegateMBeanServer.java (rev 0)
+++ projects/jbossmx/trunk/mbeanserver/src/main/org/jboss/jmx/mbeanserver/DelegateMBeanServer.java 2009-03-30 14:10:52 UTC (rev 86472)
@@ -0,0 +1,392 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat Middleware LLC, and individual contributors
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.jmx.mbeanserver;
+
+import java.io.ObjectInputStream;
+import java.util.Set;
+
+import javax.management.Attribute;
+import javax.management.AttributeList;
+import javax.management.AttributeNotFoundException;
+import javax.management.InstanceAlreadyExistsException;
+import javax.management.InstanceNotFoundException;
+import javax.management.IntrospectionException;
+import javax.management.InvalidAttributeValueException;
+import javax.management.ListenerNotFoundException;
+import javax.management.MBeanException;
+import javax.management.MBeanInfo;
+import javax.management.MBeanRegistrationException;
+import javax.management.MBeanServer;
+import javax.management.MBeanServerDelegate;
+import javax.management.NotCompliantMBeanException;
+import javax.management.NotificationFilter;
+import javax.management.NotificationListener;
+import javax.management.ObjectInstance;
+import javax.management.ObjectName;
+import javax.management.OperationsException;
+import javax.management.QueryExp;
+import javax.management.ReflectionException;
+import javax.management.loading.ClassLoaderRepository;
+
+/**
+ * DelegateMBeanServer.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public abstract class DelegateMBeanServer implements MBeanServer
+{
+ /** The next MBeaNServer */
+ private MBeanServer next;
+
+ /** The delegate state */
+ private DelegateState state;
+
+ public DelegateMBeanServer(DelegateState state)
+ {
+ if (state == null)
+ throw new IllegalArgumentException("Null state");
+ this.state = state;
+ }
+
+ /**
+ * Get the next.
+ *
+ * @return the next
+ */
+ protected MBeanServer getNext()
+ {
+ return next;
+ }
+
+ /**
+ * Set the next.
+ *
+ * @param next the next.
+ */
+ protected void setNext(MBeanServer next)
+ {
+ this.next = next;
+ }
+
+ /**
+ * Get the outer.
+ *
+ * @return the outer.
+ */
+ protected MBeanServer getOuter()
+ {
+ return getState().getOuter();
+ }
+
+ /**
+ * Get the delegate.
+ *
+ * @return the delegate.
+ */
+ protected MBeanServerDelegate getDelegate()
+ {
+ return getState().getDelegate();
+ }
+
+ /**
+ * Get the state.
+ *
+ * @return the state.
+ */
+ protected DelegateState getState()
+ {
+ return state;
+ }
+
+ public String getDefaultDomain()
+ {
+ return getNext().getDefaultDomain();
+ }
+
+ public String[] getDomains()
+ {
+ return getNext().getDomains();
+ }
+
+ public Integer getMBeanCount()
+ {
+ return getNext().getMBeanCount();
+ }
+
+ public MBeanInfo getMBeanInfo(ObjectName name)
+ throws InstanceNotFoundException,
+ IntrospectionException,
+ ReflectionException
+ {
+ return getNext().getMBeanInfo(name);
+ }
+
+ public Object getAttribute(ObjectName name, String attribute)
+ throws MBeanException,
+ AttributeNotFoundException,
+ InstanceNotFoundException,
+ ReflectionException
+ {
+ return getNext().getAttribute(name, attribute);
+ }
+
+ public AttributeList getAttributes(ObjectName name, String[] attributes)
+ throws InstanceNotFoundException,
+ ReflectionException
+ {
+ return getNext().getAttributes(name, attributes);
+ }
+
+ public void setAttribute(ObjectName name, Attribute attribute)
+ throws InstanceNotFoundException,
+ AttributeNotFoundException,
+ InvalidAttributeValueException,
+ MBeanException,
+ ReflectionException
+ {
+ getNext().setAttribute(name, attribute);
+ }
+
+ public AttributeList setAttributes(ObjectName name, AttributeList attributes)
+ throws InstanceNotFoundException,
+ ReflectionException
+ {
+ return getNext().setAttributes(name, attributes);
+ }
+
+ public Object invoke(ObjectName name, String operationName, Object[] params, String[] signature)
+ throws InstanceNotFoundException,
+ MBeanException,
+ ReflectionException
+ {
+ return getNext().invoke(name, operationName, params, signature);
+ }
+
+ public ObjectInstance registerMBean(Object object, ObjectName name)
+ throws InstanceAlreadyExistsException,
+ MBeanRegistrationException,
+ NotCompliantMBeanException
+ {
+ return getNext().registerMBean(object, name);
+ }
+
+ public void unregisterMBean(ObjectName name) throws InstanceNotFoundException, MBeanRegistrationException
+ {
+ getNext().unregisterMBean(name);
+ }
+
+ public ObjectInstance createMBean(String className,
+ ObjectName name,
+ Object[] params,
+ String[] signature)
+ throws ReflectionException,
+ InstanceAlreadyExistsException,
+ MBeanRegistrationException,
+ MBeanException,
+ NotCompliantMBeanException
+ {
+ return getNext().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
+ {
+ return getNext().createMBean(className, name, loaderName, params, signature);
+ }
+
+ public ObjectInstance createMBean(String className,
+ ObjectName name,
+ ObjectName loaderName)
+ throws ReflectionException,
+ InstanceAlreadyExistsException,
+ MBeanRegistrationException,
+ MBeanException,
+ NotCompliantMBeanException,
+ InstanceNotFoundException
+ {
+ return getNext().createMBean(className, name, loaderName);
+ }
+
+ public ObjectInstance createMBean(String className, ObjectName name)
+ throws ReflectionException,
+ InstanceAlreadyExistsException,
+ MBeanRegistrationException,
+ MBeanException,
+ NotCompliantMBeanException
+ {
+ return getNext().createMBean(className, name);
+ }
+
+ public Object instantiate(String className, Object[] params, String[] signature)
+ throws ReflectionException,
+ MBeanException
+ {
+ return getNext().instantiate(className, params, signature);
+ }
+
+ public Object instantiate(String className, ObjectName loaderName, Object[] params, String[] signature)
+ throws ReflectionException,
+ MBeanException,
+ InstanceNotFoundException
+ {
+ return getNext().instantiate(className, loaderName, params, signature);
+ }
+
+ public Object instantiate(String className, ObjectName loaderName)
+ throws ReflectionException,
+ MBeanException,
+ InstanceNotFoundException
+ {
+ return getNext().instantiate(className, loaderName);
+ }
+
+ public Object instantiate(String className) throws ReflectionException, MBeanException
+ {
+ return getNext().instantiate(className);
+ }
+
+ public ObjectInstance getObjectInstance(ObjectName name) throws InstanceNotFoundException
+ {
+ return getNext().getObjectInstance(name);
+ }
+
+ public boolean isInstanceOf(ObjectName name, String className) throws InstanceNotFoundException
+ {
+ return getNext().isInstanceOf(name, className);
+ }
+
+ public boolean isRegistered(ObjectName name)
+ {
+ return getNext().isRegistered(name);
+ }
+
+ @SuppressWarnings("unchecked")
+ public Set queryMBeans(ObjectName name, QueryExp query)
+ {
+ return getNext().queryMBeans(name, query);
+ }
+
+ @SuppressWarnings("unchecked")
+ public Set queryNames(ObjectName name, QueryExp query)
+ {
+ return getNext().queryNames(name, query);
+ }
+
+ public void addNotificationListener(ObjectName name,
+ NotificationListener listener,
+ NotificationFilter filter,
+ Object handback)
+ throws InstanceNotFoundException
+ {
+ getNext().addNotificationListener(name, listener, filter, handback);
+ }
+
+ public void addNotificationListener(ObjectName name,
+ ObjectName listener,
+ NotificationFilter filter,
+ Object handback)
+ throws InstanceNotFoundException
+ {
+ getNext().addNotificationListener(name, listener, filter, handback);
+ }
+
+ public void removeNotificationListener(ObjectName name,
+ NotificationListener listener,
+ NotificationFilter filter,
+ Object handback)
+ throws InstanceNotFoundException,
+ ListenerNotFoundException
+ {
+ getNext().removeNotificationListener(name, listener, filter, handback);
+ }
+
+ public void removeNotificationListener(ObjectName name, NotificationListener listener)
+ throws InstanceNotFoundException,
+ ListenerNotFoundException
+ {
+ getNext().removeNotificationListener(name, listener);
+ }
+
+ public void removeNotificationListener(ObjectName name,
+ ObjectName listener,
+ NotificationFilter filter,
+ Object handback)
+ throws InstanceNotFoundException,
+ ListenerNotFoundException
+ {
+ getNext().removeNotificationListener(name, listener, filter, handback);
+ }
+
+ public void removeNotificationListener(ObjectName name, ObjectName listener)
+ throws InstanceNotFoundException,
+ ListenerNotFoundException
+ {
+ getNext().removeNotificationListener(name, listener);
+ }
+
+ public ClassLoader getClassLoader(ObjectName loaderName) throws InstanceNotFoundException
+ {
+ return getNext().getClassLoader(loaderName);
+ }
+
+ public ClassLoader getClassLoaderFor(ObjectName mbeanName) throws InstanceNotFoundException
+ {
+ return getNext().getClassLoaderFor(mbeanName);
+ }
+
+ public ClassLoaderRepository getClassLoaderRepository()
+ {
+ return getNext().getClassLoaderRepository();
+ }
+
+ public ObjectInputStream deserialize(ObjectName name, byte[] data)
+ throws InstanceNotFoundException,
+ OperationsException
+ {
+ return getNext().deserialize(name, data);
+ }
+
+ public ObjectInputStream deserialize(String className, byte[] data)
+ throws OperationsException,
+ ReflectionException
+ {
+ return getNext().deserialize(className, data);
+ }
+
+ public ObjectInputStream deserialize(String className, ObjectName loaderName, byte[] data)
+ throws InstanceNotFoundException,
+ OperationsException,
+ ReflectionException
+ {
+ return getNext().deserialize(className, loaderName, data);
+ }
+}
Added: projects/jbossmx/trunk/mbeanserver/src/main/org/jboss/jmx/mbeanserver/DelegateState.java
===================================================================
--- projects/jbossmx/trunk/mbeanserver/src/main/org/jboss/jmx/mbeanserver/DelegateState.java (rev 0)
+++ projects/jbossmx/trunk/mbeanserver/src/main/org/jboss/jmx/mbeanserver/DelegateState.java 2009-03-30 14:10:52 UTC (rev 86472)
@@ -0,0 +1,85 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat Middleware LLC, and individual contributors
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.jmx.mbeanserver;
+
+import javax.management.MBeanServer;
+import javax.management.MBeanServerDelegate;
+
+/**
+ * DelegateState.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class DelegateState
+{
+ /** The outer most mbeanserver */
+ private MBeanServer outer;
+
+ /** The MBeanServer delegate */
+ private MBeanServerDelegate delegate;
+
+ /**
+ * Construct an DelegateState.
+ *
+ * @param outer the wrapping MBeanServer, passed to MBeans
+ * at registration.
+ * @param delegate the delegate to use for Notifications.
+ */
+ public DelegateState(MBeanServer outer, MBeanServerDelegate delegate)
+ {
+ if (delegate == null)
+ throw new IllegalStateException("Null delegate");
+ this.outer = outer;
+ this.delegate = delegate;
+ }
+
+ /**
+ * Get the outer.
+ *
+ * @return the outer.
+ */
+ public MBeanServer getOuter()
+ {
+ return outer;
+ }
+
+ /**
+ * Set the outer.
+ *
+ * @param outer the outer.
+ */
+ protected void setOuter(MBeanServer outer)
+ {
+ this.outer = outer;
+ }
+
+ /**
+ * Get the delegate.
+ *
+ * @return the delegate.
+ */
+ public MBeanServerDelegate getDelegate()
+ {
+ return delegate;
+ }
+}
Added: projects/jbossmx/trunk/mbeanserver/src/main/org/jboss/jmx/mbeanserver/JBossMBeanRegistry.java
===================================================================
--- projects/jbossmx/trunk/mbeanserver/src/main/org/jboss/jmx/mbeanserver/JBossMBeanRegistry.java (rev 0)
+++ projects/jbossmx/trunk/mbeanserver/src/main/org/jboss/jmx/mbeanserver/JBossMBeanRegistry.java 2009-03-30 14:10:52 UTC (rev 86472)
@@ -0,0 +1,379 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2007, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.jmx.mbeanserver;
+
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+import javax.management.InstanceAlreadyExistsException;
+import javax.management.InstanceNotFoundException;
+import javax.management.MBeanRegistrationException;
+import javax.management.MBeanServer;
+import javax.management.MalformedObjectNameException;
+import javax.management.NotCompliantMBeanException;
+import javax.management.ObjectInstance;
+import javax.management.ObjectName;
+import javax.management.RuntimeOperationsException;
+
+/**
+ * JBossMBeanRegistry.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class JBossMBeanRegistry
+{
+ /** The current registry entry */
+ static ThreadLocal<RegistryEntry> current = new ThreadLocal<RegistryEntry>();
+
+ /**
+ * A map of domain name to another map containing object name canonical
+ * key properties to registry entries.
+ * domain -> canonicalKeyProperties -> MBeanEntry
+ */
+ private Map<String, Map<String, RegistryEntry>> domainMap = new ConcurrentHashMap<String, Map<String, RegistryEntry>>();
+
+ /** The default domain for this registry */
+ private String defaultDomain;
+
+ /** The MBeanServer for which we are the registry. */
+ private MBeanServer server;
+
+ /**
+ * Create a new JBossMBeanRegistry.
+ *
+ * @param server the server
+ */
+ public JBossMBeanRegistry(MBeanServer server)
+ {
+ this.server = server;
+ defaultDomain = server.getDefaultDomain();
+ }
+
+ /**
+ * Register an mbean.<p>
+ *
+ * The object name passed maybe unqualified.<p>
+ *
+ * The map is a user definable string to value object map for holding
+ * information against a registered object. This map may contain metadata
+ * related to the registration, such as registration date/time, classloader
+ * references, etc. <p>
+ *
+ * Pass org.jboss.mx.classloader in the values map to
+ * set the context classloader<p>
+ *
+ * Other values are user definable and can be retrieved using the
+ * getValue(ObjectName,String) method.
+ *
+ * @param object the mbean to register.
+ * @param name the object name to assign to the mbean.
+ * @param valueMap a map of other information to include in the
+ * registry
+ *
+ * @return an object instance for the registered mbean
+ *
+ * @exception InstanceAlreadyExistsException when the object name
+ * is already registered.
+ * @exception MBeanRegistrationException when an exception is raised
+ * during preRegister for the mbean.
+ * @exception NotCompliantMBeanException when the passed object is
+ * a valid mbean.
+ */
+ public ObjectInstance registerMBean(Object object, ObjectName name, Map<String, Object> valueMap)
+ throws InstanceAlreadyExistsException, MBeanRegistrationException, NotCompliantMBeanException
+ {
+ RegistryEntry entry = new RegistryEntry(qualifyName(name), valueMap);
+ RegistryEntry previous = current.get();
+ current.set(entry);
+ try
+ {
+ return server.registerMBean(object, entry.getObjectName());
+ }
+ finally
+ {
+ current.set(previous);
+ }
+ }
+
+
+ /**
+ * Unregister an mbean. <p>
+ *
+ * This method is invoked by the MBeanServer for
+ * unregisterMBean().<p>
+ *
+ * The object name passed maybe unqualified.<p>
+ *
+ * MBeans in JMImplementation cannot be unregistered
+ *
+ * @param name the mbean to unregister.
+ *
+ * @exception InstanceNotFoundException when the object name is
+ * not registered.
+ * @exception MBeanRegistrationException when an exception is raised
+ * during preDeregister for the mbean.
+ */
+ public void unregisterMBean(ObjectName name)
+ throws InstanceNotFoundException, MBeanRegistrationException
+ {
+ RegistryEntry entry = new RegistryEntry(qualifyName(name), null);
+ RegistryEntry previous = current.get();
+ current.set(entry);
+ try
+ {
+ server.unregisterMBean(name);
+ }
+ finally
+ {
+ current.set(previous);
+ }
+ }
+
+ /**
+ * Retrieve the registration for an object name.<p>
+ *
+ * This method is invoked by the MBeanServer for
+ * methods passing an ObjectName that are not covered in other methods.<p>
+ *
+ * The object name passed maybe unqualified.
+ *
+ * @param name the object name to retrieve
+ *
+ * @return the mbean's registration
+ *
+ * @exception InstanceNotFoundException when the object name is not
+ * registered.
+ */
+ public RegistryEntry get(ObjectName name)
+ throws InstanceNotFoundException
+ {
+ return get(name, true);
+ }
+
+ /**
+ * Retrieve the registration for an object name.<p>
+ *
+ * This method is invoked by the MBeanServer for
+ * methods passing an ObjectName that are not covered in other methods.<p>
+ *
+ * The object name passed maybe unqualified.
+ *
+ * @param name the object name to retrieve
+ * @param errorIfNotFound whether to throw an error if not found
+ * @return the mbean's registration
+ *
+ * @exception InstanceNotFoundException when the object name is not
+ * registered.
+ */
+ public RegistryEntry get(ObjectName name, boolean errorIfNotFound)
+ throws InstanceNotFoundException
+ {
+ if (name == null)
+ throw new RuntimeOperationsException(new IllegalArgumentException("null object name"));
+
+ // Determine the domain and retrieve its entries
+ String domain = name.getDomain();
+
+ if (domain.length() == 0)
+ domain = defaultDomain;
+
+ String props = name.getCanonicalKeyPropertyListString();
+ Map<String, RegistryEntry> mbeanMap = getMBeanMap(domain, false);
+
+ // Retrieve the registry entry
+ RegistryEntry entry = null;
+ if ((null == mbeanMap || null == (entry = mbeanMap.get(props))) && errorIfNotFound)
+ throw new InstanceNotFoundException(name + " is not registered.");
+
+ // We are done
+ return entry;
+ }
+
+ /**
+ * Retrieve the default domain for this registry.<p>
+ *
+ * @return the default domain
+ */
+ public String getDefaultDomain()
+ {
+ return server.getDefaultDomain();
+ }
+
+ /**
+ * Retrieve the domains for this registry.<p>
+ *
+ * @return the domains
+ */
+ public String[] getDomains()
+ {
+ return server.getDomains();
+ }
+
+ public ObjectInstance getObjectInstance(ObjectName name)
+ throws InstanceNotFoundException
+ {
+ return server.getObjectInstance(name);
+ }
+
+ /**
+ * Retrieve the object instance for an object name.
+ *
+ * @param name the object name of the mbean
+ * @param key the key to retrieve
+ * @return the object instance
+ * @exception InstanceNotFoundException when the object name is not
+ * registered
+ */
+ public Object getValue(ObjectName name, String key)
+ throws InstanceNotFoundException
+ {
+ return get(name).getValue(key);
+ }
+
+ /**
+ * Test whether an object name is registered. <p>
+ *
+ * This method is invoked by the MBeanServer for
+ * isRegistered().<p>
+ *
+ * The object name passed maybe unqualified.
+ *
+ * @param name the object name
+ * @return true when the object name is registered, false otherwise
+ */
+ public boolean contains(ObjectName name)
+ {
+ return server.isRegistered(name);
+ }
+
+ /**
+ * Retrieve the number of mbeans registered.<p>
+ *
+ * This method is invoked by the MBeanServer for
+ * getMBeanCount().
+ *
+ * @return the number of mbeans registered.
+ */
+ public int getSize()
+ {
+ return server.getMBeanCount();
+ }
+
+ /**
+ * Adds an MBean entry<p>
+ *
+ * WARNING: The object name should be fully qualified.
+ *
+ * @param entry the MBean entry to add
+ * @exception InstanceAlreadyExistsException when the MBean's object name
+ * is already registered
+ */
+ protected synchronized void add(RegistryEntry entry)
+ throws InstanceAlreadyExistsException
+ {
+ // Determine the MBean's name and properties
+ ObjectName name = entry.getObjectName();
+ String domain = name.getDomain();
+ String props = name.getCanonicalKeyPropertyListString();
+
+ // Create a properties -> entry map if we don't have one
+ Map<String, RegistryEntry> mbeanMap = getMBeanMap(domain, true);
+
+ // Make sure we aren't already registered
+ if (mbeanMap.get(props) != null)
+ throw new InstanceAlreadyExistsException(name + " already registered.");
+
+ // Ok, we are registered
+ mbeanMap.put(props, entry);
+ }
+
+ /**
+ * Removes an MBean entry
+ *
+ * @param name the object name of the entry to remove
+ * @exception InstanceNotFoundException when the object name is not
+ * registered
+ */
+ protected synchronized void remove(ObjectName name) throws InstanceNotFoundException
+ {
+ // Determine the MBean's name and properties
+ String domain = name.getDomain();
+ String props = name.getCanonicalKeyPropertyListString();
+ Map<String, RegistryEntry> mbeanMap = getMBeanMap(domain, false);
+
+ // Remove the entry, raise an exception when it didn't exist
+ if (null == mbeanMap || null == mbeanMap.remove(props))
+ throw new InstanceNotFoundException(name + " not registered.");
+ }
+
+ /**
+ * Qualify an object name with the default domain<p>
+ *
+ * Adds the default domain if no domain is specified.
+ *
+ * @param name the name to qualify
+ * @return the original name or the name prepended with the default domain
+ * if no domain is specified.
+ * @exception RuntimeOperationsException containing an
+ * IllegalArgumentException when there is a problem
+ */
+ protected ObjectName qualifyName(ObjectName name)
+ {
+ if (name == null)
+ throw new RuntimeOperationsException(
+ new IllegalArgumentException("Null object name"));
+ try
+ {
+ if (name.getDomain().length() == 0)
+ return new ObjectName(defaultDomain + ":" + name.getCanonicalKeyPropertyListString());
+ else
+ return name;
+ }
+ catch (MalformedObjectNameException e)
+ {
+ throw new RuntimeOperationsException(
+ new IllegalArgumentException(e.toString()));
+ }
+ }
+
+ /**
+ * The <code>getMBeanMap</code> method provides synchronized access
+ * to the mbean map for a domain. This is actually a solution to a
+ * bug that resulted in wiping out the jboss domain mbeanMap for no
+ * apparent reason.
+ *
+ * @param domain a <code>String</code> value
+ * @param createIfMissing a <code>boolean</code> value
+ * @return a <code>Map</code> value
+ */
+ private Map<String, RegistryEntry> getMBeanMap(String domain, boolean createIfMissing)
+ {
+ Map<String, RegistryEntry> mbeanMap = domainMap.get(domain);
+ if (mbeanMap == null && createIfMissing)
+ {
+ mbeanMap = new ConcurrentHashMap<String, RegistryEntry>();
+ domainMap.put(domain, mbeanMap);
+ }
+ return mbeanMap;
+ }
+}
Added: projects/jbossmx/trunk/mbeanserver/src/main/org/jboss/jmx/mbeanserver/JBossMBeanServer.java
===================================================================
--- projects/jbossmx/trunk/mbeanserver/src/main/org/jboss/jmx/mbeanserver/JBossMBeanServer.java (rev 0)
+++ projects/jbossmx/trunk/mbeanserver/src/main/org/jboss/jmx/mbeanserver/JBossMBeanServer.java 2009-03-30 14:10:52 UTC (rev 86472)
@@ -0,0 +1,1072 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat Middleware LLC, and individual contributors
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.jmx.mbeanserver;
+
+import java.io.ObjectInputStream;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.management.Attribute;
+import javax.management.AttributeList;
+import javax.management.AttributeNotFoundException;
+import javax.management.InstanceAlreadyExistsException;
+import javax.management.InstanceNotFoundException;
+import javax.management.IntrospectionException;
+import javax.management.InvalidAttributeValueException;
+import javax.management.ListenerNotFoundException;
+import javax.management.MBeanException;
+import javax.management.MBeanInfo;
+import javax.management.MBeanParameterInfo;
+import javax.management.MBeanRegistrationException;
+import javax.management.MBeanServer;
+import javax.management.MalformedObjectNameException;
+import javax.management.NotCompliantMBeanException;
+import javax.management.NotificationFilter;
+import javax.management.NotificationListener;
+import javax.management.ObjectInstance;
+import javax.management.ObjectName;
+import javax.management.OperationsException;
+import javax.management.ReflectionException;
+import javax.management.RuntimeOperationsException;
+import javax.management.modelmbean.DescriptorSupport;
+import javax.management.modelmbean.ModelMBeanAttributeInfo;
+import javax.management.modelmbean.ModelMBeanConstructorInfo;
+import javax.management.modelmbean.ModelMBeanInfo;
+import javax.management.modelmbean.ModelMBeanInfoSupport;
+import javax.management.modelmbean.ModelMBeanNotificationInfo;
+import javax.management.modelmbean.ModelMBeanOperationInfo;
+import javax.management.modelmbean.RequiredModelMBean;
+
+/**
+ * JBossMBeanServer.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class JBossMBeanServer extends DelegateMBeanServer
+{
+ /** The old registry name */
+ private static ObjectName OLD_REGISTRY_NAME;
+
+ /** The new registry name */
+ public static ObjectName REGISTRY_NAME;
+
+ {
+ try
+ {
+ OLD_REGISTRY_NAME = new ObjectName("JMImplementation:type=MBeanRegistry");
+ REGISTRY_NAME = new ObjectName("org.jboss.jmx:type=MBeanRegistry");
+ }
+ catch (MalformedObjectNameException e)
+ {
+ throw new RuntimeException("Unexpected error", e);
+ }
+ }
+
+ /** The registry */
+ private JBossMBeanRegistry registry;
+
+ /**
+ * Create a new JBossMBeanServer.
+ *
+ * @param state the state
+ */
+ public JBossMBeanServer(DelegateState state)
+ {
+ super(state);
+ }
+
+ @Override
+ public MBeanInfo getMBeanInfo(ObjectName name)
+ throws InstanceNotFoundException,
+ IntrospectionException,
+ ReflectionException
+ {
+ name = mapObjectName(name);
+
+ ClassLoader cl = getTCL(name);
+ ClassLoader previous = null;
+ if (cl != null)
+ previous = SecurityActions.setContextClassLoader(cl);
+ try
+ {
+ return getNext().getMBeanInfo(mapObjectName(name));
+ }
+ finally
+ {
+ if (cl != null)
+ SecurityActions.setContextClassLoader(previous);
+ }
+ }
+
+ @Override
+ public Object getAttribute(ObjectName name, String attribute)
+ throws MBeanException,
+ AttributeNotFoundException,
+ InstanceNotFoundException,
+ ReflectionException
+ {
+ name = mapObjectName(name);
+
+ ClassLoader cl = getTCL(name);
+ ClassLoader previous = null;
+ if (cl != null)
+ previous = SecurityActions.setContextClassLoader(cl);
+ try
+ {
+ return getNext().getAttribute(name, attribute);
+ }
+ finally
+ {
+ if (cl != null)
+ SecurityActions.setContextClassLoader(previous);
+ }
+ }
+
+ @Override
+ public AttributeList getAttributes(ObjectName name, String[] attributes)
+ throws InstanceNotFoundException,
+ ReflectionException
+ {
+ name = mapObjectName(name);
+
+ ClassLoader cl = getTCL(name);
+ ClassLoader previous = null;
+ if (cl != null)
+ previous = SecurityActions.setContextClassLoader(cl);
+ try
+ {
+ return getNext().getAttributes(name, attributes);
+ }
+ finally
+ {
+ if (cl != null)
+ SecurityActions.setContextClassLoader(previous);
+ }
+ }
+
+ @Override
+ public void setAttribute(ObjectName name, Attribute attribute)
+ throws InstanceNotFoundException,
+ AttributeNotFoundException,
+ InvalidAttributeValueException,
+ MBeanException,
+ ReflectionException
+ {
+ name = mapObjectName(name);
+
+ ClassLoader cl = getTCL(name);
+ ClassLoader previous = null;
+ if (cl != null)
+ previous = SecurityActions.setContextClassLoader(cl);
+ try
+ {
+ getNext().setAttribute(name, attribute);
+ }
+ finally
+ {
+ if (cl != null)
+ SecurityActions.setContextClassLoader(previous);
+ }
+ }
+
+ @Override
+ public AttributeList setAttributes(ObjectName name, AttributeList attributes)
+ throws InstanceNotFoundException,
+ ReflectionException
+ {
+ name = mapObjectName(name);
+
+ ClassLoader cl = getTCL(name);
+ ClassLoader previous = null;
+ if (cl != null)
+ previous = SecurityActions.setContextClassLoader(cl);
+ try
+ {
+ return getNext().setAttributes(name, attributes);
+ }
+ finally
+ {
+ if (cl != null)
+ SecurityActions.setContextClassLoader(previous);
+ }
+ }
+
+ @Override
+ public Object invoke(ObjectName name, String operationName, Object[] params, String[] signature)
+ throws InstanceNotFoundException,
+ MBeanException,
+ ReflectionException
+ {
+ name = mapObjectName(name);
+
+ ClassLoader cl = getTCL(name);
+ ClassLoader previous = null;
+ if (cl != null)
+ previous = SecurityActions.setContextClassLoader(cl);
+ try
+ {
+ return getNext().invoke(name, operationName, params, signature);
+ }
+ finally
+ {
+ if (cl != null)
+ SecurityActions.setContextClassLoader(previous);
+ }
+ }
+
+ @Override
+ public ObjectInstance registerMBean(Object object, ObjectName name)
+ throws InstanceAlreadyExistsException,
+ MBeanRegistrationException,
+ NotCompliantMBeanException
+ {
+ RegistryEntry previous = checkCurrent(name, null);
+ try
+ {
+ ObjectInstance result = getNext().registerMBean(object, name);
+ try
+ {
+ register(result, null);
+ }
+ catch (InstanceAlreadyExistsException e)
+ {
+ try
+ {
+ getNext().unregisterMBean(name);
+ }
+ catch (Exception ignored)
+ {
+ ignored.printStackTrace();
+ }
+ throw e;
+ }
+ return result;
+ }
+ finally
+ {
+ restoreCurrent(previous);
+ }
+ }
+
+ @Override
+ public void unregisterMBean(ObjectName name) throws InstanceNotFoundException, MBeanRegistrationException
+ {
+ getNext().unregisterMBean(name);
+ try
+ {
+ unregister(name);
+ }
+ catch (InstanceNotFoundException ignored)
+ {
+ ignored.printStackTrace();
+ }
+ }
+
+ @Override
+ public ObjectInstance createMBean(String className,
+ ObjectName name,
+ Object[] params,
+ String[] signature)
+ throws ReflectionException,
+ InstanceAlreadyExistsException,
+ MBeanRegistrationException,
+ MBeanException,
+ NotCompliantMBeanException
+ {
+ RegistryEntry previous = checkCurrent(name, null);
+ try
+ {
+ ObjectInstance result = getNext().createMBean(className, name, params, signature);
+ try
+ {
+ register(result, null);
+ }
+ catch (InstanceAlreadyExistsException e)
+ {
+ try
+ {
+ getNext().unregisterMBean(name);
+ }
+ catch (Exception ignored)
+ {
+ ignored.printStackTrace();
+ }
+ throw e;
+ }
+ return result;
+ }
+ finally
+ {
+ restoreCurrent(previous);
+ }
+ }
+
+ @Override
+ public ObjectInstance createMBean(String className,
+ ObjectName name,
+ ObjectName loaderName,
+ Object[] params,
+ String[] signature)
+ throws ReflectionException,
+ InstanceAlreadyExistsException,
+ MBeanRegistrationException,
+ MBeanException,
+ NotCompliantMBeanException,
+ InstanceNotFoundException
+ {
+ RegistryEntry previous = checkCurrent(name, null);
+ try
+ {
+ ClassLoader cl = getOuter().getClassLoader(loaderName);
+ ClassLoader previousCl = null;
+ if (cl != null)
+ previousCl = SecurityActions.setContextClassLoader(cl);
+ try
+ {
+ ObjectInstance result = getNext().createMBean(className, name, loaderName, params, signature);
+ try
+ {
+ register(result, loaderName);
+ }
+ catch (InstanceAlreadyExistsException e)
+ {
+ try
+ {
+ getNext().unregisterMBean(name);
+ }
+ catch (Exception ignored)
+ {
+ ignored.printStackTrace();
+ }
+ throw e;
+ }
+ return result;
+ }
+ finally
+ {
+ if (cl != null)
+ SecurityActions.setContextClassLoader(previousCl);
+ }
+ }
+ finally
+ {
+ restoreCurrent(previous);
+ }
+ }
+
+ @Override
+ public ObjectInstance createMBean(String className,
+ ObjectName name,
+ ObjectName loaderName)
+ throws ReflectionException,
+ InstanceAlreadyExistsException,
+ MBeanRegistrationException,
+ MBeanException,
+ NotCompliantMBeanException,
+ InstanceNotFoundException
+ {
+ ClassLoader cl = getOuter().getClassLoader(loaderName);
+ ClassLoader previousCl = null;
+ if (cl != null)
+ previousCl = SecurityActions.setContextClassLoader(cl);
+ try
+ {
+ RegistryEntry previous = checkCurrent(name, cl);
+ try
+ {
+ ObjectInstance result = getNext().createMBean(className, name, loaderName);
+ try
+ {
+ register(result, loaderName);
+ }
+ catch (InstanceAlreadyExistsException e)
+ {
+ try
+ {
+ getNext().unregisterMBean(name);
+ }
+ catch (Exception ignored)
+ {
+ ignored.printStackTrace();
+ }
+ throw e;
+ }
+ return result;
+ }
+ finally
+ {
+ restoreCurrent(previous);
+ }
+ }
+ finally
+ {
+ if (cl != null)
+ SecurityActions.setContextClassLoader(previousCl);
+ }
+ }
+
+ @Override
+ public ObjectInstance createMBean(String className, ObjectName name)
+ throws ReflectionException,
+ InstanceAlreadyExistsException,
+ MBeanRegistrationException,
+ MBeanException,
+ NotCompliantMBeanException
+ {
+ RegistryEntry previous = checkCurrent(name, null);
+ try
+ {
+ ObjectInstance result = getNext().createMBean(className, name);
+ try
+ {
+ register(result, null);
+ }
+ catch (InstanceAlreadyExistsException e)
+ {
+ try
+ {
+ getNext().unregisterMBean(name);
+ }
+ catch (Exception ignored)
+ {
+ ignored.printStackTrace();
+ }
+ throw e;
+ }
+ return result;
+ }
+ finally
+ {
+ restoreCurrent(previous);
+ }
+ }
+
+ @Override
+ public Object instantiate(String className, ObjectName loaderName, Object[] params, String[] signature)
+ throws ReflectionException,
+ MBeanException,
+ InstanceNotFoundException
+ {
+ ClassLoader cl = getOuter().getClassLoader(loaderName);
+ ClassLoader previous = null;
+ if (cl != null)
+ previous = SecurityActions.setContextClassLoader(cl);
+ try
+ {
+ return getNext().instantiate(className, loaderName, params, signature);
+ }
+ finally
+ {
+ if (cl != null)
+ SecurityActions.setContextClassLoader(previous);
+ }
+ }
+
+ @Override
+ public Object instantiate(String className) throws ReflectionException, MBeanException
+ {
+ return getNext().instantiate(className);
+ }
+
+ @Override
+ public ObjectInstance getObjectInstance(ObjectName name) throws InstanceNotFoundException
+ {
+ name = mapObjectName(name);
+
+ ClassLoader cl = getTCL(name);
+ ClassLoader previous = null;
+ if (cl != null)
+ previous = SecurityActions.setContextClassLoader(cl);
+ try
+ {
+ return getNext().getObjectInstance(name);
+ }
+ finally
+ {
+ if (cl != null)
+ SecurityActions.setContextClassLoader(previous);
+ }
+ }
+
+ @Override
+ public boolean isInstanceOf(ObjectName name, String className) throws InstanceNotFoundException
+ {
+ name = mapObjectName(name);
+
+ ClassLoader cl = getTCL(name);
+ ClassLoader previous = null;
+ if (cl != null)
+ previous = SecurityActions.setContextClassLoader(cl);
+ try
+ {
+ return getNext().isInstanceOf(name, className);
+ }
+ finally
+ {
+ if (cl != null)
+ SecurityActions.setContextClassLoader(previous);
+ }
+ }
+
+ @Override
+ public boolean isRegistered(ObjectName name)
+ {
+ return getNext().isRegistered(mapObjectName(name));
+ }
+
+ @Override
+ public void addNotificationListener(ObjectName name,
+ NotificationListener listener,
+ NotificationFilter filter,
+ Object handback)
+ throws InstanceNotFoundException
+ {
+ name = mapObjectName(name);
+
+ ClassLoader cl = getTCL(name);
+ ClassLoader previous = null;
+ if (cl != null)
+ previous = SecurityActions.setContextClassLoader(cl);
+ try
+ {
+ getNext().addNotificationListener(name, listener, filter, handback);
+ }
+ finally
+ {
+ if (cl != null)
+ SecurityActions.setContextClassLoader(previous);
+ }
+ }
+
+ @Override
+ public void addNotificationListener(ObjectName name,
+ ObjectName listener,
+ NotificationFilter filter,
+ Object handback)
+ throws InstanceNotFoundException
+ {
+ name = mapObjectName(name);
+
+ ClassLoader cl = getTCL(name);
+ ClassLoader previous = null;
+ if (cl != null)
+ previous = SecurityActions.setContextClassLoader(cl);
+ try
+ {
+ getNext().addNotificationListener(name, listener, filter, handback);
+ }
+ finally
+ {
+ if (cl != null)
+ SecurityActions.setContextClassLoader(previous);
+ }
+ }
+
+ @Override
+ public void removeNotificationListener(ObjectName name,
+ NotificationListener listener,
+ NotificationFilter filter,
+ Object handback)
+ throws InstanceNotFoundException,
+ ListenerNotFoundException
+ {
+ name = mapObjectName(name);
+
+ ClassLoader cl = getTCL(name);
+ ClassLoader previous = null;
+ if (cl != null)
+ previous = SecurityActions.setContextClassLoader(cl);
+ try
+ {
+ getNext().removeNotificationListener(name, listener, filter, handback);
+ }
+ finally
+ {
+ if (cl != null)
+ SecurityActions.setContextClassLoader(previous);
+ }
+ }
+
+ @Override
+ public void removeNotificationListener(ObjectName name, NotificationListener listener)
+ throws InstanceNotFoundException,
+ ListenerNotFoundException
+ {
+ name = mapObjectName(name);
+
+ ClassLoader cl = getTCL(name);
+ ClassLoader previous = null;
+ if (cl != null)
+ previous = SecurityActions.setContextClassLoader(cl);
+ try
+ {
+ getNext().removeNotificationListener(name, listener);
+ }
+ finally
+ {
+ if (cl != null)
+ SecurityActions.setContextClassLoader(previous);
+ }
+ }
+
+ @Override
+ public void removeNotificationListener(ObjectName name,
+ ObjectName listener,
+ NotificationFilter filter,
+ Object handback)
+ throws InstanceNotFoundException,
+ ListenerNotFoundException
+ {
+ name = mapObjectName(name);
+
+ ClassLoader cl = getTCL(name);
+ ClassLoader previous = null;
+ if (cl != null)
+ previous = SecurityActions.setContextClassLoader(cl);
+ try
+ {
+ getNext().removeNotificationListener(name, listener, filter, handback);
+ }
+ finally
+ {
+ if (cl != null)
+ SecurityActions.setContextClassLoader(previous);
+ }
+ }
+
+ @Override
+ public void removeNotificationListener(ObjectName name, ObjectName listener)
+ throws InstanceNotFoundException,
+ ListenerNotFoundException
+ {
+ name = mapObjectName(name);
+
+ ClassLoader cl = getTCL(name);
+ ClassLoader previous = null;
+ if (cl != null)
+ previous = SecurityActions.setContextClassLoader(cl);
+ try
+ {
+ getNext().removeNotificationListener(name, listener);
+ }
+ finally
+ {
+ if (cl != null)
+ SecurityActions.setContextClassLoader(previous);
+ }
+ }
+
+ @Override
+ public ClassLoader getClassLoader(ObjectName loaderName) throws InstanceNotFoundException
+ {
+ ClassLoader cl = getTCL(loaderName);
+ ClassLoader previous = null;
+ if (cl != null)
+ previous = SecurityActions.setContextClassLoader(cl);
+ try
+ {
+ return getNext().getClassLoader(loaderName);
+ }
+ finally
+ {
+ if (cl != null)
+ SecurityActions.setContextClassLoader(previous);
+ }
+ }
+
+ @Override
+ public ClassLoader getClassLoaderFor(ObjectName mbeanName) throws InstanceNotFoundException
+ {
+ mbeanName = mapObjectName(mbeanName);
+
+ ClassLoader cl = getTCL(mbeanName);
+ if (cl != null)
+ return cl;
+ return getNext().getClassLoaderFor(mbeanName);
+ }
+
+ @Override
+ @Deprecated
+ public ObjectInputStream deserialize(ObjectName name, byte[] data)
+ throws InstanceNotFoundException,
+ OperationsException
+ {
+ name = mapObjectName(name);
+
+ ClassLoader cl = getTCL(name);
+ ClassLoader previous = null;
+ if (cl != null)
+ previous = SecurityActions.setContextClassLoader(cl);
+ try
+ {
+ return getNext().deserialize(name, data);
+ }
+ finally
+ {
+ if (cl != null)
+ SecurityActions.setContextClassLoader(previous);
+ }
+ }
+
+ @Override
+ @Deprecated
+ public ObjectInputStream deserialize(String className, ObjectName loaderName, byte[] data)
+ throws InstanceNotFoundException,
+ OperationsException,
+ ReflectionException
+ {
+ ClassLoader cl = getOuter().getClassLoader(loaderName);
+ ClassLoader previous = null;
+ if (cl != null)
+ previous = SecurityActions.setContextClassLoader(cl);
+ try
+ {
+ return getNext().deserialize(className, loaderName, data);
+ }
+ finally
+ {
+ if (cl != null)
+ SecurityActions.setContextClassLoader(previous);
+ }
+ }
+
+ /**
+ * Check current
+ *
+ * @param name the current name
+ * @param cl the classloader
+ * @return any previous current
+ */
+ protected RegistryEntry checkCurrent(ObjectName name, ClassLoader cl)
+ {
+ if (name == null)
+ throw new RuntimeOperationsException(
+ new IllegalArgumentException("Null object name"));
+
+ RegistryEntry current = JBossMBeanRegistry.current.get();
+ if (current == null || name.equals(current.getObjectName()) == false)
+ {
+ Map<String, Object> values = null;
+ if (cl != null)
+ {
+ values = new HashMap<String, Object>();
+ values.put(RegistryEntry.CLASSLOADER, cl);
+ }
+ JBossMBeanRegistry.current.set(new RegistryEntry(name, values));
+ }
+ return current;
+ }
+
+ /**
+ * Restore the current entry
+ *
+ * @param previous any previous current
+ */
+ protected void restoreCurrent(RegistryEntry previous)
+ {
+ JBossMBeanRegistry.current.set(previous);
+ }
+
+ /**
+ * Register an instance
+ *
+ * @param instance the instance
+ * @param loaderName the laoder name
+ * @throws InstanceAlreadyExistsException if already registered
+ */
+ protected void register(ObjectInstance instance, ObjectName loaderName) throws InstanceAlreadyExistsException
+ {
+ RegistryEntry current = JBossMBeanRegistry.current.get();
+ if (current != null && instance.getObjectName().equals(current.getObjectName()))
+ registry.add(current);
+ else
+ {
+ Map<String, Object> values = null;
+ if (loaderName != null)
+ {
+ ClassLoader cl = null;
+ try
+ {
+ cl = getOuter().getClassLoader(loaderName);
+ }
+ catch (InstanceNotFoundException ignored)
+ {
+ }
+ if (cl != null)
+ {
+ values = new HashMap<String, Object>();
+ values.put(RegistryEntry.CLASSLOADER, cl);
+ }
+ }
+ registry.add(new RegistryEntry(instance.getObjectName(), values));
+ }
+ }
+
+ /**
+ * Unregister an instance
+ *
+ * @param name the name to remove
+ * @throws InstanceNotFoundException when the instance is not found
+ */
+ protected void unregister(ObjectName name) throws InstanceNotFoundException
+ {
+ registry.remove(name);
+ }
+
+ /**
+ * Get the thread context classloader for an mbean
+ *
+ * @param name the name of the mbean
+ * @return the context classloader
+ * @throws InstanceNotFoundException if the name is not registered
+ */
+ protected ClassLoader getTCL(ObjectName name) throws InstanceNotFoundException
+ {
+ RegistryEntry entry = registry.get(name, false);
+ if (entry == null)
+ {
+ entry = JBossMBeanRegistry.current.get();
+ if (entry != null && name.equals(entry.getObjectName()) == false)
+ entry = null;
+ }
+ if (entry == null)
+ throw new InstanceNotFoundException(name + " is not registered");
+ return entry.getClassLoader();
+ }
+
+ /**
+ * Map an object name
+ *
+ * @param name the name
+ * @return the mapped name
+ */
+ protected ObjectName mapObjectName(ObjectName name)
+ {
+ if (OLD_REGISTRY_NAME.equals(name))
+ return REGISTRY_NAME;
+ return name;
+ }
+
+ @Override
+ protected void setNext(MBeanServer next)
+ {
+ super.setNext(next);
+ MBeanServer outer = getOuter();
+
+ try
+ {
+ RequiredModelMBean mbean = new RequiredModelMBean(getRegistryManagementInterface());
+ registry = new JBossMBeanRegistry(outer);
+ mbean.setManagedResource(registry, "ObjectReference");
+ registerMBean(mbean, REGISTRY_NAME);
+ }
+ catch (RuntimeException e)
+ {
+ throw e;
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException("Error installing registry");
+ }
+ }
+
+ /**
+ * Get the management interface for the registry
+ *
+ * @return the interface
+ */
+ private static ModelMBeanInfo getRegistryManagementInterface()
+ {
+ final boolean READABLE = true;
+ final boolean WRITABLE = true;
+ final boolean BOOLEAN = true;
+
+ // Default Domain attribute
+ DescriptorSupport descDefaultDomain = new DescriptorSupport();
+ descDefaultDomain.setField("name", "DefaultDomain");
+ descDefaultDomain.setField("descriptorType", "attribute");
+ descDefaultDomain.setField("displayName", "Default Domain");
+ descDefaultDomain.setField("currencyTimeLimit", "-1");
+ ModelMBeanAttributeInfo defaultDomainInfo = new ModelMBeanAttributeInfo
+ (
+ "DefaultDomain",
+ String.class.getName(),
+ "The domain to use when an object name has no domain",
+ READABLE, !WRITABLE, !BOOLEAN,
+ descDefaultDomain
+ );
+
+ // Size attribute
+ DescriptorSupport descSize = new DescriptorSupport();
+ descSize.setField("name", "Size");
+ descSize.setField("descriptorType", "attribute");
+ descSize.setField("displayName", "Size");
+ descSize.setField("getMethod", "getSize");
+ ModelMBeanAttributeInfo sizeInfo = new ModelMBeanAttributeInfo
+ (
+ "Size",
+ Integer.TYPE.getName(),
+ "The number of MBeans registered in the MBean Server",
+ READABLE, !WRITABLE, !BOOLEAN,
+ descSize
+ );
+
+ // registerMBean operation
+ DescriptorSupport descRegisterMBean = new DescriptorSupport();
+ descRegisterMBean.setField("name", "registerMBean");
+ descRegisterMBean.setField("descriptorType", "operation");
+ descRegisterMBean.setField("role", "operation");
+ MBeanParameterInfo[] registerMBeanParms = new MBeanParameterInfo[]
+ {
+ new MBeanParameterInfo
+ (
+ "Resource",
+ Object.class.getName(),
+ "A compliant MBean to be registered in the MBean Server"
+ ),
+ new MBeanParameterInfo
+ (
+ "ObjectName",
+ ObjectName.class.getName(),
+ "The object name of the MBean"
+ ),
+ new MBeanParameterInfo
+ (
+ "ValueMap",
+ Map.class.getName(),
+ "Values associated with the registration"
+ ),
+ };
+ ModelMBeanOperationInfo registerMBeanInfo = new ModelMBeanOperationInfo
+ (
+ "registerMBean",
+ "Adds an MBean in the MBeanServer",
+ registerMBeanParms,
+ ObjectInstance.class.getName(),
+ ModelMBeanOperationInfo.ACTION_INFO,
+ descRegisterMBean
+ );
+
+ // unregisterMBean operation
+ DescriptorSupport descUnregisterMBean = new DescriptorSupport();
+ descUnregisterMBean.setField("name", "unregisterMBean");
+ descUnregisterMBean.setField("descriptorType", "operation");
+ descUnregisterMBean.setField("role", "operation");
+ MBeanParameterInfo[] unregisterMBeanParms = new MBeanParameterInfo[]
+ {
+ new MBeanParameterInfo
+ (
+ "ObjectName",
+ ObjectName.class.getName(),
+ "The object name of the MBean to remove"
+ )
+ };
+ ModelMBeanOperationInfo unregisterMBeanInfo = new ModelMBeanOperationInfo
+ (
+ "unregisterMBean",
+ "Removes an MBean from the MBeanServer",
+ unregisterMBeanParms,
+ Void.TYPE.getName(),
+ ModelMBeanOperationInfo.ACTION,
+ descUnregisterMBean
+ );
+
+ // getSize operation
+ DescriptorSupport descGetSize = new DescriptorSupport();
+ descGetSize.setField("name", "getSize");
+ descGetSize.setField("descriptorType", "operation");
+ descGetSize.setField("role", "getter");
+ MBeanParameterInfo[] getSizeParms = new MBeanParameterInfo[0];
+ ModelMBeanOperationInfo getSizeInfo = new ModelMBeanOperationInfo
+ (
+ "getSize",
+ "Gets the number of MBeans registered",
+ getSizeParms,
+ Integer.TYPE.getName(),
+ ModelMBeanOperationInfo.INFO,
+ descGetSize
+ );
+
+ // getValue operation
+ DescriptorSupport descGetValue = new DescriptorSupport();
+ descGetValue.setField("name", "getValue");
+ descGetValue.setField("descriptorType", "operation");
+ descGetValue.setField("role", "operation");
+ MBeanParameterInfo[] getValueParms = new MBeanParameterInfo[]
+ {
+ new MBeanParameterInfo
+ (
+ "ObjectName",
+ ObjectName.class.getName(),
+ "The object name of the registered MBean"
+ ),
+ new MBeanParameterInfo
+ (
+ "Key",
+ String.class.getName(),
+ "The key to the value stored"
+ )
+ };
+ ModelMBeanOperationInfo getValueInfo = new ModelMBeanOperationInfo
+ (
+ "getValue",
+ "Get a value stored in the MBean's registration",
+ getValueParms,
+ Object.class.getName(),
+ ModelMBeanOperationInfo.INFO,
+ descGetValue
+ );
+
+ // Construct the modelmbean
+ DescriptorSupport descMBean = new DescriptorSupport();
+ descMBean.setField("name", RequiredModelMBean.class.getName());
+ descMBean.setField("descriptorType", "MBean");
+ descMBean.setField("displayName", "MBeanServer Registry");
+ ModelMBeanAttributeInfo[] attrInfo = new ModelMBeanAttributeInfo[]
+ {
+ defaultDomainInfo,
+ sizeInfo
+ };
+ ModelMBeanConstructorInfo[] ctorInfo = null;
+ ModelMBeanOperationInfo[] opInfo = new ModelMBeanOperationInfo[]
+ {
+ registerMBeanInfo,
+ unregisterMBeanInfo,
+ getSizeInfo,
+ getValueInfo,
+ };
+ ModelMBeanNotificationInfo[] notifyInfo = null;
+ ModelMBeanInfoSupport info = new ModelMBeanInfoSupport
+ (
+ RequiredModelMBean.class.getName(),
+ "Managed Bean Registry",
+ attrInfo,
+ ctorInfo,
+ opInfo,
+ notifyInfo,
+ descMBean
+ );
+
+ return info;
+ }
+}
Added: projects/jbossmx/trunk/mbeanserver/src/main/org/jboss/jmx/mbeanserver/JBossMBeanServerBuilder.java
===================================================================
--- projects/jbossmx/trunk/mbeanserver/src/main/org/jboss/jmx/mbeanserver/JBossMBeanServerBuilder.java (rev 0)
+++ projects/jbossmx/trunk/mbeanserver/src/main/org/jboss/jmx/mbeanserver/JBossMBeanServerBuilder.java 2009-03-30 14:10:52 UTC (rev 86472)
@@ -0,0 +1,82 @@
+/*
+* JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.jmx.mbeanserver;
+
+import javax.management.MBeanServer;
+import javax.management.MBeanServerBuilder;
+import javax.management.MBeanServerDelegate;
+
+/**
+ * PlainMBeanServerBuilder.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class JBossMBeanServerBuilder extends MBeanServerBuilder
+{
+ /**
+ * Construct an MBeanServerBuilder
+ */
+ public JBossMBeanServerBuilder()
+ {
+ }
+
+ /**
+ * Construct an MBeanServer.
+ *
+ * @param defaultDomain the default domain when an MBean is
+ * registered with an ObjectName without a domain.
+ * @param outer the wrapping MBeanServer, passed to MBeans
+ * at registration.
+ * @param delegate the delegate to use for Notifications.
+ */
+ public MBeanServer newMBeanServer(String defaultDomain,
+ MBeanServer outer,
+ MBeanServerDelegate delegate)
+ {
+ try
+ {
+ DelegateState state = new DelegateState(outer, delegate);
+ MBeanServerChain chain = new MBeanServerChain(state);
+
+ MBeanServer server = super.newMBeanServer(defaultDomain, chain.getOuter(), delegate);
+ chain.setTarget(server);
+
+ JBossMBeanServer result = new JBossMBeanServer(state);
+ chain.addLast(result);
+ return result;
+ }
+ catch (RuntimeException e)
+ {
+ e.printStackTrace();
+ throw e;
+ }
+ }
+
+ /**
+ * Construct an MBeanServerDelegate.
+ */
+ public MBeanServerDelegate newMBeanServerDelegate()
+ {
+ return new MBeanServerDelegate();
+ }
+}
Added: projects/jbossmx/trunk/mbeanserver/src/main/org/jboss/jmx/mbeanserver/MBeanServerChain.java
===================================================================
--- projects/jbossmx/trunk/mbeanserver/src/main/org/jboss/jmx/mbeanserver/MBeanServerChain.java (rev 0)
+++ projects/jbossmx/trunk/mbeanserver/src/main/org/jboss/jmx/mbeanserver/MBeanServerChain.java 2009-03-30 14:10:52 UTC (rev 86472)
@@ -0,0 +1,115 @@
+/*
+* JBoss, Home of Professional Open Source
+Copyright 2009, Red Hat Middleware LLC, and individual contributors
+* * by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.jmx.mbeanserver;
+
+import javax.management.MBeanServer;
+
+
+/**
+ * MBeanServerChain.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class MBeanServerChain extends DelegateMBeanServer
+{
+ /**
+ * Create a new MBeanServerChain.
+ *
+ * @param state
+ */
+ public MBeanServerChain(DelegateState state)
+ {
+ super(state);
+ if (state.getOuter() == null)
+ state.setOuter(this);
+ }
+
+ /**
+ * Add as the first in the chain
+ *
+ * @param server the server
+ * @throws IllegalArgumentException for a null server
+ * @throws SecurityException if not authorised
+ */
+ public void addFirst(DelegateMBeanServer server)
+ {
+ SecurityManager sm = System.getSecurityManager();
+ if (sm != null)
+ sm.checkPermission(new RuntimePermission(getClass().getName()));
+
+ if (server == null)
+ throw new IllegalArgumentException("Null server");
+
+ server.setNext(getNext());
+ setNext(server);
+ }
+
+ /**
+ * Add as the last in the chain
+ *
+ * @param server the server
+ * @throws IllegalArgumentException for a null server
+ * @throws SecurityException if not authorised
+ */
+ public void addLast(DelegateMBeanServer server)
+ {
+ SecurityManager sm = System.getSecurityManager();
+ if (sm != null)
+ sm.checkPermission(new RuntimePermission(getClass().getName()));
+
+ if (server == null)
+ throw new IllegalArgumentException("Null server");
+
+ DelegateMBeanServer last = this;
+ MBeanServer next = last.getNext();
+ while (next instanceof DelegateMBeanServer)
+ {
+ last = (DelegateMBeanServer) next;
+ next = last.getNext();
+ }
+ server.setNext(next);
+ last.setNext(server);
+ }
+
+ /**
+ * Set the target in the chain
+ *
+ * @param server the server
+ * @throws IllegalArgumentException for a null server
+ * @throws IllegalStateException if the target is already set
+ * @throws SecurityException if not authorised
+ */
+ public void setTarget(MBeanServer server)
+ {
+ SecurityManager sm = System.getSecurityManager();
+ if (sm != null)
+ sm.checkPermission(new RuntimePermission(getClass().getName()));
+
+ if (server == null)
+ throw new IllegalArgumentException("Null server");
+
+ if (getNext() != null)
+ throw new IllegalStateException("Target is already set");
+ setNext(server);
+ }
+}
Added: projects/jbossmx/trunk/mbeanserver/src/main/org/jboss/jmx/mbeanserver/RegistryEntry.java
===================================================================
--- projects/jbossmx/trunk/mbeanserver/src/main/org/jboss/jmx/mbeanserver/RegistryEntry.java (rev 0)
+++ projects/jbossmx/trunk/mbeanserver/src/main/org/jboss/jmx/mbeanserver/RegistryEntry.java 2009-03-30 14:10:52 UTC (rev 86472)
@@ -0,0 +1,112 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat Middleware LLC, and individual contributors
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.jmx.mbeanserver;
+
+import java.util.Map;
+
+import javax.management.ObjectName;
+
+/**
+ * RegistryEntry.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+class RegistryEntry
+{
+ final static String CLASSLOADER = "org.jboss.mx.classloader";
+
+ /**
+ * The registered object name of the mbean
+ */
+ private ObjectName objectName = null;
+
+ /**
+ * The context classloader of the mbean
+ */
+ private ClassLoader cl = null;
+
+ /**
+ * The value map of the mbean
+ */
+ private Map<String, Object> valueMap = null;
+
+ /**
+ * Construct a new mbean registration entry.
+ *
+ * @param objectName the name with which the mbean is registered
+ * @param valueMap any other information to include in the registration
+ */
+ public RegistryEntry(ObjectName objectName, Map<String, Object> valueMap)
+ {
+ this.objectName = objectName;
+ this.valueMap = valueMap;
+
+ // Adrian: Unpack the classloader because this is used alot
+ if (valueMap != null)
+ this.cl = (ClassLoader) valueMap.get(CLASSLOADER);
+ }
+
+ /**
+ * Retrieve the object name with the mbean is registered.
+ *
+ * @return the object name
+ */
+ public ObjectName getObjectName()
+ {
+ return objectName;
+ }
+
+ /** A protected method used to set the entry object name when access
+ * to the entry is needed before the ultimate name under which the
+ * mbean is registered is known.
+ *
+ * @param objectName - the object name under which the mbean is registered
+ */
+ protected void setObjectName(ObjectName objectName)
+ {
+ this.objectName = objectName;
+ }
+
+ /**
+ * Retrieve the context class loader with which to invoke the mbean.
+ *
+ * @return the class loader
+ */
+ public ClassLoader getClassLoader()
+ {
+ return cl;
+ }
+
+ /**
+ * Retrieve a value from the map.
+ *
+ * @param key the key to value
+ * @return the value or null if there is no entry
+ */
+ public Object getValue(String key)
+ {
+ if (valueMap != null)
+ return valueMap.get(key);
+ return null;
+ }
+}
Added: projects/jbossmx/trunk/mbeanserver/src/main/org/jboss/jmx/mbeanserver/SecurityActions.java
===================================================================
--- projects/jbossmx/trunk/mbeanserver/src/main/org/jboss/jmx/mbeanserver/SecurityActions.java (rev 0)
+++ projects/jbossmx/trunk/mbeanserver/src/main/org/jboss/jmx/mbeanserver/SecurityActions.java 2009-03-30 14:10:52 UTC (rev 86472)
@@ -0,0 +1,59 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, Red Hat Middleware LLC, and individual contributors
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.jmx.mbeanserver;
+
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+
+/**
+ * SecurityActions.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+class SecurityActions
+{
+ public static ClassLoader setContextClassLoader(final ClassLoader cl)
+ {
+ SecurityManager sm = System.getSecurityManager();
+ if (sm == null)
+ return doSetContextClassLoader(cl);
+ else
+ {
+ return AccessController.doPrivileged(new PrivilegedAction<ClassLoader>()
+ {
+ public ClassLoader run()
+ {
+ return doSetContextClassLoader(cl);
+ }
+ });
+ }
+ }
+
+ private static ClassLoader doSetContextClassLoader(ClassLoader cl)
+ {
+ Thread thread = Thread.currentThread();
+ ClassLoader previous = thread.getContextClassLoader();
+ thread.setContextClassLoader(cl);
+ return previous;
+ }
+}
Modified: projects/jbossmx/trunk/pom.xml
===================================================================
--- projects/jbossmx/trunk/pom.xml 2009-03-30 13:37:40 UTC (rev 86471)
+++ projects/jbossmx/trunk/pom.xml 2009-03-30 14:10:52 UTC (rev 86472)
@@ -21,6 +21,7 @@
</scm>
<modules>
+ <module>mbeanserver</module>
<module>j2se</module>
<module>mbeans</module>
<module>jmx</module>
@@ -161,6 +162,11 @@
</dependency>
<dependency>
<groupId>org.jboss.mx</groupId>
+ <artifactId>jboss-mbeanserver</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.mx</groupId>
<artifactId>jboss-j2se</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
More information about the jboss-cvs-commits
mailing list