001: /**
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */package org.apache.openejb.mgmt;
017:
018: import java.util.List;
019: import java.util.Set;
020:
021: import javax.ejb.Init;
022: import javax.ejb.RemoteHome;
023: import javax.ejb.Stateless;
024: import javax.management.Attribute;
025: import javax.management.AttributeList;
026: import javax.management.AttributeNotFoundException;
027: import javax.management.InstanceNotFoundException;
028: import javax.management.IntrospectionException;
029: import javax.management.InvalidAttributeValueException;
030: import javax.management.MBeanException;
031: import javax.management.MBeanInfo;
032: import javax.management.MBeanServer;
033: import javax.management.MBeanServerFactory;
034: import javax.management.ObjectName;
035: import javax.management.QueryExp;
036: import javax.management.ReflectionException;
037: import javax.management.j2ee.ListenerRegistration;
038: import javax.management.j2ee.ManagementHome;
039:
040: @Stateless(name="MEJB")
041: @RemoteHome(ManagementHome.class)
042: public class MEJBBean {
043:
044: MBeanServer mbeanServer;
045:
046: public MEJBBean() {
047: List mbeanServers = MBeanServerFactory.findMBeanServer(null);
048: if (mbeanServers.size() > 0) {
049: mbeanServer = (MBeanServer) mbeanServers.get(0);
050: } else {
051: mbeanServer = MBeanServerFactory.createMBeanServer();
052: }
053: }
054:
055: @Init
056: public void create() {
057:
058: }
059:
060: public Object getAttribute(ObjectName objectName, String string)
061: throws MBeanException, AttributeNotFoundException,
062: InstanceNotFoundException, ReflectionException {
063: return mbeanServer.getAttribute(objectName, string);
064: }
065:
066: public AttributeList getAttributes(ObjectName objectName,
067: String[] strings) throws InstanceNotFoundException,
068: ReflectionException {
069: return mbeanServer.getAttributes(objectName, strings);
070: }
071:
072: public String getDefaultDomain() {
073: return mbeanServer.getDefaultDomain();
074: }
075:
076: public Integer getMBeanCount() {
077: return mbeanServer.getMBeanCount();
078: }
079:
080: public MBeanInfo getMBeanInfo(ObjectName objectName)
081: throws IntrospectionException, InstanceNotFoundException,
082: ReflectionException {
083: return mbeanServer.getMBeanInfo(objectName);
084: }
085:
086: public Object invoke(ObjectName objectName, String string,
087: Object[] objects, String[] strings)
088: throws InstanceNotFoundException, MBeanException,
089: ReflectionException {
090: return mbeanServer.invoke(objectName, string, objects, strings);
091: }
092:
093: public boolean isRegistered(ObjectName objectName) {
094: return mbeanServer.isRegistered(objectName);
095: }
096:
097: public Set queryNames(ObjectName objectName, QueryExp queryExp) {
098: return mbeanServer.queryNames(objectName, queryExp);
099: }
100:
101: public void setAttribute(ObjectName objectName, Attribute attribute)
102: throws InstanceNotFoundException,
103: AttributeNotFoundException, InvalidAttributeValueException,
104: MBeanException, ReflectionException {
105: mbeanServer.setAttribute(objectName, attribute);
106: }
107:
108: public AttributeList setAttributes(ObjectName objectName,
109: AttributeList attributeList)
110: throws InstanceNotFoundException, ReflectionException {
111: return mbeanServer.setAttributes(objectName, attributeList);
112: }
113:
114: public ListenerRegistration getListenerRegistry() {
115: return null;
116: }
117: }
|