1 22 package fr.dyade.aaa.agent; 23 24 import java.io.*; 25 import java.net.*; 26 import java.util.*; 27 28 import org.objectweb.util.monolog.api.BasicLevel; 29 import org.objectweb.util.monolog.api.Logger; 30 31 import fr.dyade.aaa.agent.*; 32 import fr.dyade.aaa.agent.conf.*; 33 34 public class SCAdminBase { 35 protected A3CMLConfig a3config = null; 36 37 protected Logger logmon = null; 38 39 protected SCAdminHelper scadmin = null; 40 41 public SCAdminBase() { 42 logmon = Debug.getLogger("fr.dyade.aaa.agent.SCAdmin"); 44 45 scadmin = new SCAdminHelper(); 46 } 47 48 public SCAdminBase(String path) throws Exception { 49 this(); 50 update(path); 51 } 52 53 58 public String startAgentServer(short sid) throws Exception { 59 return startAgentServer(sid, null); 60 } 61 62 public String startAgentServer(short sid, 63 File dir) throws Exception { 64 StringTokenizer st = new StringTokenizer(a3config.getJvmArgs(sid)); 65 int nb = st.countTokens(); 66 String [] jvmargs = new String [nb+2]; 67 int i=0; 68 for (; i<nb; i++){ 69 jvmargs[i] = st.nextToken(); 70 } 71 jvmargs[i++] = "-Dcom.sun.management.jmxremote"; 72 jvmargs[i++] = "-DMXServer=com.scalagent.jmx.JMXServer"; 73 74 return scadmin.startAgentServer(sid, dir, jvmargs); 75 } 76 77 public String startAgentServer(short sid, 78 File dir, 79 String [] jvmargs) throws Exception { 80 return scadmin.startAgentServer(sid, dir, jvmargs); 81 } 82 83 public String startAgentServer(short sid, 84 File dir, 85 String [] jvmargs, 86 String [] servargs) throws Exception { 87 return scadmin.startAgentServer(sid, dir, jvmargs, servargs); 88 } 89 90 95 public void killAgentServer(short sid) throws Exception { 96 scadmin.killAgentServer(sid); 97 } 98 99 107 public int joinAgentServer(short sid) throws Exception { 108 return scadmin.joinAgentServer(sid); 109 } 110 111 121 public int exitValue(short sid) 122 throws IllegalThreadStateException , UnknownServerException { 123 return scadmin.exitValue(sid); 124 } 125 126 131 public void stopAgentServer(short sid) throws Exception { 132 logmon.log(BasicLevel.DEBUG, "SCAdmin: stop AgentServer#" + sid); 133 134 A3CMLServer server = a3config.getServer(sid); 135 String host = server.hostname; 136 int port = Integer.parseInt( 137 a3config.getServiceArgs(sid, "fr.dyade.aaa.agent.AdminProxy")); 138 scadmin.stopAgentServer(sid, host, port); 139 } 140 141 146 public void crashAgentServer(short sid) throws Exception { 147 logmon.log(BasicLevel.DEBUG, "SCAdmin: stop AgentServer#" + sid); 148 149 A3CMLServer server = a3config.getServer(sid); 150 String host = server.hostname; 151 int port = Integer.parseInt( 152 a3config.getServiceArgs(sid, "fr.dyade.aaa.agent.AdminProxy")); 153 scadmin.crashAgentServer(sid, host, port); 154 } 155 156 159 public void update() throws Exception { 160 logmon.log(BasicLevel.DEBUG, "SCAdmin: update()"); 161 162 try { 163 a3config = A3CML.getXMLConfig(); 164 } catch (Exception exc) { 165 logmon.log(BasicLevel.ERROR, 166 "SCAdmin: problem during configuration parsing", exc); 167 throw new Exception ("Problem during configuration parsing"); 168 } 169 170 } 171 172 public void update(String path) throws Exception { 173 logmon.log(BasicLevel.DEBUG, "SCAdmin: update(" + path + ")"); 174 175 try { 176 a3config = A3CML.getXMLConfig(path); 177 } catch (Exception exc) { 178 logmon.log(BasicLevel.ERROR, 179 "SCAdmin: problem during configuration parsing", exc); 180 throw new Exception ("Problem during configuration parsing"); 181 } 182 } 183 } 184 | Popular Tags |