jdk/src/share/classes/javax/management/remote/rmi/RMIConnectionImpl.java
author emcmanus
Wed, 21 Oct 2009 17:33:18 +0200
changeset 4156 acaa49a2768a
parent 1510 e747d3193ef2
child 5175 56d64b1e78f9
permissions -rw-r--r--
6851617: Remove JSR 255 (JMX API 2.0) from JDK 7 Summary: See http://weblogs.java.net/blog/2009/06/16/jsr-255-jmx-api-20-postponed Reviewed-by: dfuchs
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
1247
b4c26443dee5 6754988: Update copyright year
xdono
parents: 1156
diff changeset
     2
 * Copyright 2002-2008 Sun Microsystems, Inc.  All Rights Reserved.
2
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 javax.management.remote.rmi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import static com.sun.jmx.mbeanserver.Util.cast;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import com.sun.jmx.remote.internal.ServerCommunicatorAdmin;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import com.sun.jmx.remote.internal.ServerNotifForwarder;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import com.sun.jmx.remote.security.JMXSubjectDomainCombiner;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import com.sun.jmx.remote.security.SubjectDelegator;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import com.sun.jmx.remote.util.ClassLoaderWithRepository;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import com.sun.jmx.remote.util.ClassLogger;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import com.sun.jmx.remote.util.EnvHelp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import com.sun.jmx.remote.util.OrderClassLoaders;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.rmi.MarshalledObject;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import java.rmi.UnmarshalException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import java.rmi.server.Unreferenced;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import java.security.AccessControlContext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import java.security.AccessController;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
import java.security.PrivilegedAction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
import java.security.PrivilegedActionException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
import java.security.PrivilegedExceptionAction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
import java.util.Arrays;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
import java.util.Collections;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
import java.util.Map;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
import java.util.Set;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
import javax.management.Attribute;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
import javax.management.AttributeList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
import javax.management.AttributeNotFoundException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
import javax.management.InstanceAlreadyExistsException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
import javax.management.InstanceNotFoundException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
import javax.management.IntrospectionException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
import javax.management.InvalidAttributeValueException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
import javax.management.ListenerNotFoundException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
import javax.management.MBeanException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
import javax.management.MBeanInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
import javax.management.MBeanRegistrationException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
import javax.management.MBeanServer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
import javax.management.NotCompliantMBeanException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
import javax.management.NotificationFilter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
import javax.management.ObjectInstance;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
import javax.management.ObjectName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
import javax.management.QueryExp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
import javax.management.ReflectionException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
import javax.management.RuntimeOperationsException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
import javax.management.remote.JMXServerErrorException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
import javax.management.remote.NotificationResult;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
import javax.management.remote.TargetedNotification;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
import javax.security.auth.Subject;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 * <p>Implementation of the {@link RMIConnection} interface.  User
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 * code will not usually reference this class.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 * Notice that we omit the type parameter from MarshalledObject everywhere,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
 * even though it would add useful information to the documentation.  The
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
 * reason is that it was only added in Mustang (Java SE 6), whereas versions
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
 * 1.4 and 2.0 of the JMX API must be implementable on Tiger per our
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
 * commitments for JSR 255.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
public class RMIConnectionImpl implements RMIConnection, Unreferenced {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     * Constructs a new {@link RMIConnection}. This connection can be
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     * used with either the JRMP or IIOP transport. This object does
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     * not export itself: it is the responsibility of the caller to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     * export it appropriately (see {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     * RMIJRMPServerImpl#makeClient(String,Subject)} and {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     * RMIIIOPServerImpl#makeClient(String,Subject)}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     * @param rmiServer The RMIServerImpl object for which this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     * connection is created.  The behavior is unspecified if this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     * parameter is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     * @param connectionId The ID for this connection.  The behavior
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     * is unspecified if this parameter is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     * @param defaultClassLoader The default ClassLoader to be used
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * when deserializing marshalled objects.  Can be null, to signify
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * the bootstrap class loader.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     * @param subject the authenticated subject to be used for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     * authorization.  Can be null, to signify that no subject has
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     * been authenticated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     * @param env the environment containing attributes for the new
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     * <code>RMIServerImpl</code>.  Can be null, equivalent to an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     * empty map.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    public RMIConnectionImpl(RMIServerImpl rmiServer,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
                             String connectionId,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
                             ClassLoader defaultClassLoader,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
                             Subject subject,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
                             Map<String,?> env) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        if (rmiServer == null || connectionId == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
            throw new NullPointerException("Illegal null argument");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        if (env == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
            env = Collections.emptyMap();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        this.rmiServer = rmiServer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        this.connectionId = connectionId;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        this.defaultClassLoader = defaultClassLoader;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        this.subjectDelegator = new SubjectDelegator();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        this.subject = subject;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        if (subject == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
            this.acc = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
            this.removeCallerContext = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
            this.removeCallerContext =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
                SubjectDelegator.checkRemoveCallerContext(subject);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
            if (this.removeCallerContext) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
                this.acc =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
                    JMXSubjectDomainCombiner.getDomainCombinerContext(subject);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
                this.acc =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
                    JMXSubjectDomainCombiner.getContext(subject);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        this.mbeanServer = rmiServer.getMBeanServer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        final ClassLoader dcl = defaultClassLoader;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        this.classLoaderWithRepository =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
            AccessController.doPrivileged(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
                new PrivilegedAction<ClassLoaderWithRepository>() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
                    public ClassLoaderWithRepository run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
                        return new ClassLoaderWithRepository(
1004
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
   151
                                      mbeanServer.getClassLoaderRepository(),
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
   152
                                      dcl);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
                });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        serverCommunicatorAdmin = new
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
          RMIServerCommunicatorAdmin(EnvHelp.getServerConnectionTimeout(env));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        this.env = env;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
4156
acaa49a2768a 6851617: Remove JSR 255 (JMX API 2.0) from JDK 7
emcmanus
parents: 1510
diff changeset
   161
    private synchronized ServerNotifForwarder getServerNotifFwd() {
acaa49a2768a 6851617: Remove JSR 255 (JMX API 2.0) from JDK 7
emcmanus
parents: 1510
diff changeset
   162
        // Lazily created when first use. Mainly when
acaa49a2768a 6851617: Remove JSR 255 (JMX API 2.0) from JDK 7
emcmanus
parents: 1510
diff changeset
   163
        // addNotificationListener is first called.
acaa49a2768a 6851617: Remove JSR 255 (JMX API 2.0) from JDK 7
emcmanus
parents: 1510
diff changeset
   164
        if (serverNotifForwarder == null)
acaa49a2768a 6851617: Remove JSR 255 (JMX API 2.0) from JDK 7
emcmanus
parents: 1510
diff changeset
   165
            serverNotifForwarder =
acaa49a2768a 6851617: Remove JSR 255 (JMX API 2.0) from JDK 7
emcmanus
parents: 1510
diff changeset
   166
                new ServerNotifForwarder(mbeanServer,
acaa49a2768a 6851617: Remove JSR 255 (JMX API 2.0) from JDK 7
emcmanus
parents: 1510
diff changeset
   167
                                         env,
acaa49a2768a 6851617: Remove JSR 255 (JMX API 2.0) from JDK 7
emcmanus
parents: 1510
diff changeset
   168
                                         rmiServer.getNotifBuffer(),
acaa49a2768a 6851617: Remove JSR 255 (JMX API 2.0) from JDK 7
emcmanus
parents: 1510
diff changeset
   169
                                         connectionId);
acaa49a2768a 6851617: Remove JSR 255 (JMX API 2.0) from JDK 7
emcmanus
parents: 1510
diff changeset
   170
        return serverNotifForwarder;
acaa49a2768a 6851617: Remove JSR 255 (JMX API 2.0) from JDK 7
emcmanus
parents: 1510
diff changeset
   171
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    public String getConnectionId() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        // We should call reqIncomming() here... shouldn't we?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        return connectionId;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    public void close() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        final boolean debug = logger.debugOn();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        final String  idstr = (debug?"["+this.toString()+"]":null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        synchronized (this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
            if (terminated) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
                if (debug) logger.debug("close",idstr + " already terminated.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
            if (debug) logger.debug("close",idstr + " closing.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
            terminated = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
            if (serverCommunicatorAdmin != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
                serverCommunicatorAdmin.terminate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
4156
acaa49a2768a 6851617: Remove JSR 255 (JMX API 2.0) from JDK 7
emcmanus
parents: 1510
diff changeset
   196
            if (serverNotifForwarder != null) {
acaa49a2768a 6851617: Remove JSR 255 (JMX API 2.0) from JDK 7
emcmanus
parents: 1510
diff changeset
   197
                serverNotifForwarder.terminate();
acaa49a2768a 6851617: Remove JSR 255 (JMX API 2.0) from JDK 7
emcmanus
parents: 1510
diff changeset
   198
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        rmiServer.clientClosed(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        if (debug) logger.debug("close",idstr + " closed.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    public void unreferenced() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        logger.debug("unreferenced", "called");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
            close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
            logger.debug("unreferenced", "done");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        } catch (IOException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
            logger.fine("unreferenced", e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    //-------------------------------------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    // MBeanServerConnection Wrapper
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
    //-------------------------------------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    public ObjectInstance createMBean(String className,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
                                      ObjectName name,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
                                      Subject delegationSubject)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        throws
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        ReflectionException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        InstanceAlreadyExistsException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        MBeanRegistrationException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        MBeanException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        NotCompliantMBeanException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
            final Object params[] =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
                new Object[] { className, name };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
            if (logger.debugOn())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
                logger.debug("createMBean(String,ObjectName)",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
                             "connectionId=" + connectionId +", className=" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
                             className+", name=" + name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
            return (ObjectInstance)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
                doPrivilegedOperation(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
                  CREATE_MBEAN,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
                  params,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
                  delegationSubject);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        } catch (PrivilegedActionException pe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
            Exception e = extractException(pe);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
            if (e instanceof ReflectionException)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
                throw (ReflectionException) e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
            if (e instanceof InstanceAlreadyExistsException)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
                throw (InstanceAlreadyExistsException) e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
            if (e instanceof MBeanRegistrationException)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
                throw (MBeanRegistrationException) e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
            if (e instanceof MBeanException)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
                throw (MBeanException) e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
            if (e instanceof NotCompliantMBeanException)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
                throw (NotCompliantMBeanException) e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
            if (e instanceof IOException)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
                throw (IOException) e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
            throw newIOException("Got unexpected server exception: " + e, e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
    public ObjectInstance createMBean(String className,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
                                      ObjectName name,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
                                      ObjectName loaderName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
                                      Subject delegationSubject)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        throws
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
        ReflectionException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        InstanceAlreadyExistsException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        MBeanRegistrationException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        MBeanException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
        NotCompliantMBeanException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        InstanceNotFoundException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
        IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
            final Object params[] =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
                new Object[] { className, name, loaderName };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
            if (logger.debugOn())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
                logger.debug("createMBean(String,ObjectName,ObjectName)",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
                      "connectionId=" + connectionId
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
                      +", className=" + className
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
                      +", name=" + name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
                      +", loaderName=" + loaderName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
            return (ObjectInstance)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
                doPrivilegedOperation(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
                  CREATE_MBEAN_LOADER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
                  params,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
                  delegationSubject);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        } catch (PrivilegedActionException pe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
            Exception e = extractException(pe);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
            if (e instanceof ReflectionException)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
                throw (ReflectionException) e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
            if (e instanceof InstanceAlreadyExistsException)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
                throw (InstanceAlreadyExistsException) e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
            if (e instanceof MBeanRegistrationException)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
                throw (MBeanRegistrationException) e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
            if (e instanceof MBeanException)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
                throw (MBeanException) e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
            if (e instanceof NotCompliantMBeanException)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
                throw (NotCompliantMBeanException) e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
            if (e instanceof InstanceNotFoundException)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
                throw (InstanceNotFoundException) e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
            if (e instanceof IOException)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
                throw (IOException) e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
            throw newIOException("Got unexpected server exception: " + e, e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
1510
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 1247
diff changeset
   310
    @SuppressWarnings("rawtypes")  // MarshalledObject
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
    public ObjectInstance createMBean(String className,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
                                      ObjectName name,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
                                      MarshalledObject params,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
                                      String signature[],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
                                      Subject delegationSubject)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
        throws
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
        ReflectionException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
        InstanceAlreadyExistsException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
        MBeanRegistrationException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
        MBeanException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
        NotCompliantMBeanException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
        IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
        final Object[] values;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
        final boolean debug = logger.debugOn();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
        if (debug) logger.debug(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
                  "createMBean(String,ObjectName,Object[],String[])",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
                  "connectionId=" + connectionId
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
                  +", unwrapping parameters using classLoaderWithRepository.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
        values =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
            nullIsEmpty(unwrap(params, classLoaderWithRepository, Object[].class));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
            final Object params2[] =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
                new Object[] { className, name, values,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
                               nullIsEmpty(signature) };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
            if (debug)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
               logger.debug("createMBean(String,ObjectName,Object[],String[])",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
                             "connectionId=" + connectionId
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
                             +", className=" + className
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
                             +", name=" + name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
                             +", params=" + objects(values)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
                             +", signature=" + strings(signature));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
            return (ObjectInstance)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
                doPrivilegedOperation(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
                  CREATE_MBEAN_PARAMS,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
                  params2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
                  delegationSubject);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
        } catch (PrivilegedActionException pe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
            Exception e = extractException(pe);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
            if (e instanceof ReflectionException)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
                throw (ReflectionException) e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
            if (e instanceof InstanceAlreadyExistsException)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
                throw (InstanceAlreadyExistsException) e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
            if (e instanceof MBeanRegistrationException)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
                throw (MBeanRegistrationException) e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
            if (e instanceof MBeanException)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
                throw (MBeanException) e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
            if (e instanceof NotCompliantMBeanException)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
                throw (NotCompliantMBeanException) e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
            if (e instanceof IOException)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
                throw (IOException) e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
            throw newIOException("Got unexpected server exception: " + e, e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
1510
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 1247
diff changeset
   371
    @SuppressWarnings("rawtypes")  // MarshalledObject
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
    public ObjectInstance createMBean(String className,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
                                 ObjectName name,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
                                 ObjectName loaderName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
                                 MarshalledObject params,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
                                 String signature[],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
                                 Subject delegationSubject)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
        throws
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
        ReflectionException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
        InstanceAlreadyExistsException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
        MBeanRegistrationException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
        MBeanException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
        NotCompliantMBeanException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
        InstanceNotFoundException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
        IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
        final Object[] values;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
        final boolean debug = logger.debugOn();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
        if (debug) logger.debug(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
                 "createMBean(String,ObjectName,ObjectName,Object[],String[])",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
                 "connectionId=" + connectionId
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
                 +", unwrapping params with MBean extended ClassLoader.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
        values = nullIsEmpty(unwrap(params,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
                                    getClassLoader(loaderName),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
                                    defaultClassLoader,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
                                    Object[].class));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
            final Object params2[] =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
               new Object[] { className, name, loaderName, values,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
                              nullIsEmpty(signature) };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
           if (debug) logger.debug(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
                 "createMBean(String,ObjectName,ObjectName,Object[],String[])",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
                 "connectionId=" + connectionId
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
                 +", className=" + className
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
                 +", name=" + name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
                 +", loaderName=" + loaderName
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
                 +", params=" + objects(values)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
                 +", signature=" + strings(signature));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
            return (ObjectInstance)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
                doPrivilegedOperation(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
                  CREATE_MBEAN_LOADER_PARAMS,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
                  params2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
                  delegationSubject);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
        } catch (PrivilegedActionException pe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
            Exception e = extractException(pe);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
            if (e instanceof ReflectionException)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
                throw (ReflectionException) e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
            if (e instanceof InstanceAlreadyExistsException)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
                throw (InstanceAlreadyExistsException) e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
            if (e instanceof MBeanRegistrationException)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
                throw (MBeanRegistrationException) e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
            if (e instanceof MBeanException)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
                throw (MBeanException) e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
            if (e instanceof NotCompliantMBeanException)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
                throw (NotCompliantMBeanException) e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
            if (e instanceof InstanceNotFoundException)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
                throw (InstanceNotFoundException) e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
            if (e instanceof IOException)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
                throw (IOException) e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
            throw newIOException("Got unexpected server exception: " + e, e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
    public void unregisterMBean(ObjectName name, Subject delegationSubject)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
        throws
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
        InstanceNotFoundException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
        MBeanRegistrationException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
        IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
            final Object params[] = new Object[] { name };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
            if (logger.debugOn()) logger.debug("unregisterMBean",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
                 "connectionId=" + connectionId
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
                 +", name="+name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
            doPrivilegedOperation(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
              UNREGISTER_MBEAN,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
              params,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
              delegationSubject);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
        } catch (PrivilegedActionException pe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
            Exception e = extractException(pe);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
            if (e instanceof InstanceNotFoundException)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
                throw (InstanceNotFoundException) e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
            if (e instanceof MBeanRegistrationException)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
                throw (MBeanRegistrationException) e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
            if (e instanceof IOException)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
                throw (IOException) e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
            throw newIOException("Got unexpected server exception: " + e, e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
    public ObjectInstance getObjectInstance(ObjectName name,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
                                            Subject delegationSubject)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
        throws
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
        InstanceNotFoundException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
        IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
        checkNonNull("ObjectName", name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
            final Object params[] = new Object[] { name };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
            if (logger.debugOn()) logger.debug("getObjectInstance",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
                 "connectionId=" + connectionId
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
                 +", name="+name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
            return (ObjectInstance)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
                doPrivilegedOperation(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
                  GET_OBJECT_INSTANCE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
                  params,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
                  delegationSubject);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
        } catch (PrivilegedActionException pe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
            Exception e = extractException(pe);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
            if (e instanceof InstanceNotFoundException)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
                throw (InstanceNotFoundException) e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
            if (e instanceof IOException)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
                throw (IOException) e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
            throw newIOException("Got unexpected server exception: " + e, e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
1510
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 1247
diff changeset
   497
    @SuppressWarnings("rawtypes")  // MarshalledObject
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
    public Set<ObjectInstance>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
        queryMBeans(ObjectName name,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
                    MarshalledObject query,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
                    Subject delegationSubject)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
        throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
        final QueryExp queryValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
        final boolean debug=logger.debugOn();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
        if (debug) logger.debug("queryMBeans",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
                 "connectionId=" + connectionId
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
                 +" unwrapping query with defaultClassLoader.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
        queryValue = unwrap(query, defaultClassLoader, QueryExp.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
            final Object params[] = new Object[] { name, queryValue };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
            if (debug) logger.debug("queryMBeans",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
                 "connectionId=" + connectionId
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
                 +", name="+name +", query="+query);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
            return cast(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
                doPrivilegedOperation(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
                  QUERY_MBEANS,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
                  params,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
                  delegationSubject));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
        } catch (PrivilegedActionException pe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
            Exception e = extractException(pe);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
            if (e instanceof IOException)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
                throw (IOException) e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
            throw newIOException("Got unexpected server exception: " + e, e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
1510
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 1247
diff changeset
   532
    @SuppressWarnings("rawtypes")  // MarshalledObject
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
    public Set<ObjectName>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
        queryNames(ObjectName name,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
                   MarshalledObject query,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
                   Subject delegationSubject)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
        throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
        final QueryExp queryValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
        final boolean debug=logger.debugOn();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
        if (debug) logger.debug("queryNames",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
                 "connectionId=" + connectionId
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
                 +" unwrapping query with defaultClassLoader.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
        queryValue = unwrap(query, defaultClassLoader, QueryExp.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
            final Object params[] = new Object[] { name, queryValue };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
            if (debug) logger.debug("queryNames",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
                 "connectionId=" + connectionId
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
                 +", name="+name +", query="+query);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
            return cast(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
                doPrivilegedOperation(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
                  QUERY_NAMES,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
                  params,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
                  delegationSubject));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
        } catch (PrivilegedActionException pe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
            Exception e = extractException(pe);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
            if (e instanceof IOException)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
                throw (IOException) e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
            throw newIOException("Got unexpected server exception: " + e, e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
    public boolean isRegistered(ObjectName name,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
                                Subject delegationSubject) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
            final Object params[] = new Object[] { name };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
            return ((Boolean)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
                doPrivilegedOperation(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
                  IS_REGISTERED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
                  params,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
                  delegationSubject)).booleanValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
        } catch (PrivilegedActionException pe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
            Exception e = extractException(pe);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
            if (e instanceof IOException)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
                throw (IOException) e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
            throw newIOException("Got unexpected server exception: " + e, e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
    public Integer getMBeanCount(Subject delegationSubject)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
        throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
            final Object params[] = new Object[] { };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
            if (logger.debugOn()) logger.debug("getMBeanCount",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
                 "connectionId=" + connectionId);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
            return (Integer)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
                doPrivilegedOperation(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
                  GET_MBEAN_COUNT,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
                  params,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
                  delegationSubject);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
        } catch (PrivilegedActionException pe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
            Exception e = extractException(pe);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
            if (e instanceof IOException)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
                throw (IOException) e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
            throw newIOException("Got unexpected server exception: " + e, e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
    public Object getAttribute(ObjectName name,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
                               String attribute,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
                               Subject delegationSubject)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
        throws
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
        MBeanException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
        AttributeNotFoundException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
        InstanceNotFoundException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
        ReflectionException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
        IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
            final Object params[] = new Object[] { name, attribute };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
            if (logger.debugOn()) logger.debug("getAttribute",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
                                   "connectionId=" + connectionId
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
                                   +", name=" + name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
                                   +", attribute="+ attribute);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
            return
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
                doPrivilegedOperation(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
                  GET_ATTRIBUTE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
                  params,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
                  delegationSubject);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
        } catch (PrivilegedActionException pe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
            Exception e = extractException(pe);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
            if (e instanceof MBeanException)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
                throw (MBeanException) e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
            if (e instanceof AttributeNotFoundException)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
                throw (AttributeNotFoundException) e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
            if (e instanceof InstanceNotFoundException)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
                throw (InstanceNotFoundException) e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
            if (e instanceof ReflectionException)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
                throw (ReflectionException) e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
            if (e instanceof IOException)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
                throw (IOException) e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
            throw newIOException("Got unexpected server exception: " + e, e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
    public AttributeList getAttributes(ObjectName name,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
                                       String[] attributes,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
                                       Subject delegationSubject)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
        throws
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
        InstanceNotFoundException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
        ReflectionException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
        IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
            final Object params[] = new Object[] { name, attributes };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
            if (logger.debugOn()) logger.debug("getAttributes",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
                                   "connectionId=" + connectionId
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
                                   +", name=" + name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
                                   +", attributes="+ strings(attributes));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
            return (AttributeList)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
                doPrivilegedOperation(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
                  GET_ATTRIBUTES,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
                  params,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
                  delegationSubject);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
        } catch (PrivilegedActionException pe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
            Exception e = extractException(pe);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
            if (e instanceof InstanceNotFoundException)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
                throw (InstanceNotFoundException) e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
            if (e instanceof ReflectionException)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
                throw (ReflectionException) e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
            if (e instanceof IOException)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
                throw (IOException) e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
            throw newIOException("Got unexpected server exception: " + e, e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
1510
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 1247
diff changeset
   674
    @SuppressWarnings("rawtypes")  // MarshalledObject
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
    public void setAttribute(ObjectName name,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
                             MarshalledObject attribute,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
                             Subject delegationSubject)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
        throws
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
        InstanceNotFoundException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
        AttributeNotFoundException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
        InvalidAttributeValueException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
        MBeanException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
        ReflectionException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
        IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
        final Attribute attr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
        final boolean debug=logger.debugOn();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
        if (debug) logger.debug("setAttribute",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
                 "connectionId=" + connectionId
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
                 +" unwrapping attribute with MBean extended ClassLoader.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
        attr = unwrap(attribute,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
                      getClassLoaderFor(name),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
                      defaultClassLoader,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
                      Attribute.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
            final Object params[] = new Object[] { name, attr };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
            if (debug) logger.debug("setAttribute",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
                             "connectionId=" + connectionId
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
                             +", name="+name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
                             +", attribute="+attr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
            doPrivilegedOperation(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
              SET_ATTRIBUTE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
              params,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
              delegationSubject);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
        } catch (PrivilegedActionException pe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
            Exception e = extractException(pe);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
            if (e instanceof InstanceNotFoundException)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
                throw (InstanceNotFoundException) e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
            if (e instanceof AttributeNotFoundException)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
                throw (AttributeNotFoundException) e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
            if (e instanceof InvalidAttributeValueException)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
                throw (InvalidAttributeValueException) e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
            if (e instanceof MBeanException)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
                throw (MBeanException) e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
            if (e instanceof ReflectionException)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
                throw (ReflectionException) e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
            if (e instanceof IOException)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
                throw (IOException) e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
            throw newIOException("Got unexpected server exception: " + e, e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
1510
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 1247
diff changeset
   727
    @SuppressWarnings("rawtypes")  // MarshalledObject
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
    public AttributeList setAttributes(ObjectName name,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
                         MarshalledObject attributes,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
                         Subject delegationSubject)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
        throws
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
        InstanceNotFoundException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
        ReflectionException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
        IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
        final AttributeList attrlist;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
        final boolean debug=logger.debugOn();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
        if (debug) logger.debug("setAttributes",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
                 "connectionId=" + connectionId
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
                 +" unwrapping attributes with MBean extended ClassLoader.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
        attrlist =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
            unwrap(attributes,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
                   getClassLoaderFor(name),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
                   defaultClassLoader,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
                   AttributeList.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
            final Object params[] = new Object[] { name, attrlist };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
            if (debug) logger.debug("setAttributes",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
                             "connectionId=" + connectionId
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
                             +", name="+name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
                             +", attributes="+attrlist);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
            return (AttributeList)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
                doPrivilegedOperation(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
                  SET_ATTRIBUTES,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
                  params,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
                  delegationSubject);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
        } catch (PrivilegedActionException pe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
            Exception e = extractException(pe);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
            if (e instanceof InstanceNotFoundException)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
                throw (InstanceNotFoundException) e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
            if (e instanceof ReflectionException)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
                throw (ReflectionException) e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
            if (e instanceof IOException)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
                throw (IOException) e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
            throw newIOException("Got unexpected server exception: " + e, e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
1510
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 1247
diff changeset
   773
    @SuppressWarnings("rawtypes")  // MarshalledObject
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
    public Object invoke(ObjectName name,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
                         String operationName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
                         MarshalledObject params,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
                         String signature[],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
                         Subject delegationSubject)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
        throws
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
        InstanceNotFoundException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
        MBeanException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
        ReflectionException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
        IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
        checkNonNull("ObjectName", name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
        checkNonNull("Operation name", operationName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
        final Object[] values;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
        final boolean debug=logger.debugOn();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
        if (debug) logger.debug("invoke",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
                 "connectionId=" + connectionId
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
                 +" unwrapping params with MBean extended ClassLoader.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
        values = nullIsEmpty(unwrap(params,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
                                    getClassLoaderFor(name),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
                                    defaultClassLoader,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
                                    Object[].class));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
            final Object params2[] =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
                new Object[] { name, operationName, values,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
                               nullIsEmpty(signature) };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
            if (debug) logger.debug("invoke",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
                             "connectionId=" + connectionId
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
                             +", name="+name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
                             +", operationName="+operationName
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
                             +", params="+objects(values)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
                             +", signature="+strings(signature));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
            return
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
                doPrivilegedOperation(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
                  INVOKE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
                  params2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
                  delegationSubject);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
        } catch (PrivilegedActionException pe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
            Exception e = extractException(pe);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
            if (e instanceof InstanceNotFoundException)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
                throw (InstanceNotFoundException) e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
            if (e instanceof MBeanException)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
                throw (MBeanException) e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
            if (e instanceof ReflectionException)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
                throw (ReflectionException) e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
            if (e instanceof IOException)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
                throw (IOException) e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
            throw newIOException("Got unexpected server exception: " + e, e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
    public String getDefaultDomain(Subject delegationSubject)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
        throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
            final Object params[] = new Object[] { };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
            if (logger.debugOn())  logger.debug("getDefaultDomain",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
                                    "connectionId=" + connectionId);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
            return (String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
                doPrivilegedOperation(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
                  GET_DEFAULT_DOMAIN,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
                  params,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
                  delegationSubject);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
        } catch (PrivilegedActionException pe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
            Exception e = extractException(pe);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
            if (e instanceof IOException)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
                throw (IOException) e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
            throw newIOException("Got unexpected server exception: " + e, e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
    public String[] getDomains(Subject delegationSubject) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
            final Object params[] = new Object[] { };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
            if (logger.debugOn())  logger.debug("getDomains",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
                                    "connectionId=" + connectionId);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
            return (String[])
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
                doPrivilegedOperation(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
                  GET_DOMAINS,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
                  params,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
                  delegationSubject);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
        } catch (PrivilegedActionException pe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
            Exception e = extractException(pe);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
            if (e instanceof IOException)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
                throw (IOException) e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
            throw newIOException("Got unexpected server exception: " + e, e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
    public MBeanInfo getMBeanInfo(ObjectName name, Subject delegationSubject)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
        throws
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
        InstanceNotFoundException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
        IntrospectionException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
        ReflectionException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
        IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
        checkNonNull("ObjectName", name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
            final Object params[] = new Object[] { name };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
            if (logger.debugOn())  logger.debug("getMBeanInfo",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
                                    "connectionId=" + connectionId
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
                                    +", name="+name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
            return (MBeanInfo)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
                doPrivilegedOperation(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
                  GET_MBEAN_INFO,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
                  params,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
                  delegationSubject);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
        } catch (PrivilegedActionException pe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
            Exception e = extractException(pe);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
            if (e instanceof InstanceNotFoundException)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
                throw (InstanceNotFoundException) e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
            if (e instanceof IntrospectionException)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
                throw (IntrospectionException) e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
            if (e instanceof ReflectionException)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
                throw (ReflectionException) e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
            if (e instanceof IOException)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
                throw (IOException) e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
            throw newIOException("Got unexpected server exception: " + e, e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
    public boolean isInstanceOf(ObjectName name,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
                                String className,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
                                Subject delegationSubject)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
        throws InstanceNotFoundException, IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
        checkNonNull("ObjectName", name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
            final Object params[] = new Object[] { name, className };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
            if (logger.debugOn())  logger.debug("isInstanceOf",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
                                    "connectionId=" + connectionId
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
                                    +", name="+name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
                                    +", className="+className);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
            return ((Boolean)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
                doPrivilegedOperation(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
                  IS_INSTANCE_OF,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
                  params,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
                  delegationSubject)).booleanValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
        } catch (PrivilegedActionException pe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
            Exception e = extractException(pe);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
            if (e instanceof InstanceNotFoundException)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
                throw (InstanceNotFoundException) e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
            if (e instanceof IOException)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
                throw (IOException) e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
            throw newIOException("Got unexpected server exception: " + e, e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
1510
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 1247
diff changeset
   937
    @SuppressWarnings("rawtypes")  // MarshalledObject
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
    public Integer[] addNotificationListeners(ObjectName[] names,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
                      MarshalledObject[] filters,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
                      Subject[] delegationSubjects)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
            throws InstanceNotFoundException, IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
        if (names == null || filters == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
            throw new IllegalArgumentException("Got null arguments.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
        Subject[] sbjs = (delegationSubjects != null) ? delegationSubjects :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
        new Subject[names.length];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
        if (names.length != filters.length || filters.length != sbjs.length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
            final String msg =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
                "The value lengths of 3 parameters are not same.";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
            throw new IllegalArgumentException(msg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
        for (int i=0; i<names.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
            if (names[i] == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
                throw new IllegalArgumentException("Null Object name.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
        int i=0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
        ClassLoader targetCl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
        NotificationFilter[] filterValues =
1004
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
   964
            new NotificationFilter[names.length];
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
        Integer[] ids = new Integer[names.length];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
        final boolean debug=logger.debugOn();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
            for (; i<names.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
                targetCl = getClassLoaderFor(names[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
                if (debug) logger.debug("addNotificationListener"+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
                                        "(ObjectName,NotificationFilter)",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
                                        "connectionId=" + connectionId +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
                      " unwrapping filter with target extended ClassLoader.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
                filterValues[i] =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
                    unwrap(filters[i], targetCl, defaultClassLoader,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
                           NotificationFilter.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
                if (debug) logger.debug("addNotificationListener"+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
                                        "(ObjectName,NotificationFilter)",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
                                        "connectionId=" + connectionId
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
                                        +", name=" + names[i]
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
                                        +", filter=" + filterValues[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
                ids[i] = (Integer)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
                    doPrivilegedOperation(ADD_NOTIFICATION_LISTENERS,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
                                          new Object[] { names[i],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
                                                         filterValues[i] },
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
                                          sbjs[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
            return ids;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
            // remove all registered listeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
            for (int j=0; j<i; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
                try {
4156
acaa49a2768a 6851617: Remove JSR 255 (JMX API 2.0) from JDK 7
emcmanus
parents: 1510
diff changeset
   999
                    getServerNotifFwd().removeNotificationListener(names[j],
acaa49a2768a 6851617: Remove JSR 255 (JMX API 2.0) from JDK 7
emcmanus
parents: 1510
diff changeset
  1000
                                                                   ids[j]);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
                } catch (Exception eee) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
                    // strange
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
            if (e instanceof PrivilegedActionException) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
                e = extractException(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
            if (e instanceof ClassCastException) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
                throw (ClassCastException) e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
            } else if (e instanceof IOException) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
                throw (IOException)e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
            } else if (e instanceof InstanceNotFoundException) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
                throw (InstanceNotFoundException) e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
            } else if (e instanceof RuntimeException) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
                throw (RuntimeException) e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
                throw newIOException("Got unexpected server exception: "+e,e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
1510
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 1247
diff changeset
  1024
    @SuppressWarnings("rawtypes")  // MarshalledObject
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
    public void addNotificationListener(ObjectName name,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
                       ObjectName listener,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
                       MarshalledObject filter,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
                       MarshalledObject handback,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
                       Subject delegationSubject)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
        throws InstanceNotFoundException, IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
        checkNonNull("Target MBean name", name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
        checkNonNull("Listener MBean name", listener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
        final NotificationFilter filterValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
        final Object handbackValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
        final boolean debug=logger.debugOn();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
        final ClassLoader targetCl = getClassLoaderFor(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
        if (debug) logger.debug("addNotificationListener"+
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
                 "(ObjectName,ObjectName,NotificationFilter,Object)",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
                 "connectionId=" + connectionId
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
                 +" unwrapping filter with target extended ClassLoader.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
        filterValue =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
            unwrap(filter, targetCl, defaultClassLoader, NotificationFilter.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
        if (debug) logger.debug("addNotificationListener"+
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
                 "(ObjectName,ObjectName,NotificationFilter,Object)",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
                 "connectionId=" + connectionId
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
                 +" unwrapping handback with target extended ClassLoader.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
        handbackValue =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
            unwrap(handback, targetCl, defaultClassLoader, Object.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
            final Object params[] =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
                new Object[] { name, listener, filterValue, handbackValue };
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
            if (debug) logger.debug("addNotificationListener"+
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
                 "(ObjectName,ObjectName,NotificationFilter,Object)",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
                             "connectionId=" + connectionId
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
                             +", name=" + name
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
                             +", listenerName=" + listener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
                             +", filter=" + filterValue
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
                             +", handback=" + handbackValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
            doPrivilegedOperation(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
              ADD_NOTIFICATION_LISTENER_OBJECTNAME,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
              params,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
              delegationSubject);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
        } catch (PrivilegedActionException pe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
            Exception e = extractException(pe);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
            if (e instanceof InstanceNotFoundException)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
                throw (InstanceNotFoundException) e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
            if (e instanceof IOException)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
                throw (IOException) e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
            throw newIOException("Got unexpected server exception: " + e, e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
    public void removeNotificationListeners(ObjectName name,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
                                            Integer[] listenerIDs,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
                                            Subject delegationSubject)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
        throws
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
        InstanceNotFoundException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
        ListenerNotFoundException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
        IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
        if (name == null || listenerIDs == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
            throw new IllegalArgumentException("Illegal null parameter");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
        for (int i = 0; i < listenerIDs.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
            if (listenerIDs[i] == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
                throw new IllegalArgumentException("Null listener ID");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1098
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
            final Object params[] = new Object[] { name, listenerIDs };
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
            if (logger.debugOn()) logger.debug("removeNotificationListener"+
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
                                   "(ObjectName,Integer[])",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
                                   "connectionId=" + connectionId
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
                                   +", name=" + name
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
                                   +", listenerIDs=" + objects(listenerIDs));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
            doPrivilegedOperation(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
              REMOVE_NOTIFICATION_LISTENER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
              params,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
              delegationSubject);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
        } catch (PrivilegedActionException pe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
            Exception e = extractException(pe);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
            if (e instanceof InstanceNotFoundException)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
                throw (InstanceNotFoundException) e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
            if (e instanceof ListenerNotFoundException)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
                throw (ListenerNotFoundException) e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
            if (e instanceof IOException)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
                throw (IOException) e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
            throw newIOException("Got unexpected server exception: " + e, e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1121
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1122
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1123
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1124
    public void removeNotificationListener(ObjectName name,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1125
                                           ObjectName listener,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1126
                                           Subject delegationSubject)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
        throws
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
        InstanceNotFoundException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
        ListenerNotFoundException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1130
        IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1132
        checkNonNull("Target MBean name", name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1133
        checkNonNull("Listener MBean name", listener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1134
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1135
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1136
            final Object params[] = new Object[] { name, listener };
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1137
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1138
            if (logger.debugOn()) logger.debug("removeNotificationListener"+
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1139
                                   "(ObjectName,ObjectName)",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1140
                                   "connectionId=" + connectionId
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
                                   +", name=" + name
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1142
                                   +", listenerName=" + listener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1143
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1144
            doPrivilegedOperation(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1145
              REMOVE_NOTIFICATION_LISTENER_OBJECTNAME,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1146
              params,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1147
              delegationSubject);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1148
        } catch (PrivilegedActionException pe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1149
            Exception e = extractException(pe);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1150
            if (e instanceof InstanceNotFoundException)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1151
                throw (InstanceNotFoundException) e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
            if (e instanceof ListenerNotFoundException)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1153
                throw (ListenerNotFoundException) e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1154
            if (e instanceof IOException)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1155
                throw (IOException) e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1156
            throw newIOException("Got unexpected server exception: " + e, e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1157
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1158
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1159
1510
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 1247
diff changeset
  1160
    @SuppressWarnings("rawtypes")  // MarshalledObject
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1161
    public void removeNotificationListener(ObjectName name,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1162
                        ObjectName listener,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1163
                        MarshalledObject filter,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1164
                        MarshalledObject handback,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1165
                        Subject delegationSubject)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1166
        throws
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1167
        InstanceNotFoundException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1168
        ListenerNotFoundException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1169
        IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1170
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1171
        checkNonNull("Target MBean name", name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1172
        checkNonNull("Listener MBean name", listener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1173
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1174
        final NotificationFilter filterValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1175
        final Object handbackValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1176
        final boolean debug=logger.debugOn();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1177
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1178
        final ClassLoader targetCl = getClassLoaderFor(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1179
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1180
        if (debug) logger.debug("removeNotificationListener"+
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1181
                 "(ObjectName,ObjectName,NotificationFilter,Object)",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1182
                 "connectionId=" + connectionId
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1183
                 +" unwrapping filter with target extended ClassLoader.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1184
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1185
        filterValue =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1186
            unwrap(filter, targetCl, defaultClassLoader, NotificationFilter.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1187
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1188
        if (debug) logger.debug("removeNotificationListener"+
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1189
                 "(ObjectName,ObjectName,NotificationFilter,Object)",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1190
                 "connectionId=" + connectionId
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1191
                 +" unwrapping handback with target extended ClassLoader.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1192
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1193
        handbackValue =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1194
            unwrap(handback, targetCl, defaultClassLoader, Object.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1195
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1196
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1197
            final Object params[] =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1198
                new Object[] { name, listener, filterValue, handbackValue };
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1199
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1200
            if (debug) logger.debug("removeNotificationListener"+
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1201
                 "(ObjectName,ObjectName,NotificationFilter,Object)",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1202
                             "connectionId=" + connectionId
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1203
                             +", name=" + name
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1204
                             +", listenerName=" + listener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1205
                             +", filter=" + filterValue
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1206
                             +", handback=" + handbackValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1207
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1208
            doPrivilegedOperation(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1209
              REMOVE_NOTIFICATION_LISTENER_OBJECTNAME_FILTER_HANDBACK,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1210
              params,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1211
              delegationSubject);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1212
        } catch (PrivilegedActionException pe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1213
            Exception e = extractException(pe);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1214
            if (e instanceof InstanceNotFoundException)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1215
                throw (InstanceNotFoundException) e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1216
            if (e instanceof ListenerNotFoundException)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1217
                throw (ListenerNotFoundException) e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1218
            if (e instanceof IOException)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1219
                throw (IOException) e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1220
            throw newIOException("Got unexpected server exception: " + e, e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1221
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1222
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1223
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1224
    public NotificationResult fetchNotifications(long clientSequenceNumber,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1225
                                                 int maxNotifications,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1226
                                                 long timeout)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1227
        throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1228
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1229
        if (logger.debugOn()) logger.debug("fetchNotifications",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1230
                               "connectionId=" + connectionId
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1231
                               +", timeout=" + timeout);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1232
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1233
        if (maxNotifications < 0 || timeout < 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1234
            throw new IllegalArgumentException("Illegal negative argument");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1235
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1236
        final boolean serverTerminated =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1237
            serverCommunicatorAdmin.reqIncoming();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1238
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1239
            if (serverTerminated) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1240
                // we must not call fetchNotifs() if the server is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1241
                // terminated (timeout elapsed).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1242
                //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1243
                return new NotificationResult(0L, 0L,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1244
                                              new TargetedNotification[0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1245
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1246
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1247
            final long csn = clientSequenceNumber;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1248
            final int mn = maxNotifications;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1249
            final long t = timeout;
4156
acaa49a2768a 6851617: Remove JSR 255 (JMX API 2.0) from JDK 7
emcmanus
parents: 1510
diff changeset
  1250
            PrivilegedAction<NotificationResult> action =
acaa49a2768a 6851617: Remove JSR 255 (JMX API 2.0) from JDK 7
emcmanus
parents: 1510
diff changeset
  1251
                new PrivilegedAction<NotificationResult>() {
acaa49a2768a 6851617: Remove JSR 255 (JMX API 2.0) from JDK 7
emcmanus
parents: 1510
diff changeset
  1252
                    public NotificationResult run() {
acaa49a2768a 6851617: Remove JSR 255 (JMX API 2.0) from JDK 7
emcmanus
parents: 1510
diff changeset
  1253
                        return getServerNotifFwd().fetchNotifs(csn, t, mn);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1254
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1255
            };
4156
acaa49a2768a 6851617: Remove JSR 255 (JMX API 2.0) from JDK 7
emcmanus
parents: 1510
diff changeset
  1256
            if (acc == null)
acaa49a2768a 6851617: Remove JSR 255 (JMX API 2.0) from JDK 7
emcmanus
parents: 1510
diff changeset
  1257
                return action.run();
acaa49a2768a 6851617: Remove JSR 255 (JMX API 2.0) from JDK 7
emcmanus
parents: 1510
diff changeset
  1258
            else
acaa49a2768a 6851617: Remove JSR 255 (JMX API 2.0) from JDK 7
emcmanus
parents: 1510
diff changeset
  1259
                return AccessController.doPrivileged(action, acc);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1260
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1261
            serverCommunicatorAdmin.rspOutgoing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1262
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1263
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1264
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1265
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1266
     * <p>Returns a string representation of this object.  In general,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1267
     * the <code>toString</code> method returns a string that
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1268
     * "textually represents" this object. The result should be a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1269
     * concise but informative representation that is easy for a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1270
     * person to read.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1271
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1272
     * @return a String representation of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1273
     **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1274
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1275
        return super.toString() + ": connectionId=" + connectionId;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1276
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1277
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1278
    //------------------------------------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1279
    // private classes
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1280
    //------------------------------------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1281
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1282
    private class PrivilegedOperation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1283
            implements PrivilegedExceptionAction<Object> {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1284
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1285
        public PrivilegedOperation(int operation, Object[] params) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1286
            this.operation = operation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1287
            this.params = params;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1288
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1289
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1290
        public Object run() throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1291
            return doOperation(operation, params);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1292
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1293
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1294
        private int operation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1295
        private Object[] params;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1296
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1297
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1298
    //------------------------------------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1299
    // private classes
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1300
    //------------------------------------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1301
    private class RMIServerCommunicatorAdmin extends ServerCommunicatorAdmin {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1302
        public RMIServerCommunicatorAdmin(long timeout) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1303
            super(timeout);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1304
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1305
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1306
        protected void doStop() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1307
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1308
                close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1309
            } catch (IOException ie) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1310
                logger.warning("RMIServerCommunicatorAdmin-doStop",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1311
                               "Failed to close: " + ie);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1312
                logger.debug("RMIServerCommunicatorAdmin-doStop",ie);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1313
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1314
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1315
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1316
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1317
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1318
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1319
    //------------------------------------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1320
    // private methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1321
    //------------------------------------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1322
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1323
    private ClassLoader getClassLoader(final ObjectName name)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1324
        throws InstanceNotFoundException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1325
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1326
            return
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1327
                AccessController.doPrivileged(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1328
                    new PrivilegedExceptionAction<ClassLoader>() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1329
                        public ClassLoader run() throws InstanceNotFoundException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1330
                            return mbeanServer.getClassLoader(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1331
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1332
                    });
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1333
        } catch (PrivilegedActionException pe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1334
            throw (InstanceNotFoundException) extractException(pe);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1335
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1336
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1337
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1338
    private ClassLoader getClassLoaderFor(final ObjectName name)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1339
        throws InstanceNotFoundException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1340
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1341
            return (ClassLoader)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1342
                AccessController.doPrivileged(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1343
                    new PrivilegedExceptionAction<Object>() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1344
                        public Object run() throws InstanceNotFoundException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1345
                            return mbeanServer.getClassLoaderFor(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1346
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1347
                    });
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1348
        } catch (PrivilegedActionException pe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1349
            throw (InstanceNotFoundException) extractException(pe);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1350
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1351
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1352
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1353
    private Object doPrivilegedOperation(final int operation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1354
                                         final Object[] params,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1355
                                         final Subject delegationSubject)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1356
        throws PrivilegedActionException, IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1357
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1358
        serverCommunicatorAdmin.reqIncoming();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1359
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1360
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1361
            final AccessControlContext reqACC;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1362
            if (delegationSubject == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1363
                reqACC = acc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1364
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1365
                if (subject == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1366
                    final String msg =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1367
                        "Subject delegation cannot be enabled unless " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1368
                        "an authenticated subject is put in place";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1369
                    throw new SecurityException(msg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1370
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1371
                reqACC = subjectDelegator.delegatedContext(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1372
                    acc, delegationSubject, removeCallerContext);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1373
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1374
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1375
            PrivilegedOperation op =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1376
                new PrivilegedOperation(operation, params);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1377
            if (reqACC == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1378
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1379
                    return op.run();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1380
                } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1381
                    if (e instanceof RuntimeException)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1382
                        throw (RuntimeException) e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1383
                    throw new PrivilegedActionException(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1384
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1385
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1386
                return AccessController.doPrivileged(op, reqACC);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1387
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1388
        } catch (Error e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1389
            throw new JMXServerErrorException(e.toString(),e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1390
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1391
            serverCommunicatorAdmin.rspOutgoing();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1392
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1393
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1394
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1395
    private Object doOperation(int operation, Object[] params)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1396
        throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1397
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1398
        switch (operation) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1399
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1400
        case CREATE_MBEAN:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1401
            return mbeanServer.createMBean((String)params[0],
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1402
                                           (ObjectName)params[1]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1403
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1404
        case CREATE_MBEAN_LOADER:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1405
            return mbeanServer.createMBean((String)params[0],
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1406
                                           (ObjectName)params[1],
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1407
                                           (ObjectName)params[2]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1408
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1409
        case CREATE_MBEAN_PARAMS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1410
            return mbeanServer.createMBean((String)params[0],
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1411
                                           (ObjectName)params[1],
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1412
                                           (Object[])params[2],
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1413
                                           (String[])params[3]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1414
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1415
        case CREATE_MBEAN_LOADER_PARAMS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1416
            return mbeanServer.createMBean((String)params[0],
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1417
                                           (ObjectName)params[1],
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1418
                                           (ObjectName)params[2],
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1419
                                           (Object[])params[3],
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1420
                                           (String[])params[4]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1421
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1422
        case GET_ATTRIBUTE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1423
            return mbeanServer.getAttribute((ObjectName)params[0],
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1424
                                            (String)params[1]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1425
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1426
        case GET_ATTRIBUTES:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1427
            return mbeanServer.getAttributes((ObjectName)params[0],
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1428
                                             (String[])params[1]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1429
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1430
        case GET_DEFAULT_DOMAIN:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1431
            return mbeanServer.getDefaultDomain();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1432
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1433
        case GET_DOMAINS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1434
            return mbeanServer.getDomains();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1435
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1436
        case GET_MBEAN_COUNT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1437
            return mbeanServer.getMBeanCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1438
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1439
        case GET_MBEAN_INFO:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1440
            return mbeanServer.getMBeanInfo((ObjectName)params[0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1441
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1442
        case GET_OBJECT_INSTANCE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1443
            return mbeanServer.getObjectInstance((ObjectName)params[0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1444
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1445
        case INVOKE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1446
            return mbeanServer.invoke((ObjectName)params[0],
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1447
                                      (String)params[1],
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1448
                                      (Object[])params[2],
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1449
                                      (String[])params[3]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1450
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1451
        case IS_INSTANCE_OF:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1452
            return mbeanServer.isInstanceOf((ObjectName)params[0],
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1453
                                            (String)params[1])
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1454
                ? Boolean.TRUE : Boolean.FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1455
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1456
        case IS_REGISTERED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1457
            return mbeanServer.isRegistered((ObjectName)params[0])
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1458
                ? Boolean.TRUE : Boolean.FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1459
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1460
        case QUERY_MBEANS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1461
            return mbeanServer.queryMBeans((ObjectName)params[0],
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1462
                                           (QueryExp)params[1]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1463
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1464
        case QUERY_NAMES:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1465
            return mbeanServer.queryNames((ObjectName)params[0],
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1466
                                          (QueryExp)params[1]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1467
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1468
        case SET_ATTRIBUTE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1469
            mbeanServer.setAttribute((ObjectName)params[0],
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1470
                                     (Attribute)params[1]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1471
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1472
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1473
        case SET_ATTRIBUTES:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1474
            return mbeanServer.setAttributes((ObjectName)params[0],
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1475
                                             (AttributeList)params[1]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1476
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1477
        case UNREGISTER_MBEAN:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1478
            mbeanServer.unregisterMBean((ObjectName)params[0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1479
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1480
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1481
        case ADD_NOTIFICATION_LISTENERS:
4156
acaa49a2768a 6851617: Remove JSR 255 (JMX API 2.0) from JDK 7
emcmanus
parents: 1510
diff changeset
  1482
            return getServerNotifFwd().addNotificationListener(
acaa49a2768a 6851617: Remove JSR 255 (JMX API 2.0) from JDK 7
emcmanus
parents: 1510
diff changeset
  1483
                                                (ObjectName)params[0],
acaa49a2768a 6851617: Remove JSR 255 (JMX API 2.0) from JDK 7
emcmanus
parents: 1510
diff changeset
  1484
                                                (NotificationFilter)params[1]);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1485
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1486
        case ADD_NOTIFICATION_LISTENER_OBJECTNAME:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1487
            mbeanServer.addNotificationListener((ObjectName)params[0],
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1488
                                                (ObjectName)params[1],
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1489
                                                (NotificationFilter)params[2],
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1490
                                                params[3]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1491
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1492
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1493
        case REMOVE_NOTIFICATION_LISTENER:
4156
acaa49a2768a 6851617: Remove JSR 255 (JMX API 2.0) from JDK 7
emcmanus
parents: 1510
diff changeset
  1494
            getServerNotifFwd().removeNotificationListener(
acaa49a2768a 6851617: Remove JSR 255 (JMX API 2.0) from JDK 7
emcmanus
parents: 1510
diff changeset
  1495
                                                   (ObjectName)params[0],
acaa49a2768a 6851617: Remove JSR 255 (JMX API 2.0) from JDK 7
emcmanus
parents: 1510
diff changeset
  1496
                                                   (Integer[])params[1]);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1497
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1498
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1499
        case REMOVE_NOTIFICATION_LISTENER_OBJECTNAME:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1500
            mbeanServer.removeNotificationListener((ObjectName)params[0],
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1501
                                                   (ObjectName)params[1]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1502
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1503
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1504
        case REMOVE_NOTIFICATION_LISTENER_OBJECTNAME_FILTER_HANDBACK:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1505
            mbeanServer.removeNotificationListener(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1506
                                          (ObjectName)params[0],
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1507
                                          (ObjectName)params[1],
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1508
                                          (NotificationFilter)params[2],
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1509
                                          params[3]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1510
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1511
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1512
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1513
            throw new IllegalArgumentException("Invalid operation");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1514
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1515
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1516
1510
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 1247
diff changeset
  1517
    private static <T> T unwrap(final MarshalledObject<?> mo,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1518
                                final ClassLoader cl,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1519
                                final Class<T> wrappedClass)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1520
            throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1521
        if (mo == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1522
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1523
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1524
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1525
            return AccessController.doPrivileged(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1526
                new PrivilegedExceptionAction<T>() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1527
                    public T run()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1528
                            throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1529
                        final ClassLoader old =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1530
                            Thread.currentThread().getContextClassLoader();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1531
                        Thread.currentThread().setContextClassLoader(cl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1532
                        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1533
                            return wrappedClass.cast(mo.get());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1534
                        } catch (ClassNotFoundException cnfe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1535
                            throw new UnmarshalException(cnfe.toString(), cnfe);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1536
                        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1537
                            Thread.currentThread().setContextClassLoader(old);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1538
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1539
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1540
                });
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1541
        } catch (PrivilegedActionException pe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1542
            Exception e = extractException(pe);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1543
            if (e instanceof IOException) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1544
                throw (IOException) e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1545
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1546
            if (e instanceof ClassNotFoundException) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1547
                throw new UnmarshalException(e.toString(), e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1548
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1549
            logger.warning("unwrap", "Failed to unmarshall object: " + e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1550
            logger.debug("unwrap", e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1551
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1552
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1553
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1554
1510
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 1247
diff changeset
  1555
    private static <T> T unwrap(final MarshalledObject<?> mo,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1556
                                final ClassLoader cl1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1557
                                final ClassLoader cl2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1558
                                final Class<T> wrappedClass)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1559
        throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1560
        if (mo == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1561
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1562
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1563
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1564
            return AccessController.doPrivileged(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1565
                   new PrivilegedExceptionAction<T>() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1566
                       public T run()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1567
                           throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1568
                           return unwrap(mo, new OrderClassLoaders(cl1, cl2),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1569
                                         wrappedClass);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1570
                       }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1571
                   });
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1572
        } catch (PrivilegedActionException pe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1573
            Exception e = extractException(pe);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1574
            if (e instanceof IOException) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1575
                throw (IOException) e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1576
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1577
            if (e instanceof ClassNotFoundException) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1578
                throw new UnmarshalException(e.toString(), e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1579
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1580
            logger.warning("unwrap", "Failed to unmarshall object: " + e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1581
            logger.debug("unwrap", e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1582
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1583
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1584
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1585
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1586
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1587
     * Construct a new IOException with a nested exception.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1588
     * The nested exception is set only if JDK >= 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1589
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1590
    private static IOException newIOException(String message,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1591
                                              Throwable cause) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1592
        final IOException x = new IOException(message);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1593
        return EnvHelp.initCause(x,cause);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1594
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1595
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1596
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1597
     * Iterate until we extract the real exception
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1598
     * from a stack of PrivilegedActionExceptions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1599
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1600
    private static Exception extractException(Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1601
        while (e instanceof PrivilegedActionException) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1602
            e = ((PrivilegedActionException)e).getException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1603
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1604
        return e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1605
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1606
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1607
    private static final Object[] NO_OBJECTS = new Object[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1608
    private static final String[] NO_STRINGS = new String[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1609
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1610
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1611
     * The JMX spec doesn't explicitly say that a null Object[] or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1612
     * String[] in e.g. MBeanServer.invoke is equivalent to an empty
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1613
     * array, but the RI behaves that way.  In the interests of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1614
     * maximal interoperability, we make it so even when we're
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1615
     * connected to some other JMX implementation that might not do
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1616
     * that.  This should be clarified in the next version of JMX.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1617
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1618
    private static Object[] nullIsEmpty(Object[] array) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1619
        return (array == null) ? NO_OBJECTS : array;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1620
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1621
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1622
    private static String[] nullIsEmpty(String[] array) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1623
        return (array == null) ? NO_STRINGS : array;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1624
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1625
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1626
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1627
     * Similarly, the JMX spec says for some but not all methods in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1628
     * MBeanServer that take an ObjectName target, that if it's null
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1629
     * you get this exception.  We specify it for all of them, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1630
     * make it so for the ones where it's not specified in JMX even if
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1631
     * the JMX implementation doesn't do so.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1632
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1633
    private static void checkNonNull(String what, Object x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1634
        if (x == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1635
            RuntimeException wrapped =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1636
                new IllegalArgumentException(what + " must not be null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1637
            throw new RuntimeOperationsException(wrapped);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1638
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1639
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1640
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1641
    //------------------------------------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1642
    // private variables
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1643
    //------------------------------------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1644
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1645
    private final Subject subject;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1646
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1647
    private final SubjectDelegator subjectDelegator;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1648
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1649
    private final boolean removeCallerContext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1650
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1651
    private final AccessControlContext acc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1652
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1653
    private final RMIServerImpl rmiServer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1654
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1655
    private final MBeanServer mbeanServer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1656
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1657
    private final ClassLoader defaultClassLoader;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1658
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1659
    private final ClassLoaderWithRepository classLoaderWithRepository;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1660
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1661
    private boolean terminated = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1662
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1663
    private final String connectionId;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1664
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1665
    private final ServerCommunicatorAdmin serverCommunicatorAdmin;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1666
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1667
    // Method IDs for doOperation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1668
    //---------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1669
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1670
    private final static int
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1671
        ADD_NOTIFICATION_LISTENERS                              = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1672
    private final static int
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1673
        ADD_NOTIFICATION_LISTENER_OBJECTNAME                    = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1674
    private final static int
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1675
        CREATE_MBEAN                                            = 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1676
    private final static int
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1677
        CREATE_MBEAN_PARAMS                                     = 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1678
    private final static int
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1679
        CREATE_MBEAN_LOADER                                     = 5;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1680
    private final static int
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1681
        CREATE_MBEAN_LOADER_PARAMS                              = 6;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1682
    private final static int
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1683
        GET_ATTRIBUTE                                           = 7;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1684
    private final static int
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1685
        GET_ATTRIBUTES                                          = 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1686
    private final static int
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1687
        GET_DEFAULT_DOMAIN                                      = 9;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1688
    private final static int
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1689
        GET_DOMAINS                                             = 10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1690
    private final static int
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1691
        GET_MBEAN_COUNT                                         = 11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1692
    private final static int
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1693
        GET_MBEAN_INFO                                          = 12;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1694
    private final static int
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1695
        GET_OBJECT_INSTANCE                                     = 13;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1696
    private final static int
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1697
        INVOKE                                                  = 14;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1698
    private final static int
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1699
        IS_INSTANCE_OF                                          = 15;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1700
    private final static int
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1701
        IS_REGISTERED                                           = 16;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1702
    private final static int
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1703
        QUERY_MBEANS                                            = 17;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1704
    private final static int
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1705
        QUERY_NAMES                                             = 18;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1706
    private final static int
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1707
        REMOVE_NOTIFICATION_LISTENER                            = 19;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1708
    private final static int
1004
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
  1709
        REMOVE_NOTIFICATION_LISTENER_OBJECTNAME                 = 20;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1710
    private final static int
1004
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
  1711
        REMOVE_NOTIFICATION_LISTENER_OBJECTNAME_FILTER_HANDBACK = 21;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1712
    private final static int
1004
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
  1713
        SET_ATTRIBUTE                                           = 22;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1714
    private final static int
1004
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
  1715
        SET_ATTRIBUTES                                          = 23;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1716
    private final static int
1004
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
  1717
        UNREGISTER_MBEAN                                        = 24;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1718
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1719
    // SERVER NOTIFICATION
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1720
    //--------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1721
4156
acaa49a2768a 6851617: Remove JSR 255 (JMX API 2.0) from JDK 7
emcmanus
parents: 1510
diff changeset
  1722
    private ServerNotifForwarder serverNotifForwarder;
1004
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
  1723
    private Map<String, ?> env;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1724
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1725
    // TRACES & DEBUG
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1726
    //---------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1727
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1728
    private static String objects(final Object[] objs) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1729
        if (objs == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1730
            return "null";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1731
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1732
            return Arrays.asList(objs).toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1733
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1734
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1735
    private static String strings(final String[] strs) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1736
        return objects(strs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1737
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1738
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1739
    private static final ClassLogger logger =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1740
        new ClassLogger("javax.management.remote.rmi", "RMIConnectionImpl");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1741
}