fr.dyade.aaa.agent.SCAdminHelper Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of a3-rt Show documentation
Show all versions of a3-rt Show documentation
Builds the Joram a3 rt project.
/*
* Copyright (C) 2001 - 2023 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.BufferedReader;
import java.io.File;
import java.io.InputStreamReader;
import java.net.Socket;
import java.net.SocketException;
import java.util.Hashtable;
import java.util.Vector;
import org.objectweb.util.monolog.api.BasicLevel;
import org.objectweb.util.monolog.api.Logger;
import fr.dyade.aaa.common.Debug;
@Deprecated
public class SCAdminHelper {
/** Hashtable that contain all Process
of running AgentServer */
protected Hashtable ASP = null;
protected Logger logmon = null;
public SCAdminHelper() {
// Get the logging monitor from current server MonologMonitorFactory
logmon = Debug.getLogger("fr.dyade.aaa.agent.SCAdmin");
ASP = new Hashtable<>();
}
/**
* Starts an agent server from its id.
*
* @param sid id of agent server to start
* @return the status string of the launched server.
* @throws Exception an error occurs.
*/
public String startAgentServer(short sid) throws Exception {
return startAgentServer(sid, null, null, null, null);
}
/**
* Starts an agent server from its id using specific jvmargs.
*
* @param sid id of agent server to start
* @param jvmargs arguments to pass to the created java program
* @return the status string of the launched server.
* @throws Exception an error occurs.
*/
public String startAgentServer(short sid,
String[] jvmargs) throws Exception {
return startAgentServer(sid, null, jvmargs, null, null);
}
/**
* Starts an agent server from its id using specific jvmargs and storage
* directory.
*
* @param sid id of agent server to start
* @param dir new working directory for the created agent server,
* current working directory if null
* @param jvmargs arguments to pass to the created java program
* @return the status string of the launched server.
* @throws Exception an error occurs.
*/
public String startAgentServer(short sid,
File dir,
String[] jvmargs) throws Exception {
return startAgentServer(sid, dir, jvmargs, null, null);
}
/**
* Starts an agent server from its id using specific jvmargs and storage
* directory.
*
* @param sid id of agent server to start
* @param dir new working directory for the created agent server,
* current working directory if null
* @param jvmargs arguments to pass to the created java program
* @param args additional arguments to pass to the created java program
* @return the status string of the launched server.
* @throws Exception an error occurs.
*/
public String startAgentServer(short sid,
File dir,
String[] jvmargs,
String[] args) throws Exception {
return startAgentServer(sid, dir, jvmargs, null, args);
}
/**
* Starts an agent server from its id.
*
* @param sid id of agent server to start
* @param dir new working directory for the created agent server,
* current working directory if null
* @param jvmargs arguments to pass to the created java program
* @param className the name of the main class
* @param args additional arguments to pass to the created java program
* @return the status string of the launched server.
* @throws Exception an error occurs.
*/
public String startAgentServer(short sid,
File dir,
String[] jvmargs,
String className,
String[] args) throws Exception {
logmon.log(BasicLevel.DEBUG,
"SCAdmin: start AgentServer#" + sid);
Process p = (Process) ASP.get(Short.valueOf(sid));
if (p != null) {
try {
logmon.log(BasicLevel.DEBUG,
"SCAdmin: AgentServer#" + sid + " -> " + p.exitValue());
} catch (IllegalThreadStateException exc) {
// there is already another AS#sid running
logmon.log(BasicLevel.WARN,
"SCAdmin: AgentServer#" + sid + " already running.");
throw new IllegalStateException("AgentServer#" + sid +
" already running.");
}
}
p = execAgentServer(sid, dir, jvmargs, className, args);
ASP.put(Short.valueOf(sid), p);
String ret = waitServerStarting(p);
closeServerStream(p);
return ret;
}
/**
* Runs an agent server from its id and specific parameters.
*
* @param sid id of agent server to start
* @param dir new working directory for the created agent server,
* current working directory if null
* @param jvmargs arguments to pass to the created java program
* @param className the name of the main class
* @param args additional arguments to pass to the created java program
* @return the created Process object.
* @throws Exception an error occurs.
*/
public Process execAgentServer(short sid,
File dir,
String[] jvmargs,
String className,
String[] args) throws Exception {
logmon.log(BasicLevel.DEBUG,
"SCAdmin: run AgentServer#" + sid);
String javapath =
new File(new File(System.getProperty("java.home"), "bin"),
"java").getPath();
String classpath = System.getProperty("java.class.path");
Vector argv = new Vector<>();
argv.addElement(javapath);
argv.addElement("-classpath");
argv.addElement(classpath);
if (jvmargs != null) {
for (int i=0; i