src/java.management/share/classes/javax/management/QueryEval.java
changeset 47216 71c04702a3d5
parent 25859 3317bb8137f4
equal deleted inserted replaced
47215:4ebc2e2fb97c 47216:71c04702a3d5
       
     1 /*
       
     2  * Copyright (c) 1999, 2008, Oracle and/or its affiliates. All rights reserved.
       
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       
     4  *
       
     5  * This code is free software; you can redistribute it and/or modify it
       
     6  * under the terms of the GNU General Public License version 2 only, as
       
     7  * published by the Free Software Foundation.  Oracle designates this
       
     8  * particular file as subject to the "Classpath" exception as provided
       
     9  * by Oracle in the LICENSE file that accompanied this code.
       
    10  *
       
    11  * This code is distributed in the hope that it will be useful, but WITHOUT
       
    12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
       
    13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
       
    14  * version 2 for more details (a copy is included in the LICENSE file that
       
    15  * accompanied this code).
       
    16  *
       
    17  * You should have received a copy of the GNU General Public License version
       
    18  * 2 along with this work; if not, write to the Free Software Foundation,
       
    19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
       
    20  *
       
    21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
       
    22  * or visit www.oracle.com if you need additional information or have any
       
    23  * questions.
       
    24  */
       
    25 
       
    26 package javax.management;
       
    27 
       
    28 // java import
       
    29 import java.io.Serializable;
       
    30 
       
    31 /**
       
    32  * Allows a query to be performed in the context of a specific MBean server.
       
    33  *
       
    34  * @since 1.5
       
    35  */
       
    36 public abstract class QueryEval implements Serializable {
       
    37 
       
    38     /* Serial version */
       
    39     private static final long serialVersionUID = 2675899265640874796L;
       
    40 
       
    41     private static ThreadLocal<MBeanServer> server =
       
    42         new InheritableThreadLocal<MBeanServer>();
       
    43 
       
    44     /**
       
    45      * <p>Sets the MBean server on which the query is to be performed.
       
    46      * The setting is valid for the thread performing the set.
       
    47      * It is copied to any threads created by that thread at the moment
       
    48      * of their creation.</p>
       
    49      *
       
    50      * <p>For historical reasons, this method is not static, but its
       
    51      * behavior does not depend on the instance on which it is
       
    52      * called.</p>
       
    53      *
       
    54      * @param s The MBean server on which the query is to be performed.
       
    55      *
       
    56      * @see #getMBeanServer
       
    57      */
       
    58     public void setMBeanServer(MBeanServer s) {
       
    59         server.set(s);
       
    60     }
       
    61 
       
    62     /**
       
    63      * <p>Return the MBean server that was most recently given to the
       
    64      * {@link #setMBeanServer setMBeanServer} method by this thread.
       
    65      * If this thread never called that method, the result is the
       
    66      * value its parent thread would have obtained from
       
    67      * <code>getMBeanServer</code> at the moment of the creation of
       
    68      * this thread, or null if there is no parent thread.</p>
       
    69      *
       
    70      * @return the MBean server.
       
    71      *
       
    72      * @see #setMBeanServer
       
    73      *
       
    74      */
       
    75     public static MBeanServer getMBeanServer() {
       
    76         return server.get();
       
    77     }
       
    78 }