jdk/src/share/classes/com/sun/jmx/remote/util/EnvHelp.java
author duke
Sat, 01 Dec 2007 00:00:00 +0000
changeset 2 90ce3da70b43
child 1004 5ba8217eb504
permissions -rw-r--r--
Initial load
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * Copyright 2003-2006 Sun Microsystems, Inc.  All Rights Reserved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package com.sun.jmx.remote.util;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.io.ObjectOutputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.io.OutputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.util.Collection;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.util.HashMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.util.Hashtable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.util.Iterator;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.util.Map;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.util.SortedMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.util.SortedSet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.util.StringTokenizer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.util.TreeMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import java.util.TreeSet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import java.security.AccessController;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import java.security.PrivilegedAction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
import java.security.PrivilegedActionException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
import java.security.PrivilegedExceptionAction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
import javax.management.ObjectName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
import javax.management.MBeanServer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
import javax.management.InstanceNotFoundException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
import javax.management.remote.JMXConnectorFactory;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
import javax.management.remote.JMXConnectorServerFactory;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
import com.sun.jmx.mbeanserver.GetPropertyAction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
public class EnvHelp {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
     * <p>Name of the attribute that specifies a default class loader
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
     * object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
     * The value associated with this attribute is a ClassLoader object</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    private static final String DEFAULT_CLASS_LOADER =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
        JMXConnectorFactory.DEFAULT_CLASS_LOADER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
     * <p>Name of the attribute that specifies a default class loader
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
     *    ObjectName.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
     * The value associated with this attribute is an ObjectName object</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    private static final String DEFAULT_CLASS_LOADER_NAME =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        JMXConnectorServerFactory.DEFAULT_CLASS_LOADER_NAME;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     * Get the Connector Server default class loader.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     * Returns:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     * <li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     *     The ClassLoader object found in <var>env</var> for
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     *     <code>jmx.remote.default.class.loader</code>, if any.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     * </li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     * <li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     *     The ClassLoader pointed to by the ObjectName found in
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     *     <var>env</var> for <code>jmx.remote.default.class.loader.name</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     *     and registered in <var>mbs</var> if any.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     * </li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     * <li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     *     The current thread's context classloader otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     * </li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     * @param env Environment attributes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     * @param mbs The MBeanServer for which the connector server provides
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     * remote access.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     * @return the connector server's default class loader.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     * @exception IllegalArgumentException if one of the following is true:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     * <li>both
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     *     <code>jmx.remote.default.class.loader</code> and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     *     <code>jmx.remote.default.class.loader.name</code> are specified,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     * </li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     * <li>or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     *     <code>jmx.remote.default.class.loader</code> is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     *     an instance of {@link ClassLoader},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     * </li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     * <li>or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     *     <code>jmx.remote.default.class.loader.name</code> is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     *     an instance of {@link ObjectName},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     * </li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     * <li>or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     *     <code>jmx.remote.default.class.loader.name</code> is specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     *     but <var>mbs</var> is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     * </li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     * @exception InstanceNotFoundException if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     * <code>jmx.remote.default.class.loader.name</code> is specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     * and the ClassLoader MBean is not found in <var>mbs</var>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    public static ClassLoader resolveServerClassLoader(Map env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
                                                       MBeanServer mbs)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        throws InstanceNotFoundException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        if (env == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
            return Thread.currentThread().getContextClassLoader();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        Object loader = env.get(DEFAULT_CLASS_LOADER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        Object name   = env.get(DEFAULT_CLASS_LOADER_NAME);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        if (loader != null && name != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
            final String msg = "Only one of " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
                DEFAULT_CLASS_LOADER + " or " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
                DEFAULT_CLASS_LOADER_NAME +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
                " should be specified.";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
            throw new IllegalArgumentException(msg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        if (loader == null && name == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
            return Thread.currentThread().getContextClassLoader();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        if (loader != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
            if (loader instanceof ClassLoader) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
                return (ClassLoader) loader;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
                final String msg =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
                    "ClassLoader object is not an instance of " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
                    ClassLoader.class.getName() + " : " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
                    loader.getClass().getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
                throw new IllegalArgumentException(msg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        ObjectName on;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        if (name instanceof ObjectName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
            on = (ObjectName) name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
            final String msg =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
                "ClassLoader name is not an instance of " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
                ObjectName.class.getName() + " : " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
                name.getClass().getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
            throw new IllegalArgumentException(msg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        if (mbs == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
            throw new IllegalArgumentException("Null MBeanServer object");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        return mbs.getClassLoader(on);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     * Get the Connector Client default class loader.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     * Returns:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     * <li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     *     The ClassLoader object found in <var>env</var> for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     *     <code>jmx.remote.default.class.loader</code>, if any.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     * </li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     * <li>The <tt>Thread.currentThread().getContextClassLoader()</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     *     otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     * </li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     * Usually a Connector Client will call
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     * ClassLoader dcl = EnvHelp.resolveClientClassLoader(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     * in its <code>connect(Map env)</code> method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     * @return The connector client default class loader.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     * @exception IllegalArgumentException if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     * <code>jmx.remote.default.class.loader</code> is specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     * and is not an instance of {@link ClassLoader}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    public static ClassLoader resolveClientClassLoader(Map env) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        if (env == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
            return Thread.currentThread().getContextClassLoader();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        Object loader = env.get(DEFAULT_CLASS_LOADER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        if (loader == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
            return Thread.currentThread().getContextClassLoader();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        if (loader instanceof ClassLoader) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
            return (ClassLoader) loader;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
            final String msg =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
                "ClassLoader object is not an instance of " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
                ClassLoader.class.getName() + " : " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
                loader.getClass().getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
            throw new IllegalArgumentException(msg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     * Initialize the cause field of a {@code Throwable} object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     * @param throwable The {@code Throwable} on which the cause is set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     * @param cause The cause to set on the supplied {@code Throwable}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     * @return the {@code Throwable} with the cause field initialized.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    public static <T extends Throwable> T initCause(T throwable,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
                                                    Throwable cause) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        throwable.initCause(cause);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        return throwable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     * Returns the cause field of a {@code Throwable} object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     * The cause field can be got only if <var>t</var> has an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     * {@link Throwable#getCause()} method (JDK Version >= 1.4)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     * @param t {@code Throwable} on which the cause must be set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     * @return the cause if getCause() succeeded and the got value is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     * null, otherwise return the <var>t</var>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    public static Throwable getCause(Throwable t) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        Throwable ret = t;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
            java.lang.reflect.Method getCause =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
                t.getClass().getMethod("getCause", (Class[]) null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
            ret = (Throwable)getCause.invoke(t, (Object[]) null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
            // OK.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
            // it must be older than 1.4.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        return (ret != null) ? ret: t;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     * <p>Name of the attribute that specifies the size of a notification
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     * buffer for a connector server. The default value is 1000.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
    public static final String BUFFER_SIZE_PROPERTY =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        "jmx.remote.x.notification.buffer.size";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     * Returns the size of a notification buffer for a connector server.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     * The default value is 1000.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
    public static int getNotifBufferSize(Map env) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        int defaultQueueSize = 1000; // default value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        // keep it for the compability for the fix:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
        // 6174229: Environment parameter should be notification.buffer.size
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        // instead of buffer.size
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
        final String oldP = "jmx.remote.x.buffer.size";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        // the default value re-specified in the system
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
            GetPropertyAction act = new GetPropertyAction(BUFFER_SIZE_PROPERTY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
            String s = AccessController.doPrivileged(act);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
            if (s != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
                defaultQueueSize = Integer.parseInt(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
            } else { // try the old one
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
                act = new GetPropertyAction(oldP);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
                s = AccessController.doPrivileged(act);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
                if (s != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
                    defaultQueueSize = Integer.parseInt(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
        } catch (RuntimeException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
            logger.warning("getNotifBufferSize",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
                           "Can't use System property "+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
                           BUFFER_SIZE_PROPERTY+ ": " + e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
              logger.debug("getNotifBufferSize", e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
        int queueSize = defaultQueueSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
            if (env.containsKey(BUFFER_SIZE_PROPERTY)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
                queueSize = (int)EnvHelp.getIntegerAttribute(env,BUFFER_SIZE_PROPERTY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
                                            defaultQueueSize,0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
                                            Integer.MAX_VALUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
            } else { // try the old one
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
                queueSize = (int)EnvHelp.getIntegerAttribute(env,oldP,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
                                            defaultQueueSize,0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
                                            Integer.MAX_VALUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
        } catch (RuntimeException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
            logger.warning("getNotifBufferSize",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
                           "Can't determine queuesize (using default): "+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
                           e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
            logger.debug("getNotifBufferSize", e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
        return queueSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
     * <p>Name of the attribute that specifies the maximum number of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
     * notifications that a client will fetch from its server.. The
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
     * value associated with this attribute should be an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
     * <code>Integer</code> object.  The default value is 1000.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
    public static final String MAX_FETCH_NOTIFS =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
        "jmx.remote.x.notification.fetch.max";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
     * Returns the maximum notification number which a client will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
     * fetch every time.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
    public static int getMaxFetchNotifNumber(Map env) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
        return (int) getIntegerAttribute(env, MAX_FETCH_NOTIFS, 1000, 1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
                                         Integer.MAX_VALUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
     * <p>Name of the attribute that specifies the timeout for a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
     * client to fetch notifications from its server. The value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
     * associated with this attribute should be a <code>Long</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
     * object.  The default value is 60000 milliseconds.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
    public static final String FETCH_TIMEOUT =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
        "jmx.remote.x.notification.fetch.timeout";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
     * Returns the timeout for a client to fetch notifications.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
    public static long getFetchTimeout(Map env) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
        return getIntegerAttribute(env, FETCH_TIMEOUT, 60000L, 0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
                                   Long.MAX_VALUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
     * Get an integer-valued attribute with name <code>name</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
     * from <code>env</code>.  If <code>env</code> is null, or does
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
     * not contain an entry for <code>name</code>, return
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
     * <code>defaultValue</code>.  The value may be a Number, or it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
     * may be a String that is parsable as a long.  It must be at
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
     * least <code>minValue</code> and at most<code>maxValue</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
     * @throws IllegalArgumentException if <code>env</code> contains
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
     * an entry for <code>name</code> but it does not meet the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
     * constraints above.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
    public static long getIntegerAttribute(Map env, String name,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
                                           long defaultValue, long minValue,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
                                           long maxValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
        final Object o;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
        if (env == null || (o = env.get(name)) == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
            return defaultValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
        final long result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
        if (o instanceof Number)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
            result = ((Number) o).longValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
        else if (o instanceof String) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
            result = Long.parseLong((String) o);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
            /* May throw a NumberFormatException, which is an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
               IllegalArgumentException.  */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
            final String msg =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
                "Attribute " + name + " value must be Integer or String: " + o;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
            throw new IllegalArgumentException(msg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
        if (result < minValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
            final String msg =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
                "Attribute " + name + " value must be at least " + minValue +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
                ": " + result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
            throw new IllegalArgumentException(msg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
        if (result > maxValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
            final String msg =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
                "Attribute " + name + " value must be at most " + maxValue +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
                ": " + result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
            throw new IllegalArgumentException(msg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
        return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
    public static final String DEFAULT_ORB="java.naming.corba.orb";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
    /* Check that all attributes have a key that is a String.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
       Could make further checks, e.g. appropriate types for attributes.  */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
    public static void checkAttributes(Map attributes) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
        for (Iterator it = attributes.keySet().iterator(); it.hasNext(); ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
            Object key = it.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
            if (!(key instanceof String)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
                final String msg =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
                    "Attributes contain key that is not a string: " + key;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
                throw new IllegalArgumentException(msg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
    /* Return a writable map containing only those attributes that are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
       serializable, and that are not hidden by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
       jmx.remote.x.hidden.attributes or the default list of hidden
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
       attributes.  */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
    public static <V> Map<String, V> filterAttributes(Map<String, V> attributes) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
        if (logger.traceOn()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
            logger.trace("filterAttributes", "starts");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
        SortedMap<String, V> map = new TreeMap<String, V>(attributes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
        purgeUnserializable(map.values());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
        hideAttributes(map);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
        return map;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
     * Remove from the given Collection any element that is not a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
     * serializable object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
    private static void purgeUnserializable(Collection<?> objects) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
        logger.trace("purgeUnserializable", "starts");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
        ObjectOutputStream oos = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
        int i = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
        for (Iterator it = objects.iterator(); it.hasNext(); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
            Object v = it.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
            if (v == null || v instanceof String) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
                if (logger.traceOn()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
                    logger.trace("purgeUnserializable",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
                                 "Value trivially serializable: " + v);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
                continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
                if (oos == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
                    oos = new ObjectOutputStream(new SinkOutputStream());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
                oos.writeObject(v);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
                if (logger.traceOn()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
                    logger.trace("purgeUnserializable",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
                                 "Value serializable: " + v);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
            } catch (IOException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
                if (logger.traceOn()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
                    logger.trace("purgeUnserializable",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
                                 "Value not serializable: " + v + ": " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
                                 e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
                it.remove();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
                oos = null; // ObjectOutputStream invalid after exception
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
       The value of this attribute, if present, is a string specifying
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
       what other attributes should not appear in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
       JMXConnectorServer.getAttributes().  It is a space-separated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
       list of attribute patterns, where each pattern is either an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
       attribute name, or an attribute prefix followed by a "*"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
       character.  The "*" has no special significance anywhere except
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
       at the end of a pattern.  By default, this list is added to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
       list defined by {@link #DEFAULT_HIDDEN_ATTRIBUTES} (which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
       uses the same format).  If the value of this attribute begins
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
       with an "=", then the remainder of the string defines the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
       complete list of attribute patterns.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
    public static final String HIDDEN_ATTRIBUTES =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
        "jmx.remote.x.hidden.attributes";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
       Default list of attributes not to show.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
       @see #HIDDEN_ATTRIBUTES
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
    /* This list is copied directly from the spec, plus
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
       java.naming.security.*.  Most of the attributes here would have
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
       been eliminated from the map anyway because they are typically
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
       not serializable.  But just in case they are, we list them here
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
       to conform to the spec.  */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
    public static final String DEFAULT_HIDDEN_ATTRIBUTES =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
        "java.naming.security.* " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
        "jmx.remote.authenticator " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
        "jmx.remote.context " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
        "jmx.remote.default.class.loader " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
        "jmx.remote.message.connection.server " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
        "jmx.remote.object.wrapping " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
        "jmx.remote.rmi.client.socket.factory " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
        "jmx.remote.rmi.server.socket.factory " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
        "jmx.remote.sasl.callback.handler " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
        "jmx.remote.tls.socket.factory " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
        "jmx.remote.x.access.file " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
        "jmx.remote.x.password.file ";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
    private static final SortedSet<String> defaultHiddenStrings =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
            new TreeSet<String>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
    private static final SortedSet<String> defaultHiddenPrefixes =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
            new TreeSet<String>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
    private static void hideAttributes(SortedMap<String, ?> map) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
        if (map.isEmpty())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
        final SortedSet<String> hiddenStrings;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
        final SortedSet<String> hiddenPrefixes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
        String hide = (String) map.get(HIDDEN_ATTRIBUTES);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
        if (hide != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
            if (hide.startsWith("="))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
                hide = hide.substring(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
            else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
                hide += " " + DEFAULT_HIDDEN_ATTRIBUTES;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
            hiddenStrings = new TreeSet<String>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
            hiddenPrefixes = new TreeSet<String>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
            parseHiddenAttributes(hide, hiddenStrings, hiddenPrefixes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
            hide = DEFAULT_HIDDEN_ATTRIBUTES;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
            synchronized (defaultHiddenStrings) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
                if (defaultHiddenStrings.isEmpty()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
                    parseHiddenAttributes(hide,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
                                          defaultHiddenStrings,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
                                          defaultHiddenPrefixes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
                hiddenStrings = defaultHiddenStrings;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
                hiddenPrefixes = defaultHiddenPrefixes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
        /* Construct a string that is greater than any key in the map.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
           Setting a string-to-match or a prefix-to-match to this string
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
           guarantees that we will never call next() on the corresponding
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
           iterator.  */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
        String sentinelKey = map.lastKey() + "X";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
        Iterator keyIterator = map.keySet().iterator();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
        Iterator stringIterator = hiddenStrings.iterator();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
        Iterator prefixIterator = hiddenPrefixes.iterator();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
        String nextString;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
        if (stringIterator.hasNext())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
            nextString = (String) stringIterator.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
            nextString = sentinelKey;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
        String nextPrefix;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
        if (prefixIterator.hasNext())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
            nextPrefix = (String) prefixIterator.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
            nextPrefix = sentinelKey;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
        /* Read each key in sorted order and, if it matches a string
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
           or prefix, remove it. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
    keys:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
        while (keyIterator.hasNext()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
            String key = (String) keyIterator.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
            /* Continue through string-match values until we find one
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
               that is either greater than the current key, or equal
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
               to it.  In the latter case, remove the key.  */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
            int cmp = +1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
            while ((cmp = nextString.compareTo(key)) < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
                if (stringIterator.hasNext())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
                    nextString = (String) stringIterator.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
                else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
                    nextString = sentinelKey;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
            if (cmp == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
                keyIterator.remove();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
                continue keys;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
            /* Continue through the prefix values until we find one
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
               that is either greater than the current key, or a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
               prefix of it.  In the latter case, remove the key.  */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
            while (nextPrefix.compareTo(key) <= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
                if (key.startsWith(nextPrefix)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
                    keyIterator.remove();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
                    continue keys;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
                if (prefixIterator.hasNext())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
                    nextPrefix = (String) prefixIterator.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
                else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
                    nextPrefix = sentinelKey;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
    private static void parseHiddenAttributes(String hide,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
                                              SortedSet<String> hiddenStrings,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
                                              SortedSet<String> hiddenPrefixes) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
        final StringTokenizer tok = new StringTokenizer(hide);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
        while (tok.hasMoreTokens()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
            String s = tok.nextToken();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
            if (s.endsWith("*"))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
                hiddenPrefixes.add(s.substring(0, s.length() - 1));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
            else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
                hiddenStrings.add(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
     * <p>Name of the attribute that specifies the timeout to keep a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
     * server side connection after answering last client request.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
     * The default value is 120000 milliseconds.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
    public static final String SERVER_CONNECTION_TIMEOUT =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
        "jmx.remote.x.server.connection.timeout";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
     * Returns the server side connection timeout.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
    public static long getServerConnectionTimeout(Map env) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
        return getIntegerAttribute(env, SERVER_CONNECTION_TIMEOUT, 120000L,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
                                   0, Long.MAX_VALUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
     * <p>Name of the attribute that specifies the period in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
     * millisecond for a client to check its connection.  The default
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
     * value is 60000 milliseconds.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
    public static final String CLIENT_CONNECTION_CHECK_PERIOD =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
        "jmx.remote.x.client.connection.check.period";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
     * Returns the client connection check period.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
    public static long getConnectionCheckPeriod(Map env) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
        return getIntegerAttribute(env, CLIENT_CONNECTION_CHECK_PERIOD, 60000L,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
                                   0, Long.MAX_VALUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
     * Computes a boolean value from a string value retrieved from a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
     * property in the given map.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
     * @param env the environment map.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
     * @param prop the name of the property in the environment map whose
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
     * returned string value must be converted into a boolean value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
     * @return
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
     *   <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
     *   <li>{@code false} if {@code env.get(prop)} is {@code null}</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
     *   <li>{@code false} if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
     *       {@code ((String)env.get(prop)).equalsIgnoreCase("false")}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
     *       is {@code true}</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
     *   <li>{@code true} if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
     *       {@code ((String)env.get(prop)).equalsIgnoreCase("true")}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
     *       is {@code true}</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
     *   </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
     * @throws IllegalArgumentException if {@code env} is {@code null} or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
     * {@code env.get(prop)} is not {@code null} and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
     * {@code ((String)env.get(prop)).equalsIgnoreCase("false")} and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
     * {@code ((String)env.get(prop)).equalsIgnoreCase("true")} are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
     * {@code false}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
     * @throws ClassCastException if {@code env.get(prop)} cannot be cast
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
     * to {@code String}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
    public static boolean computeBooleanFromString(Map env, String prop)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
        throws IllegalArgumentException, ClassCastException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
        if (env == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
            throw new IllegalArgumentException("env map cannot be null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
        String stringBoolean = (String) env.get(prop);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
        if (stringBoolean == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
        else if (stringBoolean.equalsIgnoreCase("true"))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
        else if (stringBoolean.equalsIgnoreCase("false"))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
            throw new IllegalArgumentException(prop +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
                " must be \"true\" or \"false\" instead of \"" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
                stringBoolean + "\"");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
     * Converts a map into a valid hash table, i.e.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
     * it removes all the 'null' values from the map.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
    public static <K, V> Hashtable<K, V> mapToHashtable(Map<K, V> map) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
        HashMap<K, V> m = new HashMap<K, V>(map);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
        if (m.containsKey(null)) m.remove(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
        for (Iterator i = m.values().iterator(); i.hasNext(); )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
            if (i.next() == null) i.remove();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
        return new Hashtable<K, V>(m);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
    private static final class SinkOutputStream extends OutputStream {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
        public void write(byte[] b, int off, int len) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
        public void write(int b) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
    private static final ClassLogger logger =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
        new ClassLogger("javax.management.remote.misc", "EnvHelp");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
}