001: /*
002: * Copyright (c) 1998-2008 Caucho Technology -- all rights reserved
003: *
004: * This file is part of Resin(R) Open Source
005: *
006: * Each copy or derived work must preserve the copyright notice and this
007: * notice unmodified.
008: *
009: * Resin Open Source is free software; you can redistribute it and/or modify
010: * it under the terms of the GNU General Public License as published by
011: * the Free Software Foundation; either version 2 of the License, or
012: * (at your option) any later version.
013: *
014: * Resin Open Source is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
017: * of NON-INFRINGEMENT. See the GNU General Public License for more
018: * details.
019: *
020: * You should have received a copy of the GNU General Public License
021: * along with Resin Open Source; if not, write to the
022: *
023: * Free Software Foundation, Inc.
024: * 59 Temple Place, Suite 330
025: * Boston, MA 02111-1307 USA
026: *
027: * @author Scott Ferguson
028: */
029:
030: package com.caucho.jmx;
031:
032: import com.caucho.log.Log;
033: import com.caucho.util.L10N;
034: import com.caucho.webbeans.component.WebBeansHandle;
035:
036: import java.util.logging.Logger;
037: import javax.management.*;
038:
039: /**
040: * JNDI object for the Resin mbean server.
041: */
042: public class GlobalMBeanServer extends AbstractMBeanServer implements
043: java.io.Serializable {
044: private static final L10N L = new L10N(GlobalMBeanServer.class);
045: private static final Logger log = Logger
046: .getLogger(GlobalMBeanServer.class.getName());
047:
048: private ClassLoader _loader;
049:
050: /**
051: * Creates an MBeanServerProxy based on the context class loader.
052: */
053: public GlobalMBeanServer() {
054: this (Thread.currentThread().getContextClassLoader());
055: }
056:
057: /**
058: * Creates an MBeanServerProxy based on the context class loader.
059: */
060: public GlobalMBeanServer(ClassLoader loader) {
061: super (Jmx.getMBeanServer().getDefaultDomain());
062:
063: _loader = loader;
064: }
065:
066: /**
067: * Returns the local context.
068: */
069: protected MBeanContext createContext(ClassLoader loader) {
070: AbstractMBeanServer envServer = Jmx.getMBeanServer();
071:
072: // server/2102 vs server/211{1,2}
073: return envServer.createContext(loader);
074: }
075:
076: /**
077: * Returns the local context.
078: */
079: protected MBeanContext getExistingContext(ClassLoader loader) {
080: AbstractMBeanServer envServer = Jmx.getMBeanServer();
081:
082: return envServer.getExistingContext(loader);
083: }
084:
085: /**
086: * Returns the local context.
087: */
088: protected MBeanContext getContext(ClassLoader loader) {
089: AbstractMBeanServer envServer = Jmx.getMBeanServer();
090:
091: return envServer.getContext(loader);
092: }
093:
094: /**
095: * Returns the local view.
096: */
097: protected MBeanView getView() {
098: return createContext().getGlobalView();
099: }
100:
101: /**
102: * Serialization.
103: */
104: private Object writeReplace() {
105: return new WebBeansHandle(MBeanServer.class);
106: }
107:
108: /**
109: * Returns the string form.
110: */
111: public String toString() {
112: return getClass().getSimpleName() + "[]";
113: }
114: }
|