001: /**
002: * Sequoia: Database clustering technology.
003: * Copyright (C) 2002-2004 French National Institute For Research In Computer
004: * Science And Control (INRIA).
005: * Contact: sequoia@continuent.org
006: *
007: * Licensed under the Apache License, Version 2.0 (the "License");
008: * you may not use this file except in compliance with the License.
009: * You may obtain a copy of the License at
010: *
011: * http://www.apache.org/licenses/LICENSE-2.0
012: *
013: * Unless required by applicable law or agreed to in writing, software
014: * distributed under the License is distributed on an "AS IS" BASIS,
015: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
016: * See the License for the specific language governing permissions and
017: * limitations under the License.
018: *
019: * Initial developer(s): Marc Wick.
020: * Contributor(s): ______________________.
021: */package org.continuent.sequoia.controller.jmx;
022:
023: import javax.management.MBeanServer;
024: import javax.management.MBeanServerBuilder;
025: import javax.management.MBeanServerDelegate;
026:
027: /**
028: * Base class for chained MBeanServerBuilders. <br>
029: * By default this class delegates all method calls to the nested
030: * MBeanServerBuilder. <br>
031: * See the MX4J documentation on how to use correctly this class. <br>
032: * <br>
033: * Example implementation:
034: *
035: * <pre>
036: *
037: *
038: *
039: * public class LoggingBuilder extends ChainedMBeanServerBuilder
040: * {
041: * public LoggingBuilder()
042: * {
043: * super(new MBeanServerBuilder());
044: * }
045: *
046: * public MBeanServer newMBeanServer(String defaultDomain, MBeanServer outer, MBeanServerDelegate delegate)
047: * {
048: * LoggingMBeanServer external = new LoggingMBeanServer();
049: * MBeanServer nested = getBuilder().newMBeanServer(defaultDomain, outer == null ? external : outer, delegate);
050: * external.setMBeanServer(nested);
051: * return external;
052: * }
053: * }
054: *
055: * public class LoggingMBeanServer extends ChainedMBeanServer
056: * {
057: * protected void setMBeanServer(MBeanServer server)
058: * {
059: * super.setMBeanServer(server);
060: * }
061: *
062: * public Object getAttribute(ObjectName objectName, String attribute)
063: * throws MBeanException, AttributeNotFoundException, InstanceNotFoundException, ReflectionException
064: * {
065: * Object value = super.getAttribute(objectName, attribute);
066: * System.out.println("Value is: " + value);
067: * return value;
068: * }
069: *
070: * ...
071: * }
072: *
073: *
074: *
075: * </pre>
076: *
077: * @author <a href="mailto:marc.wick@monte-bre.ch">Marc Wick </a>
078: * @version 1.0
079: */
080: public class ChainedMBeanServerBuilder extends
081: javax.management.MBeanServerBuilder {
082: private final MBeanServerBuilder builder;
083:
084: /**
085: * Creates a new chained MBeanServerBuilder
086: *
087: * @param builder The MBeanServerBuilder this object delegates to.
088: */
089: public ChainedMBeanServerBuilder(MBeanServerBuilder builder) {
090: if (builder == null)
091: throw new IllegalArgumentException();
092: this .builder = builder;
093: }
094:
095: /**
096: * Forwards the call to the chained builder.
097: *
098: * @see MBeanServerBuilder#newMBeanServerDelegate
099: */
100: public MBeanServerDelegate newMBeanServerDelegate() {
101: return getMBeanServerBuilder().newMBeanServerDelegate();
102: }
103:
104: /**
105: * Forwards the call to the chained builder.
106: *
107: * @see MBeanServerBuilder#newMBeanServer(java.lang.String,
108: * javax.management.MBeanServer, javax.management.MBeanServerDelegate)
109: */
110: public MBeanServer newMBeanServer(String defaultDomain,
111: MBeanServer outer, MBeanServerDelegate delegate) {
112: return getMBeanServerBuilder().newMBeanServer(defaultDomain,
113: outer, delegate);
114: }
115:
116: /**
117: * Returns the chained MBeanServerBuilder this object delegates to.
118: */
119: protected MBeanServerBuilder getMBeanServerBuilder() {
120: return builder;
121: }
122:
123: }
|