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