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);
}
}
}
}
}

View File

@@ -0,0 +1,329 @@
/*
* 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.arc;
/**
Taxonomy values.
See http://opensolaris.org/os/community/arc/policies/interface-taxonomy/
<p>
<h3>Policy</h3>
<ul>
<li>Applies to All software produced by SMI</li>
<li>Authority SAC</li>
<li>Approval SAC</li>
<li>Effective April, 1992</li>
<li>Policy </li>
<ul><li>All software interfaces must be classified according to this taxonomy.
Interfaces are defined as APIs, files and directory structures, file formats, protocols,
(sometimes) even performance and reliability behaviors, and any other attribute upon
which another component might reasonably depend.</li>
<li>An ARC must review, approve and archive the specification for all interfaces
other than Project Private and Internal. Unreviewed, unapproved interfaces are assumed
to be Internal. An adequate specification, suitable for archiving must exist for all
interfaces submitted for review. Often Project Private interfaces are also reviewed if
the presentation of them aids the understanding of the entire project or it is expected
they will be promoted to a broader classification in the future.</li>
<li>Adequate customer documentation must exist for all Public interfaces.
It is strongly preferred that manual pages exist for all Public interfaces
(supported on Solaris), even if only significant content of those pages are SYNOPSIS
and ATTRIBUTES sections and a textual pointer to other documentation.
Independent of the form of documentation delivery, the interface taxonomy commitment
level must be presented to the consumer.</li>
<li>In cases where the organization delivering the interface implementation does not
control the interface specification, the controlling body must be be clearly cited
in the documentation. In the case where a well-defined, versioned document is the
specification, both the name and precise version must be be cited.</li>
</ul>
</ul>
@author llc
*/
public enum Stability {
/**
<pre>
+----------------------------------------------------------------------------+
| Committed (formerly Stable, Public; encompasses Standard, Evolving) |
|----------------------------------------------------------------------------|
| | Specification | Open |
| |---------------------+--------------------------------------------------|
| | Incompatible Change | major release (X.0) |
| |---------------------+--------------------------------------------------|
| | ARC review of Specs | Yes |
| |---------------------+--------------------------------------------------|
| | Examples | Compiler command line options, |
| | | hardware (SBus, PCI, USB), RPC, POSIX utilities |
+----------------------------------------------------------------------------+
</pre>
We publish the specification of these interfaces, typically as manual pages or other product documentation.
We also tell customers we will remain compatible with them. (Scott McNealy's principle that "Compatibility is a
constraint, not a goal") The intention of a Committed interface is to enable arbitrary third parties to develop
applications to these interfaces, release them, and have confidence that they will run on all releases of the product
after the one in which the interface was introduced, and within the same Major release. Even at a Major release,
incompatible changes are expected to be rare, and to have strong justifications.
<p>
Committed interfaces are often proposed to be industry standards, as was the case with RPC.
Also, interfaces defined and controlled as industry standards are most often treated as Committed interfaces.
<p>
These are interfaces whose specification is often under the provider's control or which are specified by a
clearly versioned document controlled by a well-defined organization. If the interface specification is not
under the implementation provider's control, the provider must be willing to fork from the interface specification
if required to maintain compatibility. In the case of interface specifications controlled by a standards body,
the commitment must be to a clearly identified version of the specification, minimizing the likelihood of an
incompatible change (but it can happen through formal spec interpretations).
<p>
Also, if the interface specification is not under the control of the interface implementation provider,
then the controlling body and/or public, versioned document must be be noted in the documentation.
This is particularly important for specifications controlled by recognized standards organizations.
<p>
Although a truely exceptional event, incompatible changes are possible in any release if
the associated defect is serious enough as outlined in the EXEMPTIONS section of this document or
in a Minor release by following the End of Feature process.
*/
COMMITTED( "Committed" ),
/**
<pre>
+--------------------------------------------------------------------------+
| Uncommitted (formerly Unstable) |
|--------------------------------------------------------------------------|
| | Specification | Open |
| |---------------------+------------------------------------------------|
| | Incompatible Change | minor release (x.Y) with impact assessment |
| |---------------------+------------------------------------------------|
| | ARC review of Specs | Yes |
| |---------------------+------------------------------------------------|
| | Examples | SUNW* package abbreviations, some config utils |
+--------------------------------------------------------------------------+
</pre>
No guarantees are made about either source or binary compatibility of these interfaces
from one Minor release to the next. The most drastic incompatible change of removal of
the interface in a Minor release is allowed. Uncommitted interfaces are generally not
appropriate for use by release-independent products.
<p>
Uncommitted is not a license for gratuitous change. Any incompatible changes to the
interface should be motivated by true improvement to the interface which may include
justifiable ease of use considerations. The general expectation is that Uncommitted
interfaces are not likely to change incompatibly and if such changes occur they will be
small in impact and should often have a mitigation plan.
<p>
Uncommitted interfaces generally fall into one of the following subcategories:
<p>
<ul>
<li>
Interfaces that are experimental or transitional.
They are typically used to give outside developers early access to new or
rapidly-changing technology, or to provide an interim solution to a problem where a
more general solution is anticipated.
</li>
<li>
Interfaces whose specification is controlled by an outside body and the
implementation provider is only willing to commit to forking until the next minor
release point should that outside body introduce incompatible change.
Note that this "middle of the road" approach is often the best business decision
when the controlling body hasn't established a history of respecting compatibility.
</li>
<li>
Interfaces whose target audience values innovation (and possibly ease of use) over
stability. This attribute is often asserted for administrative interfaces for higher
web tier components. Note that ARC review may request data to support such an assertion.
</li>
<p>
A project's intention to import an Uncommitted interface from another consolidation should
be discussed with the ARC early. The stability classification of the interface -- or
a replacement interface -- might be raised. The opinion allowing any project to import an
Uncommitted interface must explain why it is acceptable, and a contract must be put into
place allowing this use. For Sun products, the similarity in the usage of Uncommitted and
Consolidation Private interfaces should be noted.
<p>
Any documentation for an Uncommitted interface must contain warnings that "these interfaces
are subject to change without warning and should not be used in unbundled products".
In some situations, it may be appropriate to document Uncommitted interfaces in white papers
rather than in standard product documentation. When changes are introduced, the changes
should be mentioned in the release notes for the affected release.
<p>
NOTE: If we choose to offer a draft standard implementation but state our intention to track
the standard (or the portions we find technically sound or likely to be standardized),
we set customer expectations for incompatible changes by classifying the interface Uncommitted.
The interface must be reclassified Committed when standard is final.
Such an intention could be encoded "Uncommitted->Committed".)
</pre>
*/
UNCOMMITTED( "Uncommitted" ),
/**
<pre>
+--------------------------------------------------------------------+
| Volatile (encompasses External) |
|--------------------------------------------------------------------|
| | Specification | Open |
| |---------------------+------------------------------------------|
| | Incompatible Change | micro release (x.y.z) or patch release |
| |---------------------+------------------------------------------|
| | Arc review of Specs | A precise reference is normally recorded |
| |---------------------+------------------------------------------|
| | Examples | Gimp user interface, IETF internet-draft |
+--------------------------------------------------------------------+
</pre>
Volatile interfaces may change at any time and for any reason.
<p>
Use of the Volatile interface stability level allows interface providers to
quickly track a fluid, rapidly evolving specification. In many cases, this is
preferred to providing additional stability to the interface, as it may better
meet the expectations of the consumer.
<p>
The most common application of this taxonomy level is to interfaces that are
controlled by a body other than the final implementation provider, but unlike
specifications controlled by standards bodies or communities we place trust in,
it can not be asserted that an incompatible change to the interface
specification would be exceedingly rare. In some cases it may not even be
possible to clearly identify the controlling body. Although not prohibited by
this taxonomy, the Volatile classification is not typically applied to
interfaces where the specification is controlled by the implementation provider.
<p>
It should be noted that in some cases it will be preferable to apply a less
fluid interface classification to an interface even if the controlling body is
separate from the implementor. Use of the Uncommitted classification extends the
stability commitment over micro/patch releases, allowing use of additional
support models for software that depends upon these interfaces, at the potential
cost of less frequent updates. Committed should be considered for required, core
interfaces. If instability in the interface definition can't be reconciled with
the requirement for stability, then alternate solutions should be considered.
<p>
This classification is typically used for free or open source software (FOSS),
also referred to as community software, and similar models where it is deemed
more important to track the community with minimal latency than to provide
stability to our customers. When applying this classification level to community
software, particular attention should be paid to the considerations presented in
the preceding paragraph.
<p>
It also may be appropriate to apply the Volatile classification level to
interfaces in the process of being defined by trusted or widely accepted
organization. These are generically referred to as draft standards. An "IETF
internet draft" is a well understood example of a specification under
development.
<p>
There may also cases where Volatile is appropriate for experimental interfaces,
but in most cases Uncommitted should be considered first.
<p>
Irrespective of the control of the specification, the Volatile classification
must not be applied to "core" interfaces (those that must be used) for which no
alternate (and more stable) interface exists. Volatile interfaces must also
adhere to Sun internal standards in the following areas:
<ul>
<li>Security, Authentication</li>
<li>The existence of (perhaps vestigial) Manual Pages and conformance to Sun section numbering</li>
<li>File System Semantics (Solaris examples: /usr may be read-only, /var is where
all significant run-time growth occurs, ...)</li>
</ul>
All Volatile interfaces should be labeled as such in all associated
documentation and the consequence of using such interfaces must be explained
either as part of that documentation or by reference.
<p>
Shipping incompatible change in a patch should be strongly avoided. It is not
strictly prohibited for the following two reasons:
<ul>
<li>Since the patch provider may not be in explicit control of the changes to the
upstream implementation, it cannot guarantee with reasonable assurance that an
unidentified incompatibility is not present.
</li>
<li>A strong business case may exist for shipping a newer version as a patch if that
newer version closes significant escalations.
</li>
</ul>
In general, the intent of allowing change in a patch is to allow for change in
Update Releases.
<p>
Sun products should consider Volatile interfaces as equivalent to Consolidation
Private. A contract is required for use of these interfaces outside of the
supplying consolidation.
<p>
Extreme care in the use of Volatile interfaces is required by layered or
unbundled products. Layered products that depend upon Volatile interfaces must
include as part of their review material how they intend to manage the
dependency. It is not explicitly prohibited, but it is probable that unbundled
or layered products that ship asynchronously from the Volatile interfaces upon
which they depend will face nearly insurmountable difficulty in constructing a
plan to manage such a dependency.
*/
VOLATILE( "Volatile" ),
/**
<pre>
+--------------------------------------------------------------------+
| Not-an-interface |
|--------------------------------------------------------------------|
| | Specification | None |
| |---------------------+------------------------------------------|
| | Incompatible Change | micro release (x.y.z) or patch release |
| |---------------------+------------------------------------------|
| | Arc review of Specs | None |
| |---------------------+------------------------------------------|
| | Examples | CLI output, error text |
+--------------------------------------------------------------------+
</pre>
In the course of reviewing or documenting interfaces, the situation often occurs
that an attribute will be present which may be inferred to be an interface, but
actually is not. A couple of common examples of this are output from CLIs
intended only for human consumption and the exact layout of a GUI.
<p>
This classification is simply a convenience term to be used to clarify such
situations where such confusion is identified as likely. Failure to apply this
term to an attribute is no indication that said attribute is some form of
interface. It only indicates that the potential for confusion was not
identified.
*/
NOT_AN_INTERFACE( "Not-An-Interface" ),
/**
See: http://opensolaris.org/os/community/arc/policies/interface-taxonomy/
<p>
Javadoc or other means should establish the nature of the private interface.
*/
PRIVATE( "Private" ),
/**
Not a formal term. Indicates that the interface, while visible, is experimental,
and can be removed at any time.
*/
EXPERIMENTAL( "Experimental" ),
/**
Interrim classification; a real one should be chosen asap.
*/
UNSPECIFIED( "Unspecified" );
private final String mName;
private Stability( final String name ) { mName = name; }
public String toString() { return mName; }
}

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.arc;
import java.lang.annotation.Documented;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
import static java.lang.annotation.ElementType.*;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
/**
Annotates classes, methods or fields as to the ARC taxonomy (stability level).
Note that a class can be annotated as a whole, but that annotations on its methods
and fields override the whole-class annotation.
@author llc
*/
@Retention(RUNTIME)
@Documented
@Target( {METHOD, TYPE, ANNOTATION_TYPE, FIELD, PACKAGE})
public @interface Taxonomy {
public Stability stability() default Stability.UNSPECIFIED;
public String description() default "";
}

View File

@@ -0,0 +1,54 @@
/*
* 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.probe.provider;
/**
*
* @author abbagani
*/
public enum PluginPoint {
SERVER ("server", "server"),
APPLICATIONS ("applications", "server/applications");
String name;
String path;
PluginPoint(String lname, String lpath) {
name = lname;
path = lpath;
}
public String getName() {
return name;
}
public String getPath() {
return path;
}
}

View File

@@ -0,0 +1,39 @@
/*
* 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.probe.provider;
/**
*
* @author abbagani
*/
public interface StatsProvider {
public void enable();
public void disable();
}

View File

@@ -0,0 +1,86 @@
/*
* 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.probe.provider;
/**
*
* @author abbagani
*/
public class StatsProviderInfo {
public StatsProviderInfo(String configElement, PluginPoint pp,
String subTreeRoot, Object statsProvider){
this(configElement, pp, subTreeRoot, statsProvider, null);
}
public StatsProviderInfo(String configElement, PluginPoint pp,
String subTreeRoot, Object statsProvider,
String invokerId){
this.configElement = configElement;
this.pp = pp;
this.subTreeRoot = subTreeRoot;
this.statsProvider = statsProvider;
this.invokerId = invokerId;
}
private String configElement;
private PluginPoint pp;
private String subTreeRoot;
private Object statsProvider;
private String configLevelStr = null;
private final String invokerId;
public String getConfigElement() {
return configElement;
}
public PluginPoint getPluginPoint() {
return pp;
}
public String getSubTreeRoot() {
return subTreeRoot;
}
public Object getStatsProvider() {
return statsProvider;
}
public String getConfigLevel() {
return configLevelStr;
}
public void setConfigLevel(String configLevelStr) {
this.configLevelStr = configLevelStr;
}
public String getInvokerId() {
return invokerId;
}
}

View File

@@ -0,0 +1,137 @@
/*
* 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.probe.provider;
import java.util.Vector;
/**
*
* @author abbagani
*/
public class StatsProviderManager {
private StatsProviderManager(){
}
public static boolean register(String configElement, PluginPoint pp,
String subTreeRoot, Object statsProvider) {
return (register(pp, configElement, subTreeRoot, statsProvider, null));
}
public static boolean register(PluginPoint pp, String configElement,
String subTreeRoot, Object statsProvider,
String invokerId) {
StatsProviderInfo spInfo =
new StatsProviderInfo(configElement, pp, subTreeRoot, statsProvider, invokerId);
return registerStatsProvider(spInfo);
}
public static boolean register(String configElement, PluginPoint pp,
String subTreeRoot, Object statsProvider,
String configLevelStr) {
return(register(configElement, pp, subTreeRoot, statsProvider, configLevelStr, null));
}
public static boolean register(String configElement, PluginPoint pp,
String subTreeRoot, Object statsProvider,
String configLevelStr, String invokerId) {
StatsProviderInfo spInfo =
new StatsProviderInfo(configElement, pp, subTreeRoot, statsProvider, invokerId);
spInfo.setConfigLevel(configLevelStr);
return registerStatsProvider(spInfo);
}
private static boolean registerStatsProvider(StatsProviderInfo spInfo) {
//Ideally want to start this in a thread, so we can reduce the startup time
if (spmd == null) {
//Make an entry into the toBeRegistered map
toBeRegistered.add(spInfo);
} else {
spmd.register(spInfo);
return true;
}
return false;
}
public static boolean unregister(Object statsProvider) {
//Unregister the statsProvider if the delegate is not null
if (spmd == null) {
for (StatsProviderInfo spInfo : toBeRegistered) {
if (spInfo.getStatsProvider() == statsProvider) {
toBeRegistered.remove(spInfo);
break;
}
}
} else {
spmd.unregister(statsProvider);
return true;
}
return false;
}
public static boolean hasListeners(String probeStr) {
//See if the probe has any listeners registered
if (spmd == null) {
return false;
} else {
return spmd.hasListeners(probeStr);
}
}
public static void setStatsProviderManagerDelegate(
StatsProviderManagerDelegate lspmd) {
//System.out.println("in StatsProviderManager.setStatsProviderManagerDelegate ***********");
if (lspmd == null) {
//Should log and throw an exception
return;
}
//Assign the Delegate
spmd = lspmd;
//System.out.println("Running through the toBeRegistered array to call register ***********");
//First register the pending StatsProviderRegistryElements
for (StatsProviderInfo spInfo : toBeRegistered) {
spmd.register(spInfo);
}
//Now that you registered the pending calls, Clear the toBeRegistered store
toBeRegistered.clear();
}
//variables
static StatsProviderManagerDelegate spmd; // populate this during our initilaization process
static Vector<StatsProviderInfo> toBeRegistered = new Vector();
}

View File

@@ -0,0 +1,40 @@
/*
* 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.probe.provider;
/**
*
* @author abbagani
*/
public interface StatsProviderManagerDelegate {
public void register(StatsProviderInfo spInfo);
public void unregister(Object statsProvider);
public boolean hasListeners(String probeStr);
}

View File

@@ -0,0 +1,54 @@
/*
* Copyright (c) 2009, 2012, 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.probe.provider.annotations;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.lang.annotation.ElementType;
/**
*
* @author Prashanth Abbagani
* Date: April 16, 2009
*/
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD})
public @interface Probe {
public String name() default "";
public boolean hidden() default false;
public boolean self() default false;
public String providerName() default "";
public String moduleName() default "";
public boolean stateful() default false;
public String profileNames() default "";
public boolean statefulReturn() default false;
public boolean statefulException() default false;
}

View File

@@ -0,0 +1,47 @@
/*
* 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.probe.provider.annotations;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.lang.annotation.ElementType;
/**
*
* @author Prashanth Abbagani
* Date: May 26, 2009
*/
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD})
public @interface ProbeListener {
public abstract String value();
}

View File

@@ -0,0 +1,47 @@
/*
* 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.probe.provider.annotations;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.lang.annotation.ElementType;
/**
*
* @author Prashanth Abbagani
* Date: April 16, 2009
*/
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.PARAMETER})
public @interface ProbeParam {
public String value();
}

View File

@@ -0,0 +1,50 @@
/*
* 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.probe.provider.annotations;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.lang.annotation.ElementType;
/**
*
* @author Prashanth Abbagani
* Date: April 16, 2009
*/
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE})
public @interface ProbeProvider {
public String providerName() default "";
public String moduleProviderName() default "";
public String moduleName() default "";
public String probeProviderName() default "";
}

View File

@@ -0,0 +1,46 @@
/*
* Copyright (c) 2004, 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.
*/
/*
* AverageRangeStatistic.java
*
* Created on May 11, 2004, 2:15 PM
*/
package com.sun.org.glassfish.external.statistics;
/**
* An interface that Specifies standard measurements of the lowest and highest
* values an attribute has held as well as its current value.
* Extending RangeStatistic, it also provides the average value.
*/
public interface AverageRangeStatistic extends RangeStatistic {
public long getAverage();
}

View File

@@ -0,0 +1,43 @@
/*
* 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.statistics;
/**
* Specifies standard measurements of the upper and lower limits of the value of an attribute.
*/
public interface BoundaryStatistic extends Statistic {
/**
* The upper limit of the value of this attribute.
*/
long getUpperBound();
/**
* The lower limit of the value of this attribute.The upper limit of the value of this attribute.
*/
long getLowerBound();
}

View File

@@ -0,0 +1,33 @@
/*
* 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.statistics;
/**
* The BoundedRangeStatistic model aggregates the attributes of RangeStatistic and BoundaryStatistic and provides standard measurements of a range that has fixed limits.
*/
public interface BoundedRangeStatistic extends BoundaryStatistic, RangeStatistic {
}

View File

@@ -0,0 +1,38 @@
/*
* 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.statistics;
/**
* Specifies standard count measurements.
*/
public interface CountStatistic extends Statistic {
/**
* The count since the last reset.
*/
long getCount();
}

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.statistics;
/**
* Specifies standard measurements of the lowest and highest values an attribute has held as well as its current value.
*/
public interface RangeStatistic extends Statistic {
/**
* The highest value this attribute has held since the beginninYg of the measurement.
*/
long getHighWaterMark();
/**
* The lowest value this attribute has held since the beginning of the measurement.
*/
long getLowWaterMark();
/**
* The current value of this attribute.
*/
long getCurrent();
}

View File

@@ -0,0 +1,59 @@
/*
* 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.statistics;
/**
* The Statistic model and its sub-models specify the data models which are requried to be used to provide the performance data described by the specific attributes in the Stats models.
*/
public interface Statistic {
/**
* The name of this Statistic.
*/
String getName();
/**
* The unit of measurement for this Statistic.
* Valid values for TimeStatistic measurements are "HOUR", "MINUTE", "SECOND", "MILLISECOND", "MICROSECOND" and "NANOSECOND".
*/
String getUnit();
/**
* A human-readable description of the Statistic.
*/
String getDescription();
/**
* The time of the first measurement represented as a long, whose value is the number of milliseconds since January 1, 1970, 00:00:00.
*/
long getStartTime();
/**
* The time of the last measurement represented as a long, whose value is the number of milliseconds since January 1, 1970, 00:00:00.
*/
long getLastSampleTime();
}

View File

@@ -0,0 +1,46 @@
/*
* 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.statistics;
public interface Stats {
/**
* Get a Statistic by name.
*/
Statistic getStatistic(String statisticName);
/**
* Returns an array of Strings which are the names of the attributes from the specific Stats submodel that this object supports. Attributes named in the list must correspond to attributes that will return a Statistic object of the appropriate type which contains valid performance data. The return value of attributes in the Stats submodel that are not included in the statisticNames list must be null. For each name in the statisticNames list there must be one Statistic with the same name in the statistics list.
*/
String [] getStatisticNames();
/**
* Returns an array containing all of the Statistic objects supported by this Stats object.
*/
Statistic[] getStatistics();
}

View File

@@ -0,0 +1,47 @@
/*
* 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.statistics;
/**
* Custom statistic type created for the Sun ONE Application Server.
* The goal is to be able to represent changing attribute values that are strings
* in the form of Statistics. Semantically, it is analogous to a {@link CountStatistic},
* the only difference being in the value that is returned. Unlike a CountStatistic
* (which always is unidirectional), this Statistic type is not having any
* specified direction, simply because there is no natural order. An example
* of the values that an instance of this statistic type can assume is: A State
* Statistic which can have "CONNECTED, CLOSED, DISCONNECTED" as the permissible
* values and the current value can be any one of them (and them only).
* The permissible values are upto a particular implementation.
*/
public interface StringStatistic extends Statistic {
/**
* Returns the String value of the statistic
*/
String getCurrent();
}

View File

@@ -0,0 +1,53 @@
/*
* 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.statistics;
/**
* Specifies standard timing measurements.
*/
public interface TimeStatistic extends Statistic {
/**
* Number of times the operation was invoked since the beginning of this measurement.
*/
long getCount();
/**
* The maximum amount of time taken to complete one invocation of this operation since the beginning of this measurement.
*/
long getMaxTime();
/**
* The minimum amount of time taken to complete one invocation of this operation since the beginning of this measurement.
*/
long getMinTime();
/**
* This is the sum total of time taken to complete every invocation of this operation since the beginning of this measurement. Dividing totalTime by count will give you the average execution time for this operation.
*/
long getTotalTime();
}

View File

@@ -0,0 +1,44 @@
/*
* 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.statistics.annotations;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.lang.annotation.ElementType;
/**
*
* @author Jennifer Chou
* Date: Sep 16, 2009
*/
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD})
public @interface Reset {
}

View File

@@ -0,0 +1,155 @@
/*
* Copyright (c) 2009, 2013, 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.statistics.impl;
import java.util.Map;
import java.lang.reflect.*;
import com.sun.org.glassfish.external.statistics.AverageRangeStatistic;
/**
* An implementation of AverageRangeStatistic that provides ways to change the
* state externally through mutators. Convenience class that is useful for
* components that gather the statistical data.
* By merely changing the count (which is a mandatory measurement), rest of the statistical
* information could be deduced.
*/
public final class AverageRangeStatisticImpl extends StatisticImpl implements
AverageRangeStatistic, InvocationHandler {
private long currentVal = 0L;
private long highWaterMark = Long.MIN_VALUE;
private long lowWaterMark = Long.MAX_VALUE;
private long numberOfSamples = 0L;
private long runningTotal = 0L;
private final long initCurrentVal;
private final long initHighWaterMark;
private final long initLowWaterMark;
private final long initNumberOfSamples;
private final long initRunningTotal;
private final AverageRangeStatistic as =
(AverageRangeStatistic) Proxy.newProxyInstance(
AverageRangeStatistic.class.getClassLoader(),
new Class[] { AverageRangeStatistic.class },
this);
public AverageRangeStatisticImpl(long curVal, long highMark, long lowMark,
String name, String unit, String desc,
long startTime, long sampleTime) {
super(name, unit, desc, startTime, sampleTime);
currentVal = curVal;
initCurrentVal = curVal;
highWaterMark = highMark;
initHighWaterMark = highMark;
lowWaterMark = lowMark;
initLowWaterMark = lowMark;
numberOfSamples = 0L;
initNumberOfSamples = numberOfSamples;
runningTotal = 0L;
initRunningTotal = runningTotal;
}
public synchronized AverageRangeStatistic getStatistic() {
return as;
}
public synchronized String toString() {
return super.toString() + NEWLINE +
"Current: " + getCurrent() + NEWLINE +
"LowWaterMark: " + getLowWaterMark() + NEWLINE +
"HighWaterMark: " + getHighWaterMark() + NEWLINE +
"Average:" + getAverage();
}
public synchronized Map getStaticAsMap() {
Map m = super.getStaticAsMap();
m.put("current", getCurrent());
m.put("lowwatermark", getLowWaterMark());
m.put("highwatermark", getHighWaterMark());
m.put("average", getAverage());
return m;
}
public synchronized void reset() {
super.reset();
currentVal = initCurrentVal;
highWaterMark = initHighWaterMark;
lowWaterMark = initLowWaterMark;
numberOfSamples = initNumberOfSamples;
runningTotal = initRunningTotal;
sampleTime = -1L;
}
public synchronized long getAverage() {
if(numberOfSamples == 0) {
return -1;
} else {
return runningTotal / numberOfSamples;
}
}
public synchronized long getCurrent() {
return currentVal;
}
public synchronized void setCurrent(long curVal) {
currentVal = curVal;
lowWaterMark = (curVal >= lowWaterMark ? lowWaterMark : curVal);
highWaterMark = (curVal >= highWaterMark ? curVal : highWaterMark);
numberOfSamples++;
runningTotal += curVal;
sampleTime = System.currentTimeMillis();
}
public synchronized long getHighWaterMark() {
return highWaterMark;
}
public synchronized long getLowWaterMark() {
return lowWaterMark;
}
// todo: equals implementation
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
checkMethod(method);
Object result;
try {
result = method.invoke(this, args);
} catch (InvocationTargetException e) {
throw e.getTargetException();
} catch (Exception e) {
throw new RuntimeException("unexpected invocation exception: " +
e.getMessage());
}
return result;
}
}

View File

@@ -0,0 +1,96 @@
/*
* Copyright (c) 2009, 2013, 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.statistics.impl;
import com.sun.org.glassfish.external.statistics.BoundaryStatistic;
import java.util.Map;
import java.lang.reflect.*;
/**
* @author Sreenivas Munnangi
*/
public final class BoundaryStatisticImpl extends StatisticImpl
implements BoundaryStatistic, InvocationHandler {
private final long lowerBound;
private final long upperBound;
private final BoundaryStatistic bs =
(BoundaryStatistic) Proxy.newProxyInstance(
BoundaryStatistic.class.getClassLoader(),
new Class[] { BoundaryStatistic.class },
this);
public BoundaryStatisticImpl(long lower, long upper, String name,
String unit, String desc, long startTime,
long sampleTime) {
super(name, unit, desc, startTime, sampleTime);
upperBound = upper;
lowerBound = lower;
}
public synchronized BoundaryStatistic getStatistic() {
return bs;
}
public synchronized Map getStaticAsMap() {
Map m = super.getStaticAsMap();
m.put("lowerbound", getLowerBound());
m.put("upperbound", getUpperBound());
return m;
}
public synchronized long getLowerBound() {
return lowerBound;
}
public synchronized long getUpperBound() {
return upperBound;
}
@Override
public synchronized void reset() {
super.reset();
sampleTime = -1L;
}
// todo: equals implementation
public Object invoke(Object proxy, Method m, Object[] args) throws Throwable {
checkMethod(m);
Object result;
try {
result = m.invoke(this, args);
} catch (InvocationTargetException e) {
throw e.getTargetException();
} catch (Exception e) {
throw new RuntimeException("unexpected invocation exception: " +
e.getMessage());
}
return result;
}
}

View File

@@ -0,0 +1,161 @@
/*
* Copyright (c) 2009, 2013, 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.statistics.impl;
import com.sun.org.glassfish.external.statistics.BoundedRangeStatistic;
import java.util.Map;
import java.lang.reflect.*;
/**
* @author Sreenivas Munnangi
*/
public final class BoundedRangeStatisticImpl extends StatisticImpl
implements BoundedRangeStatistic, InvocationHandler {
private long lowerBound = 0L;
private long upperBound = 0L;
private long currentVal = 0L;
private long highWaterMark = Long.MIN_VALUE;
private long lowWaterMark = Long.MAX_VALUE;
private final long initLowerBound;
private final long initUpperBound;
private final long initCurrentVal;
private final long initHighWaterMark;
private final long initLowWaterMark;
private final BoundedRangeStatistic bs =
(BoundedRangeStatistic) Proxy.newProxyInstance(
BoundedRangeStatistic.class.getClassLoader(),
new Class[] { BoundedRangeStatistic.class },
this);
public synchronized String toString() {
return super.toString() + NEWLINE +
"Current: " + getCurrent() + NEWLINE +
"LowWaterMark: " + getLowWaterMark() + NEWLINE +
"HighWaterMark: " + getHighWaterMark() + NEWLINE +
"LowerBound: " + getLowerBound() + NEWLINE +
"UpperBound: " + getUpperBound();
}
public BoundedRangeStatisticImpl(long curVal, long highMark, long lowMark,
long upper, long lower, String name,
String unit, String desc, long startTime,
long sampleTime) {
super(name, unit, desc, startTime, sampleTime);
currentVal = curVal;
initCurrentVal = curVal;
highWaterMark = highMark;
initHighWaterMark = highMark;
lowWaterMark = lowMark;
initLowWaterMark = lowMark;
upperBound = upper;
initUpperBound = upper;
lowerBound = lower;
initLowerBound = lower;
}
public synchronized BoundedRangeStatistic getStatistic() {
return bs;
}
public synchronized Map getStaticAsMap() {
Map m = super.getStaticAsMap();
m.put("current", getCurrent());
m.put("lowerbound", getLowerBound());
m.put("upperbound", getUpperBound());
m.put("lowwatermark", getLowWaterMark());
m.put("highwatermark", getHighWaterMark());
return m;
}
public synchronized long getCurrent() {
return currentVal;
}
public synchronized void setCurrent(long curVal) {
currentVal = curVal;
lowWaterMark = (curVal >= lowWaterMark ? lowWaterMark : curVal);
highWaterMark = (curVal >= highWaterMark ? curVal : highWaterMark);
sampleTime = System.currentTimeMillis();
}
public synchronized long getHighWaterMark() {
return highWaterMark;
}
public synchronized void setHighWaterMark(long hwm) {
highWaterMark = hwm;
}
public synchronized long getLowWaterMark() {
return lowWaterMark;
}
public synchronized void setLowWaterMark(long lwm) {
lowWaterMark = lwm;
}
public synchronized long getLowerBound() {
return lowerBound;
}
public synchronized long getUpperBound() {
return upperBound;
}
@Override
public synchronized void reset() {
super.reset();
lowerBound = initLowerBound;
upperBound = initUpperBound;
currentVal = initCurrentVal;
highWaterMark = initHighWaterMark;
lowWaterMark = initLowWaterMark;
sampleTime = -1L;
}
// todo: equals implementation
public Object invoke(Object proxy, Method m, Object[] args) throws Throwable {
checkMethod(m);
Object result;
try {
result = m.invoke(this, args);
} catch (InvocationTargetException e) {
throw e.getTargetException();
} catch (Exception e) {
throw new RuntimeException("unexpected invocation exception: " +
e.getMessage());
}
return result;
}
}

View File

@@ -0,0 +1,118 @@
/*
* Copyright (c) 2009, 2013, 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.statistics.impl;
import com.sun.org.glassfish.external.statistics.CountStatistic;
import java.util.Map;
import java.lang.reflect.*;
/**
* @author Sreenivas Munnangi
*/
public final class CountStatisticImpl extends StatisticImpl
implements CountStatistic, InvocationHandler {
private long count = 0L;
private final long initCount;
private final CountStatistic cs =
(CountStatistic) Proxy.newProxyInstance(
CountStatistic.class.getClassLoader(),
new Class[] { CountStatistic.class },
this);
public CountStatisticImpl(long countVal, String name, String unit,
String desc, long sampleTime, long startTime) {
super(name, unit, desc, startTime, sampleTime);
count = countVal;
initCount = countVal;
}
public CountStatisticImpl(String name, String unit, String desc) {
this(0L, name, unit, desc, -1L, System.currentTimeMillis());
}
public synchronized CountStatistic getStatistic() {
return cs;
}
public synchronized Map getStaticAsMap() {
Map m = super.getStaticAsMap();
m.put("count", getCount());
return m;
}
public synchronized String toString() {
return super.toString() + NEWLINE + "Count: " + getCount();
}
public synchronized long getCount() {
return count;
}
public synchronized void setCount(long countVal) {
count = countVal;
sampleTime = System.currentTimeMillis();
}
public synchronized void increment() {
count++;
sampleTime = System.currentTimeMillis();
}
public synchronized void increment(long delta) {
count = count + delta;
sampleTime = System.currentTimeMillis();
}
public synchronized void decrement() {
count--;
sampleTime = System.currentTimeMillis();
}
@Override
public synchronized void reset() {
super.reset();
count = initCount;
sampleTime = -1L;
}
// todo: equals implementation
public Object invoke(Object proxy, Method m, Object[] args) throws Throwable {
checkMethod(m);
Object result;
try {
result = m.invoke(this, args);
} catch (InvocationTargetException e) {
throw e.getTargetException();
} catch (Exception e) {
throw new RuntimeException("unexpected invocation exception: " +
e.getMessage());
}
return result;
}
}

View File

@@ -0,0 +1,140 @@
/*
* Copyright (c) 2009, 2013, 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.statistics.impl;
import com.sun.org.glassfish.external.statistics.RangeStatistic;
import java.util.Map;
import java.lang.reflect.*;
/**
* @author Sreenivas Munnangi
*/
public final class RangeStatisticImpl extends StatisticImpl
implements RangeStatistic, InvocationHandler {
private long currentVal = 0L;
private long highWaterMark = Long.MIN_VALUE;
private long lowWaterMark = Long.MAX_VALUE;
private final long initCurrentVal;
private final long initHighWaterMark;
private final long initLowWaterMark;
private final RangeStatistic rs =
(RangeStatistic) Proxy.newProxyInstance(
RangeStatistic.class.getClassLoader(),
new Class[] { RangeStatistic.class },
this);
public RangeStatisticImpl(long curVal, long highMark, long lowMark,
String name, String unit, String desc,
long startTime, long sampleTime) {
super(name, unit, desc, startTime, sampleTime);
currentVal = curVal;
initCurrentVal = curVal;
highWaterMark = highMark;
initHighWaterMark = highMark;
lowWaterMark = lowMark;
initLowWaterMark = lowMark;
}
public synchronized RangeStatistic getStatistic() {
return rs;
}
public synchronized Map getStaticAsMap() {
Map m = super.getStaticAsMap();
m.put("current", getCurrent());
m.put("lowwatermark", getLowWaterMark());
m.put("highwatermark", getHighWaterMark());
return m;
}
public synchronized long getCurrent() {
return currentVal;
}
public synchronized void setCurrent(long curVal) {
currentVal = curVal;
lowWaterMark = (curVal >= lowWaterMark ? lowWaterMark : curVal);
highWaterMark = (curVal >= highWaterMark ? curVal : highWaterMark);
sampleTime = System.currentTimeMillis();
}
/**
* Returns the highest value of this statistic, since measurement started.
*/
public synchronized long getHighWaterMark() {
return highWaterMark;
}
public synchronized void setHighWaterMark(long hwm) {
highWaterMark = hwm;
}
/**
* Returns the lowest value of this statistic, since measurement started.
*/
public synchronized long getLowWaterMark() {
return lowWaterMark;
}
public synchronized void setLowWaterMark(long lwm) {
lowWaterMark = lwm;
}
@Override
public synchronized void reset() {
super.reset();
currentVal = initCurrentVal;
highWaterMark = initHighWaterMark;
lowWaterMark = initLowWaterMark;
sampleTime = -1L;
}
public synchronized String toString() {
return super.toString() + NEWLINE +
"Current: " + getCurrent() + NEWLINE +
"LowWaterMark: " + getLowWaterMark() + NEWLINE +
"HighWaterMark: " + getHighWaterMark();
}
// todo: equals implementation
public Object invoke(Object proxy, Method m, Object[] args) throws Throwable {
checkMethod(m);
Object result;
try {
result = m.invoke(this, args);
} catch (InvocationTargetException e) {
throw e.getTargetException();
} catch (Exception e) {
throw new RuntimeException("unexpected invocation exception: " +
e.getMessage());
}
return result;
}
}

View File

@@ -0,0 +1,145 @@
/*
* Copyright (c) 2009, 2013, 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.statistics.impl;
import com.sun.org.glassfish.external.statistics.Statistic;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
/**
* @author Sreenivas Munnangi
*/
public abstract class StatisticImpl implements Statistic {
private final String statisticName;
private final String statisticUnit;
private final String statisticDesc;
protected long sampleTime = -1L;
private long startTime;
public static final String UNIT_COUNT = "count";
public static final String UNIT_SECOND = "second";
public static final String UNIT_MILLISECOND = "millisecond";
public static final String UNIT_MICROSECOND = "microsecond";
public static final String UNIT_NANOSECOND = "nanosecond";
public static final String START_TIME = "starttime";
public static final String LAST_SAMPLE_TIME = "lastsampletime";
protected final Map<String, Object> statMap = new ConcurrentHashMap<String, Object> ();
protected static final String NEWLINE = System.getProperty( "line.separator" );
protected StatisticImpl(String name, String unit, String desc,
long start_time, long sample_time) {
if (isValidString(name)) {
statisticName = name;
} else {
statisticName = "name";
}
if (isValidString(unit)) {
statisticUnit = unit;
} else {
statisticUnit = "unit";
}
if (isValidString(desc)) {
statisticDesc = desc;
} else {
statisticDesc = "description";
}
startTime = start_time;
sampleTime = sample_time;
}
protected StatisticImpl(String name, String unit, String desc) {
this(name, unit, desc, System.currentTimeMillis(), System.currentTimeMillis());
}
public synchronized Map getStaticAsMap() {
if (isValidString(statisticName)) {
statMap.put("name", statisticName);
}
if (isValidString(statisticUnit)) {
statMap.put("unit", statisticUnit);
}
if (isValidString(statisticDesc)) {
statMap.put("description", statisticDesc);
}
statMap.put(StatisticImpl.START_TIME, startTime);
statMap.put(StatisticImpl.LAST_SAMPLE_TIME, sampleTime);
return statMap;
}
public String getName() {
return this.statisticName;
}
public String getDescription() {
return this.statisticDesc;
}
public String getUnit() {
return this.statisticUnit;
}
public synchronized long getLastSampleTime() {
return sampleTime;
}
public synchronized long getStartTime() {
return startTime;
}
public synchronized void reset() {
startTime = System.currentTimeMillis();
}
public synchronized String toString() {
return "Statistic " + getClass().getName() + NEWLINE +
"Name: " + getName() + NEWLINE +
"Description: " + getDescription() + NEWLINE +
"Unit: " + getUnit() + NEWLINE +
"LastSampleTime: " + getLastSampleTime() + NEWLINE +
"StartTime: " + getStartTime();
}
protected static boolean isValidString(String str) {
return (str!=null && str.length()>0);
}
protected void checkMethod(Method method) {
if (method == null || method.getDeclaringClass() == null
|| !Statistic.class.isAssignableFrom(method.getDeclaringClass())
|| Modifier.isStatic(method.getModifiers())) {
throw new RuntimeException("Invalid method on invoke");
}
}
}

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.statistics.impl;
import com.sun.org.glassfish.external.statistics.Stats;
import com.sun.org.glassfish.external.statistics.Statistic;
import java.io.Serializable;
import java.util.ArrayList;
/**
* @author Jennifer Chou
*/
public final class StatsImpl implements Stats {
private final StatisticImpl[] statArray;
protected StatsImpl(StatisticImpl[] statisticArray) {
statArray = statisticArray;
}
public synchronized Statistic getStatistic(String statisticName) {
Statistic stat = null;
for (Statistic s : statArray) {
if (s.getName().equals(statisticName)) {
stat = s;
break;
}
}
return stat;
}
public synchronized String[] getStatisticNames() {
ArrayList list = new ArrayList();
for (Statistic s : statArray) {
list.add(s.getName());
}
String[] strArray = new String[list.size()];
return (String[])list.toArray(strArray);
}
public synchronized Statistic[] getStatistics() {
return this.statArray;
}
/**
* Call reset on all of the Statistic objects contained by this Stats object
*/
public synchronized void reset() {
for (StatisticImpl s : statArray) {
s.reset();
}
};
}

View File

@@ -0,0 +1,106 @@
/*
* Copyright (c) 2009, 2013, 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.statistics.impl;
import com.sun.org.glassfish.external.statistics.StringStatistic;
import java.util.Map;
import java.lang.reflect.*;
/**
* @author Sreenivas Munnangi
*/
public final class StringStatisticImpl extends StatisticImpl
implements StringStatistic, InvocationHandler {
private volatile String str = null;
private final String initStr;
private final StringStatistic ss =
(StringStatistic) Proxy.newProxyInstance(
StringStatistic.class.getClassLoader(),
new Class[] { StringStatistic.class },
this);
public StringStatisticImpl(String str, String name, String unit,
String desc, long sampleTime, long startTime) {
super(name, unit, desc, startTime, sampleTime);
this.str = str;
initStr = str;
}
public StringStatisticImpl(String name, String unit, String desc) {
this("", name, unit, desc, System.currentTimeMillis(), System.currentTimeMillis());
}
public synchronized StringStatistic getStatistic() {
return ss;
}
public synchronized Map getStaticAsMap() {
Map m = super.getStaticAsMap();
if (getCurrent() != null) {
m.put("current", getCurrent());
}
return m;
}
public synchronized String toString() {
return super.toString() + NEWLINE + "Current-value: " + getCurrent();
}
public String getCurrent() {
return str;
}
public void setCurrent(String str) {
this.str = str;
sampleTime = System.currentTimeMillis();
}
@Override
public synchronized void reset() {
super.reset();
this.str = initStr;
sampleTime = -1L;
}
// todo: equals implementation
public Object invoke(Object proxy, Method m, Object[] args) throws Throwable {
checkMethod(m);
Object result;
try {
result = m.invoke(this, args);
} catch (InvocationTargetException e) {
throw e.getTargetException();
} catch (Exception e) {
throw new RuntimeException("unexpected invocation exception: " +
e.getMessage());
}
return result;
}
}

View File

@@ -0,0 +1,160 @@
/*
* Copyright (c) 2009, 2013, 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.statistics.impl;
import com.sun.org.glassfish.external.statistics.TimeStatistic;
import java.util.Map;
import java.lang.reflect.*;
/**
* @author Sreenivas Munnangi
*/
public final class TimeStatisticImpl extends StatisticImpl
implements TimeStatistic, InvocationHandler {
private long count = 0L;
private long maxTime = 0L;
private long minTime = 0L;
private long totTime = 0L;
private final long initCount;
private final long initMaxTime;
private final long initMinTime;
private final long initTotTime;
private final TimeStatistic ts =
(TimeStatistic) Proxy.newProxyInstance(
TimeStatistic.class.getClassLoader(),
new Class[] { TimeStatistic.class },
this);
public synchronized final String toString() {
return super.toString() + NEWLINE +
"Count: " + getCount() + NEWLINE +
"MinTime: " + getMinTime() + NEWLINE +
"MaxTime: " + getMaxTime() + NEWLINE +
"TotalTime: " + getTotalTime();
}
public TimeStatisticImpl(long counter, long maximumTime, long minimumTime,
long totalTime, String name, String unit,
String desc, long startTime, long sampleTime) {
super(name, unit, desc, startTime, sampleTime);
count = counter;
initCount = counter;
maxTime = maximumTime;
initMaxTime = maximumTime;
minTime = minimumTime;
initMinTime = minimumTime;
totTime = totalTime;
initTotTime = totalTime;
}
public synchronized TimeStatistic getStatistic() {
return ts;
}
public synchronized Map getStaticAsMap() {
Map m = super.getStaticAsMap();
m.put("count", getCount());
m.put("maxtime", getMaxTime());
m.put("mintime", getMinTime());
m.put("totaltime", getTotalTime());
return m;
}
public synchronized void incrementCount(long current) {
if (count == 0) {
totTime = current;
maxTime = current;
minTime = current;
} else {
totTime = totTime + current;
maxTime = (current >= maxTime ? current : maxTime);
minTime = (current >= minTime ? minTime : current);
}
count++;
sampleTime = System.currentTimeMillis();
}
/**
* Returns the number of times an operation was invoked
*/
public synchronized long getCount() {
return count;
}
/**
* Returns the maximum amount of time that it took for one invocation of an
* operation, since measurement started.
*/
public synchronized long getMaxTime() {
return maxTime;
}
/**
* Returns the minimum amount of time that it took for one invocation of an
* operation, since measurement started.
*/
public synchronized long getMinTime() {
return minTime;
}
/**
* Returns the amount of time that it took for all invocations,
* since measurement started.
*/
public synchronized long getTotalTime() {
return totTime;
}
@Override
public synchronized void reset() {
super.reset();
count = initCount;
maxTime = initMaxTime;
minTime = initMinTime;
totTime = initTotTime;
sampleTime = -1L;
}
// todo: equals implementation
public Object invoke(Object proxy, Method m, Object[] args) throws Throwable {
checkMethod(m);
Object result;
try {
result = m.invoke(this, args);
} catch (InvocationTargetException e) {
throw e.getTargetException();
} catch (Exception e) {
throw new RuntimeException("unexpected invocation exception: " +
e.getMessage());
}
return result;
}
}

View File

@@ -0,0 +1,274 @@
/*
* Copyright (c) 2007, 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.gmbal;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import javax.management.Attribute;
import javax.management.AttributeList;
import javax.management.AttributeNotFoundException;
import javax.management.Descriptor;
import javax.management.InstanceNotFoundException;
import javax.management.IntrospectionException;
import javax.management.InvalidAttributeValueException;
import javax.management.JMException;
import javax.management.MBeanException;
import javax.management.MBeanInfo;
import javax.management.MBeanServerConnection;
import javax.management.MalformedObjectNameException;
import javax.management.ObjectName;
import javax.management.ReflectionException;
import javax.management.RuntimeOperationsException;
import javax.management.modelmbean.ModelMBeanInfo;
/** This class implements a generic AMXMBeanInterface MBean which is connected to a possibly
* remote MBeanServerConnection (note that MBeanServer isA MBeanServerConnection,
* so we can actually create an AMXClientImpl simply by using the MBeanServer
* from the mom: this is useful for testing).
* <P>
* Note that this version of the AMXMBeanInterface API provides a generic get/set API that
* is identical to DynamicMBean, except that it only throws unchecked exceptions.
* This is far more convenient in practice than the JMX-standard checked exceptions.
*
* @author ken
*/
public class AMXClient implements AMXMBeanInterface {
private static ObjectName makeObjectName( String str ) {
try {
return new ObjectName(str);
} catch (MalformedObjectNameException ex) {
return null ;
}
}
/** Special object name used to represent a NULL objectName result.
*/
public static final ObjectName NULL_OBJECTNAME = makeObjectName(
"null:type=Null,name=Null" ) ;
private MBeanServerConnection server ;
private ObjectName oname ;
@Override
public boolean equals( Object obj ) {
if (this == obj) {
return true ;
}
if (!(obj instanceof AMXClient)) {
return false ;
}
AMXClient other = (AMXClient)obj ;
return oname.equals( other.oname ) ;
}
@Override
public int hashCode() {
int hash = 5;
hash = 47 * hash + (this.oname != null ? this.oname.hashCode() : 0);
return hash;
}
@Override
public String toString() {
return "AMXClient[" + oname + "]" ;
}
private <T> T fetchAttribute( String name, Class<T> type ) {
try {
Object obj = server.getAttribute( oname, name ) ;
if (NULL_OBJECTNAME.equals( obj )) {
return null ;
} else {
return type.cast( obj ) ;
}
} catch (JMException exc) {
throw new GmbalException( "Exception in fetchAttribute", exc ) ;
} catch (IOException exc) {
throw new GmbalException( "Exception in fetchAttribute", exc ) ;
}
}
public AMXClient( MBeanServerConnection server,
ObjectName oname ) {
this.server = server ;
this.oname = oname ;
}
private AMXClient makeAMX( ObjectName on ) {
if (on == null) {
return null ;
}
return new AMXClient( this.server, on ) ;
}
public String getName() {
return fetchAttribute( "Name", String.class ) ;
}
public Map<String,?> getMeta() {
try {
ModelMBeanInfo mbi = (ModelMBeanInfo) server.getMBeanInfo( oname );
Descriptor desc = mbi.getMBeanDescriptor() ;
Map<String,Object> result = new HashMap<String,Object>() ;
for (String str : desc.getFieldNames()) {
result.put( str, desc.getFieldValue( str )) ;
}
return result ;
} catch (MBeanException ex) {
throw new GmbalException( "Exception in getMeta", ex ) ;
} catch (RuntimeOperationsException ex) {
throw new GmbalException( "Exception in getMeta", ex ) ;
} catch (InstanceNotFoundException ex) {
throw new GmbalException( "Exception in getMeta", ex ) ;
} catch (IntrospectionException ex) {
throw new GmbalException( "Exception in getMeta", ex ) ;
} catch (ReflectionException ex) {
throw new GmbalException( "Exception in getMeta", ex ) ;
} catch (IOException ex) {
throw new GmbalException( "Exception in getMeta", ex ) ;
}
}
public AMXClient getParent() {
ObjectName res = fetchAttribute( "Parent", ObjectName.class ) ;
return makeAMX( res ) ;
}
public AMXClient[] getChildren() {
ObjectName[] onames = fetchAttribute( "Children",
ObjectName[].class ) ;
return makeAMXArray( onames ) ;
}
private AMXClient[] makeAMXArray( ObjectName[] onames ) {
AMXClient[] result = new AMXClient[onames.length] ;
int ctr=0 ;
for (ObjectName on : onames ) {
result[ctr++] = makeAMX( on ) ;
}
return result ;
}
public Object getAttribute(String attribute) {
try {
return server.getAttribute(oname, attribute);
} catch (MBeanException ex) {
throw new GmbalException( "Exception in getAttribute", ex ) ;
} catch (AttributeNotFoundException ex) {
throw new GmbalException( "Exception in getAttribute", ex ) ;
} catch (ReflectionException ex) {
throw new GmbalException( "Exception in getAttribute", ex ) ;
} catch (InstanceNotFoundException ex) {
throw new GmbalException( "Exception in getAttribute", ex ) ;
} catch (IOException ex) {
throw new GmbalException( "Exception in getAttribute", ex ) ;
}
}
public void setAttribute(String name, Object value ) {
Attribute attr = new Attribute( name, value ) ;
setAttribute( attr ) ;
}
public void setAttribute(Attribute attribute) {
try {
server.setAttribute(oname, attribute);
} catch (InstanceNotFoundException ex) {
throw new GmbalException( "Exception in setAttribute", ex ) ;
} catch (AttributeNotFoundException ex) {
throw new GmbalException( "Exception in setAttribute", ex ) ;
} catch (InvalidAttributeValueException ex) {
throw new GmbalException( "Exception in setAttribute", ex ) ;
} catch (MBeanException ex) {
throw new GmbalException( "Exception in setAttribute", ex ) ;
} catch (ReflectionException ex) {
throw new GmbalException( "Exception in setAttribute", ex ) ;
} catch (IOException ex) {
throw new GmbalException( "Exception in setAttribute", ex ) ;
}
}
public AttributeList getAttributes(String[] attributes) {
try {
return server.getAttributes(oname, attributes);
} catch (InstanceNotFoundException ex) {
throw new GmbalException( "Exception in getAttributes", ex ) ;
} catch (ReflectionException ex) {
throw new GmbalException( "Exception in getAttributes", ex ) ;
} catch (IOException ex) {
throw new GmbalException( "Exception in getAttributes", ex ) ;
}
}
public AttributeList setAttributes(AttributeList attributes) {
try {
return server.setAttributes(oname, attributes);
} catch (InstanceNotFoundException ex) {
throw new GmbalException( "Exception in setAttributes", ex ) ;
} catch (ReflectionException ex) {
throw new GmbalException( "Exception in setAttributes", ex ) ;
} catch (IOException ex) {
throw new GmbalException( "Exception in setAttributes", ex ) ;
}
}
public Object invoke(String actionName, Object[] params, String[] signature)
throws MBeanException, ReflectionException {
try {
return server.invoke(oname, actionName, params, signature);
} catch (InstanceNotFoundException ex) {
throw new GmbalException( "Exception in invoke", ex ) ;
} catch (IOException ex) {
throw new GmbalException( "Exception in invoke", ex ) ;
}
}
public MBeanInfo getMBeanInfo() {
try {
return server.getMBeanInfo(oname);
} catch (InstanceNotFoundException ex) {
throw new GmbalException( "Exception in invoke", ex ) ;
} catch (IntrospectionException ex) {
throw new GmbalException( "Exception in invoke", ex ) ;
} catch (ReflectionException ex) {
throw new GmbalException( "Exception in invoke", ex ) ;
} catch (IOException ex) {
throw new GmbalException( "Exception in invoke", ex ) ;
}
}
public ObjectName objectName() {
return oname ;
}
}

View File

@@ -0,0 +1,75 @@
/*
* Copyright (c) 2007, 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.gmbal;
import java.util.Map;
import com.sun.org.glassfish.external.amx.AMX;
/** Base interface supported by all AMXMBeanInterface MBeans. All MBeans generated by
* gmbal comply with this interface, which means that the attributes and
* operations defined in this Java interface all appear in each
* MBean generated by calling ManagedObjectManager.register.
*
* @author LLoyd Chambers
* @author Ken Cavanaugh
*
*/
@ManagedObject
@Description( "Base interface for any MBean that works in the AMX framework" )
public interface AMXMBeanInterface {
/** Get all metadata about this MBean.
* @return The descriptor, which will be a ModelMBeanInfoSupport instance.
*/
public Map<String,?> getMeta();
/** Usually the same as the ObjectName 'name' property, but can differ
if the actual name contains characters that must be escaped for an ObjectName and/or
if the MBean has a mutable name attribute.
The type property can be obtained from the ObjectName */
@ManagedAttribute( id=AMX.ATTR_NAME )
@Description( "Return the name of this MBean.")
public String getName();
/** "go up one level": the MBean containing this one, can be null for root
* @return The container of this MBean (null if already at root).
*/
@ManagedAttribute( id=AMX.ATTR_PARENT )
@Description( "The container that contains this MBean" )
public AMXMBeanInterface getParent();
/** Containment hierarchy:
Get all AMXMBeanInterface contained by this one, in no particular order.
Valid only if isContainer().
* Note that using an array sidesteps Map/Set/OpenType issues
* @return All children of this AMXMBeanInterface MBean.
*/
@ManagedAttribute( id=AMX.ATTR_CHILDREN )
@Description( "All children of this AMX MBean")
public AMXMBeanInterface[] getChildren();
}

View File

@@ -0,0 +1,121 @@
/*
* Copyright (c) 2007, 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.gmbal;
import java.lang.annotation.Documented ;
import java.lang.annotation.Inherited ;
import java.lang.annotation.Target ;
import java.lang.annotation.ElementType ;
import java.lang.annotation.Retention ;
import java.lang.annotation.RetentionPolicy ;
import com.sun.org.glassfish.external.amx.AMX ;
/** Annotation to contol exactly how the type value in the ObjectName
* is extracted from a class when registering an instance of that class.
* The absence of this annotation is the same as the default values.
* Note that this is simply an application of the general @DescriptorKey
* mechanism, but these particular metadata attributes control some of the
* behavior of the AMXMBeanInterface API.
* <p>Note that supportsAdoption is not included here, because that attribute
* is always false for gmbal.
*
* @author ken
*/
@Documented
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Inherited
public @interface AMXMetadata {
/** True if only one MBean of this type may be created inside the same
* parent container
*
* @return whether or not this MBean must be the only one of its type.
*/
@DescriptorKey( AMX.DESC_IS_SINGLETON )
boolean isSingleton() default false ;
/** String denoting classification of MBean. Predefined values are
* configuration, monitoring, jsr77, utility, and other.
* @return The group type.
*/
@DescriptorKey( AMX.DESC_GROUP )
String group() default "other" ;
/** Return the list of types that are legal as types of children of this
* type. If unknown, must be an empty array.
* @return Array of child types
*/
@DescriptorKey( AMX.DESC_SUB_TYPES )
String[] subTypes() default {} ;
/** Return the generic AMXMBeanInterface interface to be used.
* @return name of interface to use.
*/
@DescriptorKey( AMX.DESC_GENERIC_INTERFACE_NAME )
String genericInterfaceName() default "com.sun.org.glassfish.admin.amx.core.AMXProxy" ;
/** True if the MBeanInfo is invariant, that is, has the same
* value for the lifetime of the MBean. This may be used as a hint
* to clients that the MBeanInfo can be cached.
*
* @return True if the MBeanInfo is invariant
*/
@DescriptorKey( AMX.DESC_STD_IMMUTABLE_INFO )
boolean immutableInfo() default true ;
/** Defines the name of the interface to use when generating a proxy
* for this class. Defaults to a generic interface.
* @return The interface class name for a proxy.
*/
@DescriptorKey( AMX.DESC_STD_INTERFACE_NAME )
String interfaceClassName() default "" ;
/** An explicit type to use for the MBean.
* <p>
* Note that this is NOT part of the AMXMBeanInterface-defined metadata, but gmbal
* needs it here to have a place to override the type.
* <p>
* Gmbal determines the type name as follows:
* <ol>
* <li>If the class has a final static field of type String with the
* name "AMX_TYPE", the value of the field is the type name.
* <li>Otherwise, if the class has an @AMXMetadata annotations, and the
* value of the type is not "", the value of the type is the type name.
* <li>Otherwise, if the package prefix of the class name matches one of
* the type prefixes added by an stripPrefix call to the ManagedObjectManager,
* the type name is the full class name with the matching prefix removed.
* <li>Otherwise, if the stripPackagePrefix method was called on the
* ManagedObjectManager, the type name is the class name without any
* package prefixes.
* <li>Otherwise, the type name is the class name.
* </ol>
* @return The type for this MBean.
*/
@DescriptorKey( "type" )
String type() default "" ;
}

View File

@@ -0,0 +1,62 @@
/*
* Copyright (c) 2007, 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.gmbal;
import java.lang.annotation.Documented ;
import java.lang.annotation.Target ;
import java.lang.annotation.ElementType ;
import java.lang.annotation.Retention ;
import java.lang.annotation.RetentionPolicy ;
/** This annotation is applied to a method that takes no arguments and returns a value
* that is converted into a String for use in the ObjectName when an instance of the enclosing
* class is used to construct an open MBean.
*/
@Documented
@Target({ElementType.METHOD, ElementType.FIELD, ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
public @interface Description {
/** The description to be applied to the annotated element.
* This value must not be empty. It can either be the actual string that is inserted
* into the MBean info class, or a key into a resource bundle associated with the
* ManagedObjectManager. If there is no bundle value associated with the key, or no
* resource bundle is specified, the value is used directly in the MBean info class.
*/
String value() ;
/** Optional key to use in a resource bundle for this description. If present,
* a gmbal tool will generate a resource bundle that contains key=value taken
* from the description annotation.
* <p>
* If this key is not present, the default key is given by the class name,
* if this annotation appears on a class, or the class name.method name if
* this annotation appears on a method. It is an error to use the default
* value for more than one method of the same name, except for setters and getters.
*
*/
String key() default "" ;
}

View File

@@ -0,0 +1,141 @@
/*
* Copyright (c) 2007, 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.gmbal;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/** This is taken directly from JDK 7 in order to support this feature in
* JDK 5.
*
* <p>Annotation that adds fields to a Descriptor. This can be the
* Descriptor for an MBean, or for an attribute, operation, or constructor
* in an MBean, or for a parameter of an operation or constructor.</p>
*
* <p>Consider this Standard MBean interface, for example:</p>
*
* <pre>
* public interface CacheControlMBean {
* <b>&#64;DescriptorFields("units=bytes")</b>
* public long getCacheSize();
* }
* </pre>
*
* <p>When a Standard MBean is made using this interface, the usual rules
* mean that it will have an attribute called {@code CacheSize} of type
* {@code long}. The {@code DescriptorFields} annotation will ensure
* that the MBeanAttributeInfo for this attribute will have a
* {@code Descriptor} that has a field called {@code units} with
* corresponding value {@code bytes}.</p>
*
* <p>Similarly, if the interface looks like this:</p>
*
* <pre>
* public interface CacheControlMBean {
* <b>&#64;DescriptorFields({"units=bytes", "since=1.5"})</b>
* public long getCacheSize();
* }
* </pre>
*
* <p>then the resulting {@code Descriptor} will contain the following
* fields:</p>
*
* <table border="2">
* <tr><th>Name</th><th>Value</th></tr>
* <tr><td>units</td><td>"bytes"</td></tr>
* <tr><td>since</td><td>"1.5"</td></tr>
* </table>
*
* <p>The {@code @DescriptorFields} annotation can be applied to:</p>
*
* <ul>
* <li>a Standard MBean or MXBean interface;
* <li>a method in such an interface;
* <li>a parameter of a method in a Standard MBean or MXBean interface
* when that method is an operation (not a getter or setter for an attribute);
* <li>a public constructor in the class that implements a Standard MBean
* or MXBean;
* <li>a parameter in such a constructor.
* </ul>
*
* <p>Other uses of the annotation will either fail to compile or be
* ignored.</p>
*
* <p>Interface annotations are checked only on the exact interface
* that defines the management interface of a Standard MBean or an
* MXBean, not on its parent interfaces. Method annotations are
* checked only in the most specific interface in which the method
* appears; in other words, if a child interface overrides a method
* from a parent interface, only {@code @DescriptorFields} annotations in
* the method in the child interface are considered.
*
* <p>The Descriptor fields contributed in this way must be consistent
* with each other and with any fields contributed by
* DescriptorKey annotations. That is, two
* different annotations, or two members of the same annotation, must
* not define a different value for the same Descriptor field. Fields
* from annotations on a getter method must also be consistent with
* fields from annotations on the corresponding setter method.</p>
*
* <p>The Descriptor resulting from these annotations will be merged
* with any Descriptor fields provided by the implementation, such as
* the <a href="Descriptor.html#immutableInfo">{@code
* immutableInfo}</a> field for an MBean. The fields from the annotations
* must be consistent with these fields provided by the implementation.</p>
*
* <h4>{@literal @DescriptorFields and @DescriptorKey}</h4>
*
* <p>The DescriptorKey annotation provides
* another way to use annotations to define Descriptor fields.
* <code>&#64;DescriptorKey</code> requires more work but is also more
* robust, because there is less risk of mistakes such as misspelling
* the name of the field or giving an invalid value.
* <code>&#64;DescriptorFields</code> is more convenient but includes
* those risks. <code>&#64;DescriptorFields</code> is more
* appropriate for occasional use, but for a Descriptor field that you
* add in many places, you should consider a purpose-built annotation
* using <code>&#64;DescriptorKey</code>.
*
* @since 1.7
*/
@Documented
@Inherited // for @MBean and @MXBean classes
@Target({ElementType.CONSTRUCTOR, ElementType.METHOD, ElementType.FIELD,
ElementType.PARAMETER, ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
public @interface DescriptorFields {
/**
* <p>The descriptor fields. Each element of the string looks like
* {@code "name=value"}.</p>
*/
public String[] value();
}

View File

@@ -0,0 +1,214 @@
/*
* Copyright (c) 2005, 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.gmbal;
import java.lang.annotation.*;
/** This is taken directly from JDK 7 in order to support this feature in
* JDK 5.
*
* <p>Meta-annotation that describes how an annotation element relates
* to a field in a Descriptor. This can be the Descriptor for
* an MBean, or for an attribute, operation, or constructor in an
* MBean, or for a parameter of an operation or constructor.</p>
*
* <p>(The DescriptorFields annotation
* provides another way to add fields to a {@code Descriptor}. See
* the documentation for that annotation for a comparison of the
* two possibilities.)</p>
*
* <p>Consider this annotation for example:</p>
*
* <pre>
* &#64;Documented
* &#64;Target(ElementType.METHOD)
* &#64;Retention(RetentionPolicy.RUNTIME)
* public &#64;interface Units {
* <b>&#64;DescriptorKey("units")</b>
* String value();
* }
* </pre>
*
* <p>and this use of the annotation:</p>
*
* <pre>
* public interface CacheControlMBean {
* <b>&#64;Units("bytes")</b>
* public long getCacheSize();
* }
* </pre>
*
* <p>When a Standard MBean is made from the {@code CacheControlMBean},
* the usual rules mean that it will have an attribute called
* {@code CacheSize} of type {@code long}. The {@code @Units}
* annotation, given the above definition, will ensure that the
* MBeanAttributeInfo for this attribute will have a
* {@code Descriptor} that has a field called {@code units} with
* corresponding value {@code bytes}.</p>
*
* <p>Similarly, if the annotation looks like this:</p>
*
* <pre>
* &#64;Documented
* &#64;Target(ElementType.METHOD)
* &#64;Retention(RetentionPolicy.RUNTIME)
* public &#64;interface Units {
* <b>&#64;DescriptorKey("units")</b>
* String value();
*
* <b>&#64;DescriptorKey("descriptionResourceKey")</b>
* String resourceKey() default "";
*
* <b>&#64;DescriptorKey("descriptionResourceBundleBaseName")</b>
* String resourceBundleBaseName() default "";
* }
* </pre>
*
* <p>and it is used like this:</p>
*
* <pre>
* public interface CacheControlMBean {
* <b>&#64;Units("bytes",
* resourceKey="bytes.key",
* resourceBundleBaseName="com.example.foo.MBeanResources")</b>
* public long getCacheSize();
* }
* </pre>
*
* <p>then the resulting {@code Descriptor} will contain the following
* fields:</p>
*
* <table border="2">
* <tr><th>Name</th><th>Value</th></tr>
* <tr><td>units</td><td>"bytes"</td></tr>
* <tr><td>descriptionResourceKey</td><td>"bytes.key"</td></tr>
* <tr><td>descriptionResourceBundleBaseName</td>
* <td>"com.example.foo.MBeanResources"</td></tr>
* </table>
*
* <p>An annotation such as {@code @Units} can be applied to:</p>
*
* <ul>
* <li>a Standard MBean or MXBean interface;
* <li>a method in such an interface;
* <li>a parameter of a method in a Standard MBean or MXBean interface
* when that method is an operation (not a getter or setter for an attribute);
* <li>a public constructor in the class that implements a Standard MBean
* or MXBean;
* <li>a parameter in such a constructor.
* </ul>
*
* <p>Other uses of the annotation are ignored.</p>
*
* <p>Interface annotations are checked only on the exact interface
* that defines the management interface of a Standard MBean or an
* MXBean, not on its parent interfaces. Method annotations are
* checked only in the most specific interface in which the method
* appears; in other words, if a child interface overrides a method
* from a parent interface, only {@code @DescriptorKey} annotations in
* the method in the child interface are considered.
*
* <p>The Descriptor fields contributed in this way by different
* annotations on the same program element must be consistent with
* each other and with any fields contributed by a
* DescriptorFields annotation. That is, two
* different annotations, or two members of the same annotation, must
* not define a different value for the same Descriptor field. Fields
* from annotations on a getter method must also be consistent with
* fields from annotations on the corresponding setter method.</p>
*
* <p>The Descriptor resulting from these annotations will be merged
* with any Descriptor fields provided by the implementation, such as
* the <a href="Descriptor.html#immutableInfo">{@code
* immutableInfo}</a> field for an MBean. The fields from the annotations
* must be consistent with these fields provided by the implementation.</p>
*
* <p>An annotation element to be converted into a descriptor field
* can be of any type allowed by the Java language, except an annotation
* or an array of annotations. The value of the field is derived from
* the value of the annotation element as follows:</p>
*
* <table border="2">
* <tr><th>Annotation element</th><th>Descriptor field</th></tr>
* <tr><td>Primitive value ({@code 5}, {@code false}, etc)</td>
* <td>Wrapped value ({@code Integer.valueOf(5)},
* {@code Boolean.FALSE}, etc)</td></tr>
* <tr><td>Class constant (e.g. {@code Thread.class})</td>
* <td>Class name from Class.getName()
* (e.g. {@code "java.lang.Thread"})</td></tr>
* <tr><td>Enum constant (e.g. ElementType.FIELD)</td>
* <td>Constant name from Enum.name()
* (e.g. {@code "FIELD"})</td></tr>
* <tr><td>Array of class constants or enum constants</td>
* <td>String array derived by applying these rules to each
* element</td></tr>
* <tr><td>Value of any other type<br>
* ({@code String}, {@code String[]}, {@code int[]}, etc)</td>
* <td>The same value</td></tr>
* </table>
*
* @since 1.6
*/
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.METHOD, ElementType.FIELD })
public @interface DescriptorKey {
String value();
/**
* <p>Do not include this field in the Descriptor if the annotation
* element has its default value. For example, suppose {@code @Units} is
* defined like this:</p>
*
* <pre>
* &#64;Documented
* &#64;Target(ElementType.METHOD)
* &#64;Retention(RetentionPolicy.RUNTIME)
* public &#64;interface Units {
* &#64;DescriptorKey("units")
* String value();
*
* <b>&#64;DescriptorKey(value = "descriptionResourceKey",
* omitIfDefault = true)</b>
* String resourceKey() default "";
*
* <b>&#64;DescriptorKey(value = "descriptionResourceBundleBaseName",
* omitIfDefault = true)</b>
* String resourceBundleBaseName() default "";
* }
* </pre>
*
* <p>Then consider a usage such as {@code @Units("bytes")} or
* {@code @Units(value = "bytes", resourceKey = "")}, where the
* {@code resourceKey} and {@code resourceBundleBaseNames} elements
* have their default values. In this case the Descriptor resulting
* from these annotations will not include a {@code descriptionResourceKey}
* or {@code descriptionResourceBundleBaseName} field.</p>
*/
boolean omitIfDefault() default false;
}

View File

@@ -0,0 +1,47 @@
/*
* Copyright (c) 2008, 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.
*/
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.sun.org.glassfish.gmbal;
/** Unchecked exception type used for all gmbal exceptions.
*
* @author ken
*/
public class GmbalException extends RuntimeException {
private static final long serialVersionUID = -7478444176079980162L;
public GmbalException( String msg ) {
super( msg ) ;
}
public GmbalException( String msg, Throwable thr ) {
super( msg, thr ) ;
}
}

View File

@@ -0,0 +1,39 @@
/*
* Copyright (c) 1997, 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.gmbal;
import javax.management.DynamicMBean;
import javax.management.NotificationEmitter;
/** Type returned from ManagedObjectManager createRoot and register methods.
* Used because all Gmbal MBeans are dynamic MBeans that support attribute
* change notification.
*
* @author ken
*/
public interface GmbalMBean extends DynamicMBean, NotificationEmitter {
}

View File

@@ -0,0 +1,101 @@
/*
* Copyright (c) 1997, 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.gmbal;
import javax.management.Attribute;
import javax.management.AttributeList;
import javax.management.AttributeNotFoundException;
import javax.management.InvalidAttributeValueException;
import javax.management.ListenerNotFoundException;
import javax.management.MBeanException;
import javax.management.MBeanInfo;
import javax.management.MBeanNotificationInfo;
import javax.management.NotificationFilter;
import javax.management.NotificationListener;
import javax.management.ReflectionException;
/** A simple no-op implementation of GmbalMBean for use in the no-op impl of
* ManagedObjectManager.
*
* @author ken
*/
public class GmbalMBeanNOPImpl implements GmbalMBean {
public Object getAttribute(String attribute)
throws AttributeNotFoundException, MBeanException, ReflectionException {
return null ;
}
public void setAttribute(Attribute attribute)
throws AttributeNotFoundException, InvalidAttributeValueException,
MBeanException, ReflectionException {
// NO-OP
}
public AttributeList getAttributes(String[] attributes) {
return null ;
}
public AttributeList setAttributes(AttributeList attributes) {
return null ;
}
public Object invoke(String actionName, Object[] params, String[] signature)
throws MBeanException, ReflectionException {
return null ;
}
public MBeanInfo getMBeanInfo() {
return null ;
}
public void removeNotificationListener(NotificationListener listener,
NotificationFilter filter, Object handback)
throws ListenerNotFoundException {
// NO-OP
}
public void addNotificationListener(NotificationListener listener,
NotificationFilter filter, Object handback) throws IllegalArgumentException {
// NO-OP
}
public void removeNotificationListener(NotificationListener listener)
throws ListenerNotFoundException {
// NO-OP
}
public MBeanNotificationInfo[] getNotificationInfo() {
return new MBeanNotificationInfo[0] ;
}
}

View File

@@ -0,0 +1,60 @@
/*
* Copyright (c) 2008, 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.
*/
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.sun.org.glassfish.gmbal;
/**
*
* @author ken
*/
public enum Impact {
/** Indicates that an action is read-like, generally only returning
* information without modifying any state.
* Corresponds to MBeanOperationInfo.INFO.
*/
INFO,
/** Indicates that an action is write-like, and may modify the state
* of an MBean in some way.
* Corresponds to MBeanOperationInfo.ACTION.
*/
ACTION,
/** Indicates that an action is both read-like and write-like.
* Corresponds to MBeanOperationInfo.ACTION_INFO.
*/
ACTION_INFO,
/** Indicates that an action has an unknown nature.
* Corresponds to MBeanOperationInfo.UNKNOWN.
*/
UNKNOWN
}

View File

@@ -0,0 +1,51 @@
/*
* Copyright (c) 2007, 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.gmbal;
import java.lang.annotation.Documented ;
import java.lang.annotation.Target ;
import java.lang.annotation.ElementType ;
import java.lang.annotation.Retention ;
import java.lang.annotation.RetentionPolicy ;
/** This annotation is applied to a class or interface representing ManagedData
* to indicate that the
* listed subclasses should have their attributes included in the corresponding
* CompositeData of the superclass. Any given instance of this class will have
* values for those attributes that are defined in the parent class
* or the subclass for the particular type of the instance.
*/
@Documented
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface IncludeSubclass {
/** List of subclasses that should be analyzed for attributes and operations.
*
* @return List of classes.
*/
Class[] value() ;
}

View File

@@ -0,0 +1,74 @@
/*
* Copyright (c) 2007, 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.gmbal;
import java.lang.annotation.Documented ;
import java.lang.annotation.Target ;
import java.lang.annotation.ElementType ;
import java.lang.annotation.Retention ;
import java.lang.annotation.RetentionPolicy ;
/** This annotation defines an attribute in open MBean (ManagedObject) or
* CompositeData (ManagedData). It is useful in cases where the parent class
* cannot be annotated (for example, Object.toString(), or a framework class
* that must be extended
* but cannot be modified). The attribute id is defined in the annotation, and
* it is implemented by the methods inherited by the Managed entity.
* <p>
* An example of a use of this is to handle @ManagedData that inherits from
* Collection<X>, and it is desired to display a read-only attribute containing
* the elements of the Collection. Simple add the annotation
* <p>
* @InheritedAttribute( methodName="iterator" )
* <p>
* to handle this case. Note that this only supports read-only attributes.
*/
@Documented
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface InheritedAttribute {
/** The description of the attribute. Can be a key to a resource
* bundle for I18N support. Note that this needs a description, otherwise
* the InheritedAttributes annotation won't work. The Description
* annotation is used in all other cases. The description cannot be
* empty.
* @return The description.
*/
String description() ;
/** The name of the attribute, This class must inherit a method whose name
* corresponds to this id in one of the standard ways.
* @return The ID.
*/
String id() default "" ;
/** The name of the method implementing this attribute. At least one of
* id and methodName must not be empty. If only one is given, the other
* is derived according to the extended attribute name rules.
*/
String methodName() default "" ;
}

View File

@@ -0,0 +1,44 @@
/*
* Copyright (c) 2007, 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.gmbal;
import java.lang.annotation.Documented ;
import java.lang.annotation.Target ;
import java.lang.annotation.ElementType ;
import java.lang.annotation.Retention ;
import java.lang.annotation.RetentionPolicy ;
/** This annotation defines one or more attributes inherited from a superclass.
* It is simply a way to include multiple InheritedAttribute annotations on a
* single class.
*/
@Documented
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface InheritedAttributes {
InheritedAttribute[] value() ;
}

View File

@@ -0,0 +1,80 @@
/*
* Copyright (c) 2007, 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.gmbal;
import java.lang.annotation.Documented ;
import java.lang.annotation.Target ;
import java.lang.annotation.ElementType ;
import java.lang.annotation.Retention ;
import java.lang.annotation.RetentionPolicy ;
/** This annotation defines an attribute in either CompositeData (ManagedData) or
* an open MBean (ManagedObject). An attribute may be read/write (has a setter
* and a getter), read only (only has a getter),
* or write only (only has a setter) depending on the declared methods in the class.
* <p>
* A method defines a getter if it returns a non-void type and takes no argument types.
* Likewise a method defines a setter if it return void and takes exactly one
* argument.
* <p>An id is derived from a method name as follows:
* <ol>
* <li>If the method is a getter, and has a name of the form getXXX, the derived
* id is xXX (note the initial lower case change).
* <li>If the method is a getter with a boolean return type, and has a name of
* the form isXXX, the derived id is xXX
* <li>If the method is a setter, and has a name of the form setXXX, the
* detived id is xXX.
* <li>Otherwise the derived ID is the method name.
* </ol>
* <p>
* In certain cases, a field annotated with @ManagedAttribute
* may also represent a read-only attribute.
* The field must be final, and its type must be one of:
* <ol>
* <li>A primitive type (boolean, byte, short, char, int, long, float, double)
* <li>A primitive type wrapper (Boolean, Byte, Short, Character, Integer,
* Long, Float, Double)
* <li>A String
* <li>A BigDecimal or BigInteger
* <li>A java.util.Date
* <li>An ObjectName
* <li>An enum (which is translated to its ordinal name)
* </ol>
* Any such field can be accessed safely by multiple threads, because its value
* cannot change after an instance of the containing class has completed its
* constructor. Note that Date is not truly immutable (it should be!), but it's
* one of the Open MBean simple types, so it is included here.
*/
@Documented
@Target({ElementType.METHOD,ElementType.FIELD})
@Retention(RetentionPolicy.RUNTIME)
public @interface ManagedAttribute {
/** The id of the attribute. Defaults to value derived from method name.
* @return The id (default "").
*/
String id() default "" ;
}

View File

@@ -0,0 +1,65 @@
/*
* Copyright (c) 2007, 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.gmbal;
import java.lang.annotation.Documented ;
import java.lang.annotation.Target ;
import java.lang.annotation.ElementType ;
import java.lang.annotation.Retention ;
import java.lang.annotation.RetentionPolicy ;
/** This annotation defines CompositeData. An interface or class annotated as @ManagedData
* has a corresponding CompositeData instance constructed according to the @ManagedAttribute
* annotations on its methods. All inherited annotated methods are included.
* In the case of conflicts, the most derived method is used (that is the method
* declared in the method
* closest to the class annotated as @ManagedData).
*/
@Documented
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface ManagedData {
/** The name of the ManagedData.
* <P>
* Gmbal determines the ManagedData name as follows:
* <ol>
* <li>If the class has a final static field of type String with the
* name "GMBAL_TYPE", the value of the field is the ManagedData name.
* <li>Otherwise, if the class has an @ManagedData annotation, and the
* value of the name is not "", the value of the name is the ManagedData name.
* <li>Otherwise, if the package prefix of the class name matches one of
* the type prefixes added by an stripPrefix call to the ManagedObjectManager,
* the ManagedData name is the full class name with the matching prefix removed.
* <li>Otherwise, if the stripPackagePrefix method was called on the
* ManagedObjectManager, the ManagedData name is the class name without any
* package prefixes.
* <li>Otherwise, the ManagedData name is the class name.
* </ol>
*
*/
String name() default "" ;
}

View File

@@ -0,0 +1,43 @@
/*
* Copyright (c) 2007, 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.gmbal;
import java.lang.annotation.Documented ;
import java.lang.annotation.Target ;
import java.lang.annotation.ElementType ;
import java.lang.annotation.Retention ;
import java.lang.annotation.RetentionPolicy ;
/** This annotation defines a Managed Object. An interface or class annotated as ManagedObject
* has a corresponding open MBean constructed according to the ManagedAttribute and
* ManagedOperation annotations on its methods.
*/
@Documented
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface ManagedObject {
}

View File

@@ -0,0 +1,371 @@
/*
* Copyright (c) 2007, 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.gmbal;
import java.util.ResourceBundle ;
import java.io.Closeable ;
import java.lang.reflect.AnnotatedElement ;
import java.lang.annotation.Annotation ;
import javax.management.ObjectName ;
import javax.management.MBeanServer ;
/** An interface used to managed Open MBeans created from annotated
* objects. This is mostly a facade over MBeanServer.
* Note that certain methods must be called in the correct order:
* <ol>
* <li> Methods suspendJMXRegistration, resumeJMXRegistration,
* getDomain, getMBeanServer, getResourceBundle, setRuntimeDebug,
* setRegistrationDebugLevel, setTypelibDebug, and close may be
* called at any time.
* <li> All calls to addAnnotation, stripPrefix, and
* stripPackageName must occur before any call to a createRoot method.
* <li>All of the register and registerAtRoot methods and unregister, getObject,
* getObjectName, and dumpSkeleton may only be called after
* a createRoot method is called.
* <li>Only one call to a createRoot method is permitted on any
* ManagedObjectManager.
* <li>A call to close returns the MOM to the pre-createRoot state.
* </ol>
* If these constraints are violated, an IllegalStateException is thrown.
*/
public interface ManagedObjectManager extends Closeable {
/** If called, no MBeans created after this call will be registered with
* the JMX MBeanServer until resumeJMXRegistration is called. Each call
* increments a counter, so that nested and overlapping calls from multiple
* threads work correctly.
* May be called at any time.
*/
void suspendJMXRegistration() ;
/** Decrements the suspend counter, if the counter is greater than 0.
* When the counter goes to zero, it causes all MBeans created since
* a previous call to suspendJMXRegistration incremented the counter from 0 to 1
* to be registered with the JMX MBeanServer. After this call, all new
* MBean registration calls to the JMX MBeanServer happen within the
* register call.
* May be called at any time.
*/
void resumeJMXRegistration() ;
/** Return true if object is assignment compatible with a class or interface
* that has an @ManagedObject annotation, otherwise false. Only such objects
* may be registered to create MBeans.
* May be called at any time.
*/
boolean isManagedObject( Object obj ) ;
/** Create a default root MBean.
* One of the createRoot methods must be called before any of the registration
* methods may be called.
* Only one call to a createRoot method is permitted after an
* ManagedObjectManager is created.
* @exception IllegalStateException if called after a call to any
* createRoot method.
* @return A default root MBean which supports only the AMX attributes.
*/
GmbalMBean createRoot() ;
/** Create a root MBean from root, which much have a method with the
* @NameValue annotation.
* One of the createRoot methods must be called before any of the registration
* methods may be called.
* Only one call to createRoot is permitted after an ManagedObjectManager
* is created.
* @param root The Java object to be used to construct the root.
* @exception IllegalStateException if called after a call to any
* createRoot method.
* @return The newly constructed MBean.
*/
GmbalMBean createRoot( Object root ) ;
/** Create a root MBean from root with the given name.
* One of the createRoot methods must be called before any of the registration
* methods may be called.
* Only one call to createRoot is permitted after an ManagedObjectManager
* is created.
* @param root The Java object to be used to construct the root.
* @param name The ObjectName name field to be used in the ObjectName of
* the MBean constructed from root.
* @exception IllegalStateException if called after a call to any
* createRoot method.
* @return The newly constructed MBean.
*/
GmbalMBean createRoot( Object root, String name ) ;
/** Return the root of this ManagedObjectManager.
* May be called at any time.
* @return the root constructed in a createRoot operation, or null if called
* before a createRoot call.
*/
Object getRoot() ;
/** Construct an Open Mean for obj according to its annotations,
* and register it with domain getDomain() and the appropriate
* ObjectName. The MBeanServer from setMBeanServer (or its default) is used.
* Here parent is considered to contain obj, and this containment is
* represented by the construction of the ObjectName following the AMX
* specification for ObjectNames.
* <p>
* The MBeanInfo for the result is actually ModelMBeanInfo, and may contain
* extra metadata as defined using annotations defined with the
* @DescriptorKey and @DescriptorField meta-annotations.
* <p>
* Must be called after a successful createRoot call.
* <p>
* This version of register should not be used to register singletons.
* </ol>
* @param parent The parent object that contains obj.
* @param obj The managed object we are registering.
* @param name The name to use for registering this object.
* @return The MBean constructed from obj.
* @exception IllegalStateException if called before a createRoot method is
* called successfully.
*/
GmbalMBean register( Object parent, Object obj, String name ) ;
/** Same as register( parent, obj, name ), but here the name
* is derived from an @NameValue annotation.
* <p>
* This version of register should also be used to register singletons.
*
* @param parent The parent object that contains obj.
* @param obj The managed object we are registering.
* @return The MBean constructed from obj.
* @exception IllegalStateException if called before a createRoot method is
* called successfully.
*/
GmbalMBean register( Object parent, Object obj ) ;
/** Registers the MBean for obj at the root MBean for the ObjectManager,
* using the given name. Exactly the same as mom.register( mom.getRoot(),
* obj, name ).
* <p>
* Must be called after a successful createRoot call.
* <p>
* This version of register should not be used to register singletons.
* @param obj The object for which we construct and register an MBean.
* @param name The name of the MBean.
* @return The MBean constructed from obj.
* @exception IllegalStateException if called before a createRoot method is
* called successfully.
*/
GmbalMBean registerAtRoot( Object obj, String name ) ;
/** Same as registerAtRoot( Object, String ), but here the name
* is derived from an @ObjectKeyName annotation. Exactly the same as
* mom.register( mom.getRoot(), obj ).
* <p>
* This version of register should also be used to register singletons.
* @param obj The managed object we are registering.
* @return The MBean constructed from obj.
* @exception IllegalStateException if called before a createRoot method is
* called successfully.
*/
GmbalMBean registerAtRoot( Object obj ) ;
/** Unregister the Open MBean corresponding to obj from the
* mbean server.
* <p>
* Must be called after a successful createRoot call.
* @param obj The object originally passed to a register method.
*/
void unregister( Object obj ) ;
/** Get the ObjectName for the given object (which must have
* been registered via a register call).
* <p>
* Must be called after a successful createRoot call.
* @param obj The object originally passed to a register call.
* @return The ObjectName used to register the MBean.
*/
ObjectName getObjectName( Object obj ) ;
/** Get an AMXClient instance for the object obj, if obj is registered
* as an MBean in this mom.
* <p>
* Must be called after a successful createRoot call.
* @param obj The object corresponding to an MBean.
* @return An AMXClient that acts as a proxy for this MBean.
*/
AMXClient getAMXClient( Object obj ) ;
/** Get the Object that was registered with the given ObjectName.
* Note that getObject and getObjectName are inverse operations.
* <p>
* Must be called after a successful createRoot call.
* @param oname The ObjectName used to register the object.
* @return The Object passed to the register call.
*/
Object getObject( ObjectName oname ) ;
/** Add a type prefix to strip from type names, to shorten the names for
* a better presentation to the user. This may only be called before a
* createRot method is called.
*
* @param str Class package name to strip from type name.
* @exception IllegalStateException if called after createRoot method.
*/
void stripPrefix( String... str ) ;
/** Change the default type name algorithm so that if nothing else
* applies, the entire package prefix is stripped form the Class name.
* Otherwise, the full Class name is the type.
*
* @exception IllegalStateException if called after a createRoot method.
*/
void stripPackagePrefix() ;
/** Return the domain name that was used when this ManagedObjectManager
* was created. This is the JMX domain that will be used in all ObjectNames
* created by this ManagedObjectManager.
* <p>
* May be called at any time.
* @return Get the domain name for this ManagedObjectManager.
*/
String getDomain() ;
/** Set the MBeanServer to which all MBeans using this interface
* are published. The default value is
* java.lang.management.ManagementFactory.getPlatformMBeanServer().
* <p>
* Must be called before a successful createRoot call.
* @param server The MBeanServer to set as the MBeanServer for this
* ManagedObjectManager.
*/
void setMBeanServer( MBeanServer server ) ;
/** Get the current MBeanServer.
* <p>
* May be called at any time.
* @return The current MBeanServer, either the default, or the value passed
* to setMBeanServer.
*/
MBeanServer getMBeanServer() ;
/** Set the ResourceBundle to use for getting localized descriptions.
* If not set, the description is the value in the annotation.
* <p>
* Must be called before a successful call to a createRoot method.
* @param rb The resource bundle to use. May be null.
*/
void setResourceBundle( ResourceBundle rb ) ;
/** Get the resource bundle (if any) set by setResourceBundle.
* <p>
* May be called at any time.
* @return The resource bundle set by setResourceBundle: may be null.
*/
ResourceBundle getResourceBundle() ;
/** Method to add an annotation to an element that cannot be modified.
* This is typically needed when dealing with an implementation of an
* interface that is part of a standardized API, and so the interface
* cannot be annotated by modifiying the source code. In some cases the
* implementation of the interface also cannot be inherited, because the
* implementation is generated by a standardized code generator. Another
* possibility is that there are several different implementations of the
* standardized interface, and it is undesirable to annotate each
* implementation with @InheritedAttributes.
* @param element The annotated element (class or method for our purposes).
* @param annotation The annotation we wish to add to the element.
* @exception IllegalStateException if called after a call to a createRoot
* method.
*/
void addAnnotation( AnnotatedElement element, Annotation annotation ) ;
/** DebugLevel used to control how much debug info is printed for
* registration of objects.
*/
public enum RegistrationDebugLevel { NONE, NORMAL, FINE } ;
/** Print debug output to System.out.
* <p>
* May be called at any time.
*
* @param level NONE is no debugging at all, NORMAL traces high-level
* construction of skeletons and type converters, and dumps results of new
* skeletons and type converters, FINE traces everything in great detail.
* The tracing is done with INFO-level logger calls. The logger name is
* that package name (com.sun.org.glassfish.gmbal.impl).
*/
void setRegistrationDebug( RegistrationDebugLevel level ) ;
/** Enable generation of debug log at INFO level for runtime MBean operations
* to the com.sun.org.glassfish.gmbal.impl logger.
* <p>
* May be called at any time.
*
* @param flag true to enable runtime debug, false to disable.
*/
void setRuntimeDebug( boolean flag ) ;
/** Enabled generation of debug log for type evaluator debugging. This
* happens as part of the registration process for the first time a particular
* class is processed.
* <p>
* May be called at any time.
*
* @param level set to 1 to just see the results of the TypeEvaluator, >1 to
* see lots of details. WARNING: values >1 will result in a large amount
* of output.
*/
void setTypelibDebug( int level ) ;
/** Set debugging for JMX registrations. If true, all registrations and
* deregistrations with the MBeanServer are traced.
*
* @param flag True to enalbed registration tracing.
*/
void setJMXRegistrationDebug( boolean flag ) ;
/** Dump the skeleton used in the implementation of the MBean for obj.
* Obj must be currently registered.
* <p>
* Must be called after a successful call to a createRoot method.
*
* @param obj The registered object whose skeleton should be displayed.
* @return The string representation of the skeleton.
*/
String dumpSkeleton( Object obj ) ;
/** Suppress reporting of a duplicate root name. If this option is enabled,
* createRoot( Object ) and createRoot( Object, String ) will return null
* for a duplicate root name, otherwise a Gmbal error will be reported.
* Note that this applies ONLY to createRoot: the register methods are
* unaffected. Also note that any other errors that might occur on
* createRoot will be reported normally.
* <p>
* Must be called before a successful call to a createRoot method.
*/
void suppressDuplicateRootReport( boolean suppressReport ) ;
}

View File

@@ -0,0 +1,132 @@
/*
* Copyright (c) 2007, 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.gmbal;
import java.lang.reflect.Method ;
import java.security.AccessController;
import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;
import java.util.logging.Level;
import java.util.logging.Logger;
import com.sun.org.glassfish.gmbal.util.GenericConstructor ;
import javax.management.ObjectName;
/** Factory used to create ManagedObjectManager instances.
*/
public final class ManagedObjectManagerFactory {
private ManagedObjectManagerFactory() {}
private static GenericConstructor<ManagedObjectManager> objectNameCons =
new GenericConstructor<ManagedObjectManager>(
ManagedObjectManager.class,
"com.sun.org.glassfish.gmbal.impl.ManagedObjectManagerImpl",
ObjectName.class ) ;
private static GenericConstructor<ManagedObjectManager> stringCons =
new GenericConstructor<ManagedObjectManager>(
ManagedObjectManager.class,
"com.sun.org.glassfish.gmbal.impl.ManagedObjectManagerImpl",
String.class ) ;
/** Convenience method for getting access to a method through reflection.
* Same as Class.getDeclaredMethod, but only throws RuntimeExceptions.
* @param cls The class to search for a method.
* @param name The method name.
* @param types The array of argument types.
* @return The Method if found.
* @throws GmbalException if no such method is found.
*/
public static Method getMethod( final Class<?> cls, final String name,
final Class<?>... types ) {
try {
return AccessController.doPrivileged(
new PrivilegedExceptionAction<Method>() {
public Method run() throws Exception {
return cls.getDeclaredMethod(name, types);
}
});
} catch (PrivilegedActionException ex) {
throw new GmbalException( "Unexpected exception", ex ) ;
} catch (SecurityException exc) {
throw new GmbalException( "Unexpected exception", exc ) ;
}
}
/** Create a new ManagedObjectManager. All objectnames created will share
* the domain value passed on this call. This ManagedObjectManager is
* at the top of the containment hierarchy: the parent of the root is null.
* @param domain The domain to use for all ObjectNames created when
* MBeans are registered.
* @return A new ManagedObjectManager.
*/
public static ManagedObjectManager createStandalone(
final String domain ) {
ManagedObjectManager result = stringCons.create( domain ) ;
if (result == null) {
return ManagedObjectManagerNOPImpl.self ;
} else {
return result ;
}
}
/** Alternative form of the create method to be used when the
* rootName is not needed explicitly. If the root name is available
* from an @ObjectNameKey annotation, it is used; otherwise the
* type is used as the name, since the root is a singleton.
*
* @param rootParentName The JMX ObjectName of the parent of the root.
* The parent is outside of the control of this ManagedObjectManager.
* The ManagedObjectManager root is a child of the MBean identified
* by the rootParentName.
* @return The ManagedObjectManager.
*/
public static ManagedObjectManager createFederated(
final ObjectName rootParentName ) {
ManagedObjectManager result = objectNameCons.create( rootParentName ) ;
if (result == null) {
return ManagedObjectManagerNOPImpl.self ;
} else {
return result ;
}
}
/** Return a ManagedObjectManager that performs no operations. Useful to
* allow the same code to run with or without creating MBeans through
* gmbal.
* @return ManagedObjectManager that performs no operations.
*/
public static ManagedObjectManager createNOOP() {
return ManagedObjectManagerNOPImpl.self ;
}
}

View File

@@ -0,0 +1,175 @@
/*
* Copyright (c) 2008, 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.
*/
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.sun.org.glassfish.gmbal;
import java.io.IOException;
import java.lang.annotation.Annotation;
import java.lang.reflect.AnnotatedElement;
import java.util.ResourceBundle;
import javax.management.MBeanServer;
import javax.management.ObjectName;
/** NOP impl of ManagedObjectManager used when annotations and ManagedObjectManager
* are needed, but MBeans are not. This allows using gmbal to optionally support
* MBeans. This is the implementation of the ManagedObjectManager that is used when
* the full implementation is not available.
*
* @author ken_admin
*/
class ManagedObjectManagerNOPImpl implements ManagedObjectManager {
static final ManagedObjectManager self =
new ManagedObjectManagerNOPImpl() ;
private static final GmbalMBean gmb =
new GmbalMBeanNOPImpl() ;
private ManagedObjectManagerNOPImpl() {}
public void suspendJMXRegistration() {
// NOP
}
public void resumeJMXRegistration() {
// NOP
}
public boolean isManagedObject( Object obj ) {
return false ;
}
public GmbalMBean createRoot() {
return gmb ;
}
public GmbalMBean createRoot(Object root) {
return gmb ;
}
public GmbalMBean createRoot(Object root, String name) {
return gmb ;
}
public Object getRoot() {
return null ;
}
public GmbalMBean register(Object parent, Object obj, String name) {
return gmb ;
}
public GmbalMBean register(Object parent, Object obj) {
return gmb ;
}
public GmbalMBean registerAtRoot(Object obj, String name) {
return gmb ;
}
public GmbalMBean registerAtRoot(Object obj) {
return gmb ;
}
public void unregister(Object obj) {
// NOP
}
public ObjectName getObjectName(Object obj) {
return null ;
}
public Object getObject(ObjectName oname) {
return null ;
}
public void stripPrefix(String... str) {
// NOP
}
public String getDomain() {
return null ;
}
public void setMBeanServer(MBeanServer server) {
// NOP
}
public MBeanServer getMBeanServer() {
return null ;
}
public void setResourceBundle(ResourceBundle rb) {
// NOP
}
public ResourceBundle getResourceBundle() {
return null ;
}
public void addAnnotation(AnnotatedElement element, Annotation annotation) {
// NOP
}
public void setRegistrationDebug(RegistrationDebugLevel level) {
// NOP
}
public void setRuntimeDebug(boolean flag) {
// NOP
}
public String dumpSkeleton(Object obj) {
return "" ;
}
public void close() throws IOException {
// NOP
}
public void setTypelibDebug(int level) {
// NOP
}
public void stripPackagePrefix() {
// NOP
}
public void suppressDuplicateRootReport(boolean suppressReport) {
// NOP
}
public AMXClient getAMXClient(Object obj) {
return null ;
}
public void setJMXRegistrationDebug(boolean flag) {
// NOP
}
}

View File

@@ -0,0 +1,46 @@
/*
* Copyright (c) 2007, 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.gmbal;
import java.lang.annotation.Documented ;
import java.lang.annotation.Target ;
import java.lang.annotation.ElementType ;
import java.lang.annotation.Retention ;
import java.lang.annotation.RetentionPolicy ;
/** This annotation defines an attribute in open MBean (ManagedObject).
*/
@Documented
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface ManagedOperation {
/** The id of the operation. Defaults to the method name.
*/
String id() default "" ;
Impact impact() default Impact.UNKNOWN ;
}

View File

@@ -0,0 +1,43 @@
/*
* Copyright (c) 2007, 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.gmbal;
import java.lang.annotation.Documented ;
import java.lang.annotation.Target ;
import java.lang.annotation.ElementType ;
import java.lang.annotation.Retention ;
import java.lang.annotation.RetentionPolicy ;
/** This annotation is applied to a method that takes no arguments and returns a value
* that is converted into a String for use in the ObjectName when an instance of the enclosing
* class is used to construct an open MBean.
*/
@Documented
@Target( { ElementType.METHOD, ElementType.FIELD } )
@Retention(RetentionPolicy.RUNTIME)
public @interface NameValue {
}

View File

@@ -0,0 +1,48 @@
/*
* Copyright (c) 2007, 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.gmbal;
import java.lang.annotation.Documented ;
import java.lang.annotation.Target ;
import java.lang.annotation.ElementType ;
import java.lang.annotation.Retention ;
import java.lang.annotation.RetentionPolicy ;
/** This annotation is applied to a method that represents an MBean operation.
* It defines the names of the parameters of the operation. It must contain
* as many arguments as there are parameters in the annotated method.
*/
@Documented
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
/**
*
* @author ken
*/
public @interface ParameterNames {
String[] value() default {} ;
}

View File

@@ -0,0 +1,127 @@
/*
* Copyright (c) 2006, 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.gmbal.util;
import java.lang.reflect.Constructor ;
import java.security.AccessController;
import java.security.PrivilegedExceptionAction;
import java.util.logging.Level;
import java.util.logging.Logger;
/** Class that allows any class to be instantiated via any accessible constructor.
* Really a short hand to avoid writing a bunch of reflective code.
*/
public class GenericConstructor<T> {
private final Object lock = new Object() ;
private String typeName ;
private Class<T> resultType ;
private Class<?> type ;
private Class<?>[] signature ;
// Use the raw type of the constructor here, because
// MethodInfo can only return a raw type for a constructor.
// It is not possible to have MethodInfo return a
// Constructor<T> because T may not be known at compile time.
private Constructor constructor ;
/** Create a generic of type T for the untyped class cls.
* Generally cls is a class that has been generated and loaded, so
* no compiled code can depend on the class directly. However, the
* generated class probably implements some interface T, represented
* here by Class<T>.
* @param type The expected type of a create call.
* @param className The name of the class to use for a constructor.
* @param signature The signature of the desired constructor.
* @throws IllegalArgumentException if cls is not a subclass of type.
*/
public GenericConstructor( final Class<T> type, final String className,
final Class<?>... signature ) {
this.resultType = type ;
this.typeName = className ;
this.signature = signature.clone() ;
}
@SuppressWarnings("unchecked")
private void getConstructor() {
synchronized( lock ) {
if ((type == null) || (constructor == null)) {
try {
type = (Class<T>)Class.forName( typeName ) ;
constructor = AccessController.doPrivileged(
new PrivilegedExceptionAction<Constructor>() {
public Constructor run() throws Exception {
synchronized( lock ) {
return type.getDeclaredConstructor( signature ) ;
}
}
} ) ;
} catch (Exception exc) {
// Catch all for several checked exceptions: ignore findbugs
Logger.getLogger( "com.sun.org.glassfish.gmbal.util" ).log( Level.FINE,
"Failure in getConstructor", exc ) ;
}
}
}
}
/** Create an instance of type T using the constructor that
* matches the given arguments if possible. The constructor
* is cached, so an instance of GenericClass should always be
* used for the same types of arguments. If a call fails,
* a check is made to see if a different constructor could
* be used.
* @param args The constructor arguments.
* @return A new instance of the object.
*/
public synchronized T create( Object... args ) {
synchronized(lock) {
T result = null ;
for (int ctr=0; ctr<=1; ctr++) {
getConstructor() ;
if (constructor == null) {
break ;
}
try {
result = resultType.cast( constructor.newInstance( args ) ) ;
break ;
} catch (Exception exc) {
// There are 4 checked exceptions here with identical handling.
// Ignore FindBugs complaints.
constructor = null ;
Logger.getLogger("com.sun.org.glassfish.gmbal.util").
log(Level.WARNING, "Error invoking constructor", exc );
}
}
return result ;
}
}
}