jdk/src/share/classes/javax/management/modelmbean/RequiredModelMBean.java
author dsamersoff
Fri, 07 Dec 2012 22:49:08 +0400
changeset 16102 59bd4d83778a
parent 5506 202f599c92aa
child 20808 87159c70b5fd
permissions -rw-r--r--
8000537: Contextualize RequiredModelMBean class Summary: Contextualize RequiredModelMBean class Reviewed-by: asaha Contributed-by: jaroslav.bachorik@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
16102
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
     2
 * Copyright (c) 2000, 2012, Oracle and/or its affiliates. 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
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4156
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4156
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
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
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4156
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4156
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4156
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
/*
4156
acaa49a2768a 6851617: Remove JSR 255 (JMX API 2.0) from JDK 7
emcmanus
parents: 1510
diff changeset
    26
 * @author    IBM Corp.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 * Copyright IBM Corp. 1999-2000.  All rights reserved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
package javax.management.modelmbean;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
/* java imports */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import static com.sun.jmx.defaults.JmxProperties.MODELMBEAN_LOGGER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.io.FileOutputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.io.PrintStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.lang.reflect.InvocationTargetException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import java.lang.reflect.Method;
16102
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
    42
import java.security.AccessControlContext;
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
    43
import java.security.AccessController;
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
    44
import java.security.PrivilegedAction;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
import java.util.Date;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
import java.util.HashMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
import java.util.HashSet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
import java.util.logging.Level;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
import java.util.Map;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
import java.util.Set;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
263
db2a63668df3 6675768: NoSuchElementException thrown in RequiredModelMBean when tracing enabled
emcmanus
parents: 2
diff changeset
    53
import java.util.Vector;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
import javax.management.Attribute;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
import javax.management.AttributeChangeNotification;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
import javax.management.AttributeChangeNotificationFilter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
import javax.management.AttributeList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
import javax.management.AttributeNotFoundException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
import javax.management.Descriptor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
import javax.management.InstanceNotFoundException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
import javax.management.InvalidAttributeValueException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
import javax.management.ListenerNotFoundException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
import javax.management.MBeanAttributeInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
import javax.management.MBeanConstructorInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
import javax.management.MBeanException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
import javax.management.MBeanInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
import javax.management.MBeanNotificationInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
import javax.management.MBeanOperationInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
import javax.management.MBeanRegistration;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
import javax.management.MBeanServer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
import javax.management.MBeanServerFactory;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
import javax.management.Notification;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
import javax.management.NotificationBroadcasterSupport;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
import javax.management.NotificationEmitter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
import javax.management.NotificationFilter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
import javax.management.NotificationListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
import javax.management.ObjectName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
import javax.management.ReflectionException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
import javax.management.RuntimeErrorException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
import javax.management.RuntimeOperationsException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
import javax.management.ServiceNotFoundException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
import javax.management.loading.ClassLoaderRepository;
16102
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
    83
import sun.misc.JavaSecurityAccess;
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
    84
import sun.misc.SharedSecrets;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
import sun.reflect.misc.MethodUtil;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
import sun.reflect.misc.ReflectUtil;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
 * This class is the implementation of a ModelMBean. An appropriate
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
 * implementation of a ModelMBean must be shipped with every JMX Agent
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
 * and the class must be named RequiredModelMBean.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
 * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
 * Java resources wishing to be manageable instantiate the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
 * RequiredModelMBean using the MBeanServer's createMBean method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
 * The resource then sets the MBeanInfo and Descriptors for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
 * RequiredModelMBean instance. The attributes and operations exposed
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
 * via the ModelMBeanInfo for the ModelMBean are accessible
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
 * from MBeans, connectors/adaptors like other MBeans. Through the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
 * Descriptors, values and methods in the managed application can be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
 * defined and mapped to attributes and operations of the ModelMBean.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
 * This mapping can be defined in an XML formatted file or dynamically and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
 * programmatically at runtime.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
 * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
 * Every RequiredModelMBean which is instantiated in the MBeanServer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
 * becomes manageable:<br>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
 * its attributes and operations become remotely accessible through the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
 * connectors/adaptors connected to that MBeanServer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
 * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
 * A Java object cannot be registered in the MBeanServer unless it is a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
 * JMX compliant MBean. By instantiating a RequiredModelMBean, resources
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
 * are guaranteed that the MBean is valid.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
 * MBeanException and RuntimeOperationsException must be thrown on every
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
 * public method.  This allows for wrapping exceptions from distributed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
 * communications (RMI, EJB, etc.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
 * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
public class RequiredModelMBean
4156
acaa49a2768a 6851617: Remove JSR 255 (JMX API 2.0) from JDK 7
emcmanus
parents: 1510
diff changeset
   122
    implements ModelMBean, MBeanRegistration, NotificationEmitter {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    /*************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    /* attributes                        */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    /*************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    ModelMBeanInfo modelMBeanInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    /* Notification broadcaster for any notification to be sent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     * from the application through the RequiredModelMBean.  */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    private NotificationBroadcasterSupport generalBroadcaster = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    /* Notification broadcaster for attribute change notifications */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    private NotificationBroadcasterSupport attributeBroadcaster = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    /* handle, name, or reference for instance on which the actual invoke
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     * and operations will be executed */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    private Object managedResource = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
833
bfa2bef7517c 6323980: Annotations to simplify MBean development
emcmanus
parents: 623
diff changeset
   140
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    /* records the registering in MBeanServer */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    private boolean registered = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    private transient MBeanServer server = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
16102
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
   145
    private final static JavaSecurityAccess javaSecurityAccess = SharedSecrets.getJavaSecurityAccess();
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
   146
    final private AccessControlContext acc = AccessController.getContext();
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
   147
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    /*************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    /* constructors                      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    /*************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     * Constructs an <CODE>RequiredModelMBean</CODE> with an empty
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     * ModelMBeanInfo.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     * The RequiredModelMBean's MBeanInfo and Descriptors
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     * can be customized using the {@link #setModelMBeanInfo} method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     * After the RequiredModelMBean's MBeanInfo and Descriptors are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     * customized, the RequiredModelMBean can be registered with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     * the MBeanServer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     * @exception MBeanException Wraps a distributed communication Exception.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     * @exception RuntimeOperationsException Wraps a {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     * RuntimeException} during the construction of the object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    public RequiredModelMBean()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        throws MBeanException, RuntimeOperationsException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
            MODELMBEAN_LOGGER.logp(Level.FINER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
                    RequiredModelMBean.class.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
                    "RequiredModelMBean()", "Entry");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        modelMBeanInfo = createDefaultModelMBeanInfo();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
            MODELMBEAN_LOGGER.logp(Level.FINER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
                    RequiredModelMBean.class.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
                    "RequiredModelMBean()", "Exit");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     * Constructs a RequiredModelMBean object using ModelMBeanInfo passed in.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     * As long as the RequiredModelMBean is not registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     * with the MBeanServer yet, the RequiredModelMBean's MBeanInfo and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     * Descriptors can be customized using the {@link #setModelMBeanInfo}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     * method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     * After the RequiredModelMBean's MBeanInfo and Descriptors are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     * customized, the RequiredModelMBean can be registered with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     * MBeanServer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     * @param mbi The ModelMBeanInfo object to be used by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     *            RequiredModelMBean. The given ModelMBeanInfo is cloned
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     *            and modified as specified by {@link #setModelMBeanInfo}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     * @exception MBeanException Wraps a distributed communication Exception.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     * @exception RuntimeOperationsException Wraps an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     *    {link java.lang.IllegalArgumentException}:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     *          The MBeanInfo passed in parameter is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    public RequiredModelMBean(ModelMBeanInfo mbi)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        throws MBeanException, RuntimeOperationsException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
            MODELMBEAN_LOGGER.logp(Level.FINER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
                    RequiredModelMBean.class.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
                    "RequiredModelMBean(MBeanInfo)", "Entry");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        setModelMBeanInfo(mbi);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
            MODELMBEAN_LOGGER.logp(Level.FINER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
                    RequiredModelMBean.class.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
                    "RequiredModelMBean(MBeanInfo)", "Exit");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    /*************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
    /* initializers                      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    /*************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     * Initializes a ModelMBean object using ModelMBeanInfo passed in.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     * This method makes it possible to set a customized ModelMBeanInfo on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     * the ModelMBean as long as it is not registered with the MBeanServer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     * <br>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     * Once the ModelMBean's ModelMBeanInfo (with Descriptors) are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     * customized and set on the ModelMBean, the  ModelMBean be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     * registered with the MBeanServer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     * If the ModelMBean is currently registered, this method throws
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     * a {@link javax.management.RuntimeOperationsException} wrapping an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     * {@link IllegalStateException}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     * If the given <var>inModelMBeanInfo</var> does not contain any
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     * {@link ModelMBeanNotificationInfo} for the <code>GENERIC</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     * or <code>ATTRIBUTE_CHANGE</code> notifications, then the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     * RequiredModelMBean will supply its own default
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     * {@link ModelMBeanNotificationInfo ModelMBeanNotificationInfo}s for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     * those missing notifications.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     * @param mbi The ModelMBeanInfo object to be used
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     *        by the ModelMBean.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     * @exception MBeanException Wraps a distributed communication
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     *        Exception.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     * @exception RuntimeOperationsException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     * <ul><li>Wraps an {@link IllegalArgumentException} if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     *         the MBeanInfo passed in parameter is null.</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     *     <li>Wraps an {@link IllegalStateException} if the ModelMBean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     *         is currently registered in the MBeanServer.</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
    public void setModelMBeanInfo(ModelMBeanInfo mbi)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        throws MBeanException, RuntimeOperationsException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
            MODELMBEAN_LOGGER.logp(Level.FINER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
                    RequiredModelMBean.class.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
                "setModelMBeanInfo(ModelMBeanInfo)","Entry");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        if (mbi == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
            if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
                MODELMBEAN_LOGGER.logp(Level.FINER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
                        RequiredModelMBean.class.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
                    "setModelMBeanInfo(ModelMBeanInfo)",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
                    "ModelMBeanInfo is null: Raising exception.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
            final RuntimeException x = new
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
                IllegalArgumentException("ModelMBeanInfo must not be null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
            final String exceptionText =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
                "Exception occurred trying to initialize the " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
                "ModelMBeanInfo of the RequiredModelMBean";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
            throw new RuntimeOperationsException(x,exceptionText);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        if (registered) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
            if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
                MODELMBEAN_LOGGER.logp(Level.FINER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
                        RequiredModelMBean.class.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
                    "setModelMBeanInfo(ModelMBeanInfo)",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
                    "RequiredMBean is registered: Raising exception.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
            final String exceptionText =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
                "Exception occurred trying to set the " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
                "ModelMBeanInfo of the RequiredModelMBean";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
            final RuntimeException x = new IllegalStateException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
             "cannot call setModelMBeanInfo while ModelMBean is registered");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
            throw new RuntimeOperationsException(x,exceptionText);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
        if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
            MODELMBEAN_LOGGER.logp(Level.FINER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
                    RequiredModelMBean.class.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
                "setModelMBeanInfo(ModelMBeanInfo)",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
                "Setting ModelMBeanInfo to " + printModelMBeanInfo(mbi));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
            MODELMBEAN_LOGGER.logp(Level.FINER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
                    RequiredModelMBean.class.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
                "setModelMBeanInfo(ModelMBeanInfo)",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
                "ModelMBeanInfo notifications has " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
                (mbi.getNotifications()).length + " elements");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
        modelMBeanInfo = (ModelMBeanInfo)mbi.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
        if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
            MODELMBEAN_LOGGER.logp(Level.FINER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
                    RequiredModelMBean.class.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
                "setModelMBeanInfo(ModelMBeanInfo)","set mbeanInfo to: "+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
                 printModelMBeanInfo(modelMBeanInfo));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
            MODELMBEAN_LOGGER.logp(Level.FINER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
                    RequiredModelMBean.class.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
                "setModelMBeanInfo(ModelMBeanInfo)","Exit");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     * Sets the instance handle of the object against which to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     * execute all methods in this ModelMBean management interface
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
     * (MBeanInfo and Descriptors).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
     * @param mr Object that is the managed resource
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
     * @param mr_type The type of reference for the managed resource.
4156
acaa49a2768a 6851617: Remove JSR 255 (JMX API 2.0) from JDK 7
emcmanus
parents: 1510
diff changeset
   329
     *     <br>Can be: "ObjectReference", "Handle", "IOR", "EJBHandle",
acaa49a2768a 6851617: Remove JSR 255 (JMX API 2.0) from JDK 7
emcmanus
parents: 1510
diff changeset
   330
     *         or "RMIReference".
acaa49a2768a 6851617: Remove JSR 255 (JMX API 2.0) from JDK 7
emcmanus
parents: 1510
diff changeset
   331
     *     <br>In this implementation only "ObjectReference" is supported.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
     * @exception MBeanException The initializer of the object has
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
     *            thrown an exception.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
     * @exception InstanceNotFoundException The managed resource
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
     *            object could not be found
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
     * @exception InvalidTargetObjectTypeException The managed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
     *            resource type should be "ObjectReference".
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
     * @exception RuntimeOperationsException Wraps a {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
     *            RuntimeException} when setting the resource.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
     **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
    public void setManagedResource(Object mr, String mr_type)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
        throws MBeanException, RuntimeOperationsException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
               InstanceNotFoundException, InvalidTargetObjectTypeException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
        if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
            MODELMBEAN_LOGGER.logp(Level.FINER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
                    RequiredModelMBean.class.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
                "setManagedResource(Object,String)","Entry");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
        // check that the mr_type is supported by this JMXAgent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
        // only "objectReference" is supported
4156
acaa49a2768a 6851617: Remove JSR 255 (JMX API 2.0) from JDK 7
emcmanus
parents: 1510
diff changeset
   353
        if ((mr_type == null) ||
acaa49a2768a 6851617: Remove JSR 255 (JMX API 2.0) from JDK 7
emcmanus
parents: 1510
diff changeset
   354
            (! mr_type.equalsIgnoreCase("objectReference"))) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
            if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
                MODELMBEAN_LOGGER.logp(Level.FINER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
                        RequiredModelMBean.class.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
                    "setManagedResource(Object,String)",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
                    "Managed Resouce Type is not supported: " + mr_type);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
            throw new InvalidTargetObjectTypeException(mr_type);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
        if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
            MODELMBEAN_LOGGER.logp(Level.FINER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
                    RequiredModelMBean.class.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
                "setManagedResource(Object,String)",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
                "Managed Resouce is valid");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
        managedResource = mr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
        if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
            MODELMBEAN_LOGGER.logp(Level.FINER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
                    RequiredModelMBean.class.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
                "setManagedResource(Object, String)", "Exit");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
     * <p>Instantiates this MBean instance with the data found for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
     * the MBean in the persistent store.  The data loaded could include
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
     * attribute and operation values.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
     * <p>This method should be called during construction or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
     * initialization of this instance, and before the MBean is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
     * registered with the MBeanServer.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
     * <p>If the implementation of this class does not support
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
     * persistence, an {@link MBeanException} wrapping a {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
     * ServiceNotFoundException} is thrown.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
     * @exception MBeanException Wraps another exception, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
     * persistence is not supported
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
     * @exception RuntimeOperationsException Wraps exceptions from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
     * persistence mechanism
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
     * @exception InstanceNotFoundException Could not find or load
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
     * this MBean from persistent storage
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
    public void load()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
        throws MBeanException, RuntimeOperationsException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
               InstanceNotFoundException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
        final ServiceNotFoundException x = new ServiceNotFoundException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
                                "Persistence not supported for this MBean");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
        throw new MBeanException(x, x.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
     * <p>Captures the current state of this MBean instance and writes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
     * it out to the persistent store.  The state stored could include
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
     * attribute and operation values.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
     * <p>If the implementation of this class does not support
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
     * persistence, an {@link MBeanException} wrapping a {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
     * ServiceNotFoundException} is thrown.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
     * <p>Persistence policy from the MBean and attribute descriptor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
     * is used to guide execution of this method. The MBean should be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
     * stored if 'persistPolicy' field is:</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
     * <PRE>  != "never"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
     *   = "always"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
     *   = "onTimer" and now > 'lastPersistTime' + 'persistPeriod'
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
     *   = "NoMoreOftenThan" and now > 'lastPersistTime' + 'persistPeriod'
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
     *   = "onUnregister"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
     * </PRE>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
     * <p>Do not store the MBean if 'persistPolicy' field is:</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
     * <PRE>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
     *    = "never"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
     *    = "onUpdate"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
     *    = "onTimer" && now < 'lastPersistTime' + 'persistPeriod'
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
     * </PRE>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
     * @exception MBeanException Wraps another exception, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
     * persistence is not supported
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
     * @exception RuntimeOperationsException Wraps exceptions from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
     * persistence mechanism
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
     * @exception InstanceNotFoundException Could not find/access the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
     * persistent store
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
    public void store()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
        throws MBeanException, RuntimeOperationsException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
               InstanceNotFoundException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
        final ServiceNotFoundException x = new ServiceNotFoundException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
                                "Persistence not supported for this MBean");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
        throw new MBeanException(x, x.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
    /*************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
    /* DynamicMBean Interface            */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
    /*************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
     * The resolveForCacheValue method checks the descriptor passed in to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
     * see if there is a valid cached value in the descriptor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
     * The valid value will be in the 'value' field if there is one.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
     * If the 'currencyTimeLimit' field in the descriptor is:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
     *   <li><b>&lt;0</b> Then the value is not cached and is never valid.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
     *         Null is returned. The 'value' and 'lastUpdatedTimeStamp'
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
     *         fields are cleared.</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
     *   <li><b>=0</b> Then the value is always cached and always valid.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
     *         The 'value' field is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
     *         The 'lastUpdatedTimeStamp' field is not checked.</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
     *   <li><b>&gt;0</b> Represents the number of seconds that the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
     *         'value' field is valid.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
     *         The 'value' field is no longer valid when
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
     *         'lastUpdatedTimeStamp' + 'currencyTimeLimit' &gt; Now.</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
     * <li>When 'value' is valid, 'valid' is returned.</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
     * <li>When 'value' is no longer valid then null is returned and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
     *     'value' and 'lastUpdatedTimeStamp' fields are cleared.</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
     **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
    private Object resolveForCacheValue(Descriptor descr)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
        throws MBeanException, RuntimeOperationsException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
        final boolean tracing = MODELMBEAN_LOGGER.isLoggable(Level.FINER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
        final String mth = "resolveForCacheValue(Descriptor)";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
        if (tracing) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
            MODELMBEAN_LOGGER.logp(Level.FINER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
                    RequiredModelMBean.class.getName(),mth,"Entry");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
        Object response = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
        boolean resetValue = false, returnCachedValue = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
        long currencyPeriod = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
        if (descr == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
            if (tracing) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
                MODELMBEAN_LOGGER.logp(Level.FINER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
                        RequiredModelMBean.class.getName(),mth,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
                    "Input Descriptor is null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
            return response;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
        if (tracing) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
            MODELMBEAN_LOGGER.logp(Level.FINER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
                    RequiredModelMBean.class.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
                    mth, "descriptor is " + descr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
        final Descriptor mmbDescr = modelMBeanInfo.getMBeanDescriptor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
        if (mmbDescr == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
            if (tracing) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
                MODELMBEAN_LOGGER.logp(Level.FINER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
                    RequiredModelMBean.class.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
                        mth,"MBean Descriptor is null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
            //return response;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
        Object objExpTime = descr.getFieldValue("currencyTimeLimit");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
        String expTime;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
        if (objExpTime != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
            expTime = objExpTime.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
            expTime = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
        if ((expTime == null) && (mmbDescr != null)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
            objExpTime = mmbDescr.getFieldValue("currencyTimeLimit");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
            if (objExpTime != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
                expTime = objExpTime.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
                expTime = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
        if (expTime != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
            if (tracing) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
                MODELMBEAN_LOGGER.logp(Level.FINER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
                    RequiredModelMBean.class.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
                        mth,"currencyTimeLimit: " + expTime);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
            // convert seconds to milliseconds for time comparison
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
            currencyPeriod = ((new Long(expTime)).longValue()) * 1000;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
            if (currencyPeriod < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
                /* if currencyTimeLimit is -1 then value is never cached */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
                returnCachedValue = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
                resetValue = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
                if (tracing) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
                    MODELMBEAN_LOGGER.logp(Level.FINER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
                            RequiredModelMBean.class.getName(),mth,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
                        currencyPeriod + ": never Cached");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
            } else if (currencyPeriod == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
                /* if currencyTimeLimit is 0 then value is always cached */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
                returnCachedValue = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
                resetValue = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
                if (tracing) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
                    MODELMBEAN_LOGGER.logp(Level.FINER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
                            RequiredModelMBean.class.getName(),mth,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
                        "always valid Cache");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
                Object objtStamp =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
                    descr.getFieldValue("lastUpdatedTimeStamp");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
                String tStamp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
                if (objtStamp != null) tStamp = objtStamp.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
                else tStamp = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
                if (tracing) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
                    MODELMBEAN_LOGGER.logp(Level.FINER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
                            RequiredModelMBean.class.getName(),mth,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
                        "lastUpdatedTimeStamp: " + tStamp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
                if (tStamp == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
                    tStamp = "0";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
                long lastTime = (new Long(tStamp)).longValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
                if (tracing) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
                    MODELMBEAN_LOGGER.logp(Level.FINER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
                            RequiredModelMBean.class.getName(),mth,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
                        "currencyPeriod:" + currencyPeriod +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
                        " lastUpdatedTimeStamp:" + lastTime);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
                long now = (new Date()).getTime();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
                if (now < (lastTime + currencyPeriod)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
                    returnCachedValue = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
                    resetValue = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
                    if (tracing) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
                        MODELMBEAN_LOGGER.logp(Level.FINER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
                                RequiredModelMBean.class.getName(),mth,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
                            " timed valid Cache for " + now + " < " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
                            (lastTime + currencyPeriod));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
                } else { /* value is expired */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
                    returnCachedValue = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
                    resetValue = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
                    if (tracing) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
                        MODELMBEAN_LOGGER.logp(Level.FINER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
                                RequiredModelMBean.class.getName(),mth,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
                            "timed expired cache for " + now + " > " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
                            (lastTime + currencyPeriod));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
            if (tracing) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
                MODELMBEAN_LOGGER.logp(Level.FINER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
                        RequiredModelMBean.class.getName(),mth,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
                    "returnCachedValue:" + returnCachedValue +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
                    " resetValue: " + resetValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
            if (returnCachedValue == true) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
                Object currValue = descr.getFieldValue("value");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
                if (currValue != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
                    /* error/validity check return value here */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
                    response = currValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
                    /* need to cast string cached value to type */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
                    if (tracing) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
                        MODELMBEAN_LOGGER.logp(Level.FINER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
                                RequiredModelMBean.class.getName(),mth,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
                            "valid Cache value: " + currValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
                    response = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
                    if (tracing) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
                        MODELMBEAN_LOGGER.logp(Level.FINER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
                            RequiredModelMBean.class.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
                                mth,"no Cached value");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
            if (resetValue == true) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
                /* value is not current, so remove it */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
                descr.removeField("lastUpdatedTimeStamp");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
                descr.removeField("value");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
                response = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
                modelMBeanInfo.setDescriptor(descr,null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
                if (tracing) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
                    MODELMBEAN_LOGGER.logp(Level.FINER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
                        RequiredModelMBean.class.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
                            mth,"reset cached value to null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
        if (tracing) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
            MODELMBEAN_LOGGER.logp(Level.FINER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
                    RequiredModelMBean.class.getName(),mth,"Exit");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
        return response;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
     * Returns the attributes, operations, constructors and notifications
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
     * that this RequiredModelMBean exposes for management.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
     * @return  An instance of ModelMBeanInfo allowing retrieval all
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
     *          attributes, operations, and Notifications of this MBean.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
     **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
    public MBeanInfo getMBeanInfo() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
        if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
            MODELMBEAN_LOGGER.logp(Level.FINER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
                    RequiredModelMBean.class.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
                    "getMBeanInfo()","Entry");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
        if (modelMBeanInfo == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
            if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
                MODELMBEAN_LOGGER.logp(Level.FINER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
                        RequiredModelMBean.class.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
                    "getMBeanInfo()","modelMBeanInfo is null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
            modelMBeanInfo = createDefaultModelMBeanInfo();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
            //return new ModelMBeanInfo(" ", "", null, null, null, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
        if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
            MODELMBEAN_LOGGER.logp(Level.FINER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
                    RequiredModelMBean.class.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
                "getMBeanInfo()","ModelMBeanInfo is " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
                  modelMBeanInfo.getClassName() + " for " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
                  modelMBeanInfo.getDescription());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
            MODELMBEAN_LOGGER.logp(Level.FINER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
                    RequiredModelMBean.class.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
                "getMBeanInfo()",printModelMBeanInfo(modelMBeanInfo));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
        return((MBeanInfo) modelMBeanInfo.clone());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
    private String printModelMBeanInfo(ModelMBeanInfo info) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
        final StringBuilder retStr = new StringBuilder();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
        if (info == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
            if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
                MODELMBEAN_LOGGER.logp(Level.FINER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
                        RequiredModelMBean.class.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
                        "printModelMBeanInfo(ModelMBeanInfo)",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
                        "ModelMBeanInfo to print is null, " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
                        "printing local ModelMBeanInfo");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
            info = modelMBeanInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
        retStr.append("\nMBeanInfo for ModelMBean is:");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
        retStr.append("\nCLASSNAME: \t"+ info.getClassName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
        retStr.append("\nDESCRIPTION: \t"+ info.getDescription());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
            retStr.append("\nMBEAN DESCRIPTOR: \t"+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
                          info.getMBeanDescriptor());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
            retStr.append("\nMBEAN DESCRIPTOR: \t" + " is invalid");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
        retStr.append("\nATTRIBUTES");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
        final MBeanAttributeInfo[] attrInfo = info.getAttributes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
        if ((attrInfo != null) && (attrInfo.length>0)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
            for (int i=0; i<attrInfo.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
                final ModelMBeanAttributeInfo attInfo =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
                    (ModelMBeanAttributeInfo)attrInfo[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
                retStr.append(" ** NAME: \t"+ attInfo.getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
                retStr.append("    DESCR: \t"+ attInfo.getDescription());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
                retStr.append("    TYPE: \t"+ attInfo.getType() +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
                              "    READ: \t"+ attInfo.isReadable() +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
                              "    WRITE: \t"+ attInfo.isWritable());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
                retStr.append("    DESCRIPTOR: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
                              attInfo.getDescriptor().toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
            retStr.append(" ** No attributes **");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
        retStr.append("\nCONSTRUCTORS");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
        final MBeanConstructorInfo[] constrInfo = info.getConstructors();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
        if ((constrInfo != null) && (constrInfo.length > 0 )) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
            for (int i=0; i<constrInfo.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
                final ModelMBeanConstructorInfo ctorInfo =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
                    (ModelMBeanConstructorInfo)constrInfo[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
                retStr.append(" ** NAME: \t"+ ctorInfo.getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
                retStr.append("    DESCR: \t"+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
                              ctorInfo.getDescription());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
                retStr.append("    PARAM: \t"+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
                              ctorInfo.getSignature().length +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
                              " parameter(s)");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
                retStr.append("    DESCRIPTOR: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
                              ctorInfo.getDescriptor().toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
            retStr.append(" ** No Constructors **");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
        retStr.append("\nOPERATIONS");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
        final MBeanOperationInfo[] opsInfo = info.getOperations();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
        if ((opsInfo != null) && (opsInfo.length>0)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
            for (int i=0; i<opsInfo.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
                final ModelMBeanOperationInfo operInfo =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
                    (ModelMBeanOperationInfo)opsInfo[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
                retStr.append(" ** NAME: \t"+ operInfo.getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
                retStr.append("    DESCR: \t"+ operInfo.getDescription());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
                retStr.append("    PARAM: \t"+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
                              operInfo.getSignature().length +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
                              " parameter(s)");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
                retStr.append("    DESCRIPTOR: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
                              operInfo.getDescriptor().toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
            retStr.append(" ** No operations ** ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
        retStr.append("\nNOTIFICATIONS");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
        MBeanNotificationInfo[] notifInfo = info.getNotifications();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
        if ((notifInfo != null) && (notifInfo.length>0)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
            for (int i=0; i<notifInfo.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
                final ModelMBeanNotificationInfo nInfo =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
                    (ModelMBeanNotificationInfo)notifInfo[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
                retStr.append(" ** NAME: \t"+ nInfo.getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
                retStr.append("    DESCR: \t"+ nInfo.getDescription());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
                retStr.append("    DESCRIPTOR: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
                              nInfo.getDescriptor().toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
            retStr.append(" ** No notifications **");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
        retStr.append(" ** ModelMBean: End of MBeanInfo ** ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
        return retStr.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
     * Invokes a method on or through a RequiredModelMBean and returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
     * the result of the method execution.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
     * If the given method to be invoked, together with the provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
     * signature, matches one of RequiredModelMbean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
     * accessible methods, this one will be call. Otherwise the call to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
     * the given method will be tried on the managed resource.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
     * The last value returned by an operation may be cached in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
     * the operation's descriptor which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
     * is in the ModelMBeanOperationInfo's descriptor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
     * The valid value will be in the 'value' field if there is one.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
     * If the 'currencyTimeLimit' field in the descriptor is:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
     * <UL>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
     * <LI><b>&lt;0</b> Then the value is not cached and is never valid.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
     *      The operation method is invoked.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
     *      The 'value' and 'lastUpdatedTimeStamp' fields are cleared.</LI>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
     * <LI><b>=0</b> Then the value is always cached and always valid.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
     *      The 'value' field is returned. If there is no 'value' field
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
     *      then the operation method is invoked for the attribute.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
     *      The 'lastUpdatedTimeStamp' field and `value' fields are set to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
     *      the operation's return value and the current time stamp.</LI>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
     * <LI><b>&gt;0</b> Represents the number of seconds that the 'value'
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
     *      field is valid.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
     *      The 'value' field is no longer valid when
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
     *      'lastUpdatedTimeStamp' + 'currencyTimeLimit' &gt; Now.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
     *      <UL>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
     *         <LI>When 'value' is valid, 'value' is returned.</LI>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
     *         <LI>When 'value' is no longer valid then the operation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
     *             method is invoked. The 'lastUpdatedTimeStamp' field
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
     *             and `value' fields are updated.</lI>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
     *      </UL>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
     * </LI>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
     * </UL>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
     * <p><b>Note:</b> because of inconsistencies in previous versions of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
     * this specification, it is recommended not to use negative or zero
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
     * values for <code>currencyTimeLimit</code>.  To indicate that a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
     * cached value is never valid, omit the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
     * <code>currencyTimeLimit</code> field.  To indicate that it is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
     * always valid, use a very large number for this field.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
     * @param opName The name of the method to be invoked. The
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
     *     name can be the fully qualified method name including the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
     *     classname, or just the method name if the classname is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
     *     defined in the 'class' field of the operation descriptor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
     * @param opArgs An array containing the parameters to be set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
     *     when the operation is invoked
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
     * @param sig An array containing the signature of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
     *     operation. The class objects will be loaded using the same
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
     *     class loader as the one used for loading the MBean on which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
     *     the operation was invoked.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
     * @return  The object returned by the method, which represents the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
     *     result of invoking the method on the specified managed resource.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
     * @exception MBeanException  Wraps one of the following Exceptions:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
     * <UL>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
     * <LI> An Exception thrown by the managed object's invoked method.</LI>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
     * <LI> {@link ServiceNotFoundException}: No ModelMBeanOperationInfo or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
     *      no descriptor defined for the specified operation or the managed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
     *      resource is null.</LI>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
     * <LI> {@link InvalidTargetObjectTypeException}: The 'targetType'
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
     *      field value is not 'objectReference'.</LI>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
     * </UL>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
     * @exception ReflectionException  Wraps an {@link java.lang.Exception}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
     *      thrown while trying to invoke the method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
     * @exception RuntimeOperationsException Wraps an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
     *      {@link IllegalArgumentException} Method name is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
     **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
      The requirement to be able to invoke methods on the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
      RequiredModelMBean class itself makes this method considerably
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
      more complicated than it might otherwise be.  Note that, unlike
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
      earlier versions, we do not allow you to invoke such methods if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
      they are not explicitly mentioned in the ModelMBeanInfo.  Doing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
      so was potentially a security problem, and certainly very
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
      surprising.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
      We do not look for the method in the RequiredModelMBean class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
      itself if:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
      (a) there is a "targetObject" field in the Descriptor for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
      operation; or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
      (b) there is a "class" field in the Descriptor for the operation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
      and the named class is not RequiredModelMBean or one of its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
      superinterfaces; or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
      (c) the name of the operation is not the name of a method in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
      RequiredModelMBean (this is just an optimization).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
      In cases (a) and (b), if you have gone to the trouble of adding
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
      those fields specifically for this operation then presumably you
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
      do not want RequiredModelMBean's methods to be called.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
      We have to pay attention to class loading issues.  If the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
      "class" field is present, the named class has to be resolved
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
      relative to RequiredModelMBean's class loader to test the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
      condition (b) above, and relative to the managed resource's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
      class loader to ensure that the managed resource is in fact of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
      the named class (or a subclass).  The class names in the sig
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
      array likewise have to be resolved, first against
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
      RequiredModelMBean's class loader, then against the managed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
      resource's class loader.  There is no point in using any other
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
      loader because when we call Method.invoke we must call it on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
      a Method that is implemented by the target object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
    public Object invoke(String opName, Object[] opArgs, String[] sig)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
            throws MBeanException, ReflectionException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
        final boolean tracing = MODELMBEAN_LOGGER.isLoggable(Level.FINER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
        final String mth = "invoke(String, Object[], String[])";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
        if (tracing) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
            MODELMBEAN_LOGGER.logp(Level.FINER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
                    RequiredModelMBean.class.getName(), mth, "Entry");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
        if (opName == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
            final RuntimeException x =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
                new IllegalArgumentException("Method name must not be null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
            throw new RuntimeOperationsException(x,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
                      "An exception occurred while trying to " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
                      "invoke a method on a RequiredModelMBean");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
        String opClassName = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
        String opMethodName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
        // Parse for class name and method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
        int opSplitter = opName.lastIndexOf(".");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
        if (opSplitter > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
            opClassName = opName.substring(0,opSplitter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
            opMethodName = opName.substring(opSplitter+1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
        } else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
            opMethodName = opName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
        /* Ignore anything after a left paren.  We keep this for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
           compatibility but it isn't specified.  */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
        opSplitter = opMethodName.indexOf("(");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
        if (opSplitter > 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
            opMethodName = opMethodName.substring(0,opSplitter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
        if (tracing) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
            MODELMBEAN_LOGGER.logp(Level.FINER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
                    RequiredModelMBean.class.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
                    mth, "Finding operation " + opName + " as " + opMethodName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
        ModelMBeanOperationInfo opInfo =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
            modelMBeanInfo.getOperation(opMethodName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
        if (opInfo == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
            final String msg =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
                "Operation " + opName + " not in ModelMBeanInfo";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
            throw new MBeanException(new ServiceNotFoundException(msg), msg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
        final Descriptor opDescr = opInfo.getDescriptor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
        if (opDescr == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
            final String msg = "Operation descriptor null";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
            throw new MBeanException(new ServiceNotFoundException(msg), msg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
        final Object cached = resolveForCacheValue(opDescr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
        if (cached != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
            if (tracing) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
                MODELMBEAN_LOGGER.logp(Level.FINER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
                        RequiredModelMBean.class.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
                        mth,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
                        "Returning cached value");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
            return cached;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
        if (opClassName == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
            opClassName = (String) opDescr.getFieldValue("class");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
        // may still be null now
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
        opMethodName = (String) opDescr.getFieldValue("name");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
        if (opMethodName == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
            final String msg =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
                "Method descriptor must include `name' field";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
            throw new MBeanException(new ServiceNotFoundException(msg), msg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
        final String targetTypeField = (String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
            opDescr.getFieldValue("targetType");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
        if (targetTypeField != null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
            && !targetTypeField.equalsIgnoreCase("objectReference")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
            final String msg =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
                "Target type must be objectReference: " + targetTypeField;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
            throw new MBeanException(new InvalidTargetObjectTypeException(msg),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
                                     msg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
        final Object targetObjectField = opDescr.getFieldValue("targetObject");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
        if (tracing && targetObjectField != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
                MODELMBEAN_LOGGER.logp(Level.FINER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
                    RequiredModelMBean.class.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
                        mth, "Found target object in descriptor");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
        /* Now look for the method, either in RequiredModelMBean itself
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
           or in the target object.  Set "method" and "targetObject"
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
           appropriately.  */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
        Method method;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
        Object targetObject;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
        method = findRMMBMethod(opMethodName, targetObjectField,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
                                opClassName, sig);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
        if (method != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
            targetObject = this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
            if (tracing) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
                MODELMBEAN_LOGGER.logp(Level.FINER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
                    RequiredModelMBean.class.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
                        mth, "looking for method in managedResource class");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
            if (targetObjectField != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
                targetObject = targetObjectField;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
                targetObject = managedResource;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
                if (targetObject == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
                    final String msg =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
                        "managedResource for invoke " + opName +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
                        " is null";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
                    Exception snfe = new ServiceNotFoundException(msg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
                    throw new MBeanException(snfe);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
1510
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 1004
diff changeset
  1031
            final Class<?> targetClass;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
            if (opClassName != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
                try {
16102
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
  1035
                    AccessControlContext stack = AccessController.getContext();
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
  1036
                    final Object obj = targetObject;
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
  1037
                    final String className = opClassName;
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
  1038
                    final ClassNotFoundException[] caughtException = new ClassNotFoundException[1];
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
  1039
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
  1040
                    targetClass = javaSecurityAccess.doIntersectionPrivilege(new PrivilegedAction<Class<?>>() {
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
  1041
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
  1042
                        @Override
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
  1043
                        public Class<?> run() {
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
  1044
                            try {
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
  1045
                                ReflectUtil.checkPackageAccess(className);
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
  1046
                                final ClassLoader targetClassLoader =
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
  1047
                                    obj.getClass().getClassLoader();
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
  1048
                                return Class.forName(className, false,
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
  1049
                                                            targetClassLoader);
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
  1050
                            } catch (ClassNotFoundException e) {
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
  1051
                                caughtException[0] = e;
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
  1052
                            }
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
  1053
                            return null;
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
  1054
                        }
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
  1055
                    }, stack, acc);
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
  1056
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
  1057
                    if (caughtException[0] != null) {
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
  1058
                        throw caughtException[0];
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
  1059
                    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
                } catch (ClassNotFoundException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
                    final String msg =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
                        "class for invoke " + opName + " not found";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
                    throw new ReflectionException(e, msg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
            } else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
                targetClass = targetObject.getClass();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
            method = resolveMethod(targetClass, opMethodName, sig);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
        if (tracing) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
            MODELMBEAN_LOGGER.logp(Level.FINER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
                RequiredModelMBean.class.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
                    mth, "found " + opMethodName + ", now invoking");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
        final Object result =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
            invokeMethod(opName, method, targetObject, opArgs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
        if (tracing) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
            MODELMBEAN_LOGGER.logp(Level.FINER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
                RequiredModelMBean.class.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
                    mth, "successfully invoked method");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
        if (result != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
            cacheResult(opInfo, opDescr, result);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
        return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
16102
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
  1092
    private Method resolveMethod(Class<?> targetClass,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
                                        String opMethodName,
16102
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
  1094
                                        final String[] sig)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
            throws ReflectionException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
        final boolean tracing = MODELMBEAN_LOGGER.isLoggable(Level.FINER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1098
        if (tracing) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
            MODELMBEAN_LOGGER.logp(Level.FINER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
                RequiredModelMBean.class.getName(),"resolveMethod",
1004
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 834
diff changeset
  1101
                  "resolving " + targetClass.getName() + "." + opMethodName);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
1510
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 1004
diff changeset
  1104
        final Class<?>[] argClasses;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
        if (sig == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
            argClasses = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
        else {
16102
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
  1109
            final AccessControlContext stack = AccessController.getContext();
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
  1110
            final ReflectionException[] caughtException = new ReflectionException[1];
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
            final ClassLoader targetClassLoader = targetClass.getClassLoader();
1510
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 1004
diff changeset
  1112
            argClasses = new Class<?>[sig.length];
16102
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
  1113
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
  1114
            javaSecurityAccess.doIntersectionPrivilege(new PrivilegedAction<Void>() {
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
  1115
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
  1116
                @Override
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
  1117
                public Void run() {
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
  1118
                    for (int i = 0; i < sig.length; i++) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
                        if (tracing) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
                            MODELMBEAN_LOGGER.logp(Level.FINER,
16102
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
  1121
                                RequiredModelMBean.class.getName(),"resolveMethod",
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
  1122
                                    "resolve type " + sig[i]);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1123
                        }
16102
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
  1124
                        argClasses[i] = (Class<?>) primitiveClassMap.get(sig[i]);
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
  1125
                        if (argClasses[i] == null) {
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
  1126
                            try {
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
  1127
                                ReflectUtil.checkPackageAccess(sig[i]);
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
  1128
                                argClasses[i] =
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
  1129
                                    Class.forName(sig[i], false, targetClassLoader);
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
  1130
                            } catch (ClassNotFoundException e) {
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
  1131
                                if (tracing) {
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
  1132
                                    MODELMBEAN_LOGGER.logp(Level.FINER,
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
  1133
                                            RequiredModelMBean.class.getName(),
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
  1134
                                            "resolveMethod",
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
  1135
                                            "class not found");
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
  1136
                                }
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
  1137
                                final String msg = "Parameter class not found";
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
  1138
                                caughtException[0] = new ReflectionException(e, msg);
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
  1139
                            }
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
  1140
                        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
                    }
16102
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
  1142
                    return null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1143
                }
16102
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
  1144
            }, stack, acc);
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
  1145
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
  1146
            if (caughtException[0] != null) {
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
  1147
                throw caughtException[0];
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1148
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1149
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1150
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1151
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
            return targetClass.getMethod(opMethodName, argClasses);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1153
        } catch (NoSuchMethodException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1154
            final String msg =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1155
                "Target method not found: " + targetClass.getName() + "." +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1156
                opMethodName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1157
            throw new ReflectionException(e, msg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1158
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1159
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1160
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1161
    /* Map e.g. "int" to int.class.  Goodness knows how many time this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1162
       particular wheel has been reinvented.  */
1510
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 1004
diff changeset
  1163
    private static final Class<?>[] primitiveClasses = {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1164
        int.class, long.class, boolean.class, double.class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1165
        float.class, short.class, byte.class, char.class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1166
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1167
    private static final Map<String,Class<?>> primitiveClassMap =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1168
        new HashMap<String,Class<?>>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1169
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1170
        for (int i = 0; i < primitiveClasses.length; i++) {
1510
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 1004
diff changeset
  1171
            final Class<?> c = primitiveClasses[i];
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1172
            primitiveClassMap.put(c.getName(), c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1173
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1174
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1175
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1176
    /* Find a method in RequiredModelMBean as determined by the given
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1177
       parameters.  Return null if there is none, or if the parameters
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1178
       exclude using it.  Called from invoke. */
16102
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
  1179
    private Method findRMMBMethod(String opMethodName,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1180
                                         Object targetObjectField,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1181
                                         String opClassName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1182
                                         String[] sig) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1183
        final boolean tracing = MODELMBEAN_LOGGER.isLoggable(Level.FINER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1184
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1185
        if (tracing) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1186
            MODELMBEAN_LOGGER.logp(Level.FINER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1187
                RequiredModelMBean.class.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1188
                    "invoke(String, Object[], String[])",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1189
                  "looking for method in RequiredModelMBean class");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1190
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1191
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1192
        if (!isRMMBMethodName(opMethodName))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1193
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1194
        if (targetObjectField != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1195
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1196
        final Class<RequiredModelMBean> rmmbClass = RequiredModelMBean.class;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1197
        final Class<?> targetClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1198
        if (opClassName == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1199
            targetClass = rmmbClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1200
        else {
16102
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
  1201
            AccessControlContext stack = AccessController.getContext();
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
  1202
            final String className = opClassName;
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
  1203
            targetClass = javaSecurityAccess.doIntersectionPrivilege(new PrivilegedAction<Class<?>>() {
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
  1204
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
  1205
                @Override
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
  1206
                public Class<?> run() {
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
  1207
                    try {
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
  1208
                        ReflectUtil.checkPackageAccess(className);
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
  1209
                        final ClassLoader targetClassLoader =
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
  1210
                            rmmbClass.getClassLoader();
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
  1211
                        Class clz = Class.forName(className, false,
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
  1212
                                                    targetClassLoader);
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
  1213
                        if (!rmmbClass.isAssignableFrom(clz))
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
  1214
                            return null;
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
  1215
                        return clz;
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
  1216
                    } catch (ClassNotFoundException e) {
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
  1217
                        return null;
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
  1218
                    }
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
  1219
                }
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
  1220
            }, stack, acc);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1221
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1222
        try {
16102
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
  1223
            return targetClass != null ? resolveMethod(targetClass, opMethodName, sig) : null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1224
        } catch (ReflectionException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1225
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1226
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1227
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1228
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1229
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1230
     * Invoke the given method, and throw the somewhat unpredictable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1231
     * appropriate exception if the method itself gets an exception.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1232
     */
16102
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
  1233
    private Object invokeMethod(String opName, final Method method,
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
  1234
                                final Object targetObject, final Object[] opArgs)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1235
            throws MBeanException, ReflectionException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1236
        try {
16102
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
  1237
            final Throwable[] caughtException = new Throwable[1];
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
  1238
            AccessControlContext stack = AccessController.getContext();
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
  1239
            Object rslt = javaSecurityAccess.doIntersectionPrivilege(new PrivilegedAction<Object>() {
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
  1240
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
  1241
                @Override
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
  1242
                public Object run() {
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
  1243
                    try {
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
  1244
                        ReflectUtil.checkPackageAccess(method.getDeclaringClass());
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
  1245
                        return MethodUtil.invoke(method, targetObject, opArgs);
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
  1246
                    } catch (InvocationTargetException e) {
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
  1247
                        caughtException[0] = e;
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
  1248
                    } catch (IllegalAccessException e) {
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
  1249
                        caughtException[0] = e;
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
  1250
                    }
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
  1251
                    return null;
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
  1252
                }
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
  1253
            }, stack, acc);
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
  1254
            if (caughtException[0] != null) {
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
  1255
                if (caughtException[0] instanceof Exception) {
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
  1256
                    throw (Exception)caughtException[0];
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
  1257
                } else if(caughtException[0] instanceof Error) {
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
  1258
                    throw (Error)caughtException[0];
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
  1259
                }
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
  1260
            }
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
  1261
            return rslt;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1262
        } catch (RuntimeErrorException ree) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1263
            throw new RuntimeOperationsException(ree,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1264
                      "RuntimeException occurred in RequiredModelMBean "+
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1265
                      "while trying to invoke operation " + opName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1266
        } catch (RuntimeException re) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1267
            throw new RuntimeOperationsException(re,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1268
                      "RuntimeException occurred in RequiredModelMBean "+
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1269
                      "while trying to invoke operation " + opName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1270
        } catch (IllegalAccessException iae) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1271
            throw new ReflectionException(iae,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1272
                      "IllegalAccessException occurred in " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1273
                      "RequiredModelMBean while trying to " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1274
                      "invoke operation " + opName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1275
        } catch (InvocationTargetException ite) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1276
            Throwable mmbTargEx = ite.getTargetException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1277
            if (mmbTargEx instanceof RuntimeException) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1278
                throw new MBeanException ((RuntimeException)mmbTargEx,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1279
                      "RuntimeException thrown in RequiredModelMBean "+
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1280
                      "while trying to invoke operation " + opName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1281
            } else if (mmbTargEx instanceof Error) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1282
                throw new RuntimeErrorException((Error)mmbTargEx,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1283
                      "Error occurred in RequiredModelMBean while trying "+
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1284
                      "to invoke operation " + opName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1285
            } else if (mmbTargEx instanceof ReflectionException) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1286
                throw (ReflectionException) mmbTargEx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1287
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1288
                throw new MBeanException ((Exception)mmbTargEx,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1289
                      "Exception thrown in RequiredModelMBean "+
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1290
                      "while trying to invoke operation " + opName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1291
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1292
        } catch (Error err) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1293
            throw new RuntimeErrorException(err,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1294
                  "Error occurred in RequiredModelMBean while trying "+
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1295
                  "to invoke operation " + opName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1296
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1297
            throw new ReflectionException(e,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1298
                  "Exception occurred in RequiredModelMBean while " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1299
                  "trying to invoke operation " + opName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1300
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1301
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1302
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1303
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1304
     * Cache the result of an operation in the descriptor, if that is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1305
     * called for by the descriptor's configuration.  Note that we
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1306
     * don't remember operation parameters when caching the result, so
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1307
     * this is unlikely to be useful if there are any.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1308
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1309
    private void cacheResult(ModelMBeanOperationInfo opInfo,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1310
                             Descriptor opDescr, Object result)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1311
            throws MBeanException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1312
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1313
        Descriptor mmbDesc =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1314
            modelMBeanInfo.getMBeanDescriptor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1315
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1316
        Object objctl =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1317
            opDescr.getFieldValue("currencyTimeLimit");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1318
        String ctl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1319
        if (objctl != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1320
            ctl = objctl.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1321
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1322
            ctl = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1323
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1324
        if ((ctl == null) && (mmbDesc != null)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1325
            objctl =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1326
                mmbDesc.getFieldValue("currencyTimeLimit");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1327
            if (objctl != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1328
                ctl = objctl.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1329
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1330
                ctl = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1331
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1332
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1333
        if ((ctl != null) && !(ctl.equals("-1"))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1334
            opDescr.setField("value", result);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1335
            opDescr.setField("lastUpdatedTimeStamp",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1336
                    String.valueOf((new Date()).getTime()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1337
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1338
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1339
            modelMBeanInfo.setDescriptor(opDescr,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1340
                                         "operation");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1341
            if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1342
                MODELMBEAN_LOGGER.logp(Level.FINER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1343
                        RequiredModelMBean.class.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1344
                        "invoke(String,Object[],Object[])",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1345
                        "new descriptor is " + opDescr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1346
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1347
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1348
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1349
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1350
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1351
     * Determine whether the given name is the name of a public method
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1352
     * in this class.  This is only an optimization: it prevents us
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1353
     * from trying to do argument type lookups and reflection on a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1354
     * method that will obviously fail because it has the wrong name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1355
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1356
     * The first time this method is called we do the reflection, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1357
     * every other time we reuse the remembered values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1358
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1359
     * It's conceivable that the (possibly malicious) first caller
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1360
     * doesn't have the required permissions to do reflection, in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1361
     * which case we don't touch anything so as not to interfere
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1362
     * with a later permissionful caller.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1363
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1364
    private static Set<String> rmmbMethodNames;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1365
    private static synchronized boolean isRMMBMethodName(String name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1366
        if (rmmbMethodNames == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1367
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1368
                Set<String> names = new HashSet<String>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1369
                Method[] methods = RequiredModelMBean.class.getMethods();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1370
                for (int i = 0; i < methods.length; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1371
                    names.add(methods[i].getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1372
                rmmbMethodNames = names;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1373
            } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1374
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1375
                // This is only an optimization so we'll go on to discover
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1376
                // whether the name really is an RMMB method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1377
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1378
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1379
        return rmmbMethodNames.contains(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1380
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1381
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1382
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1383
     * Returns the value of a specific attribute defined for this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1384
     * ModelMBean.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1385
     * The last value returned by an attribute may be cached in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1386
     * attribute's descriptor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1387
     * The valid value will be in the 'value' field if there is one.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1388
     * If the 'currencyTimeLimit' field in the descriptor is:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1389
     * <UL>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1390
     * <LI>  <b>&lt;0</b> Then the value is not cached and is never valid.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1391
     *       The getter method is invoked for the attribute.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1392
     *       The 'value' and 'lastUpdatedTimeStamp' fields are cleared.</LI>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1393
     * <LI>  <b>=0</b> Then the value is always cached and always valid.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1394
     *       The 'value' field is returned. If there is no'value' field
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1395
     *       then the getter method is invoked for the attribute.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1396
     *       The 'lastUpdatedTimeStamp' field and `value' fields are set
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1397
     *       to the attribute's value and the current time stamp.</LI>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1398
     * <LI>  <b>&gt;0</b> Represents the number of seconds that the 'value'
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1399
     *       field is valid.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1400
     *       The 'value' field is no longer valid when
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1401
     *       'lastUpdatedTimeStamp' + 'currencyTimeLimit' &gt; Now.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1402
     *   <UL>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1403
     *        <LI>When 'value' is valid, 'value' is returned.</LI>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1404
     *        <LI>When 'value' is no longer valid then the getter
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1405
     *            method is invoked for the attribute.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1406
     *            The 'lastUpdatedTimeStamp' field and `value' fields
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1407
     *            are updated.</LI>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1408
     *   </UL></LI>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1409
     * </UL>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1410
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1411
     * <p><b>Note:</b> because of inconsistencies in previous versions of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1412
     * this specification, it is recommended not to use negative or zero
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1413
     * values for <code>currencyTimeLimit</code>.  To indicate that a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1414
     * cached value is never valid, omit the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1415
     * <code>currencyTimeLimit</code> field.  To indicate that it is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1416
     * always valid, use a very large number for this field.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1417
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1418
     * <p>If the 'getMethod' field contains the name of a valid
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1419
     * operation descriptor, then the method described by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1420
     * operation descriptor is executed.  The response from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1421
     * method is returned as the value of the attribute.  If the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1422
     * operation fails or the returned value is not compatible with
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1423
     * the declared type of the attribute, an exception will be thrown.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1424
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1425
     * <p>If no 'getMethod' field is defined then the default value of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1426
     * attribute is returned. If the returned value is not compatible with
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1427
     * the declared type of the attribute, an exception will be thrown.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1428
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1429
     * <p>The declared type of the attribute is the String returned by
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1430
     * {@link ModelMBeanAttributeInfo#getType()}.  A value is compatible
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1431
     * with this type if one of the following is true:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1432
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1433
     * <li>the value is null;</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1434
     * <li>the declared name is a primitive type name (such as "int")
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1435
     *     and the value is an instance of the corresponding wrapper
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1436
     *     type (such as java.lang.Integer);</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1437
     * <li>the name of the value's class is identical to the declared name;</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1438
     * <li>the declared name can be loaded by the value's class loader and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1439
     *     produces a class to which the value can be assigned.</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1440
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1441
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1442
     * <p>In this implementation, in every case where the getMethod needs to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1443
     * be called, because the method is invoked through the standard "invoke"
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1444
     * method and thus needs operationInfo, an operation must be specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1445
     * for that getMethod so that the invocation works correctly.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1446
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1447
     * @param attrName A String specifying the name of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1448
     * attribute to be retrieved. It must match the name of a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1449
     * ModelMBeanAttributeInfo.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1450
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1451
     * @return The value of the retrieved attribute from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1452
     * descriptor 'value' field or from the invocation of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1453
     * operation in the 'getMethod' field of the descriptor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1454
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1455
     * @exception AttributeNotFoundException The specified attribute is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1456
     *    not accessible in the MBean.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1457
     *    The following cases may result in an AttributeNotFoundException:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1458
     *    <UL>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1459
     *      <LI> No ModelMBeanInfo was found for the Model MBean.</LI>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1460
     *      <LI> No ModelMBeanAttributeInfo was found for the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1461
     *           attribute name.</LI>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1462
     *      <LI> The ModelMBeanAttributeInfo isReadable method returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1463
     *           'false'.</LI>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1464
     *    </UL>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1465
     * @exception MBeanException  Wraps one of the following Exceptions:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1466
     *    <UL>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1467
     *      <LI> {@link InvalidAttributeValueException}: A wrong value type
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1468
     *           was received from the attribute's getter method or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1469
     *           no 'getMethod' field defined in the descriptor for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1470
     *           the attribute and no default value exists.</LI>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1471
     *      <LI> {@link ServiceNotFoundException}: No
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1472
     *           ModelMBeanOperationInfo defined for the attribute's
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1473
     *           getter method or no descriptor associated with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1474
     *           ModelMBeanOperationInfo or the managed resource is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1475
     *           null.</LI>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1476
     *      <LI> {@link InvalidTargetObjectTypeException} The 'targetType'
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1477
     *           field value is not 'objectReference'.</LI>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1478
     *      <LI> An Exception thrown by the managed object's getter.</LI>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1479
     *    </UL>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1480
     * @exception ReflectionException  Wraps an {@link java.lang.Exception}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1481
     *    thrown while trying to invoke the getter.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1482
     * @exception RuntimeOperationsException Wraps an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1483
     *    {@link IllegalArgumentException}: The attribute name in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1484
     *    parameter is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1485
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1486
     * @see #setAttribute(javax.management.Attribute)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1487
     **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1488
    public Object getAttribute(String attrName)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1489
        throws AttributeNotFoundException, MBeanException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1490
               ReflectionException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1491
        if (attrName == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1492
            throw new RuntimeOperationsException(new
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1493
                IllegalArgumentException("attributeName must not be null"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1494
                "Exception occurred trying to get attribute of a " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1495
                "RequiredModelMBean");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1496
        final String mth = "getAttribute(String)";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1497
        final boolean tracing = MODELMBEAN_LOGGER.isLoggable(Level.FINER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1498
        if (tracing) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1499
            MODELMBEAN_LOGGER.logp(Level.FINER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1500
                    RequiredModelMBean.class.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1501
                mth, "Entry with " + attrName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1502
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1503
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1504
        /* Check attributeDescriptor for getMethod */
526
61ba2d5ea9da 6701459: Synchronization bug pattern found in javax.management.relation.RelationService
emcmanus
parents: 263
diff changeset
  1505
        Object response;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1506
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1507
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1508
            if (modelMBeanInfo == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1509
                throw new AttributeNotFoundException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1510
                      "getAttribute failed: ModelMBeanInfo not found for "+
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1511
                      attrName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1512
526
61ba2d5ea9da 6701459: Synchronization bug pattern found in javax.management.relation.RelationService
emcmanus
parents: 263
diff changeset
  1513
            ModelMBeanAttributeInfo attrInfo = modelMBeanInfo.getAttribute(attrName);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1514
            Descriptor mmbDesc = modelMBeanInfo.getMBeanDescriptor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1515
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1516
            if (attrInfo == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1517
                throw new AttributeNotFoundException("getAttribute failed:"+
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1518
                      " ModelMBeanAttributeInfo not found for " + attrName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1519
526
61ba2d5ea9da 6701459: Synchronization bug pattern found in javax.management.relation.RelationService
emcmanus
parents: 263
diff changeset
  1520
            Descriptor attrDescr = attrInfo.getDescriptor();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1521
            if (attrDescr != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1522
                if (!attrInfo.isReadable())
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1523
                    throw new AttributeNotFoundException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1524
                          "getAttribute failed: " + attrName +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1525
                          " is not readable ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1526
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1527
                response = resolveForCacheValue(attrDescr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1528
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1529
                /* return current cached value */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1530
                if (tracing) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1531
                    MODELMBEAN_LOGGER.logp(Level.FINER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1532
                            RequiredModelMBean.class.getName(), mth,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1533
                        "*** cached value is " + response);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1534
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1535
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1536
                if (response == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1537
                    /* no cached value, run getMethod */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1538
                    if (tracing) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1539
                        MODELMBEAN_LOGGER.logp(Level.FINER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1540
                                RequiredModelMBean.class.getName(), mth,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1541
                            "**** cached value is null - getting getMethod");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1542
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1543
                    String attrGetMethod =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1544
                        (String)(attrDescr.getFieldValue("getMethod"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1545
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1546
                    if (attrGetMethod != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1547
                        /* run method from operations descriptor */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1548
                        if (tracing) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1549
                            MODELMBEAN_LOGGER.logp(Level.FINER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1550
                                    RequiredModelMBean.class.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1551
                                mth, "invoking a getMethod for " +  attrName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1552
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1553
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1554
                        Object getResponse =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1555
                            invoke(attrGetMethod, new Object[] {},
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1556
                                   new String[] {});
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1557
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1558
                        if (getResponse != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1559
                            // error/validity check return value here
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1560
                            if (tracing) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1561
                                MODELMBEAN_LOGGER.logp(Level.FINER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1562
                                        RequiredModelMBean.class.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1563
                                        mth, "got a non-null response " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1564
                                        "from getMethod\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1565
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1566
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1567
                            response = getResponse;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1568
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1569
                            // change cached value in attribute descriptor
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1570
                            Object objctl =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1571
                                attrDescr.getFieldValue("currencyTimeLimit");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1572
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1573
                            String ctl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1574
                            if (objctl != null) ctl = objctl.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1575
                            else ctl = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1576
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1577
                            if ((ctl == null) && (mmbDesc != null)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1578
                                objctl = mmbDesc.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1579
                                    getFieldValue("currencyTimeLimit");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1580
                                if (objctl != null) ctl = objctl.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1581
                                else ctl = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1582
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1583
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1584
                            if ((ctl != null) && !(ctl.equals("-1"))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1585
                                if (tracing) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1586
                                    MODELMBEAN_LOGGER.logp(Level.FINER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1587
                                            RequiredModelMBean.class.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1588
                                            mth,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1589
                                            "setting cached value and " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1590
                                            "lastUpdatedTime in descriptor");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1591
                                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1592
                                attrDescr.setField("value", response);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1593
                                final String stamp = String.valueOf(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1594
                                    (new Date()).getTime());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1595
                                attrDescr.setField("lastUpdatedTimeStamp",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1596
                                                   stamp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1597
                                attrInfo.setDescriptor(attrDescr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1598
                                modelMBeanInfo.setDescriptor(attrDescr,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1599
                                                             "attribute");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1600
                                if (tracing) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1601
                                    MODELMBEAN_LOGGER.logp(Level.FINER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1602
                                            RequiredModelMBean.class.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1603
                                        mth,"new descriptor is " +attrDescr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1604
                                    MODELMBEAN_LOGGER.logp(Level.FINER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1605
                                            RequiredModelMBean.class.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1606
                                        mth,"AttributeInfo descriptor is " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1607
                                            attrInfo.getDescriptor());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1608
                                    final String attStr = modelMBeanInfo.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1609
                                        getDescriptor(attrName,"attribute").
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1610
                                            toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1611
                                    MODELMBEAN_LOGGER.logp(Level.FINER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1612
                                            RequiredModelMBean.class.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1613
                                            mth,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1614
                                            "modelMBeanInfo: AttributeInfo " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1615
                                            "descriptor is " + attStr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1616
                                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1617
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1618
                        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1619
                            // response was invalid or really returned null
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1620
                            if (tracing) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1621
                                MODELMBEAN_LOGGER.logp(Level.FINER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1622
                                        RequiredModelMBean.class.getName(), mth,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1623
                                    "got a null response from getMethod\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1624
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1625
                            response = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1626
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1627
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1628
                        // not getMethod so return descriptor (default) value
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1629
                        String qualifier="";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1630
                        response = attrDescr.getFieldValue("value");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1631
                        if (response == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1632
                            qualifier="default ";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1633
                            response = attrDescr.getFieldValue("default");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1634
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1635
                        if (tracing) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1636
                            MODELMBEAN_LOGGER.logp(Level.FINER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1637
                                    RequiredModelMBean.class.getName(), mth,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1638
                                "could not find getMethod for " +attrName +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1639
                                ", returning descriptor " +qualifier + "value");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1640
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1641
                        // !! cast response to right class
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1642
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1643
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1644
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1645
                // make sure response class matches type field
16102
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
  1646
                final String respType = attrInfo.getType();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1647
                if (response != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1648
                    String responseClass = response.getClass().getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1649
                    if (!respType.equals(responseClass)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1650
                        boolean wrongType = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1651
                        boolean primitiveType = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1652
                        boolean correspondingTypes = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1653
                        for (int i = 0; i < primitiveTypes.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1654
                            if (respType.equals(primitiveTypes[i])) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1655
                                primitiveType = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1656
                                if (responseClass.equals(primitiveWrappers[i]))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1657
                                    correspondingTypes = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1658
                                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1659
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1660
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1661
                        if (primitiveType) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1662
                            // inequality may come from primitive/wrapper class
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1663
                            if (!correspondingTypes)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1664
                                wrongType = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1665
                        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1666
                            // inequality may come from type subclassing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1667
                            boolean subtype;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1668
                            try {
16102
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
  1669
                                final Class respClass = response.getClass();
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
  1670
                                final Exception[] caughException = new Exception[1];
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
  1671
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
  1672
                                AccessControlContext stack = AccessController.getContext();
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
  1673
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
  1674
                                Class c = javaSecurityAccess.doIntersectionPrivilege(new PrivilegedAction<Class<?>>() {
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
  1675
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
  1676
                                    @Override
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
  1677
                                    public Class<?> run() {
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
  1678
                                        try {
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
  1679
                                            ReflectUtil.checkPackageAccess(respType);
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
  1680
                                            ClassLoader cl =
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
  1681
                                                respClass.getClassLoader();
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
  1682
                                            return Class.forName(respType, true, cl);
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
  1683
                                        } catch (Exception e) {
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
  1684
                                            caughException[0] = e;
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
  1685
                                        }
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
  1686
                                        return null;
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
  1687
                                    }
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
  1688
                                }, stack, acc);
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
  1689
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
  1690
                                if (caughException[0] != null) {
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
  1691
                                    throw caughException[0];
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
  1692
                                }
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
  1693
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1694
                                subtype = c.isInstance(response);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1695
                            } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1696
                                subtype = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1697
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1698
                                if (tracing) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1699
                                    MODELMBEAN_LOGGER.logp(Level.FINER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1700
                                            RequiredModelMBean.class.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1701
                                        mth, "Exception: ",e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1702
                                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1703
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1704
                            if (!subtype)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1705
                                wrongType = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1706
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1707
                        if (wrongType) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1708
                            if (tracing) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1709
                                MODELMBEAN_LOGGER.logp(Level.FINER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1710
                                        RequiredModelMBean.class.getName(), mth,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1711
                                    "Wrong response type '" + respType + "'");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1712
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1713
                            // throw exception, didn't get
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1714
                            // back right attribute type
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1715
                            throw new MBeanException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1716
                              new InvalidAttributeValueException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1717
                                "Wrong value type received for get attribute"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1718
                              "An exception occurred while trying to get an " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1719
                              "attribute value through a RequiredModelMBean");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1720
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1721
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1722
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1723
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1724
                if (tracing) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1725
                    MODELMBEAN_LOGGER.logp(Level.FINER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1726
                            RequiredModelMBean.class.getName(), mth,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1727
                            "getMethod failed " + attrName +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1728
                            " not in attributeDescriptor\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1729
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1730
                throw new MBeanException(new
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1731
                    InvalidAttributeValueException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1732
                    "Unable to resolve attribute value, " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1733
                    "no getMethod defined in descriptor for attribute"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1734
                    "An exception occurred while trying to get an "+
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1735
                    "attribute value through a RequiredModelMBean");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1736
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1737
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1738
        } catch (MBeanException mbe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1739
            throw mbe;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1740
        } catch (AttributeNotFoundException t) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1741
            throw t;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1742
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1743
            if (tracing) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1744
                MODELMBEAN_LOGGER.logp(Level.FINER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1745
                        RequiredModelMBean.class.getName(), mth,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1746
                        "getMethod failed with " + e.getMessage() +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1747
                        " exception type " + (e.getClass()).toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1748
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1749
            throw new MBeanException(e,"An exception occurred while trying "+
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1750
                      "to get an attribute value: " + e.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1751
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1752
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1753
        if (tracing) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1754
            MODELMBEAN_LOGGER.logp(Level.FINER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1755
                    RequiredModelMBean.class.getName(), mth, "Exit");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1756
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1757
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1758
        return response;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1759
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1760
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1761
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1762
     * Returns the values of several attributes in the ModelMBean.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1763
     * Executes a getAttribute for each attribute name in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1764
     * attrNames array passed in.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1765
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1766
     * @param attrNames A String array of names of the attributes
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1767
     * to be retrieved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1768
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1769
     * @return The array of the retrieved attributes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1770
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1771
     * @exception RuntimeOperationsException Wraps an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1772
     * {@link IllegalArgumentException}: The object name in parameter is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1773
     * null or attributes in parameter is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1774
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1775
     * @see #setAttributes(javax.management.AttributeList)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1776
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1777
    public AttributeList getAttributes(String[] attrNames)      {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1778
        if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1779
            MODELMBEAN_LOGGER.logp(Level.FINER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1780
                    RequiredModelMBean.class.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1781
            "getAttributes(String[])","Entry");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1782
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1783
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1784
        if (attrNames == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1785
            throw new RuntimeOperationsException(new
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1786
                IllegalArgumentException("attributeNames must not be null"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1787
                "Exception occurred trying to get attributes of a "+
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1788
                "RequiredModelMBean");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1789
526
61ba2d5ea9da 6701459: Synchronization bug pattern found in javax.management.relation.RelationService
emcmanus
parents: 263
diff changeset
  1790
        AttributeList responseList = new AttributeList();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1791
        for (int i = 0; i < attrNames.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1792
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1793
                responseList.add(new Attribute(attrNames[i],
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1794
                                     getAttribute(attrNames[i])));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1795
            } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1796
                // eat exceptions because interface doesn't have an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1797
                // exception on it
623
97dd054b7f1f 6592586: RequiredModelMBean prints a WARNING message when calling getAttributes() for a non-existing attr
dfuchs
parents: 526
diff changeset
  1798
                if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
97dd054b7f1f 6592586: RequiredModelMBean prints a WARNING message when calling getAttributes() for a non-existing attr
dfuchs
parents: 526
diff changeset
  1799
                    MODELMBEAN_LOGGER.logp(Level.FINER,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1800
                            RequiredModelMBean.class.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1801
                        "getAttributes(String[])",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1802
                            "Failed to get \"" + attrNames[i] + "\": ", e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1803
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1804
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1805
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1806
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1807
        if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1808
            MODELMBEAN_LOGGER.logp(Level.FINER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1809
                RequiredModelMBean.class.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1810
                    "getAttributes(String[])","Exit");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1811
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1812
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1813
        return responseList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1814
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1815
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1816
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1817
     * Sets the value of a specific attribute of a named ModelMBean.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1818
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1819
     * If the 'setMethod' field of the attribute's descriptor
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1820
     * contains the name of a valid operation descriptor, then the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1821
     * method described by the operation descriptor is executed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1822
     * In this implementation, the operation descriptor must be specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1823
     * correctly and assigned to the modelMBeanInfo so that the 'setMethod'
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1824
     * works correctly.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1825
     * The response from the method is set as the value of the attribute
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1826
     * in the descriptor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1827
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1828
     * <p>If currencyTimeLimit is &gt; 0, then the new value for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1829
     * attribute is cached in the attribute descriptor's
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1830
     * 'value' field and the 'lastUpdatedTimeStamp' field is set to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1831
     * the current time stamp.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1832
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1833
     * <p>If the persist field of the attribute's descriptor is not null
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1834
     * then Persistence policy from the attribute descriptor is used to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1835
     * guide storing the attribute in a persistent store.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1836
     * <br>Store the MBean if 'persistPolicy' field is:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1837
     * <UL>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1838
     * <Li> != "never"</Li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1839
     * <Li> = "always"</Li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1840
     * <Li> = "onUpdate"</Li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1841
     * <Li> = "onTimer" and now &gt; 'lastPersistTime' + 'persistPeriod'</Li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1842
     * <Li> = "NoMoreOftenThan" and now &gt; 'lastPersistTime' +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1843
     *         'persistPeriod'</Li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1844
     * </UL>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1845
     * Do not store the MBean if 'persistPolicy' field is:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1846
     * <UL>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1847
     * <Li> = "never"</Li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1848
     * <Li> = "onTimer" && now &lt; 'lastPersistTime' + 'persistPeriod'</Li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1849
     * <Li> = "onUnregister"</Li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1850
     * <Li> = "NoMoreOftenThan" and now &lt; 'lastPersistTime' +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1851
     *        'persistPeriod'</Li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1852
     * </UL>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1853
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1854
     * <p>The ModelMBeanInfo of the Model MBean is stored in a file.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1855
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1856
     * @param attribute The Attribute instance containing the name of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1857
     *        the attribute to be set and the value it is to be set to.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1858
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1859
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1860
     * @exception AttributeNotFoundException The specified attribute is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1861
     *   not accessible in the MBean.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1862
     *   <br>The following cases may result in an AttributeNotFoundException:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1863
     *   <UL>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1864
     *     <LI> No ModelMBeanAttributeInfo is found for the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1865
     *          attribute.</LI>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1866
     *     <LI> The ModelMBeanAttributeInfo's isWritable method returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1867
     *          'false'.</LI>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1868
     *   </UL>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1869
     * @exception InvalidAttributeValueException No descriptor is defined
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1870
     *   for the specified attribute.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1871
     * @exception MBeanException Wraps one of the following Exceptions:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1872
     *   <UL>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1873
     *     <LI> An Exception thrown by the managed object's setter.</LI>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1874
     *     <LI> A {@link ServiceNotFoundException} if a setMethod field is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1875
     *          defined in the descriptor for the attribute and the managed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1876
     *          resource is null; or if no setMethod field is defined and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1877
     *          caching is not enabled for the attribute.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1878
     *          Note that if there is no getMethod field either, then caching
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1879
     *          is automatically enabled.</LI>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1880
     *     <LI> {@link InvalidTargetObjectTypeException} The 'targetType'
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1881
     *          field value is not 'objectReference'.</LI>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1882
     *     <LI> An Exception thrown by the managed object's getter.</LI>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1883
     *   </UL>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1884
     * @exception ReflectionException  Wraps an {@link java.lang.Exception}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1885
     *   thrown while trying to invoke the setter.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1886
     * @exception RuntimeOperationsException Wraps an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1887
     *   {@link IllegalArgumentException}: The attribute in parameter is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1888
     *   null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1889
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1890
     * @see #getAttribute(java.lang.String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1891
     **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1892
    public void setAttribute(Attribute attribute)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1893
        throws AttributeNotFoundException, InvalidAttributeValueException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1894
               MBeanException, ReflectionException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1895
        final boolean tracing = MODELMBEAN_LOGGER.isLoggable(Level.FINER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1896
        if (tracing) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1897
            MODELMBEAN_LOGGER.logp(Level.FINER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1898
                    RequiredModelMBean.class.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1899
                "setAttribute()","Entry");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1900
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1901
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1902
        if (attribute == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1903
            throw new RuntimeOperationsException(new
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1904
                IllegalArgumentException("attribute must not be null"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1905
                "Exception occurred trying to set an attribute of a "+
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1906
                "RequiredModelMBean");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1907
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1908
        /* run setMethod if there is one */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1909
        /* return cached value if its current */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1910
        /* set cached value in descriptor and set date/time */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1911
        /* send attribute change Notification */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1912
        /* check persistence policy and persist if need be */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1913
        String attrName = attribute.getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1914
        Object attrValue = attribute.getValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1915
        boolean updateDescriptor = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1916
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1917
        ModelMBeanAttributeInfo attrInfo =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1918
            modelMBeanInfo.getAttribute(attrName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1919
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1920
        if (attrInfo == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1921
            throw new AttributeNotFoundException("setAttribute failed: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1922
                                               attrName + " is not found ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1923
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1924
        Descriptor mmbDesc = modelMBeanInfo.getMBeanDescriptor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1925
        Descriptor attrDescr = attrInfo.getDescriptor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1926
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1927
        if (attrDescr != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1928
            if (!attrInfo.isWritable())
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1929
                throw new AttributeNotFoundException("setAttribute failed: "
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1930
                                          + attrName + " is not writable ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1931
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1932
            String attrSetMethod = (String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1933
                (attrDescr.getFieldValue("setMethod"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1934
            String attrGetMethod = (String)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1935
                (attrDescr.getFieldValue("getMethod"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1936
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1937
            String attrType = attrInfo.getType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1938
            Object currValue = "Unknown";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1939
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1940
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1941
                currValue = this.getAttribute(attrName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1942
            } catch (Throwable t) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1943
                // OK: Default "Unknown" value used for unknown attribute
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1944
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1945
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1946
            Attribute oldAttr = new Attribute(attrName, currValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1947
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1948
            /* run method from operations descriptor */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1949
            if (attrSetMethod == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1950
                if (attrValue != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1951
                    try {
1510
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 1004
diff changeset
  1952
                        final Class<?> clazz = loadClass(attrType);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1953
                        if (! clazz.isInstance(attrValue))  throw new
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1954
                            InvalidAttributeValueException(clazz.getName() +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1955
                                                           " expected, "   +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1956
                                            attrValue.getClass().getName() +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1957
                                                           " received.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1958
                    } catch (ClassNotFoundException x) {
623
97dd054b7f1f 6592586: RequiredModelMBean prints a WARNING message when calling getAttributes() for a non-existing attr
dfuchs
parents: 526
diff changeset
  1959
                        if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
97dd054b7f1f 6592586: RequiredModelMBean prints a WARNING message when calling getAttributes() for a non-existing attr
dfuchs
parents: 526
diff changeset
  1960
                            MODELMBEAN_LOGGER.logp(Level.FINER,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1961
                                    RequiredModelMBean.class.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1962
                                "setAttribute(Attribute)","Class " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1963
                                    attrType + " for attribute "
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1964
                                + attrName + " not found: ", x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1965
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1966
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1967
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1968
                updateDescriptor = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1969
            } else {
526
61ba2d5ea9da 6701459: Synchronization bug pattern found in javax.management.relation.RelationService
emcmanus
parents: 263
diff changeset
  1970
                invoke(attrSetMethod,
61ba2d5ea9da 6701459: Synchronization bug pattern found in javax.management.relation.RelationService
emcmanus
parents: 263
diff changeset
  1971
                       (new Object[] {attrValue}),
61ba2d5ea9da 6701459: Synchronization bug pattern found in javax.management.relation.RelationService
emcmanus
parents: 263
diff changeset
  1972
                       (new String[] {attrType}) );
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1973
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1974
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1975
            /* change cached value */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1976
            Object objctl = attrDescr.getFieldValue("currencyTimeLimit");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1977
            String ctl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1978
            if (objctl != null) ctl = objctl.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1979
            else ctl = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1980
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1981
            if ((ctl == null) && (mmbDesc != null)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1982
                objctl = mmbDesc.getFieldValue("currencyTimeLimit");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1983
                if (objctl != null) ctl = objctl.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1984
                else ctl = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1985
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1986
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1987
            final boolean updateCache = ((ctl != null) && !(ctl.equals("-1")));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1988
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1989
             if(attrSetMethod == null  && !updateCache && attrGetMethod != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1990
                throw new MBeanException(new ServiceNotFoundException("No " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1991
                        "setMethod field is defined in the descriptor for " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1992
                        attrName + " attribute and caching is not enabled " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1993
                        "for it"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1994
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1995
            if (updateCache || updateDescriptor) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1996
                if (tracing) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1997
                    MODELMBEAN_LOGGER.logp(Level.FINER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1998
                        RequiredModelMBean.class.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1999
                            "setAttribute(Attribute)",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2000
                            "setting cached value of " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2001
                            attrName + " to " + attrValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2002
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2003
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2004
                attrDescr.setField("value", attrValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2005
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2006
                if (updateCache) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2007
                    final String currtime = String.valueOf(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2008
                        (new Date()).getTime());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2009
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2010
                    attrDescr.setField("lastUpdatedTimeStamp", currtime);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2011
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2012
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2013
                attrInfo.setDescriptor(attrDescr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2014
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2015
                modelMBeanInfo.setDescriptor(attrDescr,"attribute");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2016
                if (tracing) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2017
                    final StringBuilder strb = new StringBuilder()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2018
                    .append("new descriptor is ").append(attrDescr)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2019
                    .append(". AttributeInfo descriptor is ")
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2020
                    .append(attrInfo.getDescriptor())
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2021
                    .append(". AttributeInfo descriptor is ")
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2022
                    .append(modelMBeanInfo.getDescriptor(attrName,"attribute"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2023
                    MODELMBEAN_LOGGER.logp(Level.FINER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2024
                            RequiredModelMBean.class.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2025
                            "setAttribute(Attribute)",strb.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2026
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2027
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2028
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2029
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2030
            if (tracing) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2031
                MODELMBEAN_LOGGER.logp(Level.FINER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2032
                        RequiredModelMBean.class.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2033
                "setAttribute(Attribute)","sending sendAttributeNotification");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2034
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2035
            sendAttributeChangeNotification(oldAttr,attribute);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2036
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2037
        } else { // if descriptor ... else no descriptor
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2038
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2039
            if (tracing) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2040
                    MODELMBEAN_LOGGER.logp(Level.FINER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2041
                            RequiredModelMBean.class.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2042
                        "setAttribute(Attribute)","setMethod failed "+attrName+
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2043
                        " not in attributeDescriptor\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2044
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2045
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2046
            throw new InvalidAttributeValueException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2047
                      "Unable to resolve attribute value, "+
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2048
                      "no defined in descriptor for attribute");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2049
        } // else no descriptor
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2050
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2051
        if (tracing) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2052
            MODELMBEAN_LOGGER.logp(Level.FINER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2053
                    RequiredModelMBean.class.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2054
                "setAttribute(Attribute)", "Exit");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2055
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2056
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2057
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2058
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2059
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2060
     * Sets the values of an array of attributes of this ModelMBean.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2061
     * Executes the setAttribute() method for each attribute in the list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2062
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2063
     * @param attributes A list of attributes: The identification of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2064
     * attributes to be set and  the values they are to be set to.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2065
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2066
     * @return  The array of attributes that were set, with their new
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2067
     *    values in Attribute instances.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2068
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2069
     * @exception RuntimeOperationsException Wraps an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2070
     *   {@link IllegalArgumentException}: The object name in parameter
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2071
     *   is null or attributes in parameter is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2072
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2073
     * @see #getAttributes
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2074
     **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2075
    public AttributeList setAttributes(AttributeList attributes) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2076
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2077
        if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2078
            MODELMBEAN_LOGGER.logp(Level.FINER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2079
                    RequiredModelMBean.class.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2080
                "setAttribute(Attribute)", "Entry");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2081
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2082
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2083
        if (attributes == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2084
            throw new RuntimeOperationsException(new
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2085
                IllegalArgumentException("attributes must not be null"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2086
                "Exception occurred trying to set attributes of a "+
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2087
                "RequiredModelMBean");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2088
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2089
        final AttributeList responseList = new AttributeList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2090
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2091
        // Go through the list of attributes
1510
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 1004
diff changeset
  2092
        for (Attribute attr : attributes.asList()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2093
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2094
                setAttribute(attr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2095
                responseList.add(attr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2096
            } catch (Exception excep) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2097
                responseList.remove(attr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2098
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2099
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2100
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2101
        return responseList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2102
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2103
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2104
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2105
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2106
    private ModelMBeanInfo createDefaultModelMBeanInfo() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2107
        return(new ModelMBeanInfoSupport((this.getClass().getName()),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2108
                   "Default ModelMBean", null, null, null, null));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2109
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2110
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2111
    /*************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2112
    /* NotificationBroadcaster Interface */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2113
    /*************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2114
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2115
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2116
    private synchronized void writeToLog(String logFileName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2117
                                         String logEntry) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2118
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2119
        if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2120
            MODELMBEAN_LOGGER.logp(Level.FINER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2121
                    RequiredModelMBean.class.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2122
                "writeToLog(String, String)",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2123
                "Notification Logging to " + logFileName + ": " + logEntry);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2124
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2125
        if ((logFileName == null) || (logEntry == null)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2126
            if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2127
                MODELMBEAN_LOGGER.logp(Level.FINER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2128
                        RequiredModelMBean.class.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2129
                    "writeToLog(String, String)",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2130
                    "Bad input parameters, will not log this entry.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2131
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2132
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2133
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2134
526
61ba2d5ea9da 6701459: Synchronization bug pattern found in javax.management.relation.RelationService
emcmanus
parents: 263
diff changeset
  2135
        FileOutputStream fos = new FileOutputStream(logFileName, true);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2136
        try {
526
61ba2d5ea9da 6701459: Synchronization bug pattern found in javax.management.relation.RelationService
emcmanus
parents: 263
diff changeset
  2137
            PrintStream logOut = new PrintStream(fos);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2138
            logOut.println(logEntry);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2139
            logOut.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2140
            if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2141
                MODELMBEAN_LOGGER.logp(Level.FINER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2142
                        RequiredModelMBean.class.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2143
                    "writeToLog(String, String)","Successfully opened log " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2144
                        logFileName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2145
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2146
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2147
            if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2148
                MODELMBEAN_LOGGER.logp(Level.FINER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2149
                    RequiredModelMBean.class.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2150
                        "writeToLog(String, String)",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2151
                        "Exception " + e.toString() +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2152
                        " trying to write to the Notification log file " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2153
                        logFileName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2154
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2155
            throw e;
526
61ba2d5ea9da 6701459: Synchronization bug pattern found in javax.management.relation.RelationService
emcmanus
parents: 263
diff changeset
  2156
        } finally {
61ba2d5ea9da 6701459: Synchronization bug pattern found in javax.management.relation.RelationService
emcmanus
parents: 263
diff changeset
  2157
            fos.close();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2158
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2159
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2160
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2161
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2162
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2163
     * Registers an object which implements the NotificationListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2164
     * interface as a listener.  This
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2165
     * object's 'handleNotification()' method will be invoked when any
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2166
     * notification is issued through or by the ModelMBean.  This does
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2167
     * not include attributeChangeNotifications.  They must be registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2168
     * for independently.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2169
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2170
     * @param listener The listener object which will handles
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2171
     *        notifications emitted by the registered MBean.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2172
     * @param filter The filter object. If null, no filtering will be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2173
     *        performed before handling notifications.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2174
     * @param handback The context to be sent to the listener with
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2175
     *        the notification when a notification is emitted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2176
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2177
     * @exception IllegalArgumentException The listener cannot be null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2178
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2179
     * @see #removeNotificationListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2180
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2181
    public void addNotificationListener(NotificationListener listener,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2182
                                        NotificationFilter filter,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2183
                                        Object handback)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2184
        throws java.lang.IllegalArgumentException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2185
        final String mth = "addNotificationListener(" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2186
                "NotificationListener, NotificationFilter, Object)";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2187
        if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2188
                MODELMBEAN_LOGGER.logp(Level.FINER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2189
                        RequiredModelMBean.class.getName(), mth, "Entry");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2190
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2191
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2192
        if (listener == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2193
            throw new IllegalArgumentException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2194
                  "notification listener must not be null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2195
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2196
        if (generalBroadcaster == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2197
            generalBroadcaster = new NotificationBroadcasterSupport();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2198
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2199
        generalBroadcaster.addNotificationListener(listener, filter,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2200
                                                   handback);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2201
        if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2202
                MODELMBEAN_LOGGER.logp(Level.FINER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2203
                        RequiredModelMBean.class.getName(), mth,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2204
                    "NotificationListener added");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2205
                MODELMBEAN_LOGGER.logp(Level.FINER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2206
                        RequiredModelMBean.class.getName(), mth, "Exit");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2207
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2208
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2209
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2210
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2211
     * Removes a listener for Notifications from the RequiredModelMBean.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2212
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2213
     * @param listener The listener name which was handling notifications
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2214
     *    emitted by the registered MBean.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2215
     *    This method will remove all information related to this listener.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2216
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2217
     * @exception ListenerNotFoundException The listener is not registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2218
     *    in the MBean or is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2219
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2220
     * @see #addNotificationListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2221
     **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2222
    public void removeNotificationListener(NotificationListener listener)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2223
        throws ListenerNotFoundException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2224
        if (listener == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2225
            throw new ListenerNotFoundException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2226
                      "Notification listener is null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2227
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2228
        final String mth="removeNotificationListener(NotificationListener)";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2229
        if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2230
                MODELMBEAN_LOGGER.logp(Level.FINER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2231
                    RequiredModelMBean.class.getName(), mth, "Entry");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2232
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2233
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2234
        if (generalBroadcaster == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2235
            throw new ListenerNotFoundException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2236
                  "No notification listeners registered");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2237
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2238
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2239
        generalBroadcaster.removeNotificationListener(listener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2240
        if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2241
            MODELMBEAN_LOGGER.logp(Level.FINER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2242
                    RequiredModelMBean.class.getName(), mth, "Exit");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2243
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2244
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2245
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2246
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2247
    public void removeNotificationListener(NotificationListener listener,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2248
                                           NotificationFilter filter,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2249
                                           Object handback)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2250
        throws ListenerNotFoundException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2251
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2252
        if (listener == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2253
            throw new ListenerNotFoundException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2254
                      "Notification listener is null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2255
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2256
        final String mth = "removeNotificationListener(" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2257
                "NotificationListener, NotificationFilter, Object)";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2258
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2259
        if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2260
            MODELMBEAN_LOGGER.logp(Level.FINER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2261
                    RequiredModelMBean.class.getName(), mth, "Entry");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2262
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2263
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2264
        if (generalBroadcaster == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2265
            throw new ListenerNotFoundException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2266
                  "No notification listeners registered");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2267
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2268
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2269
        generalBroadcaster.removeNotificationListener(listener,filter,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2270
                                                      handback);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2271
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2272
        if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2273
            MODELMBEAN_LOGGER.logp(Level.FINER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2274
                    RequiredModelMBean.class.getName(), mth, "Exit");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2275
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2276
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2277
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2278
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2279
    public void sendNotification(Notification ntfyObj)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2280
        throws MBeanException, RuntimeOperationsException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2281
        if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2282
            MODELMBEAN_LOGGER.logp(Level.FINER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2283
                    RequiredModelMBean.class.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2284
                "sendNotification(Notification)", "Entry");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2285
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2286
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2287
        if (ntfyObj == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2288
            throw new RuntimeOperationsException(new
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2289
                IllegalArgumentException("notification object must not be "+
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2290
                                         "null"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2291
                "Exception occurred trying to send a notification from a "+
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2292
                "RequiredModelMBean");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2293
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2294
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2295
        // log notification if specified in descriptor
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2296
        Descriptor ntfyDesc =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2297
            modelMBeanInfo.getDescriptor(ntfyObj.getType(),"notification");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2298
        Descriptor mmbDesc = modelMBeanInfo.getMBeanDescriptor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2299
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2300
        if (ntfyDesc != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2301
            String logging = (String) ntfyDesc.getFieldValue("log");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2302
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2303
            if (logging == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2304
                if (mmbDesc != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2305
                    logging = (String) mmbDesc.getFieldValue("log");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2306
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2307
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2308
            if ((logging != null) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2309
                (logging.equalsIgnoreCase("t") ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2310
                 logging.equalsIgnoreCase("true"))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2311
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2312
                String logfile = (String) ntfyDesc.getFieldValue("logfile");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2313
                if (logfile == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2314
                    if (mmbDesc != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2315
                        logfile = (String)mmbDesc.getFieldValue("logfile");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2316
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2317
                if (logfile != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2318
                    try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2319
                        writeToLog(logfile,"LogMsg: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2320
                            ((new Date(ntfyObj.getTimeStamp())).toString())+
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2321
                            " " + ntfyObj.getType() + " " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2322
                            ntfyObj.getMessage() + " Severity = " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2323
                            (String)ntfyDesc.getFieldValue("severity"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2324
                    } catch (Exception e) {
623
97dd054b7f1f 6592586: RequiredModelMBean prints a WARNING message when calling getAttributes() for a non-existing attr
dfuchs
parents: 526
diff changeset
  2325
                        if (MODELMBEAN_LOGGER.isLoggable(Level.FINE)) {
97dd054b7f1f 6592586: RequiredModelMBean prints a WARNING message when calling getAttributes() for a non-existing attr
dfuchs
parents: 526
diff changeset
  2326
                            MODELMBEAN_LOGGER.logp(Level.FINE,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2327
                                    RequiredModelMBean.class.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2328
                                    "sendNotification(Notification)",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2329
                                    "Failed to log " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2330
                                    ntfyObj.getType() + " notification: ", e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2331
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2332
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2333
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2334
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2335
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2336
        if (generalBroadcaster != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2337
            generalBroadcaster.sendNotification(ntfyObj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2338
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2339
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2340
        if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2341
            MODELMBEAN_LOGGER.logp(Level.FINER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2342
                RequiredModelMBean.class.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2343
                    "sendNotification(Notification)",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2344
                    "sendNotification sent provided notification object");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2345
            MODELMBEAN_LOGGER.logp(Level.FINER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2346
                RequiredModelMBean.class.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2347
                    "sendNotification(Notification)"," Exit");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2348
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2349
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2350
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2351
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2352
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2353
    public void sendNotification(String ntfyText)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2354
        throws MBeanException, RuntimeOperationsException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2355
        if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2356
            MODELMBEAN_LOGGER.logp(Level.FINER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2357
                    RequiredModelMBean.class.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2358
                "sendNotification(String)","Entry");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2359
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2360
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2361
        if (ntfyText == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2362
            throw new RuntimeOperationsException(new
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2363
                IllegalArgumentException("notification message must not "+
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2364
                                         "be null"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2365
                "Exception occurred trying to send a text notification "+
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2366
                "from a ModelMBean");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2367
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2368
        Notification myNtfyObj = new Notification("jmx.modelmbean.generic",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2369
                                                  this, 1, ntfyText);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2370
        sendNotification(myNtfyObj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2371
        if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2372
            MODELMBEAN_LOGGER.logp(Level.FINER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2373
                    RequiredModelMBean.class.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2374
                "sendNotification(String)","Notification sent");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2375
            MODELMBEAN_LOGGER.logp(Level.FINER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2376
                    RequiredModelMBean.class.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2377
                "sendNotification(String)","Exit");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2378
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2379
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2380
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2381
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2382
     * Returns `true' if the notification `notifName' is found
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2383
     * in `info'. (bug 4744667)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2384
     **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2385
    private static final
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2386
        boolean hasNotification(final ModelMBeanInfo info,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2387
                                final String notifName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2388
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2389
            if (info == null) return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2390
            else return (info.getNotification(notifName)!=null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2391
        } catch (MBeanException x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2392
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2393
        } catch (RuntimeOperationsException r) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2394
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2395
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2396
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2397
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2398
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2399
     * Creates a default ModelMBeanNotificationInfo for GENERIC
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2400
     * notification.  (bug 4744667)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2401
     **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2402
    private static final ModelMBeanNotificationInfo makeGenericInfo() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2403
        final Descriptor genericDescriptor = new DescriptorSupport( new
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2404
            String[] {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2405
                "name=GENERIC",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2406
                "descriptorType=notification",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2407
                "log=T",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2408
                "severity=6",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2409
                "displayName=jmx.modelmbean.generic"} );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2410
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2411
        return new ModelMBeanNotificationInfo(new
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2412
            String[] {"jmx.modelmbean.generic"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2413
            "GENERIC",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2414
            "A text notification has been issued by the managed resource",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2415
            genericDescriptor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2416
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2417
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2418
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2419
     * Creates a default ModelMBeanNotificationInfo for ATTRIBUTE_CHANGE
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2420
     * notification.  (bug 4744667)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2421
     **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2422
    private static final
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2423
        ModelMBeanNotificationInfo makeAttributeChangeInfo() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2424
        final Descriptor attributeDescriptor = new DescriptorSupport(new
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2425
            String[] {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2426
                "name=ATTRIBUTE_CHANGE",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2427
                "descriptorType=notification",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2428
                "log=T",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2429
                "severity=6",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2430
                "displayName=jmx.attribute.change"});
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2431
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2432
        return new ModelMBeanNotificationInfo(new
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2433
            String[] {"jmx.attribute.change"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2434
            "ATTRIBUTE_CHANGE",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2435
            "Signifies that an observed MBean attribute value has changed",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2436
            attributeDescriptor );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2437
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2438
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2439
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2440
     * Returns the array of Notifications always generated by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2441
     * RequiredModelMBean.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2442
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2443
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2444
     * RequiredModelMBean may always send also two additional notifications:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2445
     * <UL>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2446
     *   <LI> One with descriptor <code>"name=GENERIC,descriptorType=notification,log=T,severity=6,displayName=jmx.modelmbean.generic"</code></LI>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2447
     *   <LI> Second is a standard attribute change notification
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2448
     *        with descriptor <code>"name=ATTRIBUTE_CHANGE,descriptorType=notification,log=T,severity=6,displayName=jmx.attribute.change"</code></LI>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2449
     * </UL>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2450
     * Thus these two notifications are always added to those specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2451
     * by the application.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2452
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2453
     * @return MBeanNotificationInfo[]
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2454
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2455
     **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2456
    public MBeanNotificationInfo[] getNotificationInfo() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2457
        if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2458
            MODELMBEAN_LOGGER.logp(Level.FINER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2459
                    RequiredModelMBean.class.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2460
                "getNotificationInfo()","Entry");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2461
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2462
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2463
        // Using hasNotification() is not optimal, but shouldn't really
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2464
        // matter in this context...
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2465
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2466
        // hasGeneric==true if GENERIC notification is present.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2467
        // (bug 4744667)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2468
        final boolean hasGeneric = hasNotification(modelMBeanInfo,"GENERIC");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2469
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2470
        // hasAttributeChange==true if ATTRIBUTE_CHANGE notification is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2471
        // present.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2472
        // (bug 4744667)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2473
        final boolean hasAttributeChange =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2474
           hasNotification(modelMBeanInfo,"ATTRIBUTE_CHANGE");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2475
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2476
        // User supplied list of notification infos.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2477
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2478
        final ModelMBeanNotificationInfo[] currInfo =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2479
           (ModelMBeanNotificationInfo[])modelMBeanInfo.getNotifications();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2480
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2481
        // Length of the returned list of notification infos:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2482
        //    length of user suplied list + possibly 1 for GENERIC, +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2483
        //    possibly 1 for ATTRIBUTE_CHANGE
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2484
        //    (bug 4744667)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2485
        final int len = ((currInfo==null?0:currInfo.length) +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2486
                         (hasGeneric?0:1) + (hasAttributeChange?0:1));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2487
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2488
        // Returned list of notification infos:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2489
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2490
        final ModelMBeanNotificationInfo[] respInfo =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2491
           new ModelMBeanNotificationInfo[len];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2492
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2493
        // Preserve previous ordering (JMX 1.1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2494
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2495
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2496
        // Counter of "standard" notification inserted before user
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2497
        // supplied notifications.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2498
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2499
        int inserted=0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2500
        if (!hasGeneric)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2501
            // We need to add description for GENERIC notification
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2502
            // (bug 4744667)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2503
            respInfo[inserted++] = makeGenericInfo();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2504
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2505
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2506
        if (!hasAttributeChange)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2507
            // We need to add description for ATTRIBUTE_CHANGE notification
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2508
            // (bug 4744667)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2509
            respInfo[inserted++] = makeAttributeChangeInfo();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2510
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2511
        // Now copy user supplied list in returned list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2512
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2513
        final int count  = currInfo.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2514
        final int offset = inserted;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2515
        for (int j=0; j < count; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2516
            respInfo[offset+j] = currInfo[j];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2517
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2518
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2519
        if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2520
            MODELMBEAN_LOGGER.logp(Level.FINER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2521
                    RequiredModelMBean.class.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2522
                "getNotificationInfo()","Exit");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2523
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2524
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2525
        return respInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2526
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2527
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2528
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2529
    public void addAttributeChangeNotificationListener(NotificationListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2530
                                                       inlistener,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2531
                                                       String
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2532
                                                       inAttributeName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2533
                                                       Object inhandback)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2534
        throws MBeanException, RuntimeOperationsException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2535
               IllegalArgumentException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2536
        final String mth="addAttributeChangeNotificationListener(" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2537
                "NotificationListener, String, Object)";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2538
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2539
        if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2540
            MODELMBEAN_LOGGER.logp(Level.FINER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2541
                    RequiredModelMBean.class.getName(),mth,"Entry");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2542
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2543
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2544
        if (inlistener == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2545
            throw new IllegalArgumentException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2546
                  "Listener to be registered must not be null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2547
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2548
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2549
        if (attributeBroadcaster == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2550
            attributeBroadcaster = new NotificationBroadcasterSupport();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2551
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2552
        AttributeChangeNotificationFilter currFilter =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2553
            new AttributeChangeNotificationFilter();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2554
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2555
        MBeanAttributeInfo[] attrInfo = modelMBeanInfo.getAttributes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2556
        boolean found = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2557
        if (inAttributeName == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2558
            if ((attrInfo != null) && (attrInfo.length>0)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2559
                for (int i=0; i<attrInfo.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2560
                    currFilter.enableAttribute(attrInfo[i].getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2561
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2562
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2563
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2564
            if ((attrInfo != null) && (attrInfo.length>0)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2565
                for (int i=0; i<attrInfo.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2566
                    if (inAttributeName.equals(attrInfo[i].getName())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2567
                        found = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2568
                        currFilter.enableAttribute(inAttributeName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2569
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2570
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2571
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2572
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2573
            if (!found) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2574
                throw new RuntimeOperationsException(new
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2575
                    IllegalArgumentException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2576
                    "The attribute name does not exist"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2577
                    "Exception occurred trying to add an "+
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2578
                    "AttributeChangeNotification listener");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2579
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2580
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2581
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2582
        if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
263
db2a63668df3 6675768: NoSuchElementException thrown in RequiredModelMBean when tracing enabled
emcmanus
parents: 2
diff changeset
  2583
            Vector<String> enabledAttrs = currFilter.getEnabledAttributes();
db2a63668df3 6675768: NoSuchElementException thrown in RequiredModelMBean when tracing enabled
emcmanus
parents: 2
diff changeset
  2584
            String s = (enabledAttrs.size() > 1) ?
db2a63668df3 6675768: NoSuchElementException thrown in RequiredModelMBean when tracing enabled
emcmanus
parents: 2
diff changeset
  2585
                        "[" + enabledAttrs.firstElement() + ", ...]" :
db2a63668df3 6675768: NoSuchElementException thrown in RequiredModelMBean when tracing enabled
emcmanus
parents: 2
diff changeset
  2586
                        enabledAttrs.toString();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2587
            MODELMBEAN_LOGGER.logp(Level.FINER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2588
                    RequiredModelMBean.class.getName(), mth,
263
db2a63668df3 6675768: NoSuchElementException thrown in RequiredModelMBean when tracing enabled
emcmanus
parents: 2
diff changeset
  2589
                "Set attribute change filter to " + s);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2590
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2591
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2592
        attributeBroadcaster.addNotificationListener(inlistener,currFilter,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2593
                                                     inhandback);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2594
        if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2595
            MODELMBEAN_LOGGER.logp(Level.FINER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2596
                    RequiredModelMBean.class.getName(),mth,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2597
                    "Notification listener added for " + inAttributeName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2598
            MODELMBEAN_LOGGER.logp(Level.FINER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2599
                    RequiredModelMBean.class.getName(),mth,"Exit");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2600
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2601
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2602
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2603
    public void removeAttributeChangeNotificationListener(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2604
            NotificationListener inlistener, String inAttributeName)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2605
        throws MBeanException, RuntimeOperationsException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2606
               ListenerNotFoundException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2607
        if (inlistener == null) throw new
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2608
            ListenerNotFoundException("Notification listener is null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2609
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2610
        final String mth = "removeAttributeChangeNotificationListener(" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2611
                "NotificationListener, String)";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2612
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2613
        if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2614
            MODELMBEAN_LOGGER.logp(Level.FINER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2615
                    RequiredModelMBean.class.getName(),mth,"Entry");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2616
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2617
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2618
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2619
        if (attributeBroadcaster == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2620
            throw new ListenerNotFoundException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2621
                  "No attribute change notification listeners registered");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2622
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2623
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2624
        MBeanAttributeInfo[] attrInfo = modelMBeanInfo.getAttributes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2625
        boolean found = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2626
        if ((attrInfo != null) && (attrInfo.length>0)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2627
            for (int i=0; i<attrInfo.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2628
                if (attrInfo[i].getName().equals(inAttributeName)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2629
                    found = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2630
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2631
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2632
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2633
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2634
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2635
        if ((!found) && (inAttributeName != null)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2636
            throw new RuntimeOperationsException(new
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2637
                IllegalArgumentException("Invalid attribute name"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2638
                "Exception occurred trying to remove "+
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2639
                "attribute change notification listener");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2640
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2641
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2642
        /* note: */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2643
        /* this may be a problem if the same listener is registered for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2644
           multiple attributes with multiple filters and/or handback
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2645
           objects.  It may remove all of them */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2646
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2647
        attributeBroadcaster.removeNotificationListener(inlistener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2648
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2649
        if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2650
            MODELMBEAN_LOGGER.logp(Level.FINER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2651
                    RequiredModelMBean.class.getName(),mth,"Exit");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2652
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2653
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2654
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2655
    public void sendAttributeChangeNotification(AttributeChangeNotification
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2656
                                                ntfyObj)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2657
        throws MBeanException, RuntimeOperationsException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2658
        final String mth = "sendAttributeChangeNotification(" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2659
                "AttributeChangeNotification)";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2660
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2661
        if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2662
            MODELMBEAN_LOGGER.logp(Level.FINER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2663
                    RequiredModelMBean.class.getName(),mth,"Entry");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2664
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2665
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2666
        if (ntfyObj == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2667
            throw new RuntimeOperationsException(new
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2668
                IllegalArgumentException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2669
                "attribute change notification object must not be null"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2670
                "Exception occurred trying to send "+
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2671
                "attribute change notification of a ModelMBean");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2672
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2673
        Object oldv = ntfyObj.getOldValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2674
        Object newv =  ntfyObj.getNewValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2675
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2676
        if (oldv == null) oldv = "null";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2677
        if (newv == null) newv = "null";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2678
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2679
        if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2680
            MODELMBEAN_LOGGER.logp(Level.FINER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2681
                    RequiredModelMBean.class.getName(),mth,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2682
                "Sending AttributeChangeNotification with " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2683
                ntfyObj.getAttributeName() + ntfyObj.getAttributeType() +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2684
                ntfyObj.getNewValue() + ntfyObj.getOldValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2685
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2686
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2687
        // log notification if specified in descriptor
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2688
        Descriptor ntfyDesc =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2689
            modelMBeanInfo.getDescriptor(ntfyObj.getType(),"notification");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2690
        Descriptor mmbDesc = modelMBeanInfo.getMBeanDescriptor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2691
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2692
        String logging, logfile;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2693
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2694
        if (ntfyDesc != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2695
            logging =(String)  ntfyDesc.getFieldValue("log");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2696
            if (logging == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2697
                if (mmbDesc != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2698
                    logging = (String) mmbDesc.getFieldValue("log");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2699
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2700
            if ((logging != null) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2701
                ( logging.equalsIgnoreCase("t") ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2702
                  logging.equalsIgnoreCase("true"))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2703
                logfile = (String) ntfyDesc.getFieldValue("logfile");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2704
                if (logfile == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2705
                    if (mmbDesc != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2706
                        logfile = (String)mmbDesc.getFieldValue("logfile");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2707
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2708
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2709
                if (logfile != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2710
                    try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2711
                        writeToLog(logfile,"LogMsg: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2712
                           ((new Date(ntfyObj.getTimeStamp())).toString())+
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2713
                           " " + ntfyObj.getType() + " " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2714
                           ntfyObj.getMessage() +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2715
                           " Name = " + ntfyObj.getAttributeName() +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2716
                           " Old value = " + oldv +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2717
                           " New value = " + newv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2718
                    } catch (Exception e) {
623
97dd054b7f1f 6592586: RequiredModelMBean prints a WARNING message when calling getAttributes() for a non-existing attr
dfuchs
parents: 526
diff changeset
  2719
                        if (MODELMBEAN_LOGGER.isLoggable(Level.FINE)) {
97dd054b7f1f 6592586: RequiredModelMBean prints a WARNING message when calling getAttributes() for a non-existing attr
dfuchs
parents: 526
diff changeset
  2720
                            MODELMBEAN_LOGGER.logp(Level.FINE,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2721
                                    RequiredModelMBean.class.getName(),mth,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2722
                                "Failed to log " + ntfyObj.getType() +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2723
                                    " notification: ", e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2724
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2725
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2726
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2727
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2728
        } else if (mmbDesc != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2729
            logging = (String) mmbDesc.getFieldValue("log");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2730
            if ((logging != null) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2731
                ( logging.equalsIgnoreCase("t") ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2732
                  logging.equalsIgnoreCase("true") )) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2733
                logfile = (String) mmbDesc.getFieldValue("logfile");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2734
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2735
                if (logfile != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2736
                    try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2737
                        writeToLog(logfile,"LogMsg: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2738
                           ((new Date(ntfyObj.getTimeStamp())).toString())+
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2739
                           " " + ntfyObj.getType() + " " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2740
                           ntfyObj.getMessage() +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2741
                           " Name = " + ntfyObj.getAttributeName() +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2742
                           " Old value = " + oldv +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2743
                           " New value = " + newv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2744
                    } catch (Exception e) {
623
97dd054b7f1f 6592586: RequiredModelMBean prints a WARNING message when calling getAttributes() for a non-existing attr
dfuchs
parents: 526
diff changeset
  2745
                        if (MODELMBEAN_LOGGER.isLoggable(Level.FINE)) {
97dd054b7f1f 6592586: RequiredModelMBean prints a WARNING message when calling getAttributes() for a non-existing attr
dfuchs
parents: 526
diff changeset
  2746
                            MODELMBEAN_LOGGER.logp(Level.FINE,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2747
                                    RequiredModelMBean.class.getName(),mth,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2748
                                "Failed to log " + ntfyObj.getType() +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2749
                                    " notification: ", e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2750
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2751
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2752
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2753
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2754
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2755
        if (attributeBroadcaster != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2756
            attributeBroadcaster.sendNotification(ntfyObj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2757
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2758
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2759
        // XXX Revisit: This is a quickfix: it would be better to have a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2760
        //     single broadcaster. However, it is not so simple because
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2761
        //     removeAttributeChangeNotificationListener() should
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2762
        //     remove only listeners whose filter is an instanceof
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2763
        //     AttributeChangeNotificationFilter.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2764
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2765
        if (generalBroadcaster != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2766
            generalBroadcaster.sendNotification(ntfyObj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2767
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2768
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2769
        if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2770
            MODELMBEAN_LOGGER.logp(Level.FINER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2771
                    RequiredModelMBean.class.getName(),mth,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2772
                "sent notification");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2773
            MODELMBEAN_LOGGER.logp(Level.FINER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2774
                    RequiredModelMBean.class.getName(),mth,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2775
                "Exit");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2776
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2777
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2778
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2779
    public void sendAttributeChangeNotification(Attribute inOldVal,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2780
                                                Attribute inNewVal)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2781
        throws MBeanException, RuntimeOperationsException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2782
        final String mth =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2783
            "sendAttributeChangeNotification(Attribute, Attribute)";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2784
        if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2785
            MODELMBEAN_LOGGER.logp(Level.FINER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2786
                    RequiredModelMBean.class.getName(),mth,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2787
                "Entry");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2788
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2789
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2790
        // do we really want to do this?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2791
        if ((inOldVal == null) || (inNewVal == null))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2792
            throw new RuntimeOperationsException(new
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2793
               IllegalArgumentException("Attribute object must not be null"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2794
               "Exception occurred trying to send " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2795
               "attribute change notification of a ModelMBean");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2796
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2797
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2798
        if (!(inOldVal.getName().equals(inNewVal.getName())))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2799
            throw new RuntimeOperationsException(new
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2800
                IllegalArgumentException("Attribute names are not the same"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2801
                "Exception occurred trying to send " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2802
                "attribute change notification of a ModelMBean");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2803
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2804
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2805
        Object newVal = inNewVal.getValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2806
        Object oldVal = inOldVal.getValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2807
        String className = "unknown";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2808
        if (newVal != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2809
            className = newVal.getClass().getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2810
        if (oldVal != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2811
            className = oldVal.getClass().getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2812
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2813
        AttributeChangeNotification myNtfyObj = new
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2814
            AttributeChangeNotification(this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2815
                                        1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2816
                                        ((new Date()).getTime()),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2817
                                        "AttributeChangeDetected",
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2818
                                        inOldVal.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2819
                                        className,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2820
                                        inOldVal.getValue(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2821
                                        inNewVal.getValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2822
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2823
        sendAttributeChangeNotification(myNtfyObj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2824
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2825
        if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2826
            MODELMBEAN_LOGGER.logp(Level.FINER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2827
                    RequiredModelMBean.class.getName(),mth,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2828
                "Exit");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2829
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2830
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2831
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2832
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2833
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2834
     * Return the Class Loader Repository used to perform class loading.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2835
     * Subclasses may wish to redefine this method in order to return
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2836
     * the appropriate {@link javax.management.loading.ClassLoaderRepository}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2837
     * that should be used in this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2838
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2839
     * @return the Class Loader Repository.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2840
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2841
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2842
    protected ClassLoaderRepository getClassLoaderRepository() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2843
        return MBeanServerFactory.getClassLoaderRepository(server);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2844
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2845
16102
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
  2846
    private Class<?> loadClass(final String className)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2847
        throws ClassNotFoundException {
16102
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
  2848
        AccessControlContext stack = AccessController.getContext();
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
  2849
        final ClassNotFoundException[] caughtException = new ClassNotFoundException[1];
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
  2850
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
  2851
        Class c = javaSecurityAccess.doIntersectionPrivilege(new PrivilegedAction<Class<?>>() {
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
  2852
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
  2853
            @Override
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
  2854
            public Class<?> run() {
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
  2855
                try {
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
  2856
                    ReflectUtil.checkPackageAccess(className);
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
  2857
                    return Class.forName(className);
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
  2858
                } catch (ClassNotFoundException e) {
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
  2859
                    final ClassLoaderRepository clr =
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
  2860
                        getClassLoaderRepository();
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
  2861
                    try {
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
  2862
                        if (clr == null) throw new ClassNotFoundException(className);
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
  2863
                        return clr.loadClass(className);
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
  2864
                    } catch (ClassNotFoundException ex) {
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
  2865
                        caughtException[0] = ex;
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
  2866
                    }
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
  2867
                }
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
  2868
                return null;
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
  2869
            }
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
  2870
        }, stack, acc);
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
  2871
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
  2872
        if (caughtException[0] != null) {
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
  2873
            throw caughtException[0];
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2874
        }
16102
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
  2875
59bd4d83778a 8000537: Contextualize RequiredModelMBean class
dsamersoff
parents: 5506
diff changeset
  2876
        return c;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2877
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2878
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2879
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2880
    /*************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2881
    /* MBeanRegistration Interface       */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2882
    /*************************************/
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2883
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2884
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2885
     * Allows the MBean to perform any operations it needs before
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2886
     * being registered in the MBean server.  If the name of the MBean
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2887
     * is not specified, the MBean can provide a name for its
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2888
     * registration.  If any exception is raised, the MBean will not be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2889
     * registered in the MBean server.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2890
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2891
     * In order to ensure proper run-time semantics of RequireModelMBean,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2892
     * Any subclass of RequiredModelMBean overloading or overriding this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2893
     * method should call <code>super.preRegister(server, name)</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2894
     * in its own <code>preRegister</code> implementation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2895
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2896
     * @param server The MBean server in which the MBean will be registered.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2897
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2898
     * @param name The object name of the MBean.  This name is null if
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2899
     * the name parameter to one of the <code>createMBean</code> or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2900
     * <code>registerMBean</code> methods in the {@link MBeanServer}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2901
     * interface is null.  In that case, this method must return a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2902
     * non-null ObjectName for the new MBean.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2903
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2904
     * @return The name under which the MBean is to be registered.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2905
     * This value must not be null.  If the <code>name</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2906
     * parameter is not null, it will usually but not necessarily be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2907
     * the returned value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2908
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2909
     * @exception java.lang.Exception This exception will be caught by
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2910
     * the MBean server and re-thrown as an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2911
     * {@link javax.management.MBeanRegistrationException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2912
     * MBeanRegistrationException}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2913
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2914
    public ObjectName preRegister(MBeanServer server,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2915
                                  ObjectName name)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2916
        throws java.lang.Exception  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2917
        // Since ModelMbeanInfo cannot be null (otherwise exception
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2918
        // thrown at creation)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2919
        // no exception thrown on ModelMBeanInfo not set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2920
        if (name == null) throw new NullPointerException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2921
                     "name of RequiredModelMBean to registered is null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2922
        this.server = server;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2923
        return name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2924
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2925
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2926
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2927
     * Allows the MBean to perform any operations needed after having been
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2928
     * registered in the MBean server or after the registration has failed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2929
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2930
     * In order to ensure proper run-time semantics of RequireModelMBean,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2931
     * Any subclass of RequiredModelMBean overloading or overriding this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2932
     * method should call <code>super.postRegister(registrationDone)</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2933
     * in its own <code>postRegister</code> implementation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2934
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2935
     * @param registrationDone Indicates whether or not the MBean has
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2936
     * been successfully registered in the MBean server. The value
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2937
     * false means that the registration phase has failed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2938
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2939
    public void postRegister(Boolean registrationDone) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2940
        registered = registrationDone.booleanValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2941
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2942
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2943
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2944
     * Allows the MBean to perform any operations it needs before
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2945
     * being unregistered by the MBean server.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2946
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2947
     * In order to ensure proper run-time semantics of RequireModelMBean,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2948
     * Any subclass of RequiredModelMBean overloading or overriding this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2949
     * method should call <code>super.preDeregister()</code> in its own
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2950
     * <code>preDeregister</code> implementation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2951
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2952
     * @exception java.lang.Exception This exception will be caught by
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2953
     * the MBean server and re-thrown as an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2954
     * {@link javax.management.MBeanRegistrationException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2955
     * MBeanRegistrationException}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2956
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2957
    public void preDeregister() throws java.lang.Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2958
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2959
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2960
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2961
     * Allows the MBean to perform any operations needed after having been
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2962
     * unregistered in the MBean server.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2963
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2964
     * In order to ensure proper run-time semantics of RequireModelMBean,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2965
     * Any subclass of RequiredModelMBean overloading or overriding this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2966
     * method should call <code>super.postDeregister()</code> in its own
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2967
     * <code>postDeregister</code> implementation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2968
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2969
    public void postDeregister() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2970
        registered = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2971
        this.server=null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2972
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2973
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2974
    private static final String[] primitiveTypes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2975
    private static final String[] primitiveWrappers;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2976
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2977
        primitiveTypes = new String[] {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2978
            Boolean.TYPE.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2979
            Byte.TYPE.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2980
            Character.TYPE.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2981
            Short.TYPE.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2982
            Integer.TYPE.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2983
            Long.TYPE.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2984
            Float.TYPE.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2985
            Double.TYPE.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2986
            Void.TYPE.getName()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2987
        };
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2988
        primitiveWrappers = new String[] {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2989
            Boolean.class.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2990
            Byte.class.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2991
            Character.class.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2992
            Short.class.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2993
            Integer.class.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2994
            Long.class.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2995
            Float.class.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2996
            Double.class.getName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2997
            Void.class.getName()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2998
        };
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2999
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  3000
}