1. /*
  2. * @(#)QueryEval.java 4.24 04/02/10
  3. *
  4. * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package javax.management;
  8. // java import
  9. import java.io.Serializable;
  10. // RI import
  11. import javax.management.MBeanServer;
  12. /**
  13. * Allows a query to be performed in the context of a specific MBean server.
  14. *
  15. * @since 1.5
  16. */
  17. public abstract class QueryEval implements Serializable {
  18. /* Serial version */
  19. private static final long serialVersionUID = 2675899265640874796L;
  20. private static ThreadLocal server = new InheritableThreadLocal();
  21. /**
  22. * <p>Sets the MBean server on which the query is to be performed.
  23. * The setting is valid for the thread performing the set.
  24. * It is copied to any threads created by that thread at the moment
  25. * of their creation.</p>
  26. *
  27. * <p>For historical reasons, this method is not static, but its
  28. * behavior does not depend on the instance on which it is
  29. * called.</p>
  30. *
  31. * @param s The MBean server on which the query is to be performed.
  32. *
  33. * @see #getMBeanServer
  34. */
  35. public void setMBeanServer(MBeanServer s) {
  36. server.set(s);
  37. }
  38. /**
  39. * <p>Return the MBean server that was most recently given to the
  40. * {@link #setMBeanServer setMBeanServer} method by this thread.
  41. * If this thread never called that method, the result is the
  42. * value its parent thread would have obtained from
  43. * <code>getMBeanServer</code> at the moment of the creation of
  44. * this thread, or null if there is no parent thread.</p>
  45. *
  46. * @return the MBean server.
  47. *
  48. * @see #setMBeanServer
  49. *
  50. * @since.unbundled JMX 1.2
  51. */
  52. public static MBeanServer getMBeanServer() {
  53. return (MBeanServer) server.get();
  54. }
  55. }