/* * Copyright (c) 2003, 2008, 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.jmx.remote.util; import java.io.IOException; import java.io.ObjectOutputStream; import java.io.OutputStream; import java.util.Collection; import java.util.HashMap; import java.util.Hashtable; import java.util.Iterator; import java.util.Map; import java.util.SortedMap; import java.util.SortedSet; import java.util.StringTokenizer; import java.util.TreeMap; import java.util.TreeSet; import java.security.AccessController; import javax.management.ObjectName; import javax.management.MBeanServer; import javax.management.InstanceNotFoundException; import javax.management.remote.JMXConnectorFactory; import javax.management.remote.JMXConnectorServerFactory; import com.sun.jmx.mbeanserver.GetPropertyAction; import com.sun.jmx.remote.security.NotificationAccessController; import javax.management.remote.JMXConnector; import javax.management.remote.JMXConnectorServer; public class EnvHelp { /** *
Name of the attribute that specifies a default class loader * object. * The value associated with this attribute is a ClassLoader object
*/ private static final String DEFAULT_CLASS_LOADER = JMXConnectorFactory.DEFAULT_CLASS_LOADER; /** *Name of the attribute that specifies a default class loader * ObjectName. * The value associated with this attribute is an ObjectName object
*/ private static final String DEFAULT_CLASS_LOADER_NAME = JMXConnectorServerFactory.DEFAULT_CLASS_LOADER_NAME; /** * Get the Connector Server default class loader. ** Returns: *
*
jmx.remote.default.class.loader
, if any.
* jmx.remote.default.class.loader.name
,
* and registered in mbs if any.
* jmx.remote.default.class.loader
and
* jmx.remote.default.class.loader.name
are specified,
* jmx.remote.default.class.loader
is not
* an instance of {@link ClassLoader},
* jmx.remote.default.class.loader.name
is not
* an instance of {@link ObjectName},
* jmx.remote.default.class.loader.name
is specified
* but mbs is null.
* jmx.remote.default.class.loader.name
is specified
* and the ClassLoader MBean is not found in mbs.
*/
public static ClassLoader resolveServerClassLoader(Map* Returns: *
*
jmx.remote.default.class.loader
, if any.
* * Usually a Connector Client will call *
* ClassLoader dcl = EnvHelp.resolveClientClassLoader(env); ** in its
connect(Map env)
method.
*
* @return The connector client default class loader.
*
* @exception IllegalArgumentException if
* jmx.remote.default.class.loader
is specified
* and is not an instance of {@link ClassLoader}.
*/
public static ClassLoader resolveClientClassLoader(MapName of the attribute that specifies the size of a notification
* buffer for a connector server. The default value is 1000.
*/
public static final String BUFFER_SIZE_PROPERTY =
"jmx.remote.x.notification.buffer.size";
/**
* Returns the size of a notification buffer for a connector server.
* The default value is 1000.
*/
public static int getNotifBufferSize(Map Name of the attribute that specifies the maximum number of
* notifications that a client will fetch from its server.. The
* value associated with this attribute should be an
* Name of the attribute that specifies the timeout for a
* client to fetch notifications from its server. The value
* associated with this attribute should be a Name of the attribute that specifies an object that will check
* accesses to add/removeNotificationListener and also attempts to
* receive notifications. The value associated with this attribute
* should be a Name of the attribute that specifies the timeout to keep a
* server side connection after answering last client request.
* The default value is 120000 milliseconds. Name of the attribute that specifies the period in
* millisecond for a client to check its connection. The default
* value is 60000 milliseconds. Name of the attribute that specifies whether a connector server
* should not prevent the VM from exiting
*/
public static final String JMX_SERVER_DAEMON = "jmx.remote.x.daemon";
/**
* Returns true if {@value SERVER_DAEMON} is specified in the {@code env}
* as a key and its value is a String and it is equal to true ignoring case.
*
* @param env
* @return
*/
public static boolean isServerDaemon(MapInteger
object. The default value is 1000.Long
* object. The default value is 60000 milliseconds.NotificationAccessController
object.
* The default value is null.name
* from env
. If env
is null, or does
* not contain an entry for name
, return
* defaultValue
. The value may be a Number, or it
* may be a String that is parsable as a long. It must be at
* least minValue
and at mostmaxValue
.
*
* @throws IllegalArgumentException if env
contains
* an entry for name
but it does not meet the
* constraints above.
*/
public static long getIntegerAttribute(Map
*
*
* @throws IllegalArgumentException if
* {@code ((String)env.get(prop)).equalsIgnoreCase("false")} and
* {@code ((String)env.get(prop)).equalsIgnoreCase("true")} are
* {@code false}.
*/
public static boolean computeBooleanFromString(String stringBoolean) {
// returns a default value of 'false' if no property is found...
return computeBooleanFromString(stringBoolean,false);
}
/**
* Computes a boolean value from a string value retrieved from a
* property in the given map.
*
* @param stringBoolean the string value that must be converted
* into a boolean value.
* @param defaultValue a default value to return in case no property
* was defined.
*
* @return
*
*
*
* @throws IllegalArgumentException if
* {@code ((String)env.get(prop)).equalsIgnoreCase("false")} and
* {@code ((String)env.get(prop)).equalsIgnoreCase("true")} are
* {@code false}.
*/
public static boolean computeBooleanFromString( String stringBoolean, boolean defaultValue) {
if (stringBoolean == null)
return defaultValue;
else if (stringBoolean.equalsIgnoreCase("true"))
return true;
else if (stringBoolean.equalsIgnoreCase("false"))
return false;
else
throw new IllegalArgumentException(
"Property value must be \"true\" or \"false\" instead of \"" +
stringBoolean + "\"");
}
/**
* Converts a map into a valid hash table, i.e.
* it removes all the 'null' values from the map.
*/
public static