IdentityMBeanServerForwarder.java 12.0 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303
/*
 * Copyright 2008 Sun Microsystems, Inc.  All Rights Reserved.
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * This code is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 only, as
 * published by the Free Software Foundation.  Sun designates this
 * particular file as subject to the "Classpath" exception as provided
 * by Sun in the LICENSE file that accompanied this code.
 *
 * This code is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * version 2 for more details (a copy is included in the LICENSE file that
 * accompanied this code).
 *
 * You should have received a copy of the GNU General Public License version
 * 2 along with this work; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
 * CA 95054 USA or visit www.sun.com if you need additional information or
 * have any questions.
 */
package javax.management.remote;

import java.io.ObjectInputStream;
import java.util.Set;
import javax.management.Attribute;
import javax.management.AttributeList;
import javax.management.AttributeNotFoundException;
import javax.management.InstanceAlreadyExistsException;
import javax.management.InstanceNotFoundException;
import javax.management.IntrospectionException;
import javax.management.InvalidAttributeValueException;
import javax.management.ListenerNotFoundException;
import javax.management.MBeanException;
import javax.management.MBeanInfo;
import javax.management.MBeanRegistrationException;
import javax.management.MBeanServer;
import javax.management.NotCompliantMBeanException;
import javax.management.NotificationFilter;
import javax.management.NotificationListener;
import javax.management.ObjectInstance;
import javax.management.ObjectName;
import javax.management.OperationsException;
import javax.management.QueryExp;
import javax.management.ReflectionException;
import javax.management.loading.ClassLoaderRepository;

/**
 * An {@link MBeanServerForwarder} that forwards all {@link MBeanServer}
 * operations unchanged to the next {@code MBeanServer} in the chain.
 * This class is typically subclassed to override some but not all methods.
 */
public class IdentityMBeanServerForwarder implements MBeanServerForwarder {

    private MBeanServer next;

    /**
     * <p>Construct a forwarder that has no next {@code MBeanServer}.
     * The resulting object will be unusable until {@link #setMBeanServer
     * setMBeanServer} is called to establish the next item in the chain.</p>
     */
    public IdentityMBeanServerForwarder() {
    }

    /**
     * <p>Construct a forwarder that forwards to the given {@code MBeanServer}.
     * It is not an error for {@code next} to be null, but the resulting object
     * will be unusable until {@link #setMBeanServer setMBeanServer} is called
     * to establish the next item in the chain.</p>
     */
    public IdentityMBeanServerForwarder(MBeanServer next) {
        this.next = next;
    }

    public synchronized MBeanServer getMBeanServer() {
        return next;
    }

    public synchronized void setMBeanServer(MBeanServer mbs) {
        next = mbs;
    }

    private synchronized MBeanServer next() {
        return next;
    }

    public void unregisterMBean(ObjectName name)
            throws InstanceNotFoundException, MBeanRegistrationException {
        next().unregisterMBean(name);
    }

    public AttributeList setAttributes(ObjectName name,
                                        AttributeList attributes)
            throws InstanceNotFoundException, ReflectionException {
        return next().setAttributes(name, attributes);
    }

    public void setAttribute(ObjectName name, Attribute attribute)
            throws InstanceNotFoundException, AttributeNotFoundException,
                   InvalidAttributeValueException, MBeanException,
                   ReflectionException {
        next().setAttribute(name, attribute);
    }

    public void removeNotificationListener(ObjectName name,
                                            NotificationListener listener,
                                            NotificationFilter filter,
                                            Object handback)
            throws InstanceNotFoundException, ListenerNotFoundException {
        next().removeNotificationListener(name, listener, filter, handback);
    }

    public void removeNotificationListener(ObjectName name,
                                            NotificationListener listener)
            throws InstanceNotFoundException, ListenerNotFoundException {
        next().removeNotificationListener(name, listener);
    }

    public void removeNotificationListener(ObjectName name, ObjectName listener,
                                            NotificationFilter filter,
                                            Object handback)
            throws InstanceNotFoundException, ListenerNotFoundException {
        next().removeNotificationListener(name, listener, filter, handback);
    }

    public void removeNotificationListener(ObjectName name, ObjectName listener)
            throws InstanceNotFoundException, ListenerNotFoundException {
        next().removeNotificationListener(name, listener);
    }

    public ObjectInstance registerMBean(Object object, ObjectName name)
            throws InstanceAlreadyExistsException, MBeanRegistrationException,
                   NotCompliantMBeanException {
        return next().registerMBean(object, name);
    }

    public Set<ObjectName> queryNames(ObjectName name, QueryExp query) {
        return next().queryNames(name, query);
    }

    public Set<ObjectInstance> queryMBeans(ObjectName name, QueryExp query) {
        return next().queryMBeans(name, query);
    }

    public boolean isRegistered(ObjectName name) {
        return next().isRegistered(name);
    }

    public boolean isInstanceOf(ObjectName name, String className)
            throws InstanceNotFoundException {
        return next().isInstanceOf(name, className);
    }

    public Object invoke(ObjectName name, String operationName, Object[] params,
                          String[] signature)
            throws InstanceNotFoundException, MBeanException,
                   ReflectionException {
        return next().invoke(name, operationName, params, signature);
    }

    public Object instantiate(String className, ObjectName loaderName,
                               Object[] params, String[] signature)
            throws ReflectionException, MBeanException,
                   InstanceNotFoundException {
        return next().instantiate(className, loaderName, params, signature);
    }

    public Object instantiate(String className, Object[] params,
                               String[] signature)
            throws ReflectionException, MBeanException {
        return next().instantiate(className, params, signature);
    }

    public Object instantiate(String className, ObjectName loaderName)
            throws ReflectionException, MBeanException,
                   InstanceNotFoundException {
        return next().instantiate(className, loaderName);
    }

    public Object instantiate(String className)
            throws ReflectionException, MBeanException {
        return next().instantiate(className);
    }

    public ObjectInstance getObjectInstance(ObjectName name)
            throws InstanceNotFoundException {
        return next().getObjectInstance(name);
    }

    public MBeanInfo getMBeanInfo(ObjectName name)
            throws InstanceNotFoundException, IntrospectionException,
                   ReflectionException {
        return next().getMBeanInfo(name);
    }

    public Integer getMBeanCount() {
        return next().getMBeanCount();
    }

    public String[] getDomains() {
        return next().getDomains();
    }

    public String getDefaultDomain() {
        return next().getDefaultDomain();
    }

    public ClassLoaderRepository getClassLoaderRepository() {
        return next().getClassLoaderRepository();
    }

    public ClassLoader getClassLoaderFor(ObjectName mbeanName)
            throws InstanceNotFoundException {
        return next().getClassLoaderFor(mbeanName);
    }

    public ClassLoader getClassLoader(ObjectName loaderName)
            throws InstanceNotFoundException {
        return next().getClassLoader(loaderName);
    }

    public AttributeList getAttributes(ObjectName name, String[] attributes)
            throws InstanceNotFoundException, ReflectionException {
        return next().getAttributes(name, attributes);
    }

    public Object getAttribute(ObjectName name, String attribute)
            throws MBeanException, AttributeNotFoundException,
                   InstanceNotFoundException, ReflectionException {
        return next().getAttribute(name, attribute);
    }

    @Deprecated
    public ObjectInputStream deserialize(String className,
                                          ObjectName loaderName,
                                          byte[] data)
            throws InstanceNotFoundException, OperationsException,
                   ReflectionException {
        return next().deserialize(className, loaderName, data);
    }

    @Deprecated
    public ObjectInputStream deserialize(String className, byte[] data)
            throws OperationsException, ReflectionException {
        return next().deserialize(className, data);
    }

    @Deprecated
    public ObjectInputStream deserialize(ObjectName name, byte[] data)
            throws InstanceNotFoundException, OperationsException {
        return next().deserialize(name, data);
    }

    public ObjectInstance createMBean(String className, ObjectName name,
                                       ObjectName loaderName, Object[] params,
                                       String[] signature)
            throws ReflectionException, InstanceAlreadyExistsException,
                   MBeanRegistrationException, MBeanException,
                   NotCompliantMBeanException, InstanceNotFoundException {
        return next().createMBean(className, name, loaderName, params, signature);
    }

    public ObjectInstance createMBean(String className, ObjectName name,
                                       Object[] params, String[] signature)
            throws ReflectionException, InstanceAlreadyExistsException,
                   MBeanRegistrationException, MBeanException,
                   NotCompliantMBeanException {
        return next().createMBean(className, name, params, signature);
    }

    public ObjectInstance createMBean(String className, ObjectName name,
                                       ObjectName loaderName)
            throws ReflectionException, InstanceAlreadyExistsException,
                   MBeanRegistrationException, MBeanException,
                   NotCompliantMBeanException, InstanceNotFoundException {
        return next().createMBean(className, name, loaderName);
    }

    public ObjectInstance createMBean(String className, ObjectName name)
            throws ReflectionException, InstanceAlreadyExistsException,
                   MBeanRegistrationException, MBeanException,
                   NotCompliantMBeanException {
        return next().createMBean(className, name);
    }

    public void addNotificationListener(ObjectName name, ObjectName listener,
                                         NotificationFilter filter,
                                         Object handback)
            throws InstanceNotFoundException {
        next().addNotificationListener(name, listener, filter, handback);
    }

    public void addNotificationListener(ObjectName name,
                                         NotificationListener listener,
                                         NotificationFilter filter,
                                         Object handback)
            throws InstanceNotFoundException {
        next().addNotificationListener(name, listener, filter, handback);
    }
}