/**
 * JOnAS: Java(TM) Open Application Server
 * Copyright (C) 2008 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 1any 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.server;

import org.ow2.jonas.lib.management.domain.DomainMonitor;
import org.ow2.jonas.lib.management.domain.J2EEDomain;
import org.ow2.jonas.lib.management.domain.proxy.server.ServerProxy;
import org.ow2.jonas.lib.management.extensions.base.BaseManagement;
import org.ow2.jonas.management.extensions.server.api.IServer;

/**
 * Provides informations about a server in the domain.
 * General information or server statistics are based on the corresponding ServerProxy object.
 * @author Adriana Danes
 *
 */
public class ServerMonitoring extends BaseManagement implements IServer {

    /**
     * Ref. to DomainMonitor.
     */
    private DomainMonitor dm = null;

    /**
     * Constructor.
     */
    public ServerMonitoring() {
        super();
        dm = J2EEDomain.getInstance().getDomainMonitor();
    }

    /**
     * Return the version of a server in the domain.
     * @param serverName the name of the server.
     * @return the server's version
     */
    public String getServerVersion(final String serverName) {
        ServerProxy srvProxy = dm.findServerProxy(serverName);
        return srvProxy.getJOnASVersion();
    }
    /**
     * Get the JMX connection URL of a server in the domain.
     * @param serverName the server's name.
     * @return the JMX connection URL of the server
     */
    public String getConnectionUrl(final String serverName) {
        ServerProxy srvProxy = dm.findServerProxy(serverName);
        return srvProxy.getConnectionUrl();
    }

    /**
     * Get the memory used by a server in the domain.
     * @param serverName the server's name.
     * @return the used memory
     */
    public long getCurrentUsedMemory(final String serverName) {
        ServerProxy srvProxy = dm.findServerProxy(serverName);
        return srvProxy.getCurrentUsedMemory();
    }

    /**
     * Get the number of threads used by a server in the domain.
     * @param serverName the server's name.
     * @return the number of threads
     */
    public int getAllThreadsCount(final String serverName){
        ServerProxy srvProxy = dm.findServerProxy(serverName);
        return srvProxy.getAllThreadsCount();
    }

    /**
     * @return bytes received by connector tomcat.
     * @param serverName Server name
     */
    public long getBytesReceivedByConnectorTomcat(final String serverName) {
        ServerProxy srvProxy = dm.findServerProxy(serverName);
        return srvProxy.getBytesReceivedByConnectorTomcat();
    }

    /**
     * @return bytes sent by connector tomcat.
     * @param serverName Server name
     */
    public long getBytesSentByConnectorTomcat(final String serverName) {
        ServerProxy srvProxy = dm.findServerProxy(serverName);
        return srvProxy.getBytesSentByConnectorTomcat();
    }

    /**
     * @return current number of Entity bean.
     * @param serverName Server name
     */
    public int getCurrentNumberOfEntityBean(final String serverName) {
        ServerProxy srvProxy = dm.findServerProxy(serverName);
        return srvProxy.getCurrentNumberOfEntityBean();
    }

    /**
     * @return current number of EJB.
     * @param serverName Server name
     */
    public int getCurrentNumberOfEJB(final String serverName) {
        ServerProxy srvProxy = dm.findServerProxy(serverName);
        return srvProxy.getCurrentNumberOfEJB();
    }

    /**
     * @return current number of message driven bean.
     * @param serverName Server name
     */
    public int getCurrentNumberOfMDB(final String serverName) {
        ServerProxy srvProxy = dm.findServerProxy(serverName);
        return srvProxy.getCurrentNumberOfMDB();
    }

    /**
     * @return current number of state full bean.
     * @param serverName Server name
     */
    public int getCurrentNumberOfSBF(final String serverName) {
        ServerProxy srvProxy = dm.findServerProxy(serverName);
        return srvProxy.getCurrentNumberOfSBF();
    }

    /**
     * @return current number of state less bean.
     * @param serverName Server name
     */
    public int getCurrentNumberOfSBL(final String serverName) {
        ServerProxy srvProxy = dm.findServerProxy(serverName);
        return srvProxy.getCurrentNumberOfSBL();
    }

    /**
     * @return current threads busy by connector tomcat.
     * @param serverName Server name
     */
    public int getCurrentThreadBusyByConnectorTomcat(final String serverName) {
        ServerProxy srvProxy = dm.findServerProxy(serverName);
        return srvProxy.getCurrentThreadBusyByConnectorTomcat();
    }

    /**
     * @return current threads count by tomcat connector
     * @param serverName Server name
     */
    public int getCurrentThreadCountByConnectorTomcat(final String serverName) {
        ServerProxy srvProxy = dm.findServerProxy(serverName);
        return srvProxy.getCurrentThreadCountByConnectorTomcat();
    }

    /**
     * Get the total memory of the server in the domain.
     * @param serverName the server's name.
     * @return the total memory
     */
    public Long getCurrentTotalMemory(final String serverName) {
        ServerProxy srvProxy = dm.findServerProxy(serverName);
        return srvProxy.getCurrentTotalMemory();
    }

    /**
     * @return error count by connector tomcat.
     * @param serverName Server name
     */
    public int getErrorCountByConnectorTomcat(final String serverName) {
        ServerProxy srvProxy = dm.findServerProxy(serverName);
        return srvProxy.getErrorCountByConnectorTomcat();
    }

    /**
     * Get the JVM vendor.
     * @param serverName the server's name.
     * @return the JVM vendor
     */
    public String getJavaVendor(final String serverName) {
        ServerProxy srvProxy = dm.findServerProxy(serverName);
        return srvProxy.getJavaVendor();
    }

    /**
     * Get the java version.
     * @param serverName the server's name.
     * @return the java version
     */
    public String getJavaVersion(final String serverName) {
        ServerProxy srvProxy = dm.findServerProxy(serverName);
        return srvProxy.getJavaVersion();
    }

    /**
     * @return the max threads by connector tomcat.
     * @param serverName Server name
     */
    public int getMaxThreadsByConnectorTomcat(final String serverName) {
        ServerProxy srvProxy = dm.findServerProxy(serverName);
        return srvProxy.getMaxThreadsByConnectorTomcat();
    }

    /**
     * @return processing time by connector tomcat.
     * @param serverName Server name
     */

    public long getProcessingTimeByConnectorTomcat(final String serverName) {
        ServerProxy srvProxy = dm.findServerProxy(serverName);
        return srvProxy.getProcessingTimeByConnectorTomcat();
    }

    /**
     * Get the the protocols used bye the server.
     * @param serverName the server's name.
     * @return the protocols used bye the server
     */
    public String getProtocols(final String serverName) {
        ServerProxy srvProxy = dm.findServerProxy(serverName);
        return srvProxy.getProtocols();
    }

    /**
     * @return request count by connector tomcat.
     * @param serverName Server name
     */
    public int getRequestCountByConnectorTomcat(final String serverName) {
        ServerProxy srvProxy = dm.findServerProxy(serverName);
        return srvProxy.getRequestCountByConnectorTomcat();
    }

    /**
     * @return total begun transactions.
     * @param serverName Server name
     */
    public int getTotalBegunTransactions(final String serverName) {
        ServerProxy srvProxy = dm.findServerProxy(serverName);
        return srvProxy.getTotalBegunTransactions();
    }

    /**
     * @return total commited transactions.
     * @param serverName Server name
     */
    public int getTotalCommittedTransactions(final String serverName) {
        ServerProxy srvProxy = dm.findServerProxy(serverName);
        return srvProxy.getTotalCommittedTransactions();
    }

    /**
     * @return total current transactions.
     * @param serverName Server name
     */
    public int getTotalCurrentTransactions(final String serverName) {
        ServerProxy srvProxy = dm.findServerProxy(serverName);
        return srvProxy.getTotalCurrentTransactions();
    }

    /**
     * @return total expired transactions.
     * @param serverName Server name
     */
    public int getTotalExpiredTransactions(final String serverName) {
        ServerProxy srvProxy = dm.findServerProxy(serverName);
        return srvProxy.getTotalExpiredTransactions();
    }

    /**
     * @return total global transactions.
     * @param serverName Server name
     */
    public int getTotalRolledbackTransactions(final String serverName) {
        ServerProxy srvProxy = dm.findServerProxy(serverName);
        return srvProxy.getTotalRolledbackTransactions();
    }

    /**
     * @return the description
     */
    public String getDescription(final String serverName) {
        ServerProxy srvProxy = dm.findServerProxy(serverName);
        return srvProxy.getDescription();
    }

    /**
     * @return the javaHome
     */
    public String getJavaHome(final String serverName) {
        ServerProxy srvProxy = dm.findServerProxy(serverName);
        return srvProxy.getJavaHome();
    }

    /**
     * @return the jonasRoot
     */
    public String getJonasRoot(final String serverName) {
        ServerProxy srvProxy = dm.findServerProxy(serverName);
        return srvProxy.getJonasRoot();
    }

    /**
     * @return the jonasBase
     */
    public String getJonasBase(final String serverName) {
        ServerProxy srvProxy = dm.findServerProxy(serverName);
        return srvProxy.getJonasRoot();
    }

    /**
     * @return the xprem
     */
    public String getXprem(final String serverName) {
        ServerProxy srvProxy = dm.findServerProxy(serverName);
        return srvProxy.getXprem();
    }

    /**
     * @return the autoBoot
     */
    public String getAutoBoot(final String serverName) {
        ServerProxy srvProxy = dm.findServerProxy(serverName);
        return srvProxy.getAutoBoot();
    }

    public String getJ2eeObjectName(final String serverName) {
        ServerProxy srvProxy = dm.findServerProxy(serverName);
        return srvProxy.getJ2eeObjectName();
    }

    public int getConnectionFailuresJCAConnection(final String serverName) {
        ServerProxy srvProxy = dm.findServerProxy(serverName);
        return srvProxy.getConnectionFailuresJCAConnection();
    }

    public int getConnectionLeaksJCAConnection(final String serverName) {
        ServerProxy srvProxy = dm.findServerProxy(serverName);
        return srvProxy.getConnectionLeaksJCAConnection();
    }

    public int getCurrentBusyJCAConnection(final String serverName) {
        ServerProxy srvProxy = dm.findServerProxy(serverName);
        return srvProxy.getCurrentBusyJCAConnection();
    }

    public int getCurrentWorkerPoolSize(final String serverName) {
        ServerProxy srvProxy = dm.findServerProxy(serverName);
        return srvProxy.getCurrentWorkerPoolSize();
    }

    public int getCurrentOpenedJCAConnection(final String serverName) {
        ServerProxy srvProxy = dm.findServerProxy(serverName);
        return srvProxy.getCurrentOpenedJCAConnection();
    }

    public int getWaiterCountJCAConnection(final String serverName) {
        ServerProxy srvProxy = dm.findServerProxy(serverName);
        return srvProxy.getWaiterCountJCAConnection();
    }

    public long getWaitingTimeJCAConnection(final String serverName) {
        ServerProxy srvProxy = dm.findServerProxy(serverName);
        return srvProxy.getWaitingTimeJCAConnection();
    }

    public boolean getTomcat(final String serverName) {
        ServerProxy srvProxy = dm.findServerProxy(serverName);
        return srvProxy.getTomcat();
    }

    public boolean getTransaction(final String serverName) {
        ServerProxy srvProxy = dm.findServerProxy(serverName);
        return srvProxy.getTransaction();
    }

    public boolean getWorkers(final String serverName) {
        ServerProxy srvProxy = dm.findServerProxy(serverName);
        return srvProxy.getWorkers();
    }

    public int getMaxWorkerPoolSize(final String serverName) {
        ServerProxy srvProxy = dm.findServerProxy(serverName);
        return srvProxy.getMaxWorkerPoolSize();
    }

    public int getMinWorkerPoolSize(final String serverName) {
        ServerProxy srvProxy = dm.findServerProxy(serverName);
        return srvProxy.getMinWorkerPoolSize();
    }

    public int getConnectionFailuresJDBCResource(final String serverName) {
        ServerProxy srvProxy = dm.findServerProxy(serverName);
        return srvProxy.getConnectionFailuresJDBCResource();
    }

    public int getConnectionLeaksJDBCResource(final String serverName) {
        ServerProxy srvProxy = dm.findServerProxy(serverName);
        return srvProxy.getConnectionLeaksJDBCResource();
    }

    public int getCurrentBusyJDBCResource(final String serverName) {
        ServerProxy srvProxy = dm.findServerProxy(serverName);
        return srvProxy.getCurrentBusyJDBCResource();
    }

    public int getCurrentOpenedJDBCResource(final String serverName) {
        ServerProxy srvProxy = dm.findServerProxy(serverName);
        return srvProxy.getCurrentOpenedJDBCResource();
    }

    public int getRejectedOpenJDBCResource(final String serverName) {
        ServerProxy srvProxy = dm.findServerProxy(serverName);
        return srvProxy.getRejectedOpenJDBCResource();
    }

    public int getServedOpenJDBCResource(final String serverName) {
        ServerProxy srvProxy = dm.findServerProxy(serverName);
        return srvProxy.getServedOpenJDBCResource();
    }

    public int getWaiterCountJDBCResource(final String serverName) {
        ServerProxy srvProxy = dm.findServerProxy(serverName);
        return srvProxy.getWaiterCountJDBCResource();
    }

    public long getWaitingTimeJDBCResource(final String serverName) {
        ServerProxy srvProxy = dm.findServerProxy(serverName);
        return srvProxy.getWaitingTimeJDBCResource();
    }

    public int getServedOpenJCAConnection(final String serverName) {
        ServerProxy srvProxy = dm.findServerProxy(serverName);
        return srvProxy.getServedOpenJCAConnection();
    }

    public int getRejectedOpenJCAConnection(final String serverName) {
        ServerProxy srvProxy = dm.findServerProxy(serverName);
        return srvProxy.getRejectedOpenJCAConnection();
    }

    public boolean getJcaConnection(final String serverName) {
        ServerProxy srvProxy = dm.findServerProxy(serverName);
        return srvProxy.getJcaConnection();
    }

    public boolean getJdbcDatasource(final String serverName) {
        ServerProxy srvProxy = dm.findServerProxy(serverName);
        return srvProxy.getJdbcDatasource();
    }

    public boolean getJmsJoram(final String serverName) {
        ServerProxy srvProxy = dm.findServerProxy(serverName);
        return srvProxy.getJmsJoram();
    }

    public int getJmsQueuesNbMsgsDeliverSinceCreation(final String serverName) {
        ServerProxy srvProxy = dm.findServerProxy(serverName);
        return srvProxy.getJmsQueuesNbMsgsDeliverSinceCreation();
    }

    public int getJmsQueuesNbMsgsReceiveSinceCreation(final String serverName) {
        ServerProxy srvProxy = dm.findServerProxy(serverName);
        return srvProxy.getJmsQueuesNbMsgsReceiveSinceCreation();
    }

    public int getJmsQueuesNbMsgsSendToDMQSinceCreation(final String serverName) {
        ServerProxy srvProxy = dm.findServerProxy(serverName);
        return srvProxy.getJmsQueuesNbMsgsSendToDMQSinceCreation();
    }

    public int getJmsTopicsNbMsgsDeliverSinceCreation(final String serverName) {
        ServerProxy srvProxy = dm.findServerProxy(serverName);
        return srvProxy.getJmsTopicsNbMsgsDeliverSinceCreation();
    }

    public int getJmsTopicsNbMsgsReceiveSinceCreation(final String serverName) {
        ServerProxy srvProxy = dm.findServerProxy(serverName);
        return srvProxy.getJmsTopicsNbMsgsReceiveSinceCreation();
    }

    public int getJmsTopicsNbMsgsSendToDMQSinceCreation(final String serverName) {
        ServerProxy srvProxy = dm.findServerProxy(serverName);
        return srvProxy.getJmsTopicsNbMsgsSendToDMQSinceCreation();
    }

    public String getHostName(final String serverName) {
        ServerProxy srvProxy = dm.findServerProxy(serverName);
        return srvProxy.getHostName();
    }

    public String getJOnASVersion(final String serverName) {
        ServerProxy srvProxy = dm.findServerProxy(serverName);
        return srvProxy.getJOnASVersion();
    }

    public String getLoadCPU(final String serverName) {
        ServerProxy srvProxy = dm.findServerProxy(serverName);
        return srvProxy.getLoadCPU();
    }

}
