001: /**
002: * JOnAS: Java(TM) Open Application Server
003: * Copyright (C) 2006 Bull S.A.
004: * Contact: jonas-team@objectweb.org
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
019: * USA
020: *
021: * --------------------------------------------------------------------------
022: * $Id: LogicalClusterFactory.java 9397 2006-08-08 12:48:39Z durieuxp $
023: * --------------------------------------------------------------------------
024: */package org.objectweb.jonas.management.cluster;
025:
026: import java.util.Collection;
027: import java.util.HashMap;
028:
029: import javax.management.JMException;
030: import javax.management.ObjectName;
031:
032: import org.objectweb.jonas.management.monitoring.DomainMonitor;
033: import org.objectweb.jonas.management.monitoring.ServerProxy;
034:
035: import org.objectweb.util.monolog.api.BasicLevel;
036:
037: /**
038: * Factory for logical clusters
039: */
040: public class LogicalClusterFactory extends ClusterFactory {
041:
042: /**
043: * List of the logical clusters in this domain.
044: * key = clusterName, value = LogicalCluster
045: */
046: private HashMap myclusters = new HashMap();
047:
048: public LogicalClusterFactory(DomainMonitor dm) {
049: super (dm);
050: }
051:
052: public BaseCluster getCluster(String name) {
053: return (BaseCluster) myclusters.get(name);
054: }
055:
056: public boolean notifyServer(ServerProxy proxy) {
057: String serverName = proxy.getServerName();
058: logger.log(BasicLevel.DEBUG, serverName);
059:
060: LogicalCluster domaincluster = (LogicalCluster) myclusters
061: .get(domainName);
062: if (domaincluster == null) {
063: domaincluster = createLogicalCluster(domainName);
064: if (domaincluster == null) {
065: return false;
066: }
067: }
068:
069: // add a server to the default cluster
070: return domaincluster.addServer(serverName, proxy);
071: }
072:
073: public Collection getClusterList() {
074: return myclusters.values();
075: }
076:
077: /**
078: * Create a logical cluster
079: */
080: public LogicalCluster createLogicalCluster(String name) {
081: LogicalCluster cluster = null;
082: ObjectName clon = null;
083: try {
084: cluster = new LogicalCluster(this );
085: clon = cluster.setName(name);
086: } catch (JMException e) {
087: logger.log(BasicLevel.ERROR,
088: "Cannot create LogicalCluster:" + e);
089: return null;
090: }
091: // Register the MBean if not done
092: if (!mbeanServer.isRegistered(clon)) {
093: try {
094: // A MBean is registered for each Cluster
095: logger.log(BasicLevel.DEBUG,
096: "Resister Cluster MBean : " + clon);
097: mbeanServer.registerMBean(cluster, clon);
098: } catch (Exception e) {
099: logger.log(BasicLevel.ERROR, "Cannot register cluster:"
100: + e);
101: return null;
102: }
103: }
104: if (logger.isLoggable(BasicLevel.DEBUG)) {
105: logger.log(BasicLevel.DEBUG, "Adding cluster : " + name);
106: }
107: myclusters.put(name, cluster);
108: return cluster;
109: }
110:
111: }
|