src/java.management/share/classes/javax/management/relation/MBeanServerNotificationFilter.java
author erikj
Tue, 12 Sep 2017 19:03:39 +0200
changeset 47216 71c04702a3d5
parent 43235 jdk/src/java.management/share/classes/javax/management/relation/MBeanServerNotificationFilter.java@da1786d695b6
permissions -rw-r--r--
8187443: Forest Consolidation: Move files to unified layout Reviewed-by: darcy, ihse
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: 25859
diff changeset
     2
 * Copyright (c) 2000, 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: 1639
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: 1639
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: 1639
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1639
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1639
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.relation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import static com.sun.jmx.mbeanserver.Util.cast;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import static com.sun.jmx.defaults.JmxProperties.RELATION_LOGGER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import com.sun.jmx.mbeanserver.GetPropertyAction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.io.ObjectInputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.io.ObjectOutputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.io.ObjectStreamField;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.security.AccessController;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.util.List;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.util.Vector;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import javax.management.MBeanServerNotification;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import javax.management.Notification;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
import javax.management.NotificationFilterSupport;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
import javax.management.ObjectName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
import java.util.List;
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
    48
import java.lang.System.Logger.Level;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
import java.util.Vector;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * Filter for {@link MBeanServerNotification}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * This filter filters MBeanServerNotification notifications by
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * selecting the ObjectNames of interest and the operations (registration,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * unregistration, both) of interest (corresponding to notification
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * types).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * <p>The <b>serialVersionUID</b> of this class is <code>2605900539589789736L</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
@SuppressWarnings("serial")  // serialVersionUID must be constant
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
public class MBeanServerNotificationFilter extends NotificationFilterSupport {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    // Serialization compatibility stuff:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    // Two serial forms are supported in this class. The selected form depends
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    // on system property "jmx.serial.form":
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    //  - "1.0" for JMX 1.0
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    //  - any other value for JMX 1.1 and higher
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    // Serial version for old serial form
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    private static final long oldSerialVersionUID = 6001782699077323605L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    // Serial version for new serial form
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    private static final long newSerialVersionUID = 2605900539589789736L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    // Serializable fields in old serial form
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    private static final ObjectStreamField[] oldSerialPersistentFields =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
      new ObjectStreamField("mySelectObjNameList", Vector.class),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
      new ObjectStreamField("myDeselectObjNameList", Vector.class)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    // Serializable fields in new serial form
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    private static final ObjectStreamField[] newSerialPersistentFields =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
      new ObjectStreamField("selectedNames", List.class),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
      new ObjectStreamField("deselectedNames", List.class)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    // Actual serial version and serial form
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    private static final long serialVersionUID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     * @serialField selectedNames List List of {@link ObjectName}s of interest
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     *         <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     *         <li><code>null</code> means that all {@link ObjectName}s are implicitly selected
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     *         (check for explicit deselections)</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     *         <li>Empty vector means that no {@link ObjectName} is explicitly selected</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     *         </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     * @serialField deselectedNames List List of {@link ObjectName}s with no interest
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     *         <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     *         <li><code>null</code> means that all {@link ObjectName}s are implicitly deselected
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     *         (check for explicit selections))</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     *         <li>Empty vector means that no {@link ObjectName} is explicitly deselected</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     *         </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    private static final ObjectStreamField[] serialPersistentFields;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    private static boolean compat = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
            GetPropertyAction act = new GetPropertyAction("jmx.serial.form");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
            String form = AccessController.doPrivileged(act);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
            compat = (form != null && form.equals("1.0"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
            // OK : Too bad, no compat with 1.0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        if (compat) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
            serialPersistentFields = oldSerialPersistentFields;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
            serialVersionUID = oldSerialVersionUID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
            serialPersistentFields = newSerialPersistentFields;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
            serialVersionUID = newSerialVersionUID;
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
    // END Serialization compatibility stuff
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    // Private members
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     * @serial List of {@link ObjectName}s of interest
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     *         <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     *         <li><code>null</code> means that all {@link ObjectName}s are implicitly selected
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     *         (check for explicit deselections)</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     *         <li>Empty vector means that no {@link ObjectName} is explicitly selected</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     *         </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    private List<ObjectName> selectedNames = new Vector<ObjectName>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     * @serial List of {@link ObjectName}s with no interest
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     *         <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     *         <li><code>null</code> means that all {@link ObjectName}s are implicitly deselected
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     *         (check for explicit selections))</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     *         <li>Empty vector means that no {@link ObjectName} is explicitly deselected</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     *         </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    private List<ObjectName> deselectedNames = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    // Constructor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     * Creates a filter selecting all MBeanServerNotification notifications for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     * all ObjectNames.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    public MBeanServerNotificationFilter() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        super();
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
   163
        RELATION_LOGGER.log(Level.TRACE, "ENTRY");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        enableType(MBeanServerNotification.REGISTRATION_NOTIFICATION);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        enableType(MBeanServerNotification.UNREGISTRATION_NOTIFICATION);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
   168
        RELATION_LOGGER.log(Level.TRACE, "RETURN");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    // Accessors
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     * Disables any MBeanServerNotification (all ObjectNames are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     * deselected).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    public synchronized void disableAllObjectNames() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
   182
        RELATION_LOGGER.log(Level.TRACE, "ENTRY");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        selectedNames = new Vector<ObjectName>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        deselectedNames = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
   187
        RELATION_LOGGER.log(Level.TRACE, "RETURN");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     * Disables MBeanServerNotifications concerning given ObjectName.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     * @param objectName  ObjectName no longer of interest
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     * @exception IllegalArgumentException  if the given ObjectName is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    public synchronized void disableObjectName(ObjectName objectName)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        throws IllegalArgumentException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        if (objectName == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
            String excMsg = "Invalid parameter.";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
            throw new IllegalArgumentException(excMsg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
   206
        RELATION_LOGGER.log(Level.TRACE, "ENTRY {0}" + objectName);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        // Removes from selected ObjectNames, if present
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        if (selectedNames != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
            if (selectedNames.size() != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
                selectedNames.remove(objectName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        // Adds it in deselected ObjectNames
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        if (deselectedNames != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
            // If all are deselected, no need to do anything :)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
            if (!(deselectedNames.contains(objectName))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
                // ObjectName was not already deselected
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
                deselectedNames.add(objectName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
   224
        RELATION_LOGGER.log(Level.TRACE, "RETURN");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     * Enables all MBeanServerNotifications (all ObjectNames are selected).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    public synchronized void enableAllObjectNames() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
   233
        RELATION_LOGGER.log(Level.TRACE, "ENTRY");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        selectedNames = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        deselectedNames = new Vector<ObjectName>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
   238
        RELATION_LOGGER.log(Level.TRACE, "RETURN");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     * Enables MBeanServerNotifications concerning given ObjectName.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     * @param objectName  ObjectName of interest
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     * @exception IllegalArgumentException  if the given ObjectName is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
    public synchronized void enableObjectName(ObjectName objectName)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        throws IllegalArgumentException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        if (objectName == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
            String excMsg = "Invalid parameter.";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
            throw new IllegalArgumentException(excMsg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
   257
        RELATION_LOGGER.log(Level.TRACE, "ENTRY {0}", objectName);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        // Removes from deselected ObjectNames, if present
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        if (deselectedNames != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
            if (deselectedNames.size() != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
                deselectedNames.remove(objectName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        // Adds it in selected ObjectNames
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
        if (selectedNames != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
            // If all are selected, no need to do anything :)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
            if (!(selectedNames.contains(objectName))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
                // ObjectName was not already selected
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
                selectedNames.add(objectName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
   275
        RELATION_LOGGER.log(Level.TRACE, "RETURN");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     * Gets all the ObjectNames enabled.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     * @return Vector of ObjectNames:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     * <P>- null means all ObjectNames are implicitly selected, except the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     * ObjectNames explicitly deselected
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
     * <P>- empty means all ObjectNames are deselected, i.e. no ObjectName
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     * selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
    public synchronized Vector<ObjectName> getEnabledObjectNames() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        if (selectedNames != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
            return new Vector<ObjectName>(selectedNames);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
     * Gets all the ObjectNames disabled.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
     * @return Vector of ObjectNames:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
     * <P>- null means all ObjectNames are implicitly deselected, except the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
     * ObjectNames explicitly selected
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     * <P>- empty means all ObjectNames are selected, i.e. no ObjectName
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     * deselected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
    public synchronized Vector<ObjectName> getDisabledObjectNames() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
        if (deselectedNames != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
            return new Vector<ObjectName>(deselectedNames);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
    // NotificationFilter interface
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
     * Invoked before sending the specified notification to the listener.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
     * <P>If:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
     * <P>- the ObjectName of the concerned MBean is selected (explicitly OR
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
     * (implicitly and not explicitly deselected))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
     * <P>AND
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     * <P>- the type of the operation (registration or unregistration) is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     * selected
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
     * <P>then the notification is sent to the listener.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
     * @param notif  The notification to be sent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
     * @return true if the notification has to be sent to the listener, false
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
     * otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
     * @exception IllegalArgumentException  if null parameter
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
    public synchronized boolean isNotificationEnabled(Notification notif)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
        throws IllegalArgumentException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
        if (notif == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
            String excMsg = "Invalid parameter.";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
            throw new IllegalArgumentException(excMsg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
   342
        RELATION_LOGGER.log(Level.TRACE, "ENTRY {0}", notif);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
        // Checks the type first
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
        String ntfType = notif.getType();
1510
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 2
diff changeset
   346
        Vector<String> enabledTypes = getEnabledTypes();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
        if (!(enabledTypes.contains(ntfType))) {
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
   348
            RELATION_LOGGER.log(Level.TRACE,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
                    "Type not selected, exiting");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
        // We have a MBeanServerNotification: downcasts it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
        MBeanServerNotification mbsNtf = (MBeanServerNotification)notif;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
        // Checks the ObjectName
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
        ObjectName objName = mbsNtf.getMBeanName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
        // Is it selected?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
        boolean isSelectedFlg = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
        if (selectedNames != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
            // Not all are implicitly selected:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
            // checks for explicit selection
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
            if (selectedNames.size() == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
                // All are explicitly not selected
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
   365
                RELATION_LOGGER.log(Level.TRACE,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
                        "No ObjectNames selected, exiting");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
            isSelectedFlg = selectedNames.contains(objName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
            if (!isSelectedFlg) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
                // Not in the explicit selected list
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
   373
                RELATION_LOGGER.log(Level.TRACE,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
                        "ObjectName not in selected list, exiting");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
        if (!isSelectedFlg) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
            // Not explicitly selected: is it deselected?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
            if (deselectedNames == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
                // All are implicitly deselected and it is not explicitly
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
                // selected
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
   385
                RELATION_LOGGER.log(Level.TRACE,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
                        "ObjectName not selected, and all " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
                        "names deselected, exiting");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
            } else if (deselectedNames.contains(objName)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
                // Explicitly deselected
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
   392
                RELATION_LOGGER.log(Level.TRACE,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
                        "ObjectName explicitly not selected, exiting");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
43235
da1786d695b6 8172971: java.management could use System.Logger
dfuchs
parents: 25859
diff changeset
   398
        RELATION_LOGGER.log(Level.TRACE,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
                "ObjectName selected, exiting");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
     * Deserializes an {@link MBeanServerNotificationFilter} from an {@link ObjectInputStream}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
    private void readObject(ObjectInputStream in)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
            throws IOException, ClassNotFoundException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
      if (compat)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
      {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
        // Read an object serialized in the old serial form
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
        ObjectInputStream.GetField fields = in.readFields();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
        selectedNames = cast(fields.get("mySelectObjNameList", null));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
        if (fields.defaulted("mySelectObjNameList"))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
          throw new NullPointerException("mySelectObjNameList");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
        deselectedNames = cast(fields.get("myDeselectObjNameList", null));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
        if (fields.defaulted("myDeselectObjNameList"))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
          throw new NullPointerException("myDeselectObjNameList");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
      else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
      {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
        // Read an object serialized in the new serial form
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
        in.defaultReadObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
     * Serializes an {@link MBeanServerNotificationFilter} to an {@link ObjectOutputStream}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
    private void writeObject(ObjectOutputStream out)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
            throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
      if (compat)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
      {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
        // Serializes this instance in the old serial form
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
        ObjectOutputStream.PutField fields = out.putFields();
1510
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 2
diff changeset
   444
        fields.put("mySelectObjNameList", selectedNames);
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 2
diff changeset
   445
        fields.put("myDeselectObjNameList", deselectedNames);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
        out.writeFields();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
      else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
      {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
        // Serializes this instance in the new serial form
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
        out.defaultWriteObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
}