KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > fr > dyade > aaa > agent > SCAdminBase


1 /*
2  * Copyright (C) 2002 - 2005 ScalAgent Distributed Technologies
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
17  * USA.
18  *
19  * Initial developer(s): ScalAgent Distributed Technologies
20  * Contributor(s):
21  */

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     // Get the logging monitor from current server MonologMonitorFactory
43
logmon = Debug.getLogger("fr.dyade.aaa.agent.SCAdmin");
44
45     scadmin = new SCAdminHelper();
46   }
47
48   public SCAdminBase(String JavaDoc path) throws Exception JavaDoc {
49     this();
50     update(path);
51   }
52
53   /**
54    * Starts an agent server from its id.
55    *
56    * @param sid id of agent server to start
57    */

58   public String JavaDoc startAgentServer(short sid) throws Exception JavaDoc {
59     return startAgentServer(sid, null);
60   }
61
62   public String JavaDoc startAgentServer(short sid,
63                                  File dir) throws Exception JavaDoc {
64     StringTokenizer st = new StringTokenizer(a3config.getJvmArgs(sid));
65     int nb = st.countTokens();
66     String JavaDoc[] jvmargs = new String JavaDoc[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 JavaDoc startAgentServer(short sid,
78                                  File dir,
79                                  String JavaDoc[] jvmargs) throws Exception JavaDoc {
80     return scadmin.startAgentServer(sid, dir, jvmargs);
81   }
82
83   public String JavaDoc startAgentServer(short sid,
84                                  File dir,
85                                  String JavaDoc[] jvmargs,
86                  String JavaDoc[] servargs) throws Exception JavaDoc {
87     return scadmin.startAgentServer(sid, dir, jvmargs, servargs);
88   }
89
90   /**
91    * Kills this agent server process.
92    *
93    * @param sid id of agent server to stop
94    */

95   public void killAgentServer(short sid) throws Exception JavaDoc {
96     scadmin.killAgentServer(sid);
97   }
98
99   /**
100    * Causes the current thread to wait, if necessary, until the process
101    * running this agent server has terminated.
102    *
103    * @param sid id of agent server to stop
104    * @return the exit value of the agent server.
105    * @exception UnknownServerException if the agent server is unknown.
106    */

107   public int joinAgentServer(short sid) throws Exception JavaDoc {
108     return scadmin.joinAgentServer(sid);
109   }
110
111   /**
112    * Ask for the exit value of an agent server.
113    *
114    * @param sid id of agent server to stop
115    * @return the exit value of the agent server.
116    * @exception IllegalThreadStateException
117    * if the agent server is still running.
118    * @exception UnknownServerException
119    * if the agent server is unknown.
120    */

121   public int exitValue(short sid)
122     throws IllegalThreadStateException JavaDoc, UnknownServerException {
123     return scadmin.exitValue(sid);
124   }
125
126   /**
127    * Stops cleanly an agent server from its id.
128    *
129    * @param sid id of agent server to stop
130    */

131   public void stopAgentServer(short sid) throws Exception JavaDoc {
132     logmon.log(BasicLevel.DEBUG, "SCAdmin: stop AgentServer#" + sid);
133
134     A3CMLServer server = a3config.getServer(sid);
135     String JavaDoc 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   /**
142    * Stops violently an agent server from its id.
143    *
144    * @param sid id of agent server to stop
145    */

146   public void crashAgentServer(short sid) throws Exception JavaDoc {
147     logmon.log(BasicLevel.DEBUG, "SCAdmin: stop AgentServer#" + sid);
148
149     A3CMLServer server = a3config.getServer(sid);
150     String JavaDoc 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   /**
157    * Updates the configuration.
158    */

159   public void update() throws Exception JavaDoc {
160     logmon.log(BasicLevel.DEBUG, "SCAdmin: update()");
161
162     try {
163       a3config = A3CML.getXMLConfig();
164     } catch (Exception JavaDoc exc) {
165       logmon.log(BasicLevel.ERROR,
166                   "SCAdmin: problem during configuration parsing", exc);
167       throw new Exception JavaDoc("Problem during configuration parsing");
168     }
169
170   }
171
172   public void update(String JavaDoc path) throws Exception JavaDoc {
173     logmon.log(BasicLevel.DEBUG, "SCAdmin: update(" + path + ")");
174
175     try {
176       a3config = A3CML.getXMLConfig(path);
177     } catch (Exception JavaDoc exc) {
178       logmon.log(BasicLevel.ERROR,
179                   "SCAdmin: problem during configuration parsing", exc);
180       throw new Exception JavaDoc("Problem during configuration parsing");
181     }
182   }
183 }
184
Popular Tags