feat(jdk8): move files to new folder to avoid resources compiled.

This commit is contained in:
2025-09-07 15:25:52 +08:00
parent 3f0047bf6f
commit 8c35cfb1c0
17415 changed files with 217 additions and 213 deletions

View File

@@ -0,0 +1,144 @@
/*
* Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code 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 General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.org.glassfish.external.amx;
/**
Constants reflecting the AMX specification.
See https://glassfish.dev.java.net/nonav/v3/admin/planning/V3Changes/V3_AMX_SPI.html
*/
public final class AMX
{
private AMX()
{
// do not instantiate
}
/** Attribute yielding the ObjectName of the parent MBean */
public static final String ATTR_PARENT = "Parent";
/** Attribute yielding the children as an ObjectName[] */
public static final String ATTR_CHILDREN = "Children";
/** Attribute yielding the name of the MBean,
possibly differing from the name as found in the ObjectName via the
property {@link #NAME_KEY} */
public static final String ATTR_NAME = "Name";
/** ObjectName property for the type */
public static final String TYPE_KEY = "type";
/** ObjectName property for the name */
public static final String NAME_KEY = "name";
/** Implied name for singletons when the name property is not present */
public static final String NO_NAME = "";
/**
The ObjectName property key denoting the path of the parent MBean.
Serves to disambiguitate the ObjectName from others
that might have the same type and/or name elsewhere in the hierarchy.
*/
public static final String PARENT_PATH_KEY = "pp";
/** Prefix for AMX descriptor fields */
public static final String DESC_PREFIX = "amx.";
/** Prefix for AMX notification types */
public static final String NOTIFICATION_PREFIX = DESC_PREFIX;
/**
Descriptor value defined by JMX standard: whether the MBeanInfo is *invariant* (immutable is a misnomer).
*/
public static final String DESC_STD_IMMUTABLE_INFO = "immutableInfo";
/**
Descriptor value defined by JMX standard, the classname of the interface for the MBean.
Mainly advisory, since client code might not have access to the class.
*/
public static final String DESC_STD_INTERFACE_NAME = "interfaceName";
/**
Descriptor value: The generic AMX interface to be used if the class found in {@link #DESC_STD_INTERFACE_NAME}
cannot be loaded. The class specified here must reside in the amx-core
module eg com.sun.org.glassfish.admin.amx.core eg AMXProxy or AMXConfigProxy.
*/
public static final String DESC_GENERIC_INTERFACE_NAME = DESC_PREFIX + "genericInterfaceName";
/**
Descriptor value: whether the MBean is a singleton, in spite of having a name property in its ObjectName.
This is mainly for compatibility; named singletons are strongly discouraged.
*/
public static final String DESC_IS_SINGLETON = DESC_PREFIX + "isSingleton";
/**
Descriptor value: whether the MBean is a global singleton eg whether in the AMX domain
it can be looked up by its type and is the only MBean of that type.
*/
public static final String DESC_IS_GLOBAL_SINGLETON = DESC_PREFIX + "isGlobalSingleton";
/**
Descriptor value: Arbitrary string denoting the general classification of MBean.
Predefined values include "configuration", "monitoring", "jsr77", "utility", "other".
*/
public static final String DESC_GROUP = DESC_PREFIX + "group";
/**
Descriptor value: whether new children may be added by code other than the implementation responsible for the MBean;
this allows extension points within the hierarchy.
Adding a new child means registering an MBean with an ObjectName that implies parentage via the ancestry type=name pairs.
*/
public static final String DESC_SUPPORTS_ADOPTION = DESC_PREFIX + "supportsAdoption";
/**
Descriptor value: denotes the possible types of MBeans that children might be. If present, SHOULD include all possible and pre-known types.
An empty array indicates that child MBeans might exist, but their types cannot be predicted.
*/
public static final String DESC_SUB_TYPES = DESC_PREFIX + "subTypes";
/**
Group value indicating that the AMX is a configuration MBean.
*/
public static final String GROUP_CONFIGURATION = "configuration";
/**
Group value indicating that the AMX represents a monitoring MBean.
*/
public static final String GROUP_MONITORING = "monitoring";
/**
Group value indicating that the AMX is a utility MBean.
*/
public static final String GROUP_UTILITY = "utility";
/**
Group value indicating that the AMX is a JSR 77 MBean
(J2EE Management) .
*/
public static final String GROUP_JSR77 = "jsr77";
/**
Group value indicating that the AMX is not one
of the other types.
*/
public static final String GROUP_OTHER = "other";
}

View File

@@ -0,0 +1,318 @@
/*
* Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code 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 General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.org.glassfish.external.amx;
import javax.management.ObjectName;
import javax.management.MBeanServer;
import javax.management.MBeanServerConnection;
import java.io.IOException;
/**
* AMX behavior specific to Glassfish V3.
*/
public final class AMXGlassfish
{
public static final String DEFAULT_JMX_DOMAIN = "amx";
/** Default domain support */
public static final AMXGlassfish DEFAULT = new AMXGlassfish(DEFAULT_JMX_DOMAIN);
private final String mJMXDomain;
private final ObjectName mDomainRoot;
/** Anything other than {@link #DEFAULT} is not supported in Glassfish V3 */
public AMXGlassfish(final String jmxDomain)
{
mJMXDomain = jmxDomain;
mDomainRoot = newObjectName("", "domain-root", null);
}
/** Return a version string, or null if not running in Glassfish */
public static String getGlassfishVersion()
{
// must all exist as a check to verify that it's Glassfish V3
final String version = System.getProperty( "glassfish.version" );
return version;
}
/** JMX domain used by AMX MBeans.
* <p>
* All MBeans in this domain must be AMX-compliant, see http://tinyurl.com/nryoqp =
https://glassfish.dev.java.net/nonav/v3/admin/planning/V3Changes/V3_AMX_SPI.html
*/
public String amxJMXDomain()
{
return mJMXDomain;
}
/** JMX domain used by AMX support MBeans. Private use only */
public String amxSupportDomain()
{
return amxJMXDomain() + "-support";
}
/** name of the Domain Admin Server (DAS) as found in an ObjectName */
public String dasName()
{
return "server";
}
/** name of the Domain Admin Server (DAS) &lt;config> */
public String dasConfig()
{
return dasName() + "-config";
}
/** return the ObjectName of the AMX DomainRoot MBean */
public ObjectName domainRoot()
{
return mDomainRoot;
}
/** ObjectName for top-level monitoring MBean (parent of those for each server) */
public ObjectName monitoringRoot()
{
return newObjectName("/", "mon", null);
}
/** ObjectName for top-level monitoring MBean for specified server */
public ObjectName serverMon(final String serverName)
{
return newObjectName("/mon", "server-mon", serverName);
}
/** ObjectName for top-level monitoring MBean for the DAS. */
public ObjectName serverMonForDAS() {
return serverMon( "server" ) ;
}
/** Make a new AMX ObjectName with unchecked exception.
* name must be null to create a singleton ObjectName.
* Note that the arguments must not contain the characters
* @param pp The parent part
* @param type The ObjectName type
* @param name The ObjectName name
* @return The objectname with pp, type, and (optionally) name.
*/
public ObjectName newObjectName(
final String pp,
final String type,
final String name)
{
String props = prop(AMX.PARENT_PATH_KEY, pp) + "," + prop(AMX.TYPE_KEY, type);
if (name != null) {
props = props + "," + prop(AMX.NAME_KEY, name);
}
return newObjectName( props);
}
/** Make a new ObjectName for AMX domain with unchecked exception */
public ObjectName newObjectName(final String s)
{
String name = s;
if ( ! name.startsWith( amxJMXDomain() ) ) {
name = amxJMXDomain() + ":" + name;
}
return AMXUtil.newObjectName( name );
}
private static String prop(final String key, final String value)
{
return key + "=" + value;
}
/**
ObjectName for {@link BootAMXMBean}
*/
public ObjectName getBootAMXMBeanObjectName()
{
return AMXUtil.newObjectName( amxSupportDomain() + ":type=boot-amx" );
}
/**
Invoke the bootAMX() method on {@link BootAMXMBean}. Upon return,
AMX continues to load.
A cilent should call {@link invokeWaitAMXReady} prior to use.
*/
public void invokeBootAMX(final MBeanServerConnection conn)
{
// start AMX and wait for it to be ready
try
{
conn.invoke( getBootAMXMBeanObjectName(), BootAMXMBean.BOOT_AMX_OPERATION_NAME, null, null);
}
catch (final Exception e)
{
e.printStackTrace();
throw new RuntimeException(e);
}
}
/**
Invoke the waitAMXReady() method on the DomainRoot MBean, which must already be loaded.
*/
private static void invokeWaitAMXReady(final MBeanServerConnection conn, final ObjectName objectName)
{
try
{
conn.invoke( objectName, "waitAMXReady", null, null );
}
catch( final Exception e )
{
throw new RuntimeException(e);
}
}
/**
Listen for the registration of AMX DomainRoot
Listening starts automatically.
*/
public <T extends MBeanListener.Callback> MBeanListener<T> listenForDomainRoot(
final MBeanServerConnection server,
final T callback)
{
final MBeanListener<T> listener = new MBeanListener<T>( server, domainRoot(), callback);
listener.startListening();
return listener;
}
private static final class WaitForDomainRootListenerCallback extends MBeanListener.CallbackImpl {
private final MBeanServerConnection mConn;
public WaitForDomainRootListenerCallback( final MBeanServerConnection conn ) {
mConn = conn;
}
@Override
public void mbeanRegistered(final ObjectName objectName, final MBeanListener listener) {
super.mbeanRegistered(objectName,listener);
invokeWaitAMXReady(mConn, objectName);
mLatch.countDown();
}
}
/**
Wait until AMX has loaded and is ready for use.
<p>
This will <em>not</em> cause AMX to load; it will block forever until AMX is ready. In other words,
don't call this method unless it's a convenient thread that can wait forever.
*/
public ObjectName waitAMXReady( final MBeanServerConnection server)
{
final WaitForDomainRootListenerCallback callback = new WaitForDomainRootListenerCallback(server);
listenForDomainRoot( server, callback );
callback.await();
return callback.getRegistered();
}
/**
Listen for the registration of the {@link BootAMXMBean}.
Listening starts automatically. See {@link AMXBooter#BootAMXCallback}.
*/
public <T extends MBeanListener.Callback> MBeanListener<T> listenForBootAMX(
final MBeanServerConnection server,
final T callback)
{
final MBeanListener<T> listener = new MBeanListener<T>( server, getBootAMXMBeanObjectName(), callback);
listener.startListening();
return listener;
}
/**
Callback for {@link MBeanListener} that waits for the BootAMXMBean to appear;
it always will load early in server startup. Once it has loaded, AMX can be booted
via {@link #bootAMX}. A client should normally just call {@link #bootAMX}, but
this callback may be suclassed if desired, and used as a trigger to
boot AMX and then take other dependent actions.
*/
public static class BootAMXCallback extends MBeanListener.CallbackImpl
{
private final MBeanServerConnection mConn;
public BootAMXCallback(final MBeanServerConnection conn)
{
mConn = conn;
}
@Override
public void mbeanRegistered(final ObjectName objectName, final MBeanListener listener)
{
super.mbeanRegistered(objectName, listener);
mLatch.countDown();
}
}
/**
Ensure that AMX is loaded and ready to use. This method returns only when all
AMX subsystems have been loaded.
It can be called more than once without ill effect, subsequent calls are ignored.
@param conn connection to the MBeanServer
@return the ObjectName of the domain-root MBean
*/
public ObjectName bootAMX(final MBeanServerConnection conn)
throws IOException
{
final ObjectName domainRoot = domainRoot();
if ( !conn.isRegistered( domainRoot ) )
{
// wait for the BootAMXMBean to be available (loads at startup)
final BootAMXCallback callback = new BootAMXCallback(conn);
listenForBootAMX(conn, callback);
callback.await(); // block until the MBean appears
invokeBootAMX(conn);
final WaitForDomainRootListenerCallback drCallback = new WaitForDomainRootListenerCallback(conn);
listenForDomainRoot(conn, drCallback);
drCallback.await();
invokeWaitAMXReady(conn, domainRoot);
}
else
{
invokeWaitAMXReady(conn, domainRoot );
}
return domainRoot;
}
public ObjectName bootAMX(final MBeanServer server)
{
try
{
return bootAMX( (MBeanServerConnection)server);
}
catch( final IOException e )
{
throw new RuntimeException(e);
}
}
}

View File

@@ -0,0 +1,79 @@
/*
* Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code 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 General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.org.glassfish.external.amx;
import javax.management.MBeanServerConnection;
import javax.management.ObjectName;
/**
Small utilities for AMXBooter and related.
*/
@com.sun.org.glassfish.external.arc.Taxonomy(stability = com.sun.org.glassfish.external.arc.Stability.UNCOMMITTED)
public final class AMXUtil
{
private AMXUtil() {}
/**
Make a new ObjectName (unchecked exception).
*/
public static ObjectName newObjectName(final String s)
{
try
{
return new ObjectName( s );
}
catch( final Exception e )
{
throw new RuntimeException("bad ObjectName", e);
}
}
/**
Make a new ObjectName (unchecked exception).
@param domain
@param props
*/
public static ObjectName newObjectName(
final String domain,
final String props)
{
return newObjectName(domain + ":" + props);
}
/**
Get the ObjectName of the MBeanServerDelegateObjectName.
*/
public static ObjectName getMBeanServerDelegateObjectName()
{
return newObjectName( "JMImplementation:type=MBeanServerDelegate" );
}
public static String prop(final String key, final String value)
{
return key + "=" + value;
}
}

View File

@@ -0,0 +1,48 @@
/*
* Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code 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 General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.org.glassfish.external.amx;
import javax.management.ObjectName;
import javax.management.remote.JMXServiceURL;
/**
MBean responsible for booting the AMX system.
To get its ObjectName, use {@link AMXGlassfish#getBootAMXMBeanObjectName}.
*/
@com.sun.org.glassfish.external.arc.Taxonomy(stability = com.sun.org.glassfish.external.arc.Stability.UNCOMMITTED)
public interface BootAMXMBean
{
/**
Start AMX and return the ObjectName of DomainRoot.
*/
public ObjectName bootAMX();
/** same as method above */
public static final String BOOT_AMX_OPERATION_NAME = "bootAMX";
public JMXServiceURL[] getJMXServiceURLs();
}

View File

@@ -0,0 +1,330 @@
/*
* Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code 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 General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.org.glassfish.external.amx;
import java.util.Set;
import javax.management.MBeanServer;
import javax.management.MBeanServerConnection;
import javax.management.MBeanServerNotification;
import javax.management.Notification;
import javax.management.NotificationListener;
import javax.management.ObjectName;
import java.util.concurrent.CountDownLatch;
import static com.sun.org.glassfish.external.amx.AMX.*;
/**
* Listens for registration of MBeans of various types.
* Intended usage is for subsystems to lazy-load only when the Parent
* MBean is registered.
*/
@com.sun.org.glassfish.external.arc.Taxonomy(stability = com.sun.org.glassfish.external.arc.Stability.UNCOMMITTED)
public class MBeanListener<T extends MBeanListener.Callback> implements NotificationListener
{
private static void debug(final Object o) { System.out.println( "" + o ); }
/** listen for MBeans in a given domain of a given type[name]
OR an ObjectName (below) */
private final String mJMXDomain;
private final String mType;
private final String mName;
/** mType and mName should be null if mObjectName is non-null, and vice versa */
private final ObjectName mObjectName;
private final MBeanServerConnection mMBeanServer;
private final T mCallback;
public String toString()
{
return "MBeanListener: ObjectName=" + mObjectName + ", type=" + mType + ", name=" + mName;
}
public String getType()
{
return mType;
}
public String getName()
{
return mName;
}
public MBeanServerConnection getMBeanServer()
{
return mMBeanServer;
}
/** Callback interface. */
public interface Callback
{
public void mbeanRegistered(final ObjectName objectName, final MBeanListener listener);
public void mbeanUnregistered(final ObjectName objectName, final MBeanListener listener);
}
/**
Default callback implementation, can be subclassed if needed
Remembers only the last MBean that was seen.
*/
public static class CallbackImpl implements MBeanListener.Callback
{
private volatile ObjectName mRegistered = null;
private volatile ObjectName mUnregistered = null;
private final boolean mStopAtFirst;
public CallbackImpl() {
this(true);
}
public CallbackImpl(final boolean stopAtFirst)
{
mStopAtFirst = stopAtFirst;
}
public ObjectName getRegistered() { return mRegistered; }
public ObjectName getUnregistered() { return mUnregistered; }
protected final CountDownLatch mLatch = new CountDownLatch(1);
/** Optional: wait for the CountDownLatch to fire
If used, the subclass should countDown() the latch when the
appropriate event happens
*/
public void await()
{
try
{
mLatch.await(); // wait until BootAMXMBean is ready
}
catch (InterruptedException e)
{
throw new RuntimeException(e);
}
}
public void mbeanRegistered(final ObjectName objectName, final MBeanListener listener)
{
mRegistered = objectName;
if ( mStopAtFirst )
{
listener.stopListening();
}
}
public void mbeanUnregistered(final ObjectName objectName, final MBeanListener listener)
{
mUnregistered = objectName;
if ( mStopAtFirst )
{
listener.stopListening();
}
}
}
public T getCallback()
{
return mCallback;
}
/**
* Listener for a specific MBean.
* Caller must call {@link #start} to start listening.
* @param server
* @param objectName
* @param callback
*/
public MBeanListener(
final MBeanServerConnection server,
final ObjectName objectName,
final T callback)
{
mMBeanServer = server;
mObjectName = objectName;
mJMXDomain = null;
mType = null;
mName = null;
mCallback = callback;
}
/**
* Listener for all MBeans of specified type, with or without a name.
* Caller must call {@link #start} to start listening.
* @param server
* @param type type of the MBean (as found in the ObjectName)
* @param callback
*/
public MBeanListener(
final MBeanServerConnection server,
final String domain,
final String type,
final T callback)
{
this(server, domain, type, null, callback);
}
/**
* Listener for MBeans of specified type, with specified name (or any name
* if null is passed for the name).
* Caller must call {@link #start} to start listening.
* @param server
* @param type type of the MBean (as found in the ObjectName)
* @param name name of the MBean, or null if none
* @param callback
*/
public MBeanListener(
final MBeanServerConnection server,
final String domain,
final String type,
final String name,
final T callback)
{
mMBeanServer = server;
mJMXDomain = domain;
mType = type;
mName = name;
mObjectName = null;
mCallback = callback;
}
private boolean isRegistered( final MBeanServerConnection conn, final ObjectName objectName )
{
try
{
return conn.isRegistered(objectName);
}
catch (final Exception e)
{
throw new RuntimeException(e);
}
}
/**
Start listening. If the required MBean(s) are already present, the callback
will be synchronously made before returning. It is also possible that the
callback could happen twice for the same MBean.
*/
public void startListening()
{
// race condition: must listen *before* looking for existing MBeans
try
{
mMBeanServer.addNotificationListener( AMXUtil.getMBeanServerDelegateObjectName(), this, null, this);
}
catch (final Exception e)
{
throw new RuntimeException("Can't add NotificationListener", e);
}
if ( mObjectName != null )
{
if ( isRegistered(mMBeanServer, mObjectName) )
{
mCallback.mbeanRegistered(mObjectName, this);
}
}
else
{
// query for AMX MBeans of the requisite type
String props = TYPE_KEY + "=" + mType;
if (mName != null)
{
props = props + "," + NAME_KEY + mName;
}
final ObjectName pattern = AMXUtil.newObjectName(mJMXDomain + ":" +props);
try
{
final Set<ObjectName> matched = mMBeanServer.queryNames(pattern, null);
for (final ObjectName objectName : matched)
{
mCallback.mbeanRegistered(objectName, this);
}
}
catch( final Exception e )
{
throw new RuntimeException(e);
}
}
}
/** unregister the listener */
public void stopListening()
{
try
{
mMBeanServer.removeNotificationListener( AMXUtil.getMBeanServerDelegateObjectName(), this);
}
catch (final Exception e)
{
throw new RuntimeException("Can't remove NotificationListener " + this, e);
}
}
public void handleNotification(
final Notification notifIn,
final Object handback)
{
if (notifIn instanceof MBeanServerNotification)
{
final MBeanServerNotification notif = (MBeanServerNotification) notifIn;
final ObjectName objectName = notif.getMBeanName();
boolean match = false;
if ( mObjectName != null && mObjectName.equals(objectName) )
{
match = true;
}
else if ( objectName.getDomain().equals( mJMXDomain ) )
{
if ( mType != null && mType.equals(objectName.getKeyProperty(TYPE_KEY)) )
{
final String mbeanName = objectName.getKeyProperty(NAME_KEY);
if (mName != null && mName.equals(mbeanName))
{
match = true;
}
}
}
if ( match )
{
final String notifType = notif.getType();
if (MBeanServerNotification.REGISTRATION_NOTIFICATION.equals(notifType))
{
mCallback.mbeanRegistered(objectName, this);
}
else if (MBeanServerNotification.UNREGISTRATION_NOTIFICATION.equals(notifType))
{
mCallback.mbeanUnregistered(objectName, this);
}
}
}
}
}