All Downloads are FREE. Search and download functionalities are using the official Maven repository.

fr.dyade.aaa.agent.SCServer Maven / Gradle / Ivy

The newest version!
/*
 * Copyright (C) 2001 - 2016 ScalAgent Distributed Technologies
 *
 * 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.
 *
 * Initial developer(s): ScalAgent Distributed Technologies
 * Contributor(s): 
 */
package fr.dyade.aaa.agent;

import java.io.FileWriter;
import java.io.IOException;
import java.util.Enumeration;

import org.objectweb.util.monolog.api.BasicLevel;
import org.objectweb.util.monolog.api.Logger;

import fr.dyade.aaa.common.Debug;
import fr.dyade.aaa.common.monitoring.DumpAttributes;

public class SCServer implements SCServerMBean {
  public static Logger logger = Debug.getLogger(SCServer.class.getName());
  
  public SCServer() {
  }

  public short getServerId() {
    return AgentServer.getServerId();
  }

  public String getName() {
    return AgentServer.getName();
  }

  public void start() {
    try {
      AgentServer.start();
    } catch (Throwable exc) {
    }
  }

  public void stop() {
    AgentServer.stop(false);
  }

  public int getStatus() {
    return AgentServer.getStatus();
  }

  public String getStatusInfo() {
    return AgentServer.getStatusInfo();
  }

  public String[] getServers() {
    Enumeration e = AgentServer.elementsServerDesc();
    String[] servers = new String[AgentServer.getServerNb()];
    StringBuffer strBuf = new StringBuffer();
    for (int i=0; e.hasMoreElements(); i++) {
      ServerDesc server = e.nextElement();
      strBuf.append("sid=").append(server.sid);
      strBuf.append(",name=").append(server.name);
      if (server.gateway == -1) {
        strBuf.append(",gateway=").append(server.gateway);
      } else {
        strBuf.append(",host=").append(server.getHostname())
          .append(':').append(server.getPort());
        strBuf.append(",active=").append(server.active);
        strBuf.append(",last=").append(server.last);
      }
      servers[i] = strBuf.toString();
      strBuf.setLength(0);
    }
    return servers;
  }
  
  public void dumpAttributes(String name, String path, boolean threaddump) {
    FileWriter writer = null;
    try {
      writer = new FileWriter(path, true);
      StringBuffer strbuf = new StringBuffer();

      DumpAttributes.dumpAttributes(name, strbuf);
      if (threaddump)
        DumpAttributes.dumpAllStackTraces(strbuf);
      writer.close();
    } catch (IOException exc) {
      logger.log(BasicLevel.ERROR,
                 "SCServer.dumpAttributes, cannot open dump file \"" + path + "\"", exc);
    }

  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy