001 // Copyright 2005 The Apache Software Foundation
002 //
003 // Licensed under the Apache License, Version 2.0 (the "License");
004 // you may not use this file except in compliance with the License.
005 // You may obtain a copy of the License at
006 //
007 // http://www.apache.org/licenses/LICENSE-2.0
008 //
009 // Unless required by applicable law or agreed to in writing, software
010 // distributed under the License is distributed on an "AS IS" BASIS,
011 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012 // See the License for the specific language governing permissions and
013 // limitations under the License.
014
015 package org.apache.hivemind.management.impl;
016
017 import java.util.List;
018
019 import javax.management.MBeanServer;
020
021 import org.apache.hivemind.ServiceImplementationFactory;
022 import org.apache.hivemind.ServiceImplementationFactoryParameters;
023
024 /**
025 * An implementation of {@link org.apache.hivemind.ServiceImplementationFactory} that creates a
026 * MBeanServer using {@link javax.management.MBeanServerFactory}. Searches for an existing
027 * MBeanServer first, and creates a new one if none has been found
028 *
029 * @author Achim Huegen
030 * @since 1.1
031 */
032 public class MBeanServerFactory implements ServiceImplementationFactory
033 {
034
035 public Object createCoreServiceImplementation(
036 ServiceImplementationFactoryParameters factoryParameters)
037 {
038 String serverId = null;
039 MBeanServer server = null;
040 List servers = javax.management.MBeanServerFactory.findMBeanServer(serverId);
041 if (servers != null && servers.size() > 0)
042 server = (MBeanServer) servers.get(0);
043 else
044 server = javax.management.MBeanServerFactory.createMBeanServer();
045
046 return server;
047 }
048
049 }