/**
 * JOnAS: Java(TM) Open Application Server
 * Copyright (C) 2007 Bull S.A.
 * Contact: jonas-team@ow2.org
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
 * USA
 *
 * --------------------------------------------------------------------------
 * $Id:
 * --------------------------------------------------------------------------
 */

package org.ow2.jonas.lib.management.extensions.manager;

import org.ow2.jonas.lib.management.extensions.domain.DomainManagement;
import org.ow2.jonas.management.api.extensions.domain.IDomain;

public class ManagementEntryPoint {

    /**
     * The ManagementEntryPoint singleton for management tools.
     */
    private static ManagementEntryPoint unique = null;

    /**
     * The IDomain Interface for DomainManagement implementation.
     */
    private static IDomain domainManagement = null;

    /**
     * @return ManagementEntryPoint singleton.
     */
    public static synchronized ManagementEntryPoint getInstance() {
        if(unique == null) {
            domainManagement = new DomainManagement();
            unique = new ManagementEntryPoint();
        }
        return unique;
    }

    // General informations about the domain to which the administration tool is connected to.

    /**
     * @param pServer managed server name
     * @return Return True if is the managed server is a master
     */
    public boolean isMaster(final String pServer) {
        return domainManagement.isMaster(pServer);
    }

    /**
     * @return True if is the current server is a master.
     */
    public boolean isMaster() {
        return domainManagement.isMaster();
    }

    /**
     * @return the servers names that are belonging to the domain
     */
    public String[] getServerNames() {
        return domainManagement.getServerNames();
    }

    /**
     * Return the type of a cluster in the current domain.
     * @param clusterName the cluster's name
     */
    String getClusterType(final String clusterName){
        return domainManagement.getClusterType(clusterName);
    }

    /**
     * Return the server names that are belonging to a cluster.
     * @param clusterName the cluster name
     */
    String[] getServerNames(final String clusterName){
        return domainManagement.getServerNames();
    }

    /**
     * Return the clusters in the domain.
     */
    String[] getClusters(){
        return domainManagement.getClusters();
    }

    /**
     * Return the cluster daemons in the domain.
     */
    String[] getclusterDaemons(){
        return domainManagement.getclusterDaemons();
    }

    /**
     * Return the state of a server in the domain
     * @param serverName the server's name
     */
    String getServerState(final String serverName){
        return domainManagement.getServerState(serverName);
    }

    /**
     * Return the cluster daemon of a server in the domain.
     * @param serverName the server's name
     */
    String getServerClusterdaemon(final String serverName){
        return domainManagement.getServerClusterdaemon(serverName);
    }

    /**
     * Return the state of a cluster in the domain.
     * @param clusterName the cluster's name
     */
    String getClusterState(final String clusterName){
        return domainManagement.getClusterState(clusterName);
    }

    /**
     * Return the state of a cluster daemon in the domain.
     * @param clusterdaemonName the cluster daemon's name.
     */
    String getClusterdaemonState(final String clusterdaemonName){
        return domainManagement.getClusterdaemonState(clusterdaemonName);
    }
}
