src/java.management/share/classes/javax/management/monitor/Monitor.java
author darcy
Wed, 23 Oct 2019 13:01:40 -0700
changeset 58766 54ffb15c4839
parent 47216 71c04702a3d5
permissions -rw-r--r--
8232442: Suppress warnings on non-serializable non-transient instance fields in java.management.* Reviewed-by: rriggs, mchung
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 37518
diff changeset
     2
 * Copyright (c) 1999, 2017, 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: 2624
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: 2624
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: 2624
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2624
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2624
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package javax.management.monitor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import static com.sun.jmx.defaults.JmxProperties.MONITOR_LOGGER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import com.sun.jmx.mbeanserver.GetPropertyAction;
34
2d042367885f 6602310: Extensions to Query API for JMX 2.0
emcmanus
parents: 2
diff changeset
    30
import com.sun.jmx.mbeanserver.Introspector;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.security.AccessControlContext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.security.AccessController;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.security.PrivilegedAction;
2617
4e94fb04861b 6610888: Potential use of cleared of incorrect acc in JMX Monitor
dfuchs
parents: 526
diff changeset
    35
import java.security.ProtectionDomain;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.util.List;
2619
cc0bbd192d1a 6610896: JMX Monitor handles thread groups incorrectly
dfuchs
parents: 526
diff changeset
    37
import java.util.Map;
cc0bbd192d1a 6610896: JMX Monitor handles thread groups incorrectly
dfuchs
parents: 526
diff changeset
    38
import java.util.WeakHashMap;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.util.concurrent.CopyOnWriteArrayList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import java.util.concurrent.Executors;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import java.util.concurrent.Future;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import java.util.concurrent.LinkedBlockingQueue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import java.util.concurrent.ScheduledExecutorService;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
import java.util.concurrent.ScheduledFuture;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
import java.util.concurrent.ThreadFactory;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
import java.util.concurrent.ThreadPoolExecutor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
import java.util.concurrent.TimeUnit;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
import java.util.concurrent.atomic.AtomicInteger;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
import java.util.concurrent.atomic.AtomicLong;
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 37518
diff changeset
    50
import java.lang.System.Logger.Level;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
import javax.management.AttributeNotFoundException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
import javax.management.InstanceNotFoundException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
import javax.management.IntrospectionException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
import javax.management.MBeanAttributeInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
import javax.management.MBeanException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
import javax.management.MBeanInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
import javax.management.MBeanRegistration;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
import javax.management.MBeanServer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
import javax.management.MBeanServerConnection;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
import javax.management.NotificationBroadcasterSupport;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
import javax.management.ObjectName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
import javax.management.ReflectionException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
import static javax.management.monitor.MonitorNotification.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * Defines the part common to all monitor MBeans.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * A monitor MBean monitors values of an attribute common to a set of observed
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * MBeans. The observed attribute is monitored at intervals specified by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 * granularity period. A gauge value (derived gauge) is derived from the values
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * of the observed attribute.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
public abstract class Monitor
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    extends NotificationBroadcasterSupport
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    implements MonitorMBean, MBeanRegistration {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     * ------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     *  PACKAGE CLASSES
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     * ------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    static class ObservedObject {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        public ObservedObject(ObjectName observedObject) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
            this.observedObject = observedObject;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        public final ObjectName getObservedObject() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
            return observedObject;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        public final synchronized int getAlreadyNotified() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
            return alreadyNotified;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        public final synchronized void setAlreadyNotified(int alreadyNotified) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
            this.alreadyNotified = alreadyNotified;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        public final synchronized Object getDerivedGauge() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
            return derivedGauge;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        public final synchronized void setDerivedGauge(Object derivedGauge) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
            this.derivedGauge = derivedGauge;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        public final synchronized long getDerivedGaugeTimeStamp() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
            return derivedGaugeTimeStamp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        public final synchronized void setDerivedGaugeTimeStamp(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
                                                 long derivedGaugeTimeStamp) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
            this.derivedGaugeTimeStamp = derivedGaugeTimeStamp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        private final ObjectName observedObject;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        private int alreadyNotified;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        private Object derivedGauge;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        private long derivedGaugeTimeStamp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * ------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     *  PRIVATE VARIABLES
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     * ------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     * Attribute to observe.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    private String observedAttribute;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     * Monitor granularity period (in milliseconds).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     * The default value is set to 10 seconds.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    private long granularityPeriod = 10000;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * Monitor state.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     * The default value is set to <CODE>false</CODE>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    private boolean isActive = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     * Monitor sequence number.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     * The default value is set to 0.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    private final AtomicLong sequenceNumber = new AtomicLong();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     * Complex type attribute flag.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     * The default value is set to <CODE>false</CODE>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    private boolean isComplexTypeAttribute = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     * First attribute name extracted from complex type attribute name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    private String firstAttribute;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     * Remaining attribute names extracted from complex type attribute name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    private final List<String> remainingAttributes =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        new CopyOnWriteArrayList<String>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     * AccessControlContext of the Monitor.start() caller.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     */
2617
4e94fb04861b 6610888: Potential use of cleared of incorrect acc in JMX Monitor
dfuchs
parents: 526
diff changeset
   169
    private static final AccessControlContext noPermissionsACC =
4e94fb04861b 6610888: Potential use of cleared of incorrect acc in JMX Monitor
dfuchs
parents: 526
diff changeset
   170
            new AccessControlContext(
4e94fb04861b 6610888: Potential use of cleared of incorrect acc in JMX Monitor
dfuchs
parents: 526
diff changeset
   171
            new ProtectionDomain[] {new ProtectionDomain(null, null)});
4e94fb04861b 6610888: Potential use of cleared of incorrect acc in JMX Monitor
dfuchs
parents: 526
diff changeset
   172
    private volatile AccessControlContext acc = noPermissionsACC;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     * Scheduler Service.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    private static final ScheduledExecutorService scheduler =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        Executors.newSingleThreadScheduledExecutor(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
            new DaemonThreadFactory("Scheduler"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    /**
2619
cc0bbd192d1a 6610896: JMX Monitor handles thread groups incorrectly
dfuchs
parents: 526
diff changeset
   182
     * Map containing the thread pool executor per thread group.
cc0bbd192d1a 6610896: JMX Monitor handles thread groups incorrectly
dfuchs
parents: 526
diff changeset
   183
     */
cc0bbd192d1a 6610896: JMX Monitor handles thread groups incorrectly
dfuchs
parents: 526
diff changeset
   184
    private static final Map<ThreadPoolExecutor, Void> executors =
cc0bbd192d1a 6610896: JMX Monitor handles thread groups incorrectly
dfuchs
parents: 526
diff changeset
   185
            new WeakHashMap<ThreadPoolExecutor, Void>();
cc0bbd192d1a 6610896: JMX Monitor handles thread groups incorrectly
dfuchs
parents: 526
diff changeset
   186
cc0bbd192d1a 6610896: JMX Monitor handles thread groups incorrectly
dfuchs
parents: 526
diff changeset
   187
    /**
cc0bbd192d1a 6610896: JMX Monitor handles thread groups incorrectly
dfuchs
parents: 526
diff changeset
   188
     * Lock for executors map.
cc0bbd192d1a 6610896: JMX Monitor handles thread groups incorrectly
dfuchs
parents: 526
diff changeset
   189
     */
cc0bbd192d1a 6610896: JMX Monitor handles thread groups incorrectly
dfuchs
parents: 526
diff changeset
   190
    private static final Object executorsLock = new Object();
cc0bbd192d1a 6610896: JMX Monitor handles thread groups incorrectly
dfuchs
parents: 526
diff changeset
   191
cc0bbd192d1a 6610896: JMX Monitor handles thread groups incorrectly
dfuchs
parents: 526
diff changeset
   192
    /**
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     * Maximum Pool Size
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    private static final int maximumPoolSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        final String maximumPoolSizeSysProp = "jmx.x.monitor.maximum.pool.size";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        final String maximumPoolSizeStr = AccessController.doPrivileged(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
            new GetPropertyAction(maximumPoolSizeSysProp));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        if (maximumPoolSizeStr == null ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
            maximumPoolSizeStr.trim().length() == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
            maximumPoolSize = 10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
            int maximumPoolSizeTmp = 10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
                maximumPoolSizeTmp = Integer.parseInt(maximumPoolSizeStr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
            } catch (NumberFormatException e) {
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 37518
diff changeset
   208
                if (MONITOR_LOGGER.isLoggable(Level.TRACE)) {
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 37518
diff changeset
   209
                    MONITOR_LOGGER.log(Level.TRACE,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
                            "Wrong value for " + maximumPoolSizeSysProp +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
                            " system property", e);
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 37518
diff changeset
   212
                    MONITOR_LOGGER.log(Level.TRACE,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
                            maximumPoolSizeSysProp + " defaults to 10");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
                maximumPoolSizeTmp = 10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
            if (maximumPoolSizeTmp < 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
                maximumPoolSize = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
                maximumPoolSize = maximumPoolSizeTmp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
            }
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
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     * Future associated to the current monitor task.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
    private Future<?> monitorFuture;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     * Scheduler task to be executed by the Scheduler Service.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     */
2619
cc0bbd192d1a 6610896: JMX Monitor handles thread groups incorrectly
dfuchs
parents: 526
diff changeset
   233
    private final SchedulerTask schedulerTask = new SchedulerTask();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     * ScheduledFuture associated to the current scheduler task.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
    private ScheduledFuture<?> schedulerFuture;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     * ------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     *  PROTECTED VARIABLES
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     * ------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     * The amount by which the capacity of the monitor arrays are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     * automatically incremented when their size becomes greater than
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     * their capacity.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
    protected final static int capacityIncrement = 16;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     * The number of valid components in the vector of observed objects.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
    protected int elementCount = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     * Monitor errors that have already been notified.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     * @deprecated equivalent to {@link #alreadyNotifieds}[0].
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
    protected int alreadyNotified = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     * <p>Selected monitor errors that have already been notified.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     * <p>Each element in this array corresponds to an observed object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     * in the vector.  It contains a bit mask of the flags {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     * #OBSERVED_OBJECT_ERROR_NOTIFIED} etc, indicating whether the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     * corresponding notification has already been sent for the MBean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     * being monitored.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
    protected int alreadyNotifieds[] = new int[capacityIncrement];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     * Reference to the MBean server.  This reference is null when the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     * monitor MBean is not registered in an MBean server.  This
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     * reference is initialized before the monitor MBean is registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     * in the MBean server.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     * @see #preRegister(MBeanServer server, ObjectName name)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
    protected MBeanServer server;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
    // Flags defining possible monitor errors.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
     * This flag is used to reset the {@link #alreadyNotifieds
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
     * alreadyNotifieds} monitor attribute.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
    protected static final int RESET_FLAGS_ALREADY_NOTIFIED             = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
     * Flag denoting that a notification has occurred after changing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
     * the observed object.  This flag is used to check that the new
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
     * observed object is registered in the MBean server at the time
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
     * of the first notification.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
    protected static final int OBSERVED_OBJECT_ERROR_NOTIFIED           = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
     * Flag denoting that a notification has occurred after changing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
     * the observed attribute.  This flag is used to check that the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
     * new observed attribute belongs to the observed object at the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     * time of the first notification.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
    protected static final int OBSERVED_ATTRIBUTE_ERROR_NOTIFIED        = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
     * Flag denoting that a notification has occurred after changing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
     * the observed object or the observed attribute.  This flag is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
     * used to check that the observed attribute type is correct
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
     * (depending on the monitor in use) at the time of the first
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
     * notification.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
    protected static final int OBSERVED_ATTRIBUTE_TYPE_ERROR_NOTIFIED   = 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
     * Flag denoting that a notification has occurred after changing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     * the observed object or the observed attribute.  This flag is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     * used to notify any exception (except the cases described above)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
     * when trying to get the value of the observed attribute at the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
     * time of the first notification.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
    protected static final int RUNTIME_ERROR_NOTIFIED                   = 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
     * This field is retained for compatibility but should not be referenced.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
     * @deprecated No replacement.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
    protected String dbgTag = Monitor.class.getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
     * ------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
     *  PACKAGE VARIABLES
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
     * ------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
     * List of ObservedObjects to which the attribute to observe belongs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
    final List<ObservedObject> observedObjects =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
        new CopyOnWriteArrayList<ObservedObject>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
     * Flag denoting that a notification has occurred after changing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
     * the threshold. This flag is used to notify any exception
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
     * related to invalid thresholds settings.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
    static final int THRESHOLD_ERROR_NOTIFIED                           = 16;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
     * Enumeration used to keep trace of the derived gauge type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
     * in counter and gauge monitors.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
    enum NumericalType { BYTE, SHORT, INTEGER, LONG, FLOAT, DOUBLE };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
     * Constant used to initialize all the numeric values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
     */
526
61ba2d5ea9da 6701459: Synchronization bug pattern found in javax.management.relation.RelationService
emcmanus
parents: 34
diff changeset
   366
    static final Integer INTEGER_ZERO = 0;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
     * ------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
     *  PUBLIC METHODS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
     * ------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
     * Allows the monitor MBean to perform any operations it needs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
     * before being registered in the MBean server.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
     * Initializes the reference to the MBean server.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
     * @param server The MBean server in which the monitor MBean will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
     * be registered.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
     * @param name The object name of the monitor MBean.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
     * @return The name of the monitor MBean registered.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
     *
29927
9cc3e111a1d8 8077923: Add missing doclint in javax.management
darcy
parents: 29921
diff changeset
   387
     * @exception Exception if something goes wrong
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
    public ObjectName preRegister(MBeanServer server, ObjectName name)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
        throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 37518
diff changeset
   392
        MONITOR_LOGGER.log(Level.TRACE,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
                "initialize the reference on the MBean server");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
        this.server = server;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
        return name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
     * Allows the monitor MBean to perform any operations needed after
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
     * having been registered in the MBean server or after the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
     * registration has failed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
     * Not used in this context.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
    public void postRegister(Boolean registrationDone) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
     * Allows the monitor MBean to perform any operations it needs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
     * before being unregistered by the MBean server.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
     * Stops the monitor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
     *
29927
9cc3e111a1d8 8077923: Add missing doclint in javax.management
darcy
parents: 29921
diff changeset
   415
     * @exception Exception if something goes wrong
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
    public void preDeregister() throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 37518
diff changeset
   419
        MONITOR_LOGGER.log(Level.TRACE, "stop the monitor");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
        // Stop the Monitor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
        stop();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
     * Allows the monitor MBean to perform any operations needed after
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
     * having been unregistered by the MBean server.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
     * Not used in this context.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
    public void postDeregister() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
     * Starts the monitor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
    public abstract void start();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
     * Stops the monitor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
    public abstract void stop();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
    // GETTERS AND SETTERS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
    //--------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
     * Returns the object name of the first object in the set of observed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
     * MBeans, or <code>null</code> if there is no such object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
     * @return The object being observed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
     * @see #setObservedObject(ObjectName)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
     * @deprecated As of JMX 1.2, replaced by {@link #getObservedObjects}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
    public synchronized ObjectName getObservedObject() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
        if (observedObjects.isEmpty()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
            return observedObjects.get(0).getObservedObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
     * Removes all objects from the set of observed objects, and then adds the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
     * specified object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
     * @param object The object to observe.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
     * @exception IllegalArgumentException The specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
     * object is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
     * @see #getObservedObject()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
     * @deprecated As of JMX 1.2, replaced by {@link #addObservedObject}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
    public synchronized void setObservedObject(ObjectName object)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
        throws IllegalArgumentException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
        if (object == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
            throw new IllegalArgumentException("Null observed object");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
        if (observedObjects.size() == 1 && containsObservedObject(object))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
        observedObjects.clear();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
        addObservedObject(object);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
     * Adds the specified object in the set of observed MBeans, if this object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
     * is not already present.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
     * @param object The object to observe.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
     * @exception IllegalArgumentException The specified object is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
    public synchronized void addObservedObject(ObjectName object)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
        throws IllegalArgumentException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
        if (object == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
            throw new IllegalArgumentException("Null observed object");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
        // Check that the specified object is not already contained.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
        if (containsObservedObject(object))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
        // Add the specified object in the list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
        ObservedObject o = createObservedObject(object);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
        o.setAlreadyNotified(RESET_FLAGS_ALREADY_NOTIFIED);
1581
81388748f694 6683213: CounterMonitor's derived Gauge badly initialized
dfuchs
parents: 1446
diff changeset
   514
        o.setDerivedGauge(INTEGER_ZERO);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
        o.setDerivedGaugeTimeStamp(System.currentTimeMillis());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
        observedObjects.add(o);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
        // Update legacy protected stuff.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
        createAlreadyNotified();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
     * Removes the specified object from the set of observed MBeans.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
     * @param object The object to remove.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
    public synchronized void removeObservedObject(ObjectName object) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
        // Check for null object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
        if (object == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
        final ObservedObject o = getObservedObject(object);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
        if (o != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
            // Remove the specified object from the list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
            observedObjects.remove(o);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
            // Update legacy protected stuff.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
            createAlreadyNotified();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
     * Tests whether the specified object is in the set of observed MBeans.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
     * @param object The object to check.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
     * @return <CODE>true</CODE> if the specified object is present,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
     * <CODE>false</CODE> otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
    public synchronized boolean containsObservedObject(ObjectName object) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
        return getObservedObject(object) != null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
     * Returns an array containing the objects being observed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
     * @return The objects being observed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
    public synchronized ObjectName[] getObservedObjects() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
        ObjectName[] names = new ObjectName[observedObjects.size()];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
        for (int i = 0; i < names.length; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
            names[i] = observedObjects.get(i).getObservedObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
        return names;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
     * Gets the attribute being observed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
     * <BR>The observed attribute is not initialized by default (set to null).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
     * @return The attribute being observed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
     * @see #setObservedAttribute
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
    public synchronized String getObservedAttribute() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
        return observedAttribute;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
     * Sets the attribute to observe.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
     * <BR>The observed attribute is not initialized by default (set to null).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
     * @param attribute The attribute to observe.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
     * @exception IllegalArgumentException The specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
     * attribute is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
     * @see #getObservedAttribute
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
    public void setObservedAttribute(String attribute)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
        throws IllegalArgumentException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
        if (attribute == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
            throw new IllegalArgumentException("Null observed attribute");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
        // Update alreadyNotified array.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
        synchronized (this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
            if (observedAttribute != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
                observedAttribute.equals(attribute))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
            observedAttribute = attribute;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
            // Reset the complex type attribute information
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
            // such that it is recalculated again.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
            cleanupIsComplexTypeAttribute();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
            int index = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
            for (ObservedObject o : observedObjects) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
                resetAlreadyNotified(o, index++,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
                                     OBSERVED_ATTRIBUTE_ERROR_NOTIFIED |
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
                                     OBSERVED_ATTRIBUTE_TYPE_ERROR_NOTIFIED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
     * Gets the granularity period (in milliseconds).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
     * <BR>The default value of the granularity period is 10 seconds.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
     * @return The granularity period value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
     * @see #setGranularityPeriod
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
    public synchronized long getGranularityPeriod() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
        return granularityPeriod;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
     * Sets the granularity period (in milliseconds).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
     * <BR>The default value of the granularity period is 10 seconds.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
     * @param period The granularity period value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
     * @exception IllegalArgumentException The granularity
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
     * period is less than or equal to zero.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
     * @see #getGranularityPeriod
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
    public synchronized void setGranularityPeriod(long period)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
        throws IllegalArgumentException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
        if (period <= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
            throw new IllegalArgumentException("Nonpositive granularity " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
                                               "period");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
        if (granularityPeriod == period)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
        granularityPeriod = period;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
        // Reschedule the scheduler task if the monitor is active.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
        if (isActive()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
            cleanupFutures();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
            schedulerFuture = scheduler.schedule(schedulerTask,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
                                                 period,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
                                                 TimeUnit.MILLISECONDS);
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
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
     * Tests whether the monitor MBean is active.  A monitor MBean is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
     * marked active when the {@link #start start} method is called.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
     * It becomes inactive when the {@link #stop stop} method is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
     * called.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
     * @return <CODE>true</CODE> if the monitor MBean is active,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
     * <CODE>false</CODE> otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
    /* This method must be synchronized so that the monitoring thread will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
       correctly see modifications to the isActive variable. See the MonitorTask
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
       action executed by the Scheduled Executor Service. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
    public synchronized boolean isActive() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
        return isActive;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
     * ------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
     *  PACKAGE METHODS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
     * ------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
     * Starts the monitor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
    void doStart() {
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 37518
diff changeset
   692
            MONITOR_LOGGER.log(Level.TRACE, "start the monitor");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
        synchronized (this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
            if (isActive()) {
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 37518
diff changeset
   696
                MONITOR_LOGGER.log(Level.TRACE, "the monitor is already active");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
            isActive = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
            // Reset the complex type attribute information
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
            // such that it is recalculated again.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
            cleanupIsComplexTypeAttribute();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
            // Cache the AccessControlContext of the Monitor.start() caller.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
            // The monitor tasks will be executed within this context.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
            acc = AccessController.getContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
            // Start the scheduler.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
            cleanupFutures();
2619
cc0bbd192d1a 6610896: JMX Monitor handles thread groups incorrectly
dfuchs
parents: 526
diff changeset
   715
            schedulerTask.setMonitorTask(new MonitorTask());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
            schedulerFuture = scheduler.schedule(schedulerTask,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
                                                 getGranularityPeriod(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
                                                 TimeUnit.MILLISECONDS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
     * Stops the monitor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
    void doStop() {
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 37518
diff changeset
   726
        MONITOR_LOGGER.log(Level.TRACE, "stop the monitor");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
        synchronized (this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
            if (!isActive()) {
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 37518
diff changeset
   730
                MONITOR_LOGGER.log(Level.TRACE, "the monitor is not active");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
            isActive = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
            // Cancel the scheduler task associated with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
            // scheduler and its associated monitor task.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
            cleanupFutures();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
            // Reset the AccessControlContext.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
            //
2617
4e94fb04861b 6610888: Potential use of cleared of incorrect acc in JMX Monitor
dfuchs
parents: 526
diff changeset
   743
            acc = noPermissionsACC;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
            // Reset the complex type attribute information
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
            // such that it is recalculated again.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
            cleanupIsComplexTypeAttribute();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
     * Gets the derived gauge of the specified object, if this object is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
     * contained in the set of observed MBeans, or <code>null</code> otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
     * @param object the name of the object whose derived gauge is to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
     * be returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
     * @return The derived gauge of the specified object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
    synchronized Object getDerivedGauge(ObjectName object) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
        final ObservedObject o = getObservedObject(object);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
        return o == null ? null : o.getDerivedGauge();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
     * Gets the derived gauge timestamp of the specified object, if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
     * this object is contained in the set of observed MBeans, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
     * <code>0</code> otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
     * @param object the name of the object whose derived gauge
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
     * timestamp is to be returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
     * @return The derived gauge timestamp of the specified object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
    synchronized long getDerivedGaugeTimeStamp(ObjectName object) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
        final ObservedObject o = getObservedObject(object);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
        return o == null ? 0 : o.getDerivedGaugeTimeStamp();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
    Object getAttribute(MBeanServerConnection mbsc,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
                        ObjectName object,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
                        String attribute)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
        throws AttributeNotFoundException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
               InstanceNotFoundException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
               MBeanException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
               ReflectionException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
               IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
        // Check for "ObservedAttribute" replacement.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
        // This could happen if a thread A called setObservedAttribute()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
        // while other thread B was in the middle of the monitor() method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
        // and received the old observed attribute value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
        final boolean lookupMBeanInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
        synchronized (this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
            if (!isActive())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
                throw new IllegalArgumentException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
                    "The monitor has been stopped");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
            if (!attribute.equals(getObservedAttribute()))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
                throw new IllegalArgumentException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
                    "The observed attribute has been changed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
            lookupMBeanInfo =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
                (firstAttribute == null && attribute.indexOf('.') != -1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
        // Look up MBeanInfo if needed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
        final MBeanInfo mbi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
        if (lookupMBeanInfo) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
                mbi = mbsc.getMBeanInfo(object);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
            } catch (IntrospectionException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
                throw new IllegalArgumentException(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
            mbi = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
        // Check for complex type attribute
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
        final String fa;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
        synchronized (this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
            if (!isActive())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
                throw new IllegalArgumentException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
                    "The monitor has been stopped");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
            if (!attribute.equals(getObservedAttribute()))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
                throw new IllegalArgumentException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
                    "The observed attribute has been changed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
            if (firstAttribute == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
                if (attribute.indexOf('.') != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
                    MBeanAttributeInfo mbaiArray[] = mbi.getAttributes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
                    for (MBeanAttributeInfo mbai : mbaiArray) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
                        if (attribute.equals(mbai.getName())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
                            firstAttribute = attribute;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
                            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
                    if (firstAttribute == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
                        String tokens[] = attribute.split("\\.", -1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
                        firstAttribute = tokens[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
                        for (int i = 1; i < tokens.length; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
                            remainingAttributes.add(tokens[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
                        isComplexTypeAttribute = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
                    firstAttribute = attribute;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
            fa = firstAttribute;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
        return mbsc.getAttribute(object, fa);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
    Comparable<?> getComparableFromAttribute(ObjectName object,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
                                             String attribute,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
                                             Object value)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
        throws AttributeNotFoundException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
        if (isComplexTypeAttribute) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
            Object v = value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
            for (String attr : remainingAttributes)
34
2d042367885f 6602310: Extensions to Query API for JMX 2.0
emcmanus
parents: 2
diff changeset
   864
                v = Introspector.elementFromComplex(v, attr);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
            return (Comparable<?>) v;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
            return (Comparable<?>) value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
    boolean isComparableTypeValid(ObjectName object,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
                                  String attribute,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
                                  Comparable<?> value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
    String buildErrorNotification(ObjectName object,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
                                  String attribute,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
                                  Comparable<?> value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
    void onErrorNotification(MonitorNotification notification) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
    Comparable<?> getDerivedGaugeFromComparable(ObjectName object,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
                                                String attribute,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
                                                Comparable<?> value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
        return (Comparable<?>) value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
    MonitorNotification buildAlarmNotification(ObjectName object,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
                                               String attribute,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
                                               Comparable<?> value){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
    boolean isThresholdTypeValid(ObjectName object,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
                                 String attribute,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
                                 Comparable<?> value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
    static Class<? extends Number> classForType(NumericalType type) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
        switch (type) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
            case BYTE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
                return Byte.class;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
            case SHORT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
                return Short.class;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
            case INTEGER:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
                return Integer.class;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
            case LONG:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
                return Long.class;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
            case FLOAT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
                return Float.class;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
            case DOUBLE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
                return Double.class;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
            default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
                throw new IllegalArgumentException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
                    "Unsupported numerical type");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
    static boolean isValidForType(Object value, Class<? extends Number> c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
        return ((value == INTEGER_ZERO) || c.isInstance(value));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
     * Get the specified {@code ObservedObject} if this object is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
     * contained in the set of observed MBeans, or {@code null}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
     * otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
     * @param object the name of the {@code ObservedObject} to retrieve.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
     * @return The {@code ObservedObject} associated to the supplied
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
     * {@code ObjectName}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
    synchronized ObservedObject getObservedObject(ObjectName object) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
        for (ObservedObject o : observedObjects)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
            if (o.getObservedObject().equals(object))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
                return o;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
     * Factory method for ObservedObject creation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
    ObservedObject createObservedObject(ObjectName object) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
        return new ObservedObject(object);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
     * Create the {@link #alreadyNotified} array from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
     * the {@code ObservedObject} array list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
    synchronized void createAlreadyNotified() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
        // Update elementCount.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
        elementCount = observedObjects.size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
        // Update arrays.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
        alreadyNotifieds = new int[elementCount];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
        for (int i = 0; i < elementCount; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
            alreadyNotifieds[i] = observedObjects.get(i).getAlreadyNotified();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
        updateDeprecatedAlreadyNotified();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
     * Update the deprecated {@link #alreadyNotified} field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
    synchronized void updateDeprecatedAlreadyNotified() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
        if (elementCount > 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
            alreadyNotified = alreadyNotifieds[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
            alreadyNotified = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
     * Update the {@link #alreadyNotifieds} array element at the given index
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
     * with the already notified flag in the given {@code ObservedObject}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
     * Ensure the deprecated {@link #alreadyNotified} field is updated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
     * if appropriate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
    synchronized void updateAlreadyNotified(ObservedObject o, int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
        alreadyNotifieds[index] = o.getAlreadyNotified();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
        if (index == 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
            updateDeprecatedAlreadyNotified();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
     * Check if the given bits in the given element of {@link #alreadyNotifieds}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
     * are set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
    synchronized boolean isAlreadyNotified(ObservedObject o, int mask) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
        return ((o.getAlreadyNotified() & mask) != 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
     * Set the given bits in the given element of {@link #alreadyNotifieds}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
     * Ensure the deprecated {@link #alreadyNotified} field is updated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
     * if appropriate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
    synchronized void setAlreadyNotified(ObservedObject o, int index,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
                                         int mask, int an[]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
        final int i = computeAlreadyNotifiedIndex(o, index, an);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
        if (i == -1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
        o.setAlreadyNotified(o.getAlreadyNotified() | mask);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
        updateAlreadyNotified(o, i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
     * Reset the given bits in the given element of {@link #alreadyNotifieds}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
     * Ensure the deprecated {@link #alreadyNotified} field is updated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
     * if appropriate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
    synchronized void resetAlreadyNotified(ObservedObject o,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
                                           int index, int mask) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
        o.setAlreadyNotified(o.getAlreadyNotified() & ~mask);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
        updateAlreadyNotified(o, index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
     * Reset all bits in the given element of {@link #alreadyNotifieds}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
     * Ensure the deprecated {@link #alreadyNotified} field is updated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
     * if appropriate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
    synchronized void resetAllAlreadyNotified(ObservedObject o,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
                                              int index, int an[]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
        final int i = computeAlreadyNotifiedIndex(o, index, an);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
        if (i == -1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
        o.setAlreadyNotified(RESET_FLAGS_ALREADY_NOTIFIED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
        updateAlreadyNotified(o, index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
     * Check if the {@link #alreadyNotifieds} array has been modified.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
     * If true recompute the index for the given observed object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
    synchronized int computeAlreadyNotifiedIndex(ObservedObject o,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
                                                 int index, int an[]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
        if (an == alreadyNotifieds) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
            return index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
            return observedObjects.indexOf(o);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
     * ------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
     *  PRIVATE METHODS
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
     * ------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
     * This method is used by the monitor MBean to create and send a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
     * monitor notification to all the listeners registered for this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
     * kind of notification.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
     * @param type The notification type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
     * @param timeStamp The notification emission date.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
     * @param msg The notification message.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
     * @param derGauge The derived gauge.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
     * @param trigger The threshold/string (depending on the monitor
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
     * type) that triggered off the notification.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
     * @param object The ObjectName of the observed object that triggered
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
     * off the notification.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
     * @param onError Flag indicating if this monitor notification is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
     * an error notification or an alarm notification.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
    private void sendNotification(String type, long timeStamp, String msg,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
                                  Object derGauge, Object trigger,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
                                  ObjectName object, boolean onError) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
        if (!isActive())
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 37518
diff changeset
  1084
        if (MONITOR_LOGGER.isLoggable(Level.TRACE)) {
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 37518
diff changeset
  1085
            MONITOR_LOGGER.log(Level.TRACE, "send notification: " +
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
                    "\n\tNotification observed object = " + object +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
                    "\n\tNotification observed attribute = " + observedAttribute +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
                    "\n\tNotification derived gauge = " + derGauge);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
        long seqno = sequenceNumber.getAndIncrement();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
        MonitorNotification mn =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
            new MonitorNotification(type,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
                                    this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
                                    seqno,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
                                    timeStamp,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1098
                                    msg,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
                                    object,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
                                    observedAttribute,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
                                    derGauge,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
                                    trigger);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
        if (onError)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
            onErrorNotification(mn);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
        sendNotification(mn);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
     * This method is called by the monitor each time
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
     * the granularity period has been exceeded.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
     * @param o The observed object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
    private void monitor(ObservedObject o, int index, int an[]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
526
61ba2d5ea9da 6701459: Synchronization bug pattern found in javax.management.relation.RelationService
emcmanus
parents: 34
diff changeset
  1115
        String attribute;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
        String notifType = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
        String msg = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
        Object derGauge = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
        Object trigger = null;
526
61ba2d5ea9da 6701459: Synchronization bug pattern found in javax.management.relation.RelationService
emcmanus
parents: 34
diff changeset
  1120
        ObjectName object;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1121
        Comparable<?> value = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1122
        MonitorNotification alarm = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1123
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1124
        if (!isActive())
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1125
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1126
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
        // Check that neither the observed object nor the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
        // observed attribute are null.  If the observed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
        // object or observed attribute is null, this means
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1130
        // that the monitor started before a complete
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
        // initialization and nothing is done.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1132
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1133
        synchronized (this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1134
            object = o.getObservedObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1135
            attribute = getObservedAttribute();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1136
            if (object == null || attribute == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1137
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1138
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1139
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1140
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
        // Check that the observed object is registered in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1142
        // MBean server and that the observed attribute
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1143
        // belongs to the observed object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1144
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1145
        Object attributeValue = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1146
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1147
            attributeValue = getAttribute(server, object, attribute);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1148
            if (attributeValue == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1149
                if (isAlreadyNotified(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1150
                        o, OBSERVED_ATTRIBUTE_TYPE_ERROR_NOTIFIED))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1151
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
                else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1153
                    notifType = OBSERVED_ATTRIBUTE_TYPE_ERROR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1154
                    setAlreadyNotified(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1155
                        o, index, OBSERVED_ATTRIBUTE_TYPE_ERROR_NOTIFIED, an);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1156
                    msg = "The observed attribute value is null.";
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 37518
diff changeset
  1157
                    MONITOR_LOGGER.log(Level.TRACE, msg);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1158
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1159
        } catch (NullPointerException np_ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1160
            if (isAlreadyNotified(o, RUNTIME_ERROR_NOTIFIED))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1161
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1162
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1163
                notifType = RUNTIME_ERROR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1164
                setAlreadyNotified(o, index, RUNTIME_ERROR_NOTIFIED, an);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1165
                msg =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1166
                    "The monitor must be registered in the MBean " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1167
                    "server or an MBeanServerConnection must be " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1168
                    "explicitly supplied.";
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 37518
diff changeset
  1169
                MONITOR_LOGGER.log(Level.TRACE, msg);
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 37518
diff changeset
  1170
                MONITOR_LOGGER.log(Level.TRACE, np_ex::toString);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1171
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1172
        } catch (InstanceNotFoundException inf_ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1173
            if (isAlreadyNotified(o, OBSERVED_OBJECT_ERROR_NOTIFIED))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1174
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1175
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1176
                notifType = OBSERVED_OBJECT_ERROR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1177
                setAlreadyNotified(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1178
                    o, index, OBSERVED_OBJECT_ERROR_NOTIFIED, an);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1179
                msg =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1180
                    "The observed object must be accessible in " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1181
                    "the MBeanServerConnection.";
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 37518
diff changeset
  1182
                MONITOR_LOGGER.log(Level.TRACE, msg);
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 37518
diff changeset
  1183
                MONITOR_LOGGER.log(Level.TRACE, inf_ex::toString);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1184
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1185
        } catch (AttributeNotFoundException anf_ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1186
            if (isAlreadyNotified(o, OBSERVED_ATTRIBUTE_ERROR_NOTIFIED))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1187
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1188
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1189
                notifType = OBSERVED_ATTRIBUTE_ERROR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1190
                setAlreadyNotified(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1191
                    o, index, OBSERVED_ATTRIBUTE_ERROR_NOTIFIED, an);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1192
                msg =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1193
                    "The observed attribute must be accessible in " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1194
                    "the observed object.";
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 37518
diff changeset
  1195
                MONITOR_LOGGER.log(Level.TRACE, msg);
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 37518
diff changeset
  1196
                MONITOR_LOGGER.log(Level.TRACE, anf_ex::toString);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1197
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1198
        } catch (MBeanException mb_ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1199
            if (isAlreadyNotified(o, RUNTIME_ERROR_NOTIFIED))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1200
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1201
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1202
                notifType = RUNTIME_ERROR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1203
                setAlreadyNotified(o, index, RUNTIME_ERROR_NOTIFIED, an);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1204
                msg = mb_ex.getMessage() == null ? "" : mb_ex.getMessage();
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 37518
diff changeset
  1205
                MONITOR_LOGGER.log(Level.TRACE, msg);
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 37518
diff changeset
  1206
                MONITOR_LOGGER.log(Level.TRACE, mb_ex::toString);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1207
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1208
        } catch (ReflectionException ref_ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1209
            if (isAlreadyNotified(o, RUNTIME_ERROR_NOTIFIED)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1210
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1211
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1212
                notifType = RUNTIME_ERROR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1213
                setAlreadyNotified(o, index, RUNTIME_ERROR_NOTIFIED, an);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1214
                msg = ref_ex.getMessage() == null ? "" : ref_ex.getMessage();
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 37518
diff changeset
  1215
                MONITOR_LOGGER.log(Level.TRACE, msg);
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 37518
diff changeset
  1216
                MONITOR_LOGGER.log(Level.TRACE, ref_ex::toString);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1217
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1218
        } catch (IOException io_ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1219
            if (isAlreadyNotified(o, RUNTIME_ERROR_NOTIFIED))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1220
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1221
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1222
                notifType = RUNTIME_ERROR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1223
                setAlreadyNotified(o, index, RUNTIME_ERROR_NOTIFIED, an);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1224
                msg = io_ex.getMessage() == null ? "" : io_ex.getMessage();
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 37518
diff changeset
  1225
                MONITOR_LOGGER.log(Level.TRACE, msg);
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 37518
diff changeset
  1226
                MONITOR_LOGGER.log(Level.TRACE, io_ex::toString);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1227
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1228
        } catch (RuntimeException rt_ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1229
            if (isAlreadyNotified(o, RUNTIME_ERROR_NOTIFIED))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1230
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1231
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1232
                notifType = RUNTIME_ERROR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1233
                setAlreadyNotified(o, index, RUNTIME_ERROR_NOTIFIED, an);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1234
                msg = rt_ex.getMessage() == null ? "" : rt_ex.getMessage();
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 37518
diff changeset
  1235
                MONITOR_LOGGER.log(Level.TRACE, msg);
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 37518
diff changeset
  1236
                MONITOR_LOGGER.log(Level.TRACE, rt_ex::toString);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1237
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1238
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1239
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1240
        synchronized (this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1241
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1242
            // Check if the monitor has been stopped.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1243
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1244
            if (!isActive())
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1245
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1246
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1247
            // Check if the observed attribute has been changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1248
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1249
            // Avoid race condition where mbs.getAttribute() succeeded but
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1250
            // another thread replaced the observed attribute meanwhile.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1251
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1252
            // Avoid setting computed derived gauge on erroneous attribute.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1253
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1254
            if (!attribute.equals(getObservedAttribute()))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1255
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1256
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1257
            // Derive a Comparable object from the ObservedAttribute value
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1258
            // if the type of the ObservedAttribute value is a complex type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1259
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1260
            if (msg == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1261
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1262
                    value = getComparableFromAttribute(object,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1263
                                                       attribute,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1264
                                                       attributeValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1265
                } catch (ClassCastException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1266
                    if (isAlreadyNotified(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1267
                            o, OBSERVED_ATTRIBUTE_TYPE_ERROR_NOTIFIED))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1268
                        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1269
                    else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1270
                        notifType = OBSERVED_ATTRIBUTE_TYPE_ERROR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1271
                        setAlreadyNotified(o, index,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1272
                            OBSERVED_ATTRIBUTE_TYPE_ERROR_NOTIFIED, an);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1273
                        msg =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1274
                            "The observed attribute value does not " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1275
                            "implement the Comparable interface.";
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 37518
diff changeset
  1276
                        MONITOR_LOGGER.log(Level.TRACE, msg);
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 37518
diff changeset
  1277
                        MONITOR_LOGGER.log(Level.TRACE, e::toString);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1278
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1279
                } catch (AttributeNotFoundException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1280
                    if (isAlreadyNotified(o, OBSERVED_ATTRIBUTE_ERROR_NOTIFIED))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1281
                        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1282
                    else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1283
                        notifType = OBSERVED_ATTRIBUTE_ERROR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1284
                        setAlreadyNotified(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1285
                            o, index, OBSERVED_ATTRIBUTE_ERROR_NOTIFIED, an);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1286
                        msg =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1287
                            "The observed attribute must be accessible in " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1288
                            "the observed object.";
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 37518
diff changeset
  1289
                        MONITOR_LOGGER.log(Level.TRACE, msg);
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 37518
diff changeset
  1290
                        MONITOR_LOGGER.log(Level.TRACE, e::toString);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1291
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1292
                } catch (RuntimeException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1293
                    if (isAlreadyNotified(o, RUNTIME_ERROR_NOTIFIED))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1294
                        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1295
                    else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1296
                        notifType = RUNTIME_ERROR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1297
                        setAlreadyNotified(o, index,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1298
                            RUNTIME_ERROR_NOTIFIED, an);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1299
                        msg = e.getMessage() == null ? "" : e.getMessage();
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 37518
diff changeset
  1300
                        MONITOR_LOGGER.log(Level.TRACE, msg);
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 37518
diff changeset
  1301
                        MONITOR_LOGGER.log(Level.TRACE, e::toString);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1302
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1303
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1304
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1305
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1306
            // Check that the observed attribute type is supported by this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1307
            // monitor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1308
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1309
            if (msg == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1310
                if (!isComparableTypeValid(object, attribute, value)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1311
                    if (isAlreadyNotified(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1312
                            o, OBSERVED_ATTRIBUTE_TYPE_ERROR_NOTIFIED))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1313
                        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1314
                    else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1315
                        notifType = OBSERVED_ATTRIBUTE_TYPE_ERROR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1316
                        setAlreadyNotified(o, index,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1317
                            OBSERVED_ATTRIBUTE_TYPE_ERROR_NOTIFIED, an);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1318
                        msg = "The observed attribute type is not valid.";
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 37518
diff changeset
  1319
                        MONITOR_LOGGER.log(Level.TRACE, msg);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1320
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1321
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1322
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1323
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1324
            // Check that threshold type is supported by this monitor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1325
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1326
            if (msg == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1327
                if (!isThresholdTypeValid(object, attribute, value)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1328
                    if (isAlreadyNotified(o, THRESHOLD_ERROR_NOTIFIED))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1329
                        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1330
                    else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1331
                        notifType = THRESHOLD_ERROR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1332
                        setAlreadyNotified(o, index,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1333
                            THRESHOLD_ERROR_NOTIFIED, an);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1334
                        msg = "The threshold type is not valid.";
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 37518
diff changeset
  1335
                        MONITOR_LOGGER.log(Level.TRACE, msg);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1336
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1337
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1338
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1339
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1340
            // Let someone subclassing the monitor to perform additional
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1341
            // monitor consistency checks and report errors if necessary.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1342
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1343
            if (msg == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1344
                msg = buildErrorNotification(object, attribute, value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1345
                if (msg != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1346
                    if (isAlreadyNotified(o, RUNTIME_ERROR_NOTIFIED))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1347
                        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1348
                    else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1349
                        notifType = RUNTIME_ERROR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1350
                        setAlreadyNotified(o, index,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1351
                            RUNTIME_ERROR_NOTIFIED, an);
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 37518
diff changeset
  1352
                        MONITOR_LOGGER.log(Level.TRACE, msg);
2
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
            // If no errors were found then clear all error flags and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1358
            // let the monitor decide if a notification must be sent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1359
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1360
            if (msg == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1361
                // Clear all already notified flags.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1362
                //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1363
                resetAllAlreadyNotified(o, index, an);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1364
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1365
                // Get derived gauge from comparable value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1366
                //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1367
                derGauge = getDerivedGaugeFromComparable(object,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1368
                                                         attribute,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1369
                                                         value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1370
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1371
                o.setDerivedGauge(derGauge);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1372
                o.setDerivedGaugeTimeStamp(System.currentTimeMillis());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1373
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1374
                // Check if an alarm must be fired.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1375
                //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1376
                alarm = buildAlarmNotification(object,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1377
                                               attribute,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1378
                                               (Comparable<?>) derGauge);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1379
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1380
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1381
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1382
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1383
        // Notify monitor errors
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1384
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1385
        if (msg != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1386
            sendNotification(notifType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1387
                             System.currentTimeMillis(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1388
                             msg,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1389
                             derGauge,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1390
                             trigger,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1391
                             object,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1392
                             true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1393
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1394
        // Notify monitor alarms
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1395
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1396
        if (alarm != null && alarm.getType() != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1397
            sendNotification(alarm.getType(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1398
                             System.currentTimeMillis(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1399
                             alarm.getMessage(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1400
                             derGauge,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1401
                             alarm.getTrigger(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1402
                             object,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1403
                             false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1404
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1405
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1406
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1407
     * Cleanup the scheduler and monitor tasks futures.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1408
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1409
    private synchronized void cleanupFutures() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1410
        if (schedulerFuture != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1411
            schedulerFuture.cancel(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1412
            schedulerFuture = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1413
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1414
        if (monitorFuture != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1415
            monitorFuture.cancel(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1416
            monitorFuture = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1417
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1418
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1419
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1420
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1421
     * Cleanup the "is complex type attribute" info.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1422
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1423
    private synchronized void cleanupIsComplexTypeAttribute() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1424
        firstAttribute = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1425
        remainingAttributes.clear();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1426
        isComplexTypeAttribute = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1427
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1428
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1429
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1430
     * SchedulerTask nested class: This class implements the Runnable interface.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1431
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1432
     * The SchedulerTask is executed periodically with a given fixed delay by
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1433
     * the Scheduled Executor Service.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1434
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1435
    private class SchedulerTask implements Runnable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1436
2619
cc0bbd192d1a 6610896: JMX Monitor handles thread groups incorrectly
dfuchs
parents: 526
diff changeset
  1437
        private MonitorTask task;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1438
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1439
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1440
         * ------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1441
         *  CONSTRUCTORS
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1442
         * ------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1443
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1444
2619
cc0bbd192d1a 6610896: JMX Monitor handles thread groups incorrectly
dfuchs
parents: 526
diff changeset
  1445
        public SchedulerTask() {
cc0bbd192d1a 6610896: JMX Monitor handles thread groups incorrectly
dfuchs
parents: 526
diff changeset
  1446
        }
cc0bbd192d1a 6610896: JMX Monitor handles thread groups incorrectly
dfuchs
parents: 526
diff changeset
  1447
cc0bbd192d1a 6610896: JMX Monitor handles thread groups incorrectly
dfuchs
parents: 526
diff changeset
  1448
        /*
cc0bbd192d1a 6610896: JMX Monitor handles thread groups incorrectly
dfuchs
parents: 526
diff changeset
  1449
         * ------------------------------------------
cc0bbd192d1a 6610896: JMX Monitor handles thread groups incorrectly
dfuchs
parents: 526
diff changeset
  1450
         *  GETTERS/SETTERS
cc0bbd192d1a 6610896: JMX Monitor handles thread groups incorrectly
dfuchs
parents: 526
diff changeset
  1451
         * ------------------------------------------
cc0bbd192d1a 6610896: JMX Monitor handles thread groups incorrectly
dfuchs
parents: 526
diff changeset
  1452
         */
cc0bbd192d1a 6610896: JMX Monitor handles thread groups incorrectly
dfuchs
parents: 526
diff changeset
  1453
cc0bbd192d1a 6610896: JMX Monitor handles thread groups incorrectly
dfuchs
parents: 526
diff changeset
  1454
        public void setMonitorTask(MonitorTask task) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1455
            this.task = task;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1456
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1457
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1458
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1459
         * ------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1460
         *  PUBLIC METHODS
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1461
         * ------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1462
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1463
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1464
        public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1465
            synchronized (Monitor.this) {
2619
cc0bbd192d1a 6610896: JMX Monitor handles thread groups incorrectly
dfuchs
parents: 526
diff changeset
  1466
                Monitor.this.monitorFuture = task.submit();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1467
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1468
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1469
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1470
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1471
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1472
     * MonitorTask nested class: This class implements the Runnable interface.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1473
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1474
     * The MonitorTask is executed periodically with a given fixed delay by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1475
     * Scheduled Executor Service.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1476
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1477
    private class MonitorTask implements Runnable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1478
2619
cc0bbd192d1a 6610896: JMX Monitor handles thread groups incorrectly
dfuchs
parents: 526
diff changeset
  1479
        private ThreadPoolExecutor executor;
cc0bbd192d1a 6610896: JMX Monitor handles thread groups incorrectly
dfuchs
parents: 526
diff changeset
  1480
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1481
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1482
         * ------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1483
         *  CONSTRUCTORS
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1484
         * ------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1485
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1486
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1487
        public MonitorTask() {
2619
cc0bbd192d1a 6610896: JMX Monitor handles thread groups incorrectly
dfuchs
parents: 526
diff changeset
  1488
            // Find out if there's already an existing executor for the calling
cc0bbd192d1a 6610896: JMX Monitor handles thread groups incorrectly
dfuchs
parents: 526
diff changeset
  1489
            // thread and reuse it. Otherwise, create a new one and store it in
cc0bbd192d1a 6610896: JMX Monitor handles thread groups incorrectly
dfuchs
parents: 526
diff changeset
  1490
            // the executors map. If there is a SecurityManager, the group of
cc0bbd192d1a 6610896: JMX Monitor handles thread groups incorrectly
dfuchs
parents: 526
diff changeset
  1491
            // System.getSecurityManager() is used, else the group of the thread
cc0bbd192d1a 6610896: JMX Monitor handles thread groups incorrectly
dfuchs
parents: 526
diff changeset
  1492
            // instantiating this MonitorTask, i.e. the group of the thread that
cc0bbd192d1a 6610896: JMX Monitor handles thread groups incorrectly
dfuchs
parents: 526
diff changeset
  1493
            // calls "Monitor.start()".
cc0bbd192d1a 6610896: JMX Monitor handles thread groups incorrectly
dfuchs
parents: 526
diff changeset
  1494
            SecurityManager s = System.getSecurityManager();
cc0bbd192d1a 6610896: JMX Monitor handles thread groups incorrectly
dfuchs
parents: 526
diff changeset
  1495
            ThreadGroup group = (s != null) ? s.getThreadGroup() :
cc0bbd192d1a 6610896: JMX Monitor handles thread groups incorrectly
dfuchs
parents: 526
diff changeset
  1496
                Thread.currentThread().getThreadGroup();
cc0bbd192d1a 6610896: JMX Monitor handles thread groups incorrectly
dfuchs
parents: 526
diff changeset
  1497
            synchronized (executorsLock) {
cc0bbd192d1a 6610896: JMX Monitor handles thread groups incorrectly
dfuchs
parents: 526
diff changeset
  1498
                for (ThreadPoolExecutor e : executors.keySet()) {
cc0bbd192d1a 6610896: JMX Monitor handles thread groups incorrectly
dfuchs
parents: 526
diff changeset
  1499
                    DaemonThreadFactory tf =
cc0bbd192d1a 6610896: JMX Monitor handles thread groups incorrectly
dfuchs
parents: 526
diff changeset
  1500
                            (DaemonThreadFactory) e.getThreadFactory();
cc0bbd192d1a 6610896: JMX Monitor handles thread groups incorrectly
dfuchs
parents: 526
diff changeset
  1501
                    ThreadGroup tg = tf.getThreadGroup();
cc0bbd192d1a 6610896: JMX Monitor handles thread groups incorrectly
dfuchs
parents: 526
diff changeset
  1502
                    if (tg == group) {
cc0bbd192d1a 6610896: JMX Monitor handles thread groups incorrectly
dfuchs
parents: 526
diff changeset
  1503
                        executor = e;
cc0bbd192d1a 6610896: JMX Monitor handles thread groups incorrectly
dfuchs
parents: 526
diff changeset
  1504
                        break;
cc0bbd192d1a 6610896: JMX Monitor handles thread groups incorrectly
dfuchs
parents: 526
diff changeset
  1505
                    }
cc0bbd192d1a 6610896: JMX Monitor handles thread groups incorrectly
dfuchs
parents: 526
diff changeset
  1506
                }
cc0bbd192d1a 6610896: JMX Monitor handles thread groups incorrectly
dfuchs
parents: 526
diff changeset
  1507
                if (executor == null) {
cc0bbd192d1a 6610896: JMX Monitor handles thread groups incorrectly
dfuchs
parents: 526
diff changeset
  1508
                    executor = new ThreadPoolExecutor(
cc0bbd192d1a 6610896: JMX Monitor handles thread groups incorrectly
dfuchs
parents: 526
diff changeset
  1509
                            maximumPoolSize,
cc0bbd192d1a 6610896: JMX Monitor handles thread groups incorrectly
dfuchs
parents: 526
diff changeset
  1510
                            maximumPoolSize,
cc0bbd192d1a 6610896: JMX Monitor handles thread groups incorrectly
dfuchs
parents: 526
diff changeset
  1511
                            60L,
cc0bbd192d1a 6610896: JMX Monitor handles thread groups incorrectly
dfuchs
parents: 526
diff changeset
  1512
                            TimeUnit.SECONDS,
cc0bbd192d1a 6610896: JMX Monitor handles thread groups incorrectly
dfuchs
parents: 526
diff changeset
  1513
                            new LinkedBlockingQueue<Runnable>(),
cc0bbd192d1a 6610896: JMX Monitor handles thread groups incorrectly
dfuchs
parents: 526
diff changeset
  1514
                            new DaemonThreadFactory("ThreadGroup<" +
cc0bbd192d1a 6610896: JMX Monitor handles thread groups incorrectly
dfuchs
parents: 526
diff changeset
  1515
                            group.getName() + "> Executor", group));
cc0bbd192d1a 6610896: JMX Monitor handles thread groups incorrectly
dfuchs
parents: 526
diff changeset
  1516
                    executor.allowCoreThreadTimeOut(true);
cc0bbd192d1a 6610896: JMX Monitor handles thread groups incorrectly
dfuchs
parents: 526
diff changeset
  1517
                    executors.put(executor, null);
cc0bbd192d1a 6610896: JMX Monitor handles thread groups incorrectly
dfuchs
parents: 526
diff changeset
  1518
                }
cc0bbd192d1a 6610896: JMX Monitor handles thread groups incorrectly
dfuchs
parents: 526
diff changeset
  1519
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1520
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1521
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1522
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1523
         * ------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1524
         *  PUBLIC METHODS
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1525
         * ------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1526
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1527
2619
cc0bbd192d1a 6610896: JMX Monitor handles thread groups incorrectly
dfuchs
parents: 526
diff changeset
  1528
        public Future<?> submit() {
cc0bbd192d1a 6610896: JMX Monitor handles thread groups incorrectly
dfuchs
parents: 526
diff changeset
  1529
            return executor.submit(this);
cc0bbd192d1a 6610896: JMX Monitor handles thread groups incorrectly
dfuchs
parents: 526
diff changeset
  1530
        }
cc0bbd192d1a 6610896: JMX Monitor handles thread groups incorrectly
dfuchs
parents: 526
diff changeset
  1531
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1532
        public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1533
            final ScheduledFuture<?> sf;
2617
4e94fb04861b 6610888: Potential use of cleared of incorrect acc in JMX Monitor
dfuchs
parents: 526
diff changeset
  1534
            final AccessControlContext ac;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1535
            synchronized (Monitor.this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1536
                sf = Monitor.this.schedulerFuture;
2617
4e94fb04861b 6610888: Potential use of cleared of incorrect acc in JMX Monitor
dfuchs
parents: 526
diff changeset
  1537
                ac = Monitor.this.acc;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1538
            }
2617
4e94fb04861b 6610888: Potential use of cleared of incorrect acc in JMX Monitor
dfuchs
parents: 526
diff changeset
  1539
            PrivilegedAction<Void> action = new PrivilegedAction<Void>() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1540
                public Void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1541
                    if (Monitor.this.isActive()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1542
                        final int an[] = alreadyNotifieds;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1543
                        int index = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1544
                        for (ObservedObject o : Monitor.this.observedObjects) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1545
                            if (Monitor.this.isActive()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1546
                                Monitor.this.monitor(o, index++, an);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1547
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1548
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1549
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1550
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1551
                }
2617
4e94fb04861b 6610888: Potential use of cleared of incorrect acc in JMX Monitor
dfuchs
parents: 526
diff changeset
  1552
            };
4e94fb04861b 6610888: Potential use of cleared of incorrect acc in JMX Monitor
dfuchs
parents: 526
diff changeset
  1553
            if (ac == null) {
4e94fb04861b 6610888: Potential use of cleared of incorrect acc in JMX Monitor
dfuchs
parents: 526
diff changeset
  1554
                throw new SecurityException("AccessControlContext cannot be null");
4e94fb04861b 6610888: Potential use of cleared of incorrect acc in JMX Monitor
dfuchs
parents: 526
diff changeset
  1555
            }
4e94fb04861b 6610888: Potential use of cleared of incorrect acc in JMX Monitor
dfuchs
parents: 526
diff changeset
  1556
            AccessController.doPrivileged(action, ac);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1557
            synchronized (Monitor.this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1558
                if (Monitor.this.isActive() &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1559
                    Monitor.this.schedulerFuture == sf) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1560
                    Monitor.this.monitorFuture = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1561
                    Monitor.this.schedulerFuture =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1562
                        scheduler.schedule(Monitor.this.schedulerTask,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1563
                                           Monitor.this.getGranularityPeriod(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1564
                                           TimeUnit.MILLISECONDS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1565
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1566
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1567
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1568
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1569
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1570
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1571
     * Daemon thread factory used by the monitor executors.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1572
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1573
     * This factory creates all new threads used by an Executor in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1574
     * the same ThreadGroup. If there is a SecurityManager, it uses
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1575
     * the group of System.getSecurityManager(), else the group of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1576
     * the thread instantiating this DaemonThreadFactory. Each new
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1577
     * thread is created as a daemon thread with priority
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1578
     * Thread.NORM_PRIORITY. New threads have names accessible via
21656
d4c777ccb1db 8028014: Doclint warning/error cleanup in javax.management
rriggs
parents: 5506
diff changeset
  1579
     * Thread.getName() of "{@literal JMX Monitor <pool-name> Pool [Thread-M]}",
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1580
     * where M is the sequence number of the thread created by this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1581
     * factory.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1582
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1583
    private static class DaemonThreadFactory implements ThreadFactory {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1584
        final ThreadGroup group;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1585
        final AtomicInteger threadNumber = new AtomicInteger(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1586
        final String namePrefix;
526
61ba2d5ea9da 6701459: Synchronization bug pattern found in javax.management.relation.RelationService
emcmanus
parents: 34
diff changeset
  1587
        static final String nameSuffix = "]";
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1588
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1589
        public DaemonThreadFactory(String poolName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1590
            SecurityManager s = System.getSecurityManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1591
            group = (s != null) ? s.getThreadGroup() :
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1592
                                  Thread.currentThread().getThreadGroup();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1593
            namePrefix = "JMX Monitor " + poolName + " Pool [Thread-";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1594
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1595
2619
cc0bbd192d1a 6610896: JMX Monitor handles thread groups incorrectly
dfuchs
parents: 526
diff changeset
  1596
        public DaemonThreadFactory(String poolName, ThreadGroup threadGroup) {
cc0bbd192d1a 6610896: JMX Monitor handles thread groups incorrectly
dfuchs
parents: 526
diff changeset
  1597
            group = threadGroup;
cc0bbd192d1a 6610896: JMX Monitor handles thread groups incorrectly
dfuchs
parents: 526
diff changeset
  1598
            namePrefix = "JMX Monitor " + poolName + " Pool [Thread-";
cc0bbd192d1a 6610896: JMX Monitor handles thread groups incorrectly
dfuchs
parents: 526
diff changeset
  1599
        }
cc0bbd192d1a 6610896: JMX Monitor handles thread groups incorrectly
dfuchs
parents: 526
diff changeset
  1600
cc0bbd192d1a 6610896: JMX Monitor handles thread groups incorrectly
dfuchs
parents: 526
diff changeset
  1601
        public ThreadGroup getThreadGroup() {
cc0bbd192d1a 6610896: JMX Monitor handles thread groups incorrectly
dfuchs
parents: 526
diff changeset
  1602
            return group;
cc0bbd192d1a 6610896: JMX Monitor handles thread groups incorrectly
dfuchs
parents: 526
diff changeset
  1603
        }
cc0bbd192d1a 6610896: JMX Monitor handles thread groups incorrectly
dfuchs
parents: 526
diff changeset
  1604
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1605
        public Thread newThread(Runnable r) {
37518
cd27455e4276 8147553: Remove sun.misc.ManagedLocalsThread from java.management
chegar
parents: 29927
diff changeset
  1606
            Thread t = new Thread(
29921
f13586cdb0e4 8042327: Enhance thread contexts in serviceability
jbachorik
parents: 25859
diff changeset
  1607
                group,
f13586cdb0e4 8042327: Enhance thread contexts in serviceability
jbachorik
parents: 25859
diff changeset
  1608
                r,
37518
cd27455e4276 8147553: Remove sun.misc.ManagedLocalsThread from java.management
chegar
parents: 29927
diff changeset
  1609
                namePrefix + threadNumber.getAndIncrement() + nameSuffix,
cd27455e4276 8147553: Remove sun.misc.ManagedLocalsThread from java.management
chegar
parents: 29927
diff changeset
  1610
                0,
cd27455e4276 8147553: Remove sun.misc.ManagedLocalsThread from java.management
chegar
parents: 29927
diff changeset
  1611
                false
29921
f13586cdb0e4 8042327: Enhance thread contexts in serviceability
jbachorik
parents: 25859
diff changeset
  1612
            );
f13586cdb0e4 8042327: Enhance thread contexts in serviceability
jbachorik
parents: 25859
diff changeset
  1613
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1614
            t.setDaemon(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1615
            if (t.getPriority() != Thread.NORM_PRIORITY)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1616
                t.setPriority(Thread.NORM_PRIORITY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1617
            return t;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1618
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1619
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1620
}