You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by nd...@apache.org on 2007/01/13 06:08:52 UTC
svn commit: r495839 [3/7] - in
/harmony/enhanced/classlib/trunk/modules/lang-management: ./ META-INF/
make/ src/main/java/com/ src/main/java/com/ibm/ src/main/java/com/ibm/lang/
src/main/java/com/ibm/lang/management/ src/main/java/java/lang/management/...
Propchange: harmony/enhanced/classlib/trunk/modules/lang-management/src/main/java/com/ibm/lang/management/MemoryNotificationThread.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: harmony/enhanced/classlib/trunk/modules/lang-management/src/main/java/com/ibm/lang/management/MemoryNotificationThreadShutdown.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/lang-management/src/main/java/com/ibm/lang/management/MemoryNotificationThreadShutdown.java?view=auto&rev=495839
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/lang-management/src/main/java/com/ibm/lang/management/MemoryNotificationThreadShutdown.java (added)
+++ harmony/enhanced/classlib/trunk/modules/lang-management/src/main/java/com/ibm/lang/management/MemoryNotificationThreadShutdown.java Fri Jan 12 21:08:48 2007
@@ -0,0 +1,61 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.ibm.lang.management;
+
+/**
+ * A thread hooked as a VM shutdown hook to tell a MemoryNotificationThread to
+ * terminate.
+ *
+ * @since 1.5
+ */
+class MemoryNotificationThreadShutdown extends Thread {
+ private MemoryNotificationThread myVictim;
+
+ /**
+ * Basic constructor
+ *
+ * @param victim
+ * The thread to notify on shutdown
+ */
+ MemoryNotificationThreadShutdown(MemoryNotificationThread victim) {
+ myVictim = victim;
+ }
+
+ /**
+ * Shutdown hook code that coordinates the termination of a memory
+ * notification thread.
+ */
+ public void run() {
+ sendShutdownNotification(myVictim.internalID);
+ try {
+ // wait for the notification thread to terminate
+ myVictim.join();
+ } catch (InterruptedException e) {
+ // don't care
+ }
+ }
+
+ /**
+ * Wipes any pending notifications and puts a shutdown request notification
+ * on an internal notification queue.
+ *
+ * @param id
+ * The internal id of the queue to shut down
+ */
+ private native void sendShutdownNotification(int id);
+}
Propchange: harmony/enhanced/classlib/trunk/modules/lang-management/src/main/java/com/ibm/lang/management/MemoryNotificationThreadShutdown.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: harmony/enhanced/classlib/trunk/modules/lang-management/src/main/java/com/ibm/lang/management/MemoryPoolMXBeanImpl.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/lang-management/src/main/java/com/ibm/lang/management/MemoryPoolMXBeanImpl.java?view=auto&rev=495839
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/lang-management/src/main/java/com/ibm/lang/management/MemoryPoolMXBeanImpl.java (added)
+++ harmony/enhanced/classlib/trunk/modules/lang-management/src/main/java/com/ibm/lang/management/MemoryPoolMXBeanImpl.java Fri Jan 12 21:08:48 2007
@@ -0,0 +1,440 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.ibm.lang.management;
+
+import java.lang.management.ManagementPermission;
+import java.lang.management.MemoryManagerMXBean;
+import java.lang.management.MemoryPoolMXBean;
+import java.lang.management.MemoryType;
+import java.lang.management.MemoryUsage;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+
+/**
+ * Runtime type for {@link java.lang.management.MemoryPoolMXBean}
+ *
+ * @since 1.5
+ */
+public final class MemoryPoolMXBeanImpl extends DynamicMXBeanImpl implements
+ MemoryPoolMXBean {
+ private final String name;
+
+ /**
+ * IMPORTANT: bean identifier for use by VM
+ */
+ @SuppressWarnings("unused")
+ private final int id;
+
+ private final MemoryType type;
+
+ private final MemoryMXBeanImpl memBean;
+
+ /**
+ * Sets the metadata for this bean.
+ *
+ * @param name
+ * @param type
+ * @param id
+ * @param memBean
+ */
+ MemoryPoolMXBeanImpl(String name, MemoryType type, int id,
+ MemoryMXBeanImpl memBean) {
+ this.name = name;
+ this.type = type;
+ this.id = id;
+ this.memBean = memBean;
+ setMBeanInfo(ManagementUtils
+ .getMBeanInfo(java.lang.management.MemoryPoolMXBean.class
+ .getName()));
+ if (isUsageThresholdSupported()
+ || isCollectionUsageThresholdSupported()) {
+ MemoryNotificationThread t = new MemoryNotificationThread(memBean,
+ this, id);
+ t.setDaemon(true);
+ t.setName("MemoryPoolMXBean notification dispatcher");
+ t.setPriority(Thread.NORM_PRIORITY + 1);
+ t.start();
+ }
+ }
+
+ /**
+ * @return a {@link MemoryUsage}object that may be interrogated by the
+ * caller to determine the details of the memory usage. Returns
+ * <code>null</code> if the virtual machine does not support this
+ * method.
+ * @see #getCollectionUsage()
+ */
+ private native MemoryUsage getCollectionUsageImpl();
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.management.MemoryPoolMXBean#getCollectionUsage()
+ */
+ public MemoryUsage getCollectionUsage() {
+ return this.getCollectionUsageImpl();
+ }
+
+ /**
+ * @return the collection usage threshold in bytes. The default value as set
+ * by the virtual machine will be zero.
+ * @see #getCollectionUsageThreshold()
+ */
+ private native long getCollectionUsageThresholdImpl();
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.management.MemoryPoolMXBean#getCollectionUsageThreshold()
+ */
+ public long getCollectionUsageThreshold() {
+ if (!isCollectionUsageThresholdSupported()) {
+ throw new UnsupportedOperationException(
+ "VM does not support collection usage threshold.");
+ }
+ return this.getCollectionUsageThresholdImpl();
+ }
+
+ /**
+ * @return a count of the number of times that the collection usage
+ * threshold has been surpassed.
+ * @see #getCollectionUsageThresholdCount()
+ */
+ private native long getCollectionUsageThresholdCountImpl();
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.management.MemoryPoolMXBean#getCollectionUsageThresholdCount()
+ */
+ public long getCollectionUsageThresholdCount() {
+ if (!isCollectionUsageThresholdSupported()) {
+ throw new UnsupportedOperationException(
+ "VM does not support collection usage threshold.");
+ }
+ return this.getCollectionUsageThresholdCountImpl();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.management.MemoryPoolMXBean#getMemoryManagerNames()
+ */
+ public String[] getMemoryManagerNames() {
+ /* get the memory managers and check which of them manage this pool */
+ Iterator<MemoryManagerMXBean> iter = memBean.getMemoryManagerMXBeans()
+ .iterator();
+ List<String> result = new LinkedList<String>();
+ while (iter.hasNext()) {
+ MemoryManagerMXBean bean = iter.next();
+ String[] managedPools = bean.getMemoryPoolNames();
+ for (int i = 0; i < managedPools.length; i++) {
+ if (managedPools[i].equals(name)) {
+ result.add(bean.getName());
+ break;
+ }
+ }
+ }
+ return result.toArray(new String[0]);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.management.MemoryPoolMXBean#getName()
+ */
+ public String getName() {
+ return this.name;
+ }
+
+ /**
+ * @return a {@link MemoryUsage}which can be interrogated by the caller to
+ * determine details of the peak memory usage. A <code>null</code>
+ * value will be returned if the memory pool no longer exists (and
+ * the pool is therefore considered to be invalid).
+ * @see #getPeakUsage()
+ */
+ private native MemoryUsage getPeakUsageImpl();
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.management.MemoryPoolMXBean#getPeakUsage()
+ */
+ public MemoryUsage getPeakUsage() {
+ return this.getPeakUsageImpl();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.management.MemoryPoolMXBean#getType()
+ */
+ public MemoryType getType() {
+ return this.type;
+ }
+
+ /**
+ * @return an instance of {@link MemoryUsage}that can be interrogated by
+ * the caller to determine details on the pool's current memory
+ * usage. A <code>null</code> value will be returned if the memory
+ * pool no longer exists (in which case it is considered to be
+ * invalid).
+ * @see #getUsage()
+ */
+ private native MemoryUsage getUsageImpl();
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.management.MemoryPoolMXBean#getUsage()
+ */
+ public MemoryUsage getUsage() {
+ return this.getUsageImpl();
+ }
+
+ /**
+ * @return the usage threshold in bytes. The default value as set by the
+ * virtual machine depends on the platform the virtual machine is
+ * running on. will be zero.
+ * @see #getUsageThreshold()
+ */
+ private native long getUsageThresholdImpl();
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.management.MemoryPoolMXBean#getUsageThreshold()
+ */
+ public long getUsageThreshold() {
+ if (!isUsageThresholdSupported()) {
+ throw new UnsupportedOperationException(
+ "VM does not support usage threshold.");
+ }
+ return this.getUsageThresholdImpl();
+ }
+
+ /**
+ * @return a count of the number of times that the usage threshold has been
+ * surpassed.
+ * @see #getUsageThresholdCount()
+ */
+ private native long getUsageThresholdCountImpl();
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.management.MemoryPoolMXBean#getUsageThresholdCount()
+ */
+ public long getUsageThresholdCount() {
+ if (!isUsageThresholdSupported()) {
+ throw new UnsupportedOperationException(
+ "VM does not support usage threshold.");
+ }
+ return this.getUsageThresholdCountImpl();
+ }
+
+ /**
+ * @return <code>true</code> if the collection usage threshold was
+ * surpassed after the latest garbage collection run, otherwise
+ * <code>false</code>.
+ * @see #isCollectionUsageThresholdExceeded()
+ */
+ private native boolean isCollectionUsageThresholdExceededImpl();
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.management.MemoryPoolMXBean#isCollectionUsageThresholdExceeded()
+ */
+ public boolean isCollectionUsageThresholdExceeded() {
+ if (!isCollectionUsageThresholdSupported()) {
+ throw new UnsupportedOperationException(
+ "VM does not support collection usage threshold.");
+ }
+ return this.isCollectionUsageThresholdExceededImpl();
+ }
+
+ /**
+ * @return <code>true</code> if supported, <code>false</code> otherwise.
+ * @see #isCollectionUsageThresholdSupported()
+ */
+ private native boolean isCollectionUsageThresholdSupportedImpl();
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.management.MemoryPoolMXBean#isCollectionUsageThresholdSupported()
+ */
+ public boolean isCollectionUsageThresholdSupported() {
+ return this.isCollectionUsageThresholdSupportedImpl();
+ }
+
+ /**
+ * @return <code>true</code> if the usage threshold has been surpassed,
+ * otherwise <code>false</code>.
+ * @see #isUsageThresholdExceeded()
+ */
+ private native boolean isUsageThresholdExceededImpl();
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.management.MemoryPoolMXBean#isUsageThresholdExceeded()
+ */
+ public boolean isUsageThresholdExceeded() {
+ if (!isUsageThresholdSupported()) {
+ throw new UnsupportedOperationException(
+ "VM does not support usage threshold.");
+ }
+ return this.isUsageThresholdExceededImpl();
+ }
+
+ /**
+ * @return <code>true</code> if supported, <code>false</code> otherwise.
+ * @see #isUsageThresholdSupported()
+ */
+ private native boolean isUsageThresholdSupportedImpl();
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.management.MemoryPoolMXBean#isUsageThresholdSupported()
+ */
+ public boolean isUsageThresholdSupported() {
+ return this.isUsageThresholdSupportedImpl();
+ }
+
+ /**
+ * @return <code>true</code> if the memory pool has not been removed by
+ * the virtual machine, <code>false</code> otherwise.
+ * @see #isValid()
+ */
+ private native boolean isValidImpl();
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.management.MemoryPoolMXBean#isValid()
+ */
+ public boolean isValid() {
+ return this.isValidImpl();
+ }
+
+ /**
+ * @see #resetPeakUsage()
+ */
+ private native void resetPeakUsageImpl();
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.management.MemoryPoolMXBean#resetPeakUsage()
+ */
+ public void resetPeakUsage() {
+ SecurityManager security = System.getSecurityManager();
+ if (security != null) {
+ security.checkPermission(new ManagementPermission("control"));
+ }
+ this.resetPeakUsageImpl();
+ }
+
+ /**
+ * @param threshold
+ * the size of the new collection usage threshold expressed in
+ * bytes.
+ * @see #setCollectionUsageThreshold(long)
+ */
+ private native void setCollectionUsageThresholdImpl(long threshold);
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.management.MemoryPoolMXBean#setCollectionUsageThreshold(long)
+ */
+ public void setCollectionUsageThreshold(long threshold) {
+ if (!isCollectionUsageThresholdSupported()) {
+ throw new UnsupportedOperationException(
+ "VM does not support collection usage threshold.");
+ }
+
+ SecurityManager security = System.getSecurityManager();
+ if (security != null) {
+ security.checkPermission(new ManagementPermission("control"));
+ }
+
+ if (threshold < 0) {
+ throw new IllegalArgumentException(
+ "Collection usage threshold cannot be negative.");
+ }
+
+ if (exceedsMaxPoolSize(threshold)) {
+ throw new IllegalArgumentException(
+ "Collection usage threshold cannot exceed maximum amount of memory for pool.");
+ }
+ this.setCollectionUsageThresholdImpl(threshold);
+ }
+
+ /**
+ * @param threshold
+ * the size of the new usage threshold expressed in bytes.
+ * @see #setUsageThreshold(long)
+ */
+ private native void setUsageThresholdImpl(long threshold);
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.management.MemoryPoolMXBean#setUsageThreshold(long)
+ */
+ public void setUsageThreshold(long threshold) {
+ if (!isUsageThresholdSupported()) {
+ throw new UnsupportedOperationException(
+ "VM does not support usage threshold.");
+ }
+
+ SecurityManager security = System.getSecurityManager();
+ if (security != null) {
+ security.checkPermission(new ManagementPermission("control"));
+ }
+
+ if (threshold < 0) {
+ throw new IllegalArgumentException(
+ "Usage threshold cannot be negative.");
+ }
+
+ if (exceedsMaxPoolSize(threshold)) {
+ throw new IllegalArgumentException(
+ "Usage threshold cannot exceed maximum amount of memory for pool.");
+ }
+ this.setUsageThresholdImpl(threshold);
+ }
+
+ /**
+ * @param value
+ * @return <code>true</code> if <code>value</code> is greater than the
+ * maximum size of the corresponding memory pool. <code>false</code>
+ * if <code>value</code> does not exceed the maximum memory pool
+ * size or else no memory pool maximum size has been defined.
+ */
+ private boolean exceedsMaxPoolSize(long value) {
+ MemoryUsage m = getUsage();
+ return (m.getMax() != -1 && m.getMax() < value);
+ }
+}
Propchange: harmony/enhanced/classlib/trunk/modules/lang-management/src/main/java/com/ibm/lang/management/MemoryPoolMXBeanImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: harmony/enhanced/classlib/trunk/modules/lang-management/src/main/java/com/ibm/lang/management/OpenTypeMappingIHandler.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/lang-management/src/main/java/com/ibm/lang/management/OpenTypeMappingIHandler.java?view=auto&rev=495839
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/lang-management/src/main/java/com/ibm/lang/management/OpenTypeMappingIHandler.java (added)
+++ harmony/enhanced/classlib/trunk/modules/lang-management/src/main/java/com/ibm/lang/management/OpenTypeMappingIHandler.java Fri Jan 12 21:08:48 2007
@@ -0,0 +1,733 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.ibm.lang.management;
+
+import java.io.IOException;
+import java.lang.management.ManagementFactory;
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.security.AccessController;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
+
+import javax.management.Attribute;
+import javax.management.AttributeNotFoundException;
+import javax.management.InstanceNotFoundException;
+import javax.management.InvalidAttributeValueException;
+import javax.management.ListenerNotFoundException;
+import javax.management.MBeanAttributeInfo;
+import javax.management.MBeanException;
+import javax.management.MBeanInfo;
+import javax.management.MBeanOperationInfo;
+import javax.management.MBeanParameterInfo;
+import javax.management.MBeanServerConnection;
+import javax.management.NotificationEmitter;
+import javax.management.NotificationFilter;
+import javax.management.NotificationListener;
+import javax.management.ObjectName;
+import javax.management.ReflectionException;
+import javax.management.RuntimeMBeanException;
+
+/**
+ * Concrete instance of the {@link InvocationHandler} interface that is used to
+ * handle method invocations on MXBeans that have been obtained using the proxy
+ * method.
+ *
+ * @see ManagementFactory#newPlatformMXBeanProxy(MBeanServerConnection, String,
+ * Class)
+ */
+public class OpenTypeMappingIHandler implements InvocationHandler {
+
+ private MBeanServerConnection connection;
+
+ private ObjectName mxBeanObjectName;
+
+ private MBeanInfo info;
+
+ /**
+ * @param connection
+ * @param mxBeanType
+ * @param mxBeanName
+ * @throws IOException
+ */
+ public OpenTypeMappingIHandler(MBeanServerConnection connection,
+ String mxBeanType, String mxBeanName) throws IOException {
+ this.connection = connection;
+ setObjectName(mxBeanName);
+ checkBeanIsRegistered();
+ setInfo(mxBeanType);
+ }
+
+ /**
+ * @param mxBeanType
+ */
+ private void setInfo(String mxBeanType) {
+ this.info = ManagementUtils.getMBeanInfo(mxBeanType);
+ if (info == null) {
+ throw new IllegalArgumentException("Unknown MXBean type : "
+ + mxBeanType);
+ }
+ }
+
+ /**
+ * @param mxBeanName
+ */
+ private void setObjectName(String mxBeanName) {
+ try {
+ this.mxBeanObjectName = new ObjectName(mxBeanName);
+ } catch (Exception e) {
+ if (ManagementUtils.VERBOSE_MODE) {
+ e.printStackTrace(System.err);
+ }// end if
+ throw new IllegalArgumentException(
+ "Bean name not in valid format.", e);
+ }
+ }
+
+ /**
+ * @throws IOException
+ */
+ private void checkBeanIsRegistered() throws IOException {
+ if (!this.connection.isRegistered(this.mxBeanObjectName)) {
+ throw new IllegalArgumentException("Not registered : "
+ + this.mxBeanObjectName);
+ }
+ }
+
+ enum InvokeType {
+ ATTRIBUTE_GETTER, ATTRIBUTE_SETTER, NOTIFICATION_OP, OPERATION
+ };
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.reflect.InvocationHandler#invoke(java.lang.Object,
+ * java.lang.reflect.Method, java.lang.Object[])
+ */
+ public Object invoke(Object proxy, Method method, Object[] args)
+ throws Throwable {
+ Object result = null;
+ // Carry out the correct operation according to what the caller is
+ // trying to do (set/get an attribute or invoke an operation. Each of
+ // the below handler methods is expected to manage the conversion of
+ // input args to open types and the conversion of return values from
+ // an open type to a Java type.
+ switch (getInvokeType(method.getName())) {
+ case ATTRIBUTE_GETTER:
+ result = invokeAttributeGetter(method);
+ break;
+ case ATTRIBUTE_SETTER:
+ result = invokeAttributeSetter(method, args);
+ break;
+ case NOTIFICATION_OP:
+ result = invokeNotificationEmitterOperation(method, args);
+ break;
+ default:
+ result = invokeOperation(method, args);
+ break;
+ }
+ return result;
+ }
+
+ /**
+ * Invoke the event notification operation described by the {@link Method}instance
+ * <code>method</code> on this handler's target object.
+ *
+ * @param method
+ * describes the operation to be invoked on the target object
+ * @param args
+ * the arguments to be used in the operation call
+ * @return a <code>null</code> representing the <code>void</code> return
+ * from all {@link javax.management.NotificationEmitter} methods.
+ * @throws IOException
+ * @throws InstanceNotFoundException
+ * @throws ListenerNotFoundException
+ */
+ private Object invokeNotificationEmitterOperation(Method method,
+ final Object[] args) throws InstanceNotFoundException, IOException,
+ ListenerNotFoundException {
+ Object result = null;
+
+ if (method.getName().equals("addNotificationListener")) {
+ try {
+ AccessController
+ .doPrivileged(new PrivilegedExceptionAction<Object>() {
+ public Object run()
+ throws InstanceNotFoundException,
+ IOException {
+ connection.addNotificationListener(
+ mxBeanObjectName,
+ (NotificationListener) args[0],
+ (NotificationFilter) args[1], args[2]);
+ return null;
+ }// end method run
+ });
+ } catch (PrivilegedActionException e) {
+ Throwable t = e.getCause();
+ if (t instanceof InstanceNotFoundException) {
+ throw (InstanceNotFoundException) t;
+ } else if (t instanceof IOException) {
+ throw (IOException) t;
+ }
+ } catch (RuntimeMBeanException e) {
+ // RuntimeMBeanException wraps unchecked exceptions from the
+ // MBean server
+ throw e.getTargetException();
+ }// end catch
+ } else if (method.getName().equals("getNotificationInfo")) {
+ result = this.info.getNotifications();
+ } else if (method.getName().equals("removeNotificationListener")) {
+ if (args.length == 1) {
+ try {
+ AccessController
+ .doPrivileged(new PrivilegedExceptionAction<Object>() {
+ public Object run()
+ throws InstanceNotFoundException,
+ ListenerNotFoundException, IOException {
+ connection.removeNotificationListener(
+ mxBeanObjectName,
+ (NotificationListener) args[0]);
+ return null;
+ }// end method run
+ });
+ } catch (PrivilegedActionException e) {
+ Throwable t = e.getCause();
+ if (t instanceof InstanceNotFoundException) {
+ throw (InstanceNotFoundException) t;
+ } else if (t instanceof ListenerNotFoundException) {
+ throw (ListenerNotFoundException) t;
+ } else if (t instanceof IOException) {
+ throw (IOException) t;
+ }
+ } catch (RuntimeMBeanException e) {
+ // RuntimeMBeanException wraps unchecked exceptions from the
+ // MBean server
+ throw e.getTargetException();
+ }// end catch
+ } else {
+ try {
+ AccessController
+ .doPrivileged(new PrivilegedExceptionAction<Object>() {
+ public Object run()
+ throws InstanceNotFoundException,
+ ListenerNotFoundException, IOException {
+ connection.removeNotificationListener(
+ mxBeanObjectName,
+ (NotificationListener) args[0],
+ (NotificationFilter) args[1],
+ args[2]);
+ return null;
+ }// end method run
+ });
+ } catch (PrivilegedActionException e) {
+ Throwable t = e.getCause();
+ if (t instanceof InstanceNotFoundException) {
+ throw (InstanceNotFoundException) t;
+ } else if (t instanceof ListenerNotFoundException) {
+ throw (ListenerNotFoundException) t;
+ } else if (t instanceof IOException) {
+ throw (IOException) t;
+ }
+ } catch (RuntimeMBeanException e) {
+ // RuntimeMBeanException wraps unchecked exceptions from the
+ // MBean server
+ throw e.getTargetException();
+ }// end catch
+ }// end else
+ }// end else if removeNotificationListener
+ return result;
+ }
+
+ /**
+ * Invoke the operation described by {@link Method}instance
+ * <code>method</code> on this handler's target object.
+ * <p>
+ * All argument values are automatically converted to their corresponding
+ * MBean open types.
+ * </p>
+ * <p>
+ * If the method return is an MBean open type value it will be automatically
+ * converted to a Java type by this method.
+ * </p>
+ *
+ * @param method
+ * describes the operation to be invoked on the target object
+ * @param args
+ * the arguments to be used in the operation call
+ * @return the returned value from the operation call on the target object
+ * with any MBean open type values being automatically converted to
+ * their Java counterparts.
+ * @throws IOException
+ * @throws ReflectionException
+ * @throws MBeanException
+ * @throws InstanceNotFoundException
+ * @throws IllegalAccessException
+ * @throws InstantiationException
+ * @throws ClassNotFoundException
+ * @throws InvocationTargetException
+ * @throws NoSuchMethodException
+ * @throws IllegalArgumentException
+ * @throws SecurityException
+ */
+ private Object invokeOperation(final Method method, final Object[] args)
+ throws InstanceNotFoundException, MBeanException,
+ ReflectionException, IOException, ClassNotFoundException,
+ InstantiationException, IllegalAccessException, SecurityException,
+ IllegalArgumentException, NoSuchMethodException,
+ InvocationTargetException {
+ // For Java 5.0 platform MXBeans, no conversion
+ // to open MBean types is necessary for any of the arguments.
+ // i.e. they are all simple types.
+ Object result = null;
+ try {
+ result = AccessController
+ .doPrivileged(new PrivilegedExceptionAction<Object>() {
+ public Object run() throws InstanceNotFoundException,
+ MBeanException, ReflectionException,
+ IOException {
+ return connection.invoke(mxBeanObjectName, method
+ .getName(), args,
+ getOperationSignature(method));
+ }// end method run
+ });
+ } catch (PrivilegedActionException e) {
+ Throwable t = e.getCause();
+ if (t instanceof InstanceNotFoundException) {
+ throw (InstanceNotFoundException) t;
+ } else if (t instanceof MBeanException) {
+ throw (MBeanException) t;
+ } else if (t instanceof ReflectionException) {
+ throw (ReflectionException) t;
+ } else if (t instanceof IOException) {
+ throw (IOException) t;
+ }
+ } catch (RuntimeMBeanException e) {
+ // RuntimeMBeanException wraps unchecked exceptions from the
+ // MBean server
+ throw e.getTargetException();
+ }// end catch
+
+ String realReturnType = method.getReturnType().getName();
+ String openReturnType = getOperationOpenReturnType(method);
+
+ if (!realReturnType.equals(openReturnType)) {
+ result = ManagementUtils.convertFromOpenType(result, Class
+ .forName(openReturnType), Class.forName(realReturnType));
+ }
+
+ return result;
+ }
+
+ /**
+ * For the method available on this handler's target object that is
+ * described by the {@link Method}instance, return a string representation
+ * of the return type after mapping to an open type.
+ *
+ * @param method
+ * an instance of <code>Method</code> that describes a method
+ * on the target object.
+ * @return a string containing the open return type of the method specified
+ * by <code>method</code>.
+ */
+ private String getOperationOpenReturnType(Method method) {
+ String result = null;
+ String[] methodSig = getOperationSignature(method);
+ MBeanOperationInfo[] opInfos = this.info.getOperations();
+ for (int i = 0; i < opInfos.length; i++) {
+ MBeanOperationInfo opInfo = opInfos[i];
+ if (opInfo.getName().equals(method.getName())) {
+ MBeanParameterInfo[] opParams = opInfo.getSignature();
+ if (opParams.length == methodSig.length) {
+ boolean matchFound = true;
+ for (int j = 0; j < opParams.length; j++) {
+ if (!opParams[j].getType().equals(methodSig[j])) {
+ matchFound = false;
+ break;
+ }// end if arg types do not match
+ }// end for each argument
+ if (matchFound) {
+ result = opInfo.getReturnType();
+ break;
+ }
+ }// end if number of args matches
+ }// end if method match found
+ }// end for all operations
+
+ return result;
+ }
+
+ /**
+ * Obtain a string array of all of the argument types (in the correct order)
+ * for the method on this handler's target object. The signature types will
+ * all be open types.
+ *
+ * @param method
+ * a {@link Method}instance that describes an operation on the
+ * target object.
+ * @return an array of strings with each element holding the fully qualified
+ * name of the corresponding argument to the method. The order of
+ * the array elements corresponds exactly with the order of the
+ * method arguments.
+ */
+ private String[] getOperationSignature(Method method) {
+ String[] result = null;
+ Class[] args = method.getParameterTypes();
+ result = new String[args.length];
+ for (int i = 0; i < args.length; i++) {
+ Class clazz = args[i];
+ result[i] = clazz.getName();
+ }
+ return result;
+ }
+
+ /**
+ * Invoke the attribute set operation described by {@link Method}instance
+ * <code>method</code> on this handler's target object.
+ * <p>
+ * All argument values are automatically converted to their corresponding
+ * MBean open types.
+ * </p>
+ *
+ * @param method
+ * describes the operation to be invoked on the target object
+ * @param args
+ * the arguments to be used in the operation call
+ * @return the returned value from the operation call on the target object
+ * with any MBean open type values being automatically converted to
+ * their Java counterparts.
+ * @throws IOException
+ * @throws ReflectionException
+ * @throws MBeanException
+ * @throws InstanceNotFoundException
+ * @throws AttributeNotFoundException
+ * @throws InvalidAttributeValueException
+ */
+ private Object invokeAttributeSetter(final Method method,
+ final Object[] args) throws AttributeNotFoundException,
+ InstanceNotFoundException, MBeanException, ReflectionException,
+ IOException, InvalidAttributeValueException {
+ // In Java 5.0 platform MXBeans the following applies for all
+ // attribute setter methods :
+ // 1. no conversion to open MBean types necessary
+ // 2. all setter arguments are single value (i.e. not array or
+ // collection types).
+ // 3. all return null
+ try {
+ AccessController
+ .doPrivileged(new PrivilegedExceptionAction<Object>() {
+ public Object run() throws InstanceNotFoundException,
+ AttributeNotFoundException,
+ InvalidAttributeValueException, MBeanException,
+ ReflectionException, IOException {
+ connection.setAttribute(mxBeanObjectName,
+ new Attribute(getAttribName(method),
+ args[0]));
+ return null;
+ }// end method run
+ });
+ } catch (PrivilegedActionException e) {
+ // PrivilegedActionException wraps checked exceptions
+ Throwable t = e.getCause();
+ if (t instanceof InstanceNotFoundException) {
+ throw (InstanceNotFoundException) t;
+ } else if (t instanceof AttributeNotFoundException) {
+ throw (AttributeNotFoundException) t;
+ } else if (t instanceof InvalidAttributeValueException) {
+ throw (InvalidAttributeValueException) t;
+ } else if (t instanceof MBeanException) {
+ throw (MBeanException) t;
+ } else if (t instanceof ReflectionException) {
+ throw (ReflectionException) t;
+ } else if (t instanceof IOException) {
+ throw (IOException) t;
+ }
+ } catch (RuntimeMBeanException e) {
+ // RuntimeMBeanException wraps unchecked exceptions from the
+ // MBean server
+ throw e.getTargetException();
+ }// end catch
+
+ return null;
+ }
+
+ /**
+ * Invoke the attribute get operation described by {@link Method}instance
+ * <code>method</code> on this handler's target object.
+ * <p>
+ * All returned values are automatically converted to their corresponding
+ * MBean open types.
+ * </p>
+ *
+ * @param method
+ * describes the getter operation to be invoked on the target
+ * object
+ * @return the returned value from the getter call on the target object with
+ * any MBean open type values being automatically converted to their
+ * Java counterparts.
+ * @throws IOException
+ * @throws ReflectionException
+ * @throws MBeanException
+ * @throws InstanceNotFoundException
+ * @throws AttributeNotFoundException
+ * @throws ClassNotFoundException
+ * @throws IllegalAccessException
+ * @throws InstantiationException
+ * @throws InvocationTargetException
+ * @throws NoSuchMethodException
+ * @throws IllegalArgumentException
+ * @throws SecurityException
+ */
+ private Object invokeAttributeGetter(final Method method)
+ throws AttributeNotFoundException, InstanceNotFoundException,
+ MBeanException, ReflectionException, IOException,
+ ClassNotFoundException, InstantiationException,
+ IllegalAccessException, SecurityException,
+ IllegalArgumentException, NoSuchMethodException,
+ InvocationTargetException {
+ Object result = null;
+ String realReturnType = method.getReturnType().getName();
+ String openReturnType = getAttrOpenType(method.getName());
+
+ try {
+ result = AccessController
+ .doPrivileged(new PrivilegedExceptionAction<Object>() {
+ public Object run() throws AttributeNotFoundException,
+ InstanceNotFoundException, MBeanException,
+ ReflectionException, IOException {
+ return connection.getAttribute(mxBeanObjectName,
+ getAttribName(method));
+ }// end method run
+ });
+ } catch (PrivilegedActionException e) {
+ Throwable t = e.getCause();
+ if (t instanceof AttributeNotFoundException) {
+ throw (AttributeNotFoundException) t;
+ } else if (t instanceof InstanceNotFoundException) {
+ throw (InstanceNotFoundException) t;
+ } else if (t instanceof MBeanException) {
+ throw (MBeanException) t;
+ } else if (t instanceof ReflectionException) {
+ throw (ReflectionException) t;
+ } else if (t instanceof IOException) {
+ throw (IOException) t;
+ }
+ } catch (RuntimeMBeanException e) {
+ // RuntimeMBeanException wraps unchecked exceptions from the
+ // MBean server
+ throw e.getTargetException();
+ }// end catch
+
+ if (!realReturnType.equals(openReturnType)) {
+ result = ManagementUtils.convertFromOpenType(result, Class
+ .forName(openReturnType), Class.forName(realReturnType));
+ }
+
+ return result;
+ }
+
+ /**
+ * For the target type associated with this invocation handler, returns the
+ * name of the attribute that will be queried or updated by the Java method
+ * described in <code>method</code>.
+ *
+ * @param method
+ * a {@link Method}object describing a method on this handler's
+ * target object.
+ * @return the name of the attribute that will be queried or modified by an
+ * invocation of the method described by <code>method</code>.
+ */
+ private String getAttribName(Method method) {
+ String result = null;
+ String methodName = method.getName();
+ MBeanAttributeInfo[] attribs = info.getAttributes();
+
+ if (methodName.startsWith("get")) {
+ String attribName = methodName.substring("get".length());
+ for (int i = 0; i < attribs.length; i++) {
+ MBeanAttributeInfo attribInfo = attribs[i];
+ if (attribInfo.getName().equals(attribName)
+ && attribInfo.isReadable()) {
+ result = attribInfo.getName();
+ break;
+ }// end if
+ }// end for
+ }// end if
+
+ if (result == null) {
+ if (methodName.startsWith("is")) {
+ String attribName = methodName.substring("is".length());
+ for (int i = 0; i < attribs.length; i++) {
+ MBeanAttributeInfo attribInfo = attribs[i];
+ if (attribInfo.getName().equals(attribName)
+ && attribInfo.isReadable() && attribInfo.isIs()) {
+ result = attribInfo.getName();
+ break;
+ }// end if
+ }// end for
+ }// end if
+ }
+
+ if (result == null) {
+ if (methodName.startsWith("set")) {
+ String attribName = methodName.substring("set".length());
+ for (int i = 0; i < attribs.length; i++) {
+ MBeanAttributeInfo attribInfo = attribs[i];
+ if (attribInfo.getName().equals(attribName)
+ && attribInfo.isWritable()) {
+ result = attribInfo.getName();
+ break;
+ }// end if
+ }// end for
+ }// end if
+ }
+
+ return result;
+ }
+
+ /**
+ * Returns the name of the fully qualified open type of the attribute of the
+ * target type that is obtained from a call to the <code>methodName</code>
+ * method.
+ *
+ * @param methodName
+ * the name of a getter method on an attribute of the target
+ * type.
+ * @return the fully qualified name of the implied attribute's <i>open </i>
+ * type.
+ */
+ private String getAttrOpenType(String methodName) {
+ MBeanAttributeInfo attrInfo = getAttribInfo(methodName);
+ return attrInfo.getType();
+ }
+
+ /**
+ * Obtain the {@link MBeanAttributeInfo}meta data for the attribute of this
+ * invocation handler's target object that is returned by a call to the
+ * method called <code>methodName</code>.
+ *
+ * @param methodName
+ * the name of the getter method on the attribute under scrutiny.
+ * @return the <code>MBeanAttributeInfo</code> that describes the
+ * attribute.
+ */
+ private MBeanAttributeInfo getAttribInfo(String methodName) {
+ MBeanAttributeInfo result = null;
+ MBeanAttributeInfo[] attribs = info.getAttributes();
+
+ if (methodName.startsWith("get")) {
+ String attribName = methodName.substring("get".length());
+ for (int i = 0; i < attribs.length; i++) {
+ MBeanAttributeInfo attribInfo = attribs[i];
+ if (attribInfo.getName().equals(attribName)
+ && attribInfo.isReadable()) {
+ result = attribInfo;
+ break;
+ }// end if
+ }// end for
+ }// end if
+
+ if (result == null) {
+ if (methodName.startsWith("is")) {
+ String attribName = methodName.substring("is".length());
+ for (int i = 0; i < attribs.length; i++) {
+ MBeanAttributeInfo attribInfo = attribs[i];
+ if (attribInfo.getName().equals(attribName)
+ && attribInfo.isReadable() && attribInfo.isIs()) {
+ result = attribInfo;
+ break;
+ }// end if
+ }// end for
+ }// end if
+ }
+
+ return result;
+ }
+
+ /**
+ * Determine the type of invocation being made on the target object.
+ *
+ * @param methodName
+ * @return an instance of <code>InvokeType</code> corresponding to the
+ * nature of the operation that the caller is attemting to make on
+ * the target object.
+ */
+ private InvokeType getInvokeType(String methodName) {
+ InvokeType result = null;
+
+ if (methodName.startsWith("get")) {
+ String attribName = methodName.substring("get".length());
+ MBeanAttributeInfo[] attribs = info.getAttributes();
+ for (int i = 0; i < attribs.length; i++) {
+ MBeanAttributeInfo attribInfo = attribs[i];
+ if (attribInfo.getName().equals(attribName)
+ && attribInfo.isReadable()) {
+ result = InvokeType.ATTRIBUTE_GETTER;
+ break;
+ }// end if
+ }// end for
+ }// end if
+
+ if (result == null) {
+ if (methodName.startsWith("is")) {
+ String attribName = methodName.substring("is".length());
+ MBeanAttributeInfo[] attribs = info.getAttributes();
+ for (int i = 0; i < attribs.length; i++) {
+ MBeanAttributeInfo attribInfo = attribs[i];
+ if (attribInfo.getName().equals(attribName)
+ && attribInfo.isReadable() && attribInfo.isIs()) {
+ result = InvokeType.ATTRIBUTE_GETTER;
+ break;
+ }// end if
+ }// end for
+ }// end if
+ }
+
+ if (result == null) {
+ if (methodName.startsWith("set")) {
+ String attribName = methodName.substring("set".length());
+ MBeanAttributeInfo[] attribs = info.getAttributes();
+ for (int i = 0; i < attribs.length; i++) {
+ MBeanAttributeInfo attribInfo = attribs[i];
+ if (attribInfo.getName().equals(attribName)
+ && attribInfo.isWritable()) {
+ result = InvokeType.ATTRIBUTE_SETTER;
+ break;
+ }// end if
+ }// end for
+ }// end if
+ }
+
+ if (result == null) {
+ Method[] neMethods = NotificationEmitter.class.getMethods();
+ for (int i = 0; i < neMethods.length; i++) {
+ if (neMethods[i].getName().equals(methodName)) {
+ result = InvokeType.NOTIFICATION_OP;
+ break;
+ }// end if
+ }// end for
+ }
+
+ // If not a getter or setter or a notification emitter method then
+ // must be a vanilla DynamicMXBean operation.
+ if (result == null) {
+ result = InvokeType.OPERATION;
+ }
+ return result;
+ }
+}
Propchange: harmony/enhanced/classlib/trunk/modules/lang-management/src/main/java/com/ibm/lang/management/OpenTypeMappingIHandler.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: harmony/enhanced/classlib/trunk/modules/lang-management/src/main/java/com/ibm/lang/management/OperatingSystemMXBeanImpl.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/lang-management/src/main/java/com/ibm/lang/management/OperatingSystemMXBeanImpl.java?view=auto&rev=495839
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/lang-management/src/main/java/com/ibm/lang/management/OperatingSystemMXBeanImpl.java (added)
+++ harmony/enhanced/classlib/trunk/modules/lang-management/src/main/java/com/ibm/lang/management/OperatingSystemMXBeanImpl.java Fri Jan 12 21:08:48 2007
@@ -0,0 +1,86 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.ibm.lang.management;
+
+import java.lang.management.OperatingSystemMXBean;
+
+/**
+ * Runtime type for {@link java.lang.management.OperatingSystemMXBean}.
+ *
+ * @since 1.5
+ */
+public final class OperatingSystemMXBeanImpl extends DynamicMXBeanImpl
+ implements OperatingSystemMXBean {
+
+ private static OperatingSystemMXBeanImpl instance = new OperatingSystemMXBeanImpl();
+
+ /**
+ * Constructor intentionally private to prevent instantiation by others.
+ * Sets the metadata for this bean.
+ */
+ private OperatingSystemMXBeanImpl() {
+ setMBeanInfo(ManagementUtils
+ .getMBeanInfo(java.lang.management.OperatingSystemMXBean.class
+ .getName()));
+ }
+
+ /**
+ * Singleton accessor method.
+ *
+ * @return the <code>OperatingSystemMXBeanImpl</code> singleton.
+ */
+ static OperatingSystemMXBeanImpl getInstance() {
+ return instance;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.management.OperatingSystemMXBean#getArch()
+ */
+ public String getArch() {
+ return System.getProperty("os.arch");
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.management.OperatingSystemMXBean#getAvailableProcessors()
+ */
+ public int getAvailableProcessors() {
+ return Runtime.getRuntime().availableProcessors();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.management.OperatingSystemMXBean#getName()
+ */
+ public String getName() {
+ return System.getProperty("os.name");
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.management.OperatingSystemMXBean#getVersion()
+ */
+ public String getVersion() {
+ return System.getProperty("os.version");
+ }
+}
Propchange: harmony/enhanced/classlib/trunk/modules/lang-management/src/main/java/com/ibm/lang/management/OperatingSystemMXBeanImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: harmony/enhanced/classlib/trunk/modules/lang-management/src/main/java/com/ibm/lang/management/RuntimeMXBeanImpl.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/lang-management/src/main/java/com/ibm/lang/management/RuntimeMXBeanImpl.java?view=auto&rev=495839
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/lang-management/src/main/java/com/ibm/lang/management/RuntimeMXBeanImpl.java (added)
+++ harmony/enhanced/classlib/trunk/modules/lang-management/src/main/java/com/ibm/lang/management/RuntimeMXBeanImpl.java Fri Jan 12 21:08:48 2007
@@ -0,0 +1,255 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.ibm.lang.management;
+
+import java.lang.management.ManagementPermission;
+import java.lang.management.RuntimeMXBean;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+
+/**
+ * Runtime type for {@link java.lang.management.RuntimeMXBean}
+ *
+ * @since 1.5
+ */
+public final class RuntimeMXBeanImpl extends DynamicMXBeanImpl implements
+ RuntimeMXBean {
+
+ private static RuntimeMXBeanImpl instance = new RuntimeMXBeanImpl();
+
+ /**
+ * Constructor intentionally private to prevent instantiation by others.
+ * Sets the metadata for this bean.
+ */
+ private RuntimeMXBeanImpl() {
+ setMBeanInfo(ManagementUtils
+ .getMBeanInfo(RuntimeMXBean.class.getName()));
+ }
+
+ /**
+ * Singleton accessor method.
+ *
+ * @return the <code>RuntimeMXBeanImpl</code> singleton.
+ */
+ static RuntimeMXBeanImpl getInstance() {
+ return instance;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.management.RuntimeMXBean#getBootClassPath()
+ */
+ public String getBootClassPath() {
+ if (!isBootClassPathSupported()) {
+ throw new UnsupportedOperationException(
+ "VM does not support boot classpath.");
+ }
+
+ SecurityManager security = System.getSecurityManager();
+ if (security != null) {
+ security.checkPermission(new ManagementPermission("monitor"));
+ }
+
+ return AccessController.doPrivileged(new PrivilegedAction<String>() {
+ public String run() {
+ return System.getProperty("sun.boot.class.path");
+ }// end method run
+ });
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.management.RuntimeMXBean#getClassPath()
+ */
+ public String getClassPath() {
+ return System.getProperty("java.class.path");
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.management.RuntimeMXBean#getLibraryPath()
+ */
+ public String getLibraryPath() {
+ return System.getProperty("java.library.path");
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.management.RuntimeMXBean#getManagementSpecVersion()
+ */
+ public String getManagementSpecVersion() {
+ return "1.0";
+ }
+
+ /**
+ * @return the name of this running virtual machine.
+ * @see #getName()
+ */
+ private native String getNameImpl();
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.management.RuntimeMXBean#getName()
+ */
+ public String getName() {
+ return this.getNameImpl();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.management.RuntimeMXBean#getSpecName()
+ */
+ public String getSpecName() {
+ return System.getProperty("java.vm.specification.name");
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.management.RuntimeMXBean#getSpecVendor()
+ */
+ public String getSpecVendor() {
+ return System.getProperty("java.vm.specification.vendor");
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.management.RuntimeMXBean#getSpecVersion()
+ */
+ public String getSpecVersion() {
+ return System.getProperty("java.vm.specification.version");
+ }
+
+ /**
+ * @return the virtual machine start time in milliseconds.
+ * @see #getStartTime()
+ */
+ private native long getStartTimeImpl();
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.management.RuntimeMXBean#getStartTime()
+ */
+ public long getStartTime() {
+ return this.getStartTimeImpl();
+ }
+
+ /**
+ * @return the number of milliseconds the virtual machine has been running.
+ * @see #getUptime()
+ */
+ private native long getUptimeImpl();
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.management.RuntimeMXBean#getUptime()
+ */
+ public long getUptime() {
+ return this.getUptimeImpl();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.management.RuntimeMXBean#getVmName()
+ */
+ public String getVmName() {
+ return System.getProperty("java.vm.name");
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.management.RuntimeMXBean#getVmVendor()
+ */
+ public String getVmVendor() {
+ return System.getProperty("java.vm.vendor");
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.management.RuntimeMXBean#getVmVersion()
+ */
+ public String getVmVersion() {
+ return System.getProperty("java.vm.version");
+ }
+
+ /**
+ * @return <code>true</code> if supported, <code>false</code> otherwise.
+ * @see #isBootClassPathSupported()
+ */
+ private native boolean isBootClassPathSupportedImpl();
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.management.RuntimeMXBean#isBootClassPathSupported()
+ */
+ public boolean isBootClassPathSupported() {
+ return this.isBootClassPathSupportedImpl();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.management.RuntimeMXBean#getInputArguments()
+ */
+ public List<String> getInputArguments() {
+ SecurityManager security = System.getSecurityManager();
+ if (security != null) {
+ security.checkPermission(new ManagementPermission("monitor"));
+ }
+
+ // TODO : Retrieve the input args from the VM
+ return new ArrayList<String>();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.management.RuntimeMXBean#getSystemProperties()
+ */
+ public Map<String, String> getSystemProperties() {
+ Map<String, String> result = new HashMap<String, String>();
+ Properties props = System.getProperties();
+ Enumeration<?> propNames = props.propertyNames();
+ while (propNames.hasMoreElements()) {
+ String propName = (String) propNames.nextElement();
+ String propValue = props.getProperty(propName);
+ result.put(propName, propValue);
+ }// end while
+ return result;
+ }
+}
+
Propchange: harmony/enhanced/classlib/trunk/modules/lang-management/src/main/java/com/ibm/lang/management/RuntimeMXBeanImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: harmony/enhanced/classlib/trunk/modules/lang-management/src/main/java/com/ibm/lang/management/ThreadMXBeanImpl.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/lang-management/src/main/java/com/ibm/lang/management/ThreadMXBeanImpl.java?view=auto&rev=495839
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/lang-management/src/main/java/com/ibm/lang/management/ThreadMXBeanImpl.java (added)
+++ harmony/enhanced/classlib/trunk/modules/lang-management/src/main/java/com/ibm/lang/management/ThreadMXBeanImpl.java Fri Jan 12 21:08:48 2007
@@ -0,0 +1,669 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.ibm.lang.management;
+
+import java.lang.management.ManagementPermission;
+import java.lang.management.ThreadInfo;
+import java.lang.management.ThreadMXBean;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+
+/**
+ * Runtime type for {@link java.lang.management.ThreadMXBean}
+ *
+ * @since 1.5
+ */
+public final class ThreadMXBeanImpl extends DynamicMXBeanImpl implements
+ ThreadMXBean {
+
+ private static ThreadMXBeanImpl instance = new ThreadMXBeanImpl();
+
+ /**
+ * Constructor intentionally private to prevent instantiation by others.
+ * Sets the metadata for this bean.
+ */
+ private ThreadMXBeanImpl() {
+ setMBeanInfo(ManagementUtils.getMBeanInfo(ThreadMXBean.class.getName()));
+ }
+
+ /**
+ * Singleton accessor method.
+ *
+ * @return the <code>ThreadMXBeanImpl</code> singleton.
+ */
+ static ThreadMXBeanImpl getInstance() {
+ return instance;
+ }
+
+ /**
+ * @return an array of the identifiers of every thread in the virtual
+ * machine that has been detected as currently being in a deadlock
+ * situation.
+ * @see #findMonitorDeadlockedThreads()
+ */
+ private native long[] findMonitorDeadlockedThreadsImpl();
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.management.ThreadMXBean#findMonitorDeadlockedThreads()
+ */
+ public long[] findMonitorDeadlockedThreads() {
+ SecurityManager security = System.getSecurityManager();
+ if (security != null) {
+ security.checkPermission(new ManagementPermission("monitor"));
+ }
+ return this.findMonitorDeadlockedThreadsImpl();
+ }
+
+ /**
+ * @return the identifiers of all of the threads currently alive in the
+ * virtual machine.
+ * @see #getAllThreadIds()
+ */
+ private native long[] getAllThreadIdsImpl();
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.management.ThreadMXBean#getAllThreadIds()
+ */
+ public long[] getAllThreadIds() {
+ SecurityManager security = System.getSecurityManager();
+ if (security != null) {
+ security.checkPermission(new ManagementPermission("monitor"));
+ }
+ return this.getAllThreadIdsImpl();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.management.ThreadMXBean#getCurrentThreadCpuTime()
+ */
+ public long getCurrentThreadCpuTime() {
+ return getThreadCpuTime(Thread.currentThread().getId());
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.management.ThreadMXBean#getCurrentThreadUserTime()
+ */
+ public long getCurrentThreadUserTime() {
+ return getThreadUserTime(Thread.currentThread().getId());
+ }
+
+ /**
+ * @return the number of currently alive daemon threads.
+ * @see #getDaemonThreadCount()
+ */
+ private native int getDaemonThreadCountImpl();
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.management.ThreadMXBean#getDaemonThreadCount()
+ */
+ public int getDaemonThreadCount() {
+ return this.getDaemonThreadCountImpl();
+ }
+
+ /**
+ * @return the peak number of live threads
+ * @see #getPeakThreadCount()
+ */
+ private native int getPeakThreadCountImpl();
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.management.ThreadMXBean#getPeakThreadCount()
+ */
+ public int getPeakThreadCount() {
+ return this.getPeakThreadCountImpl();
+ }
+
+ /**
+ * @return the number of currently alive threads.
+ * @see #getThreadCount()
+ */
+ private native int getThreadCountImpl();
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.management.ThreadMXBean#getThreadCount()
+ */
+ public int getThreadCount() {
+ return this.getThreadCountImpl();
+ }
+
+ /**
+ * @param id
+ * the identifier for a thread. Must be a positive number greater
+ * than zero.
+ * @return on virtual machines where thread CPU timing is supported and
+ * enabled, and there is a living thread with identifier
+ * <code>id</code>, the number of nanoseconds CPU time used by
+ * the thread. On virtual machines where thread CPU timing is
+ * supported but not enabled, or where there is no living thread
+ * with identifier <code>id</code> present in the virtual machine,
+ * a value of <code>-1</code> is returned.
+ * @see #getThreadCpuTime(long)
+ */
+ private native long getThreadCpuTimeImpl(long id);
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.management.ThreadMXBean#getThreadCpuTime(long)
+ */
+ public long getThreadCpuTime(long id) {
+ // Validate input.
+ if (id <= 0) {
+ throw new IllegalArgumentException(
+ "Thread id must be greater than 0.");
+ }
+
+ long result = -1;
+ if (isThreadCpuTimeSupported()) {
+ if (isThreadCpuTimeEnabled()) {
+ result = this.getThreadCpuTimeImpl(id);
+ }
+ } else {
+ throw new UnsupportedOperationException(
+ "CPU time measurement is not supported on this virtual machine.");
+ }
+ return result;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.management.ThreadMXBean#getThreadInfo(long)
+ */
+ public ThreadInfo getThreadInfo(long id) {
+ return getThreadInfo(id, 0);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.management.ThreadMXBean#getThreadInfo(long[])
+ */
+ public ThreadInfo[] getThreadInfo(long[] ids) {
+ return getThreadInfo(ids, 0);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.management.ThreadMXBean#getThreadInfo(long[], int)
+ */
+ public ThreadInfo[] getThreadInfo(long[] ids, int maxDepth) {
+ SecurityManager security = System.getSecurityManager();
+ if (security != null) {
+ security.checkPermission(new ManagementPermission("monitor"));
+ }
+
+ // Validate inputs
+ for (int i = 0; i < ids.length; i++) {
+ if (ids[i] <= 0) {
+ throw new IllegalArgumentException(
+ "Thread id must be greater than 0.");
+ }
+ }
+
+ if (maxDepth < 0) {
+ throw new IllegalArgumentException(
+ "maxDepth value cannot be negative.");
+ }
+
+ // Create an array and populate with individual ThreadInfos
+ ThreadInfo[] tis = new ThreadInfo[ids.length];
+ for (int i = 0; i < ids.length; i++) {
+ tis[i] = this.getThreadInfoImpl(ids[i], maxDepth);
+ }
+ return tis;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.management.ThreadMXBean#getThreadInfo(long, int)
+ */
+ public ThreadInfo getThreadInfo(long id, int maxDepth) {
+ SecurityManager security = System.getSecurityManager();
+ if (security != null) {
+ security.checkPermission(new ManagementPermission("monitor"));
+ }
+
+ // Validate inputs
+ if (id <= 0) {
+ throw new IllegalArgumentException(
+ "Thread id must be greater than 0.");
+ }
+ if (maxDepth < 0) {
+ throw new IllegalArgumentException(
+ "maxDepth value cannot be negative.");
+ }
+ return this.getThreadInfoImpl(id, maxDepth);
+ }
+
+ /**
+ * Returns the corresponding Thread instance for a given thread id
+ *
+ * @param id
+ * id of the thread (must be > 0)
+ * @return null if thread with the id specified does not exist
+ */
+ private native Thread getThreadByIdImpl(long id);
+
+ /**
+ * Returns the object the thread is either blocked or waiting on
+ *
+ * @param thread
+ * thread
+ * @return null if thread not blocked on an object
+ */
+ private native Object getObjectThreadIsBlockedOnImpl(Thread thread);
+
+ /**
+ * Returns the thread owning an object
+ *
+ * @param obj
+ * object
+ * @return null if object not owned, else Thread owner
+ */
+ private native Thread getThreadOwningObjectImpl(Object obj);
+
+ /**
+ * Returns whether the thread is suspended or not
+ *
+ * @param thread
+ * thread
+ * @return true if Thread.suspend() has been called on the thread, otherwise
+ * false
+ */
+ private native boolean isSuspendedImpl(Thread thread);
+
+ /**
+ * Returns the number of times the thread has waited
+ *
+ * @param thread
+ * thread
+ * @return number of times the thread has waited
+ *
+ */
+ private native long getThreadWaitedCountImpl(Thread thread);
+
+ /**
+ * Returns the amount of time the thread has waited (in milliseconds)
+ *
+ * @param thread
+ * thread
+ * @return time (in milliseconds) the thread has waited, or -1 if this
+ * feature is not supported
+ *
+ */
+ private native long getThreadWaitedTimeImpl(Thread thread);
+
+ /**
+ * Returns the amount of time the thread has blocked (in milliseconds)
+ *
+ * @param thread
+ * thread
+ * @return time (in milliseconds) the thread has blocked, or -1 if this
+ * feature is not supported
+ *
+ */
+ private native long getThreadBlockedTimeImpl(Thread thread);
+
+ /**
+ * Returns the number of times the thread has blocked on a monitor
+ *
+ * @param thread
+ * thread
+ * @return number of times the thread has blocked
+ *
+ */
+ private native long getThreadBlockedCountImpl(Thread thread);
+
+ /**
+ * Create an instance of the ThreadInfo class
+ *
+ * @param threadId
+ * @param threadName
+ * @param threadState
+ * @param suspended
+ * @param inNative
+ * @param blockedCount
+ * @param blockedTime
+ * @param waitedCount
+ * @param waitedTime
+ * @param lockName
+ * @param lockOwnerId
+ * @param lockOwnerName
+ * @param stackTrace
+ * @return
+ */
+ private native ThreadInfo createThreadInfoImpl(long threadId,
+ String threadName, Thread.State threadState, boolean suspended,
+ boolean inNative, long blockedCount, long blockedTime,
+ long waitedCount, long waitedTime, String lockName,
+ long lockOwnerId, String lockOwnerName,
+ StackTraceElement[] stackTrace);
+
+ /*
+ * Get together information for a thread and create an instance of the
+ * ThreadInfo class
+ *
+ * @param id thread id @param maxDepth maximum depth of the stack trace
+ * @return an instance of ThreadInfo for valid thread ids, otherwise null
+ *
+ */
+ private ThreadInfo getThreadInfoImpl(long id, int maxDepth) {
+ final Thread thread = getThreadByIdImpl(id);
+ if (null == thread) {
+ return null;
+ }
+
+ // Generic thread info
+ long threadId = thread.getId();
+ String threadName = thread.getName();
+ Thread.State threadState = thread.getState();
+
+ // Waited and blocked information
+ long waitedTime = -1;
+ long blockedTime = -1;
+ // Waited and blocked times to be -1 if ThreadContentionMonitoring
+ // is not supported
+ if (isThreadContentionMonitoringSupported()
+ && isThreadContentionMonitoringEnabled()) {
+ waitedTime = getThreadWaitedTimeImpl(thread);
+ blockedTime = getThreadBlockedTimeImpl(thread);
+ }
+
+ // Get together information about any locks involved
+ // i.e. thread blocked or waiting on a lock
+ // see ThreadInfo spec for values if neither blocked nor waiting
+ String lockName = null;
+ long lockOwnerId = -1;
+ String lockOwnerName = null;
+
+ Object lock = getObjectThreadIsBlockedOnImpl(thread);
+ if (lock != null) {
+ // the format of the name is dictated by the ThreadInfo spec
+ lockName = lock.getClass().getName() + '@'
+ + Integer.toHexString(System.identityHashCode(lock));
+ Thread threadOwningLock = getThreadOwningObjectImpl(lock);
+ // Possible race conditions must be catered for
+ if (threadOwningLock != null) {
+ lockOwnerId = threadOwningLock.getId();
+ lockOwnerName = threadOwningLock.getName();
+ }// end if non-null thread owning lock
+ }// end if non-null lock
+
+ // Get the stack trace together.
+ // Do we have to prune it for max depth?
+ StackTraceElement[] stackTrace = AccessController
+ .doPrivileged(new PrivilegedAction<StackTraceElement[]>() {
+ public StackTraceElement[] run() {
+ return thread.getStackTrace();
+ }// end method run
+ });
+
+ boolean isInNative = false;
+ if (stackTrace.length > 0) {
+ isInNative = stackTrace[0].isNativeMethod();
+ }
+ if ((maxDepth < Integer.MAX_VALUE) && (stackTrace.length > maxDepth)) {
+ StackTraceElement[] newStackTrace = new StackTraceElement[maxDepth];
+ for (int i = 0; i < newStackTrace.length; i++) {
+ newStackTrace[i] = stackTrace[i];
+ }
+ stackTrace = newStackTrace;
+ }
+
+ // Ask our native to instantiate a ThreadInfo for us
+ ThreadInfo ti = createThreadInfoImpl(threadId, threadName, threadState,
+ isSuspendedImpl(thread), isInNative,
+ getThreadBlockedCountImpl(thread), blockedTime,
+ getThreadWaitedCountImpl(thread), waitedTime, lockName,
+ lockOwnerId, lockOwnerName, stackTrace);
+ return ti;
+ }
+
+ /**
+ * @param id
+ * the identifier for a thread. Must be a positive number greater
+ * than zero.
+ * @return on virtual machines where thread CPU timing is supported and
+ * enabled, and there is a living thread with identifier
+ * <code>id</code>, the number of nanoseconds CPU time used by
+ * the thread running in user mode. On virtual machines where thread
+ * CPU timing is supported but not enabled, or where there is no
+ * living thread with identifier <code>id</code> present in the
+ * virtual machine, a value of <code>-1</code> is returned.
+ * <p>
+ * If thread CPU timing was disabled when the thread was started
+ * then the virtual machine is free to choose any measurement start
+ * time between when the virtual machine started up and when thread
+ * CPU timing was enabled with a call to
+ * {@link #setThreadCpuTimeEnabled(boolean)}.
+ * </p>
+ * @see #getThreadUserTime(long)
+ */
+ private native long getThreadUserTimeImpl(long id);
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.management.ThreadMXBean#getThreadUserTime(long)
+ */
+ public long getThreadUserTime(long id) {
+ // Validate input.
+ if (id <= 0) {
+ throw new IllegalArgumentException(
+ "Thread id must be greater than 0.");
+ }
+
+ long result = -1;
+ if (isThreadCpuTimeSupported()) {
+ if (isThreadCpuTimeEnabled()) {
+ result = this.getThreadUserTimeImpl(id);
+ }
+ } else {
+ throw new UnsupportedOperationException(
+ "CPU time measurement is not supported on this virtual machine.");
+ }
+ return result;
+ }
+
+ /**
+ * @return the total number of started threads.
+ * @see #getTotalStartedThreadCount()
+ */
+ private native long getTotalStartedThreadCountImpl();
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.management.ThreadMXBean#getTotalStartedThreadCount()
+ */
+ public long getTotalStartedThreadCount() {
+ return this.getTotalStartedThreadCountImpl();
+ }
+
+ /**
+ * @return <code>true</code> if CPU timing of the current thread is
+ * supported, otherwise <code>false</code>.
+ * @see #isCurrentThreadCpuTimeSupported()
+ */
+ private native boolean isCurrentThreadCpuTimeSupportedImpl();
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.management.ThreadMXBean#isCurrentThreadCpuTimeSupported()
+ */
+ public boolean isCurrentThreadCpuTimeSupported() {
+ return this.isCurrentThreadCpuTimeSupportedImpl();
+ }
+
+ /**
+ * @return <code>true</code> if thread contention monitoring is enabled,
+ * <code>false</code> otherwise.
+ * @see #isThreadContentionMonitoringEnabled()
+ */
+ private native boolean isThreadContentionMonitoringEnabledImpl();
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.management.ThreadMXBean#isThreadContentionMonitoringEnabled()
+ */
+ public boolean isThreadContentionMonitoringEnabled() {
+ if (!isThreadContentionMonitoringSupported()) {
+ throw new UnsupportedOperationException(
+ "Thread contention monitoring is not supported on this virtual machine.");
+ }
+ return this.isThreadContentionMonitoringEnabledImpl();
+ }
+
+ /**
+ * @return <code>true</code> if thread contention monitoring is supported,
+ * <code>false</code> otherwise.
+ * @see #isThreadContentionMonitoringSupported()
+ */
+ private native boolean isThreadContentionMonitoringSupportedImpl();
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.management.ThreadMXBean#isThreadContentionMonitoringSupported()
+ */
+ public boolean isThreadContentionMonitoringSupported() {
+ return this.isThreadContentionMonitoringSupportedImpl();
+ }
+
+ /**
+ * @return <code>true</code> if thread CPU timing is enabled,
+ * <code>false</code> otherwise.
+ * @see #isThreadCpuTimeEnabled()
+ */
+ private native boolean isThreadCpuTimeEnabledImpl();
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.management.ThreadMXBean#isThreadCpuTimeEnabled()
+ */
+ public boolean isThreadCpuTimeEnabled() {
+ if (!isThreadCpuTimeSupported()) {
+ throw new UnsupportedOperationException(
+ "Thread CPU timing is not supported on this virtual machine.");
+ }
+ return this.isThreadCpuTimeEnabledImpl();
+ }
+
+ /**
+ * @return <code>true</code> if the virtual machine supports the CPU
+ * timing of threads, <code>false</code> otherwise.
+ * @see #isThreadCpuTimeSupported()
+ */
+ private native boolean isThreadCpuTimeSupportedImpl();
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.management.ThreadMXBean#isThreadCpuTimeSupported()
+ */
+ public boolean isThreadCpuTimeSupported() {
+ return this.isThreadCpuTimeSupportedImpl();
+ }
+
+ /**
+ * @see #resetPeakThreadCount()
+ */
+ private native void resetPeakThreadCountImpl();
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.management.ThreadMXBean#resetPeakThreadCount()
+ */
+ public void resetPeakThreadCount() {
+ SecurityManager security = System.getSecurityManager();
+ if (security != null) {
+ security.checkPermission(new ManagementPermission("control"));
+ }
+ this.resetPeakThreadCountImpl();
+ }
+
+ /**
+ * @param enable
+ * enable thread contention monitoring if <code>true</code>,
+ * otherwise disable thread contention monitoring.
+ */
+ private native void setThreadContentionMonitoringEnabledImpl(boolean enable);
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.management.ThreadMXBean#setThreadContentionMonitoringEnabled(boolean)
+ */
+ public void setThreadContentionMonitoringEnabled(boolean enable) {
+ if (!isThreadContentionMonitoringSupported()) {
+ throw new UnsupportedOperationException(
+ "Thread contention monitoring is not supported on this virtual machine.");
+ }
+
+ SecurityManager security = System.getSecurityManager();
+ if (security != null) {
+ security.checkPermission(new ManagementPermission("control"));
+ }
+ this.setThreadContentionMonitoringEnabledImpl(enable);
+ }
+
+ /**
+ * @param enable
+ * enable thread CPU timing if <code>true</code>, otherwise
+ * disable thread CPU timing
+ */
+ private native void setThreadCpuTimeEnabledImpl(boolean enable);
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.lang.management.ThreadMXBean#setThreadCpuTimeEnabled(boolean)
+ */
+ public void setThreadCpuTimeEnabled(boolean enable) {
+ if (!isThreadCpuTimeSupported()) {
+ throw new UnsupportedOperationException(
+ "Thread CPU timing is not supported on this virtual machine.");
+ }
+
+ SecurityManager security = System.getSecurityManager();
+ if (security != null) {
+ security.checkPermission(new ManagementPermission("control"));
+ }
+ this.setThreadCpuTimeEnabledImpl(enable);
+ }
+}
Propchange: harmony/enhanced/classlib/trunk/modules/lang-management/src/main/java/com/ibm/lang/management/ThreadMXBeanImpl.java
------------------------------------------------------------------------------
svn:eol-style = native