KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > quickserver > net > qsadmin > CommandHandler


1 /*
2  * This file is part of the QuickServer library
3  * Copyright (C) QuickServer.org
4  *
5  * Use, modification, copying and distribution of this software is subject to
6  * the terms and conditions of the GNU Lesser General Public License.
7  * You should have received a copy of the GNU LGP License along with this
8  * library; if not, you can download a copy from <http://www.quickserver.org/>.
9  *
10  * For questions, suggestions, bug-reports, enhancement-requests etc.
11  * visit http://www.quickserver.org
12  *
13  */

14
15 package org.quickserver.net.qsadmin;
16
17 import java.net.*;
18 import java.io.*;
19 import java.util.StringTokenizer JavaDoc;
20
21 import org.quickserver.net.server.ClientCommandHandler;
22 import org.quickserver.net.server.ClientEventHandler;
23 import org.quickserver.net.server.ClientHandler;
24 import org.quickserver.net.server.QuickServer;
25 import org.quickserver.net.AppException;
26
27 import java.util.logging.*;
28
29 import org.quickserver.util.*;
30 import org.quickserver.util.pool.thread.*;
31 import java.util.*;
32 import org.quickserver.util.pool.*;
33 import org.apache.commons.pool.ObjectPool;
34 import org.quickserver.net.server.ClientIdentifier;
35
36 /**
37  * ClientCommandHandler for QSAdminServer.
38  * <p>
39  * = Protocol =<br>
40  * Each response starts with a status.
41  * <ul>
42  * <li>+OK = Success
43  * <li>-ERR = Failed
44  * </ul>
45  * If response if one lined then it follows the status.
46  * Else You will get "info follows" as the first line
47  * followed by with many lines of response ending by a
48  * dot in a line by itself. i.e., &lt;CR&gt;&lt;LF&gt;.&lt;CR&gt;&lt;LF&gt;<br>
49  * Command supported are give below .. [ Note: &lt;&lt;target&gt;&gt; = server|self ]
50  * <br>&nbsp;<br>
51  * <table align="center" border=1>
52  * <tr><th>Command</th><th>Param</th><th>Effect</th></tr>
53  * <tr><td>start</td><td>&lt;&lt;target&gt;&gt;</td><td>Starts target.</td></tr>
54  * <tr><td>stop</td><td>&lt;&lt;target&gt;&gt;</td><td>Stops target.</td></tr>
55  * <tr><td>restart</td><td>&lt;&lt;target&gt;&gt;</td><td>=stop+start command</td></tr>
56  * <tr><td>shutdown</td><td>&nbsp;</td><td>Stops server and self. </td></tr>
57  * <tr><td>kill or exit</td><td>&nbsp;</td><td>Stops server and self and kill all threads. </td></tr>
58  * <tr><td>info</td><td>&lt;&lt;target&gt;&gt;</td><td>Information about target.</td></tr>
59  * <tr><td>noclient</td><td>&lt;&lt;target&gt;&gt;</td><td>No Client connected to the target.</td></tr>
60  * <tr><td>running</td><td>&lt;&lt;target&gt;&gt;</td><td>Checks if target is running.</td></tr>
61  * <tr><td>get</td><td>&lt;&lt;target&gt;&gt; maxClient</td><td>Gets max no of client for the target.</td></tr>
62  * <tr><td>get</td><td>&lt;&lt;target&gt;&gt; port</td><td>Gets port for the target.</td></tr>
63  * <tr><td>get</td><td>&lt;&lt;target&gt;&gt; maxAuthTryMsg</td><td>Gets maxAuthTryMsg for the target. </td></tr>
64  * <tr><td>get</td><td>&lt;&lt;target&gt;&gt; clientCommandHandler</td><td>Gets ClientCommandHandler class for the target.</td></tr>
65  * <tr><td>get</td><td>&lt;&lt;target&gt;&gt; clientAuthenticationHandler</td><td>Gets ClientAuthenticationHandler class for the target.</td></tr>
66  * <tr><td>get</td><td>&lt;&lt;target&gt;&gt; clientData</td><td>Gets ClientData class for the target.</td></tr>
67  * <tr><td>get</td><td>&lt;&lt;target&gt;&gt; timeout</td><td>Gets timeout set for clients for the target.</td></tr>
68  * <tr><td>set</td><td>&lt;&lt;target&gt;&gt; maxClient &lt;&lt;value&gt;&gt;</td><td>Sets max no of client for the target.</td></tr>
69  * <tr><td>set</td><td>&lt;&lt;target&gt;&gt; port &lt;&lt;value&gt;&gt;</td><td>Sets port for the target.*</td></tr>
70  * <tr><td>set</td><td>&lt;&lt;target&gt;&gt; maxAuthTryMsg &lt;&lt;value&gt;&gt;</td><td>Sets maxAuthTryMsg for the target. *</td></tr>
71  * <tr><td>set</td><td>&lt;&lt;target&gt;&gt; clientCommandHandler &lt;&lt;value&gt;&gt;</td><td>Sets ClientCommandHandler class for the target. *</td></tr>
72  * <tr><td>set</td><td>&lt;&lt;target&gt;&gt; clientAuthenticationHandler &lt;&lt;value&gt;&gt;</td><td>Sets ClientAuthenticationHandler class for the target. *</td></tr>
73  * <tr><td>set</td><td>&lt;&lt;target&gt;&gt; clientData &lt;&lt;value&gt;&gt;</td><td>Sets ClientData class for the target. *</td></tr>
74  * <tr><td>set</td><td>&lt;&lt;target&gt;&gt; timeout &lt;&lt;value&gt;&gt;</td><td>Sets timeout set for clients for the target. *</td></tr>
75  * <tr><td>version</td><td>&nbsp;</td><td>Gets the version of the QuickServer library used.</td></tr>
76  * <tr><td>quit</td><td>&nbsp;</td><td>Close session.</td></tr>
77  * <tr><td colspan=3>New Command in v1.2 </td></tr>
78  * <tr><td>get</td><td>self plugin</td><td>Gets pluggable command handler for QsAdminServer. *</td></tr>
79  * <tr><td>set</td><td>self plugin &lt;&lt;full class name&gt;&gt;</td><td>Sets Pluggable command handler for QsAdminServer. *</td></tr>
80  * <tr><td colspan=3>New Command in v1.3 </td></tr>
81  * <tr><td>suspendService</td><td>&lt;&lt;target&gt;&gt;</td><td>Suspends target.</td></tr>
82  * <tr><td>resumeService</td><td>&lt;&lt;target&gt;&gt;</td><td>Resume target.</td></tr>
83  * <tr><td>get</td><td>&lt;&lt;target&gt;&gt; maxAuthTry</td><td>Gets maxAuthTry for the target.</td></tr>
84  * <tr><td>set</td><td>&lt;&lt;target&gt;&gt; maxAuthTry</td><td>Sets maxAuthTry for the target.*</td></tr>
85  * <tr><td>get</td><td>&lt;&lt;target&gt;&gt; clientObjectHandler</td><td>Gets ClientObjectHandler class for the target.</td></tr>
86  * <tr><td>set</td><td>&lt;&lt;target&gt;&gt; clientObjectHandler</td><td>Sets ClientObjectHandler class for the target.*</td></tr>
87  * <tr><td>get</td><td>&lt;&lt;target&gt;&gt; timeoutMsg</td><td>Gets timeout Message for the target.</td></tr>
88  * <tr><td>set</td><td>&lt;&lt;target&gt;&gt; timeoutMsg</td><td>Sets timeout Message for the target.*</td></tr>
89  * <tr><td>get</td><td>&lt;&lt;target&gt;&gt; serviceState</td><td>Gets Service State for the target.</td></tr>
90  * <tr><td>get</td><td>&lt;&lt;target&gt;&gt; consoleLoggingFormatter</td><td>Sets consoleLoggingFormatter for the target.</td></tr>
91  * <tr><td>set</td><td>&lt;&lt;target&gt;&gt; consoleLoggingFormatter</td><td>Sets consoleLoggingFormatter for the target.</td></tr>
92  * <tr><td>get</td><td>&lt;&lt;target&gt;&gt; consoleLoggingLevel</td><td>Sets consoleLoggingLevel for the target. <br>
93  * <tr><td>set</td><td>&lt;&lt;target&gt;&gt; consoleLoggingLevel</td><td>Sets consoleLoggingLevel for the target. <br>
94  * [<code>SEVERE|WARNING|INFO|CONFIG|FINE|FINER|FINEST<code>]</td></tr>
95  * <tr><td>set</td><td>&lt;&lt;target&gt;&gt; maxClientMsg</td><td>Sets maxClientMsg for the target.</td></tr>
96  * <tr><td>get</td><td>&lt;&lt;target&gt;&gt; maxClientMsg</td><td>Gets maxClientMsg for the target.</td></tr>
97  * <tr><td colspan=3>New Command in v1.3.1 </td></tr>
98  * <tr><td>set</td><td>&lt;&lt;target&gt;&gt; loggingLevel</td><td>Sets LoggingLevel for the target. <br>
99  * [<code>SEVERE|WARNING|INFO|CONFIG|FINE|FINER|FINEST<code>]</td></tr>
100  * <tr><td colspan=3>New Command in v1.3.2 </td></tr>
101  * <tr><td>memoryInfo</td><td>&nbsp;</td><td>Memory Information {Total:Used:Max}</td></tr>
102  * <tr><td>set</td><td>&lt;&lt;target&gt;&gt; communicationLogging</td><td>Sets communication logging flag for the target.</td></tr>
103  * <tr><td>get</td><td>&lt;&lt;target&gt;&gt; communicationLogging</td><td>Gets communication logging flag for the target.</td></tr>
104
105  * <tr><td>set</td><td>&lt;&lt;target&gt;&gt; objectPoolConfig-maxActive</td><td>Sets maxActive of objectPoolConfig for the target.</td></tr>
106  * <tr><td>get</td><td>&lt;&lt;target&gt;&gt; objectPoolConfig-maxActive</td><td>Gets maxActive of objectPoolConfig for the target.</td></tr>
107
108  * <tr><td>set</td><td>&lt;&lt;target&gt;&gt; objectPoolConfig-maxIdle</td><td>Sets maxIdle of objectPoolConfig for the target.</td></tr>
109  * <tr><td>get</td><td>&lt;&lt;target&gt;&gt; objectPoolConfig-maxIdle</td><td>Gets maxIdle of objectPoolConfig for the target.</td></tr>
110  *
111  * <tr><td colspan=3>New Command in v1.4.5 </td></tr>
112  * <tr><td>all-pool-info</td><td>&lt;&lt;target&gt;&gt;</td><td>Gives stats of all pools for the target.</td></tr>
113  * <tr><td>client-thread-pool-dump</td><td>&lt;&lt;target&gt;&gt;</td><td>Gives dump of all threads in pool for the target.</td></tr>
114  * <tr><td>start</td><td>&lt;&lt;console&gt;&gt;</td><td>Starts console shell.</td></tr>
115  * <tr><td>stop</td><td>&lt;&lt;console&gt;&gt;</td><td>Stops console shell.</td></tr>
116  *
117  * <tr><td colspan=3>New Command in v1.4.6 </td></tr>
118  * <tr><td>client-handler-pool-dump</td><td>&lt;&lt;target&gt;&gt;</td><td>Gives dump of all ClientHandler in pool for the target.</td></tr>
119  * <tr><td>get</td><td>&lt;&lt;target&gt;&gt; clientEventHandler</td><td>Gets ClientEventHandler class for the target.</td></tr>
120  * <tr><td>set</td><td>&lt;&lt;target&gt;&gt; clientEventHandler &lt;&lt;value&gt;&gt;</td><td>Sets ClientEventHandler class for the target. *</td></tr>
121  * <tr><td>get</td><td>&lt;&lt;target&gt;&gt; clientWriteHandler</td><td>Gets ClientWriteHandler class for the target.</td></tr>
122  * <tr><td>set</td><td>&lt;&lt;target&gt;&gt; clientWriteHandler &lt;&lt;value&gt;&gt;</td><td>Sets ClientWriteHandler class for the target. *</td></tr>
123  * <tr><td>get</td><td>&lt;&lt;target&gt;&gt; clientExtendedEventHandler</td><td>Gets ClientExtendedEventHandler class for the target.</td></tr>
124  * <tr><td>set</td><td>&lt;&lt;target&gt;&gt; clientExtendedEventHandler &lt;&lt;value&gt;&gt;</td><td>Sets ClientExtendedEventHandler class for the target. *</td></tr>
125  * <tr><td>set</td><td>&lt;&lt;target&gt;&gt; objectPoolConfig-initSize</td><td>Sets initSize of objectPoolConfig for the target.</td></tr>
126  * <tr><td>get</td><td>&lt;&lt;target&gt;&gt; objectPoolConfig-initSize</td><td>Gets initSize of objectPoolConfig for the target.</td></tr>
127  *
128  * <tr><td colspan=3>* = Take effect after a restart command.<br>
129  * value if set null then key will be set to <code>null</code>
130  * </td></tr>
131  * </table>
132  * <br>Note:
133  * <ul>
134  * <li>Stopping the QuickServer will not disconnect any client connect to it, since
135  * client connections are handled by different thread.
136  * <li><code>restart</code> and <code>start</code> response just indicate only
137  * if command was sent. Do check the state of the target using
138  * <code>running</code> command to see if server was started successful.
139  * <li>Demo code examples\EchoServer shows the use of QsAdminServer to control itself.
140  * </ul>
141  * Eg: <br>
142  * <BLOCKQUOTE>
143  * noClient server<br>
144  * noClient self<br>
145  * get server maxClient<br>
146  * set server maxClient 10
147  * </BLOCKQUOTE>
148  * </p>
149  * @since 1.1
150  */

151 public class CommandHandler implements ClientCommandHandler, ClientEventHandler {
152     private static Logger logger = Logger.getLogger(CommandHandler.class.getName());
153
154     private CommandPlugin plugin;
155     private Runtime JavaDoc runtime;
156     StringBuffer JavaDoc temp = new StringBuffer JavaDoc();
157
158     //-- ClientEventHandler
159
public void gotConnected(ClientHandler handler)
160         throws SocketTimeoutException, IOException {
161         logger.fine("Connection opened : " + handler.getHostAddress());
162
163         handler.sendClientMsg("+OK +++++++++++++++++++++++++++++++++");
164         handler.sendClientMsg("+OK Welcome to QsAdminServer v 1.0 ");
165         handler.sendClientMsg("+OK +++++++++++++++++++++++++++++++++");
166
167         //v.2
168
if(plugin==null || runtime==null) {
169             plugin = (CommandPlugin)
170                 handler.getServer().getStoreObjects()[1];
171             //v1.3.2
172
runtime = Runtime.getRuntime();
173         }
174     }
175
176     public void lostConnection(ClientHandler handler)
177             throws IOException {
178         logger.fine("Connection lost : " + handler.getHostAddress());
179     }
180     public void closingConnection(ClientHandler handler)
181             throws IOException {
182         logger.fine("Connection closing : " + handler.getHostAddress());
183     }
184     //-- ClientEventHandler
185

186     public void handleCommand(ClientHandler handler, String JavaDoc command)
187             throws SocketTimeoutException, IOException {
188         if(command==null || command.trim().equals("")) {
189             handler.sendClientMsg("-ERR No command");
190             return;
191         }
192         
193         //v1.2 - plugin
194
if( plugin != null && plugin.handleCommand(handler,command) ) {
195             logger.fine("Handled by plugin.");
196             return;
197         }
198         QSAdminServer adminServer = (QSAdminServer)
199             handler.getServer().getStoreObjects()[2];
200
201         StringTokenizer JavaDoc st = new StringTokenizer JavaDoc(command," ");
202         String JavaDoc cmd = null;
203         cmd = st.nextToken().toLowerCase();
204         String JavaDoc param[] = new String JavaDoc[st.countTokens()];
205         
206         QuickServer target = null;
207         for (int i=0;st.hasMoreTokens();i++)
208             param[i] = st.nextToken();
209
210         if(command.equals("start console")) { /*v1.4.5*/
211             QSAdminShell.getInstance(
212                 (QuickServer) handler.getServer().getStoreObjects()[0], null);
213             handler.sendClientMsg("+OK QSAdminShell is started.");
214             return;
215         } else if(command.equals("stop console")) { /*v1.4.5*/
216             QSAdminShell shell = QSAdminShell.getInstance(null, null);
217             if(shell!=null) {
218                 try {
219                     shell.stopShell();
220                 } catch(Exception JavaDoc err) {
221                     handler.sendClientMsg("-ERR Error stopping QSAdminShell: "+err);
222                 }
223                 handler.sendClientMsg("+OK QSAdminShell is stopped.");
224             } else {
225                 handler.sendClientMsg("-ERR QSAdminShell is not running.");
226             }
227             return;
228         }
229
230         if(param.length > 0) {
231             if( param[0].equals("server") )
232                 target = (QuickServer) handler.getServer().getStoreObjects()[0];
233             else if( param[0].equals("self") )
234                 target = handler.getServer();
235             else {
236                 handler.sendClientMsg("-ERR Bad <<target>> : "+param[0]);
237                 return;
238             }
239         }
240  
241         if(cmd.equals("help")) {
242             handler.sendClientMsg("+OK info follows"+"\r\n"+
243                 "Refer Api Docs for org.quickserver.net.qsadmin.CommandHandler");
244             handler.sendClientMsg(".");
245             return;
246         } else if(cmd.equals("quit")) {
247             handler.sendClientMsg("+OK Bye ;-)");
248             handler.closeConnection();
249             return;
250         } else if(cmd.equals("shutdown")) {
251             try {
252                 QuickServer controlServer =
253                     (QuickServer) handler.getServer().getStoreObjects()[0];
254                 if(controlServer!=null && controlServer.isClosed()==false) {
255                     controlServer.stopServer();
256                 }
257                 if(handler.getServer()!=null && handler.getServer().isClosed()==false) {
258                     handler.getServer().stopServer();
259                 }
260
261                 QSAdminShell shell = QSAdminShell.getInstance(null, null);
262                 if(shell!=null) {
263                     try {
264                         shell.stopShell();
265                     } catch(Exception JavaDoc err) {
266                         logger.warning("Error stoping shell: "+err);
267                     }
268                 }
269
270                 handler.sendClientMsg("+OK Done");
271             } catch (AppException e) {
272                 handler.sendClientMsg("-ERR "+e);
273             }
274             return;
275         } else if(cmd.equals("version")) {
276             handler.sendClientMsg("+OK "+QuickServer.getVersion());
277             return;
278         } else if(cmd.equals("kill") || cmd.equals("exit")) /*v1.3,v1.3.2*/{
279             StringBuffer JavaDoc errBuf = new StringBuffer JavaDoc();
280             QuickServer controlServer =
281                 (QuickServer) handler.getServer().getStoreObjects()[0];
282             int exitCode = 0;
283
284             if(param.length!=0) {
285                 try {
286                     exitCode = Integer.parseInt(param[0]);
287                 } catch(Exception JavaDoc nfe) {/*ignore*/}
288             }
289
290             try {
291                 if(controlServer!=null && controlServer.isClosed()==false) {
292                     try {
293                         controlServer.stopServer();
294                     } catch(AppException ae) {
295                         errBuf.append(ae.toString());
296                     }
297                 }
298                 if(handler.getServer()!=null && handler.getServer().isClosed()==false) {
299                     try {
300                         handler.getServer().stopServer();
301                     } catch(AppException ae) {
302                         errBuf.append(ae.toString());
303                     }
304                 }
305
306                 QSAdminShell shell = QSAdminShell.getInstance(null, null);
307                 if(shell!=null) {
308                     try {
309                         shell.stopShell();
310                     } catch(Exception JavaDoc err) {
311                         errBuf.append(err.toString());
312                     }
313                 }
314
315                 if(errBuf.length()==0)
316                     handler.sendClientMsg("+OK Done");
317                 else
318                     handler.sendClientMsg("+OK Done, Errors: "+errBuf.toString());
319             } catch (Exception JavaDoc e) {
320                 handler.sendClientMsg("-ERR Exception : "+e+"\r\n"+errBuf.toString());
321                 if(exitCode==0) exitCode = 1;
322             } finally {
323                 try {
324                     if(controlServer!=null)
325                         controlServer.closeAllPools();
326                     if(handler.getServer()!=null)
327                         handler.getServer().closeAllPools();
328                 } catch(Exception JavaDoc er) {
329                     logger.warning("Error closing pools: "+er);
330                 }
331                 System.exit(exitCode);
332             }
333             return;
334         } else if(cmd.equals("memoryinfo")) { /*v1.3.2*/
335             //Padding : Total:Used:Max
336
float totalMemory = (float) runtime.totalMemory();
337             float usedMemory = totalMemory - (float) runtime.freeMemory();
338             float maxMemory = (float) runtime.maxMemory();
339             handler.sendClientMsg("+OK "+totalMemory+":"+usedMemory+":"+maxMemory);
340             return;
341         } else if(cmd.equals("systeminfo")) { /*v1.4.5*/
342             handler.sendClientMsg("+OK info follows");
343             handler.sendClientMsg(MyString.getSystemInfo(target.getVersion()));
344             handler.sendClientMsg(".");
345             return;
346         } else if(param.length==0) {
347             handler.sendClientMsg("-ERR Bad Command or No Param : ->"+cmd+"<-");
348             return;
349         }
350         
351         if(cmd.equals("start")) {
352             try {
353                 target.startServer();
354                 handler.sendClientMsg("+OK Server Started");
355             } catch (AppException e) {
356                 handler.sendClientMsg("-ERR "+e);
357             }
358             return;
359         } else if(cmd.equals("stop")) {
360             try {
361                 target.stopServer();
362                 handler.sendClientMsg("+OK Server Stopped");
363             } catch (AppException e) {
364                 handler.sendClientMsg("-ERR "+e);
365             }
366             return;
367         } else if(cmd.equals("restart")) {
368             try {
369                 target.stopServer();
370                 target.startServer();
371                 handler.sendClientMsg("+OK Server Restarted");
372             } catch (AppException e) {
373                 handler.sendClientMsg("-ERR "+e);
374             }
375             return;
376         } else if(cmd.equals("info")) {
377             handler.sendClientMsg("+OK info follows");
378             handler.sendClientMsg(""+target);
379             handler.sendClientMsg("Running : "+!target.isClosed());
380             handler.sendClientMsg("Max Client Allowed : "+target.getMaxConnection() );
381             handler.sendClientMsg("No Client Connected : "+target.getClientCount() );
382             if(target.isRunningSecure()==true) {
383                 handler.sendClientMsg("Running in secure mode : "+
384                     target.getSecure().getProtocol() );
385             } else {
386                 handler.sendClientMsg("Running in non-secure mode");
387             }
388             handler.sendClientMsg("Server Mode : "+target.getBasicConfig().getServerMode());
389             handler.sendClientMsg(".");
390             return;
391         } else if(cmd.equals("noclient")) {
392             handler.sendClientMsg("+OK "+target.getClientCount() );
393             return;
394         } else if(cmd.equals("running")) {
395             handler.sendClientMsg("+OK "+!target.isClosed() );
396             return;
397         } else if(cmd.equals("suspendservice")) {
398             handler.sendClientMsg("+OK "+target.suspendService() );
399             return;
400         } else if(cmd.equals("resumeservice")) {
401             handler.sendClientMsg("+OK "+target.resumeService() );
402             return;
403         } else if(cmd.equals("client-thread-pool-info")) /*v1.3.2*/{
404             temp.setLength(0);//used:idle
405
if(PoolHelper.isPoolOpen(target.getClientPool().getObjectPool())==true) {
406                 temp.append(target.getClientPool().getNumActive());
407                 temp.append(':');
408                 temp.append(target.getClientPool().getNumIdle());
409             } else {
410                 temp.append("0:0");
411             }
412             handler.sendClientMsg("+OK "+temp.toString() );
413             return;
414         } else if(cmd.equals("client-thread-pool-dump")) /*v1.4.5*/{
415             if(PoolHelper.isPoolOpen(target.getClientPool().getObjectPool())==true) {
416                 handler.sendClientMsg("+OK info follows");
417                 ClientThread ct = null;
418                 synchronized(target.getClientPool().getObjectToSynchronize()) {
419                     Iterator iterator = target.getClientPool().getAllClientThread();
420                     while(iterator.hasNext()) {
421                         ct = (ClientThread)iterator.next();
422                         handler.sendClientMsg(ct.toString());
423                     }
424                 }
425                 handler.sendClientMsg(".");
426             } else {
427                 handler.sendClientMsg("-ERR Pool Closed");
428             }
429             return;
430         } else if(cmd.equals("client-handler-pool-dump")) /*v1.4.6*/{
431             
432             ObjectPool objectPool = target.getClientHandlerPool();
433
434             if(PoolHelper.isPoolOpen(objectPool)==true) {
435                 if(QSObjectPool.class.isInstance(objectPool)==false) {
436                     handler.sendClientMsg("-ERR System Error!");
437                 }
438
439                 ClientIdentifier clientIdentifier = target.getClientIdentifier();
440                 ClientHandler foundClientHandler = null;
441                 synchronized(clientIdentifier.getObjectToSynchronize()) {
442                     Iterator iterator = clientIdentifier.findAllClient();
443                     handler.sendClientMsg("+OK info follows");
444                     while(iterator.hasNext()) {
445                         foundClientHandler = (ClientHandler) iterator.next();
446                         handler.sendClientMsg(foundClientHandler.info());
447                     }
448                 }
449                 handler.sendClientMsg(".");
450             } else {
451                 handler.sendClientMsg("-ERR Pool Closed");
452             }
453             return;
454         } else if(cmd.equals("client-data-pool-info")) /*v1.3.2*/{
455             temp.setLength(0);//used:idle
456
if(target.getClientDataPool()!=null) {
457                 if(PoolHelper.isPoolOpen(target.getClientDataPool())==true) {
458                     temp.append(target.getClientDataPool().getNumActive());
459                     temp.append(':');
460                     temp.append(target.getClientDataPool().getNumIdle());
461                     handler.sendClientMsg("+OK "+temp.toString() );
462                 } else {
463                     handler.sendClientMsg("-ERR Client Data Pool Closed");
464                 }
465             } else {
466                 handler.sendClientMsg("-ERR No Client Data Pool");
467             }
468             return;
469         } if(cmd.equals("byte-buffer-pool-info")) /*v1.4.6*/{
470             temp.setLength(0);//used:idle
471
if(target.getByteBufferPool()!=null) {
472                 if(PoolHelper.isPoolOpen(target.getByteBufferPool())==true) {
473                     temp.append(target.getByteBufferPool().getNumActive());
474                     temp.append(':');
475                     temp.append(target.getByteBufferPool().getNumIdle());
476                     handler.sendClientMsg("+OK "+temp.toString() );
477                 } else {
478                     handler.sendClientMsg("-ERR ByteBuffer Pool Closed");
479                 }
480             } else {
481                 handler.sendClientMsg("-ERR No ByteBuffer Pool");
482             }
483             return;
484         } else if(cmd.equals("all-pool-info")) /*v1.4.5*/{
485             handler.sendClientMsg("+OK info follows");
486             temp.setLength(0);//used:idle
487

488             if(PoolHelper.isPoolOpen(target.getClientPool().getObjectPool())==true) {
489                 temp.append("Client Thread Pool - ");
490                 temp.append("Num Active: ");
491                 temp.append(target.getClientPool().getNumActive());
492                 temp.append(", Num Idle: ");
493                 temp.append(target.getClientPool().getNumIdle());
494                 temp.append(", Max Idle: ");
495                 temp.append(target.getClientPool().getPoolConfig().getMaxIdle());
496                 temp.append(", Max Active: ");
497                 temp.append(target.getClientPool().getPoolConfig().getMaxActive());
498             } else {
499                 temp.append("Byte Buffer Pool - Closed");
500             }
501             handler.sendClientMsg(temp.toString());
502             temp.setLength(0);
503
504             if(PoolHelper.isPoolOpen(target.getClientHandlerPool())==true) {
505                 temp.append("Client Handler Pool - ");
506                 temp.append("Num Active: ");
507                 temp.append(target.getClientHandlerPool().getNumActive());
508                 temp.append(", Num Idle: ");
509                 temp.append(target.getClientHandlerPool().getNumIdle());
510                 temp.append(", Max Idle: ");
511                 temp.append(target.getBasicConfig().getObjectPoolConfig().getClientHandlerObjectPoolConfig().getMaxIdle());
512                 temp.append(", Max Active: ");
513                 temp.append(target.getBasicConfig().getObjectPoolConfig().getClientHandlerObjectPoolConfig().getMaxActive());
514             } else {
515                 temp.append("Client Handler Pool - Closed");
516             }
517             handler.sendClientMsg(temp.toString());
518             temp.setLength(0);
519
520             if(target.getByteBufferPool()!=null) {
521                 if(PoolHelper.isPoolOpen(target.getByteBufferPool())==true) {
522                     temp.append("ByteBuffer Pool - ");
523                     temp.append("Num Active: ");
524                     temp.append(target.getByteBufferPool().getNumActive());
525                     temp.append(", Num Idle: ");
526                     temp.append(target.getByteBufferPool().getNumIdle());
527                     temp.append(", Max Idle: ");
528                     temp.append(target.getBasicConfig().getObjectPoolConfig().getByteBufferObjectPoolConfig().getMaxIdle());
529                     temp.append(", Max Active: ");
530                     temp.append(target.getBasicConfig().getObjectPoolConfig().getByteBufferObjectPoolConfig().getMaxActive());
531                 } else {
532                     temp.append("Byte Buffer Pool - Closed");
533                 }
534             } else {
535                 temp.append("Byte Buffer Pool - Not Used");
536             }
537             handler.sendClientMsg(temp.toString());
538             temp.setLength(0);
539
540             if(target.getClientDataPool()!=null) {
541                 if(PoolHelper.isPoolOpen(target.getClientDataPool())==true) {
542                     temp.append("Client Data Pool - ");
543                     temp.append("Num Active: ");
544                     temp.append(target.getClientDataPool().getNumActive());
545                     temp.append(", Num Idle: ");
546                     temp.append(target.getClientDataPool().getNumIdle());
547                     temp.append(", Max Idle: ");
548                     temp.append(target.getBasicConfig().getObjectPoolConfig().getClientDataObjectPoolConfig().getMaxIdle());
549                     temp.append(", Max Active: ");
550                     temp.append(target.getBasicConfig().getObjectPoolConfig().getClientDataObjectPoolConfig().getMaxActive());
551                 } else {
552                     temp.append("Client Data Pool - Closed");
553                 }
554             } else {
555                 temp.append("Client Data Pool - Not Used");
556             }
557             handler.sendClientMsg(temp.toString());
558             temp.setLength(0);
559
560             handler.sendClientMsg(".");
561             return;
562         } else if(cmd.equals("set")) {
563             if(param.length < 3)/*target,key,value*/ {
564                 handler.sendClientMsg("-ERR "+"insufficient param");
565                 return;
566             }
567             if(param[2].equals("null"))
568                 param[2]=null;
569             try {
570                 if(param[1].equals("maxClient")) {
571                     long no = Long.parseLong(param[2]);
572                     target.setMaxConnection(no);
573                 } else if(param[1].equals("maxClientMsg")) {
574                     target.setMaxConnectionMsg(param[2]);
575                 } else if(param[1].equals("port")) {
576                     long no = Long.parseLong(param[2]);
577                     target.setPort((int)no);
578                 } else if(param[1].equals("port")) {
579                     long no = Long.parseLong(param[2]);
580                     target.setPort((int)no);
581                 } else if(param[1].equals("maxAuthTry")) {
582                     int no = Integer.parseInt(param[2]);
583                     target.setMaxAuthTry(no);
584                 } else if(param[1].equals("maxAuthTryMsg")) {
585                     target.setMaxAuthTryMsg(param[2]);
586                 } else if(param[1].equals("clientEventHandler")) { /*v1.4.6*/
587                     target.setClientEventHandler(param[2]);
588                 } else if(param[1].equals("clientCommandHandler")) {
589                     target.setClientCommandHandler(param[2]);
590                 } else if(param[1].equals("clientWriteHandler")) { /*v1.4.6*/
591                     target.setClientWriteHandler(param[2]);
592                 } else if(param[1].equals("clientObjectHandler")) {
593                     target.setClientObjectHandler(param[2]); /*v1.3*/
594                 } else if(param[1].equals("clientAuthenticationHandler")) {
595                     target.setClientAuthenticationHandler(param[2]);
596                 } else if(param[1].equals("clientData")) {
597                     target.setClientData(param[2]);
598                 } else if(param[1].equals("clientExtendedEventHandler")) { /*v1.4.6*/
599                     target.setClientExtendedEventHandler(param[2]);
600                 } else if(param[1].equals("timeout")) {
601                     long no = Long.parseLong(param[2]);
602                     target.setTimeout((int)no);
603                 } else if(param[1].equals("timeoutMsg")) {
604                     target.setTimeoutMsg(param[2]); /* v1.3 */
605                 } else if(param[1].equals("plugin")) /* v1.2*/{
606                     if(param[0].equals("self")) {
607                         try {
608                             adminServer.setCommandPlugin(param[2]);
609                         } catch(Exception JavaDoc e) {
610                             handler.sendClientMsg("-ERR not set : "+e);
611                             return;
612                         }
613                     } else {
614                         handler.sendClientMsg("-ERR Bad target : "+param[0]+" self is only allowed.");
615                         return;
616                     }
617                 } else if(param[1].equals("consoleLoggingFormatter")) {
618                     target.setConsoleLoggingFormatter(param[2]); /* v1.3 */
619                 } else if(param[1].equals("consoleLoggingLevel")) { /* v1.3 */
620                     if(param[2].endsWith("SEVERE"))
621                         target.setConsoleLoggingLevel(Level.SEVERE);
622                     else if(param[2].endsWith("WARNING"))
623                         target.setConsoleLoggingLevel(Level.WARNING);
624                     else if(param[2].endsWith("INFO"))
625                         target.setConsoleLoggingLevel(Level.INFO);
626                     else if(param[2].endsWith("CONFIG"))
627                         target.setConsoleLoggingLevel(Level.CONFIG);
628                     else if(param[2].endsWith("FINE"))
629                         target.setConsoleLoggingLevel(Level.FINE);
630                     else if(param[2].endsWith("FINER"))
631                         target.setConsoleLoggingLevel(Level.FINER);
632                     else if(param[2].endsWith("FINEST"))
633                         target.setConsoleLoggingLevel(Level.FINEST);
634                     else if(param[2].endsWith("ALL"))
635                         target.setConsoleLoggingLevel(Level.ALL);
636                     else if(param[2].endsWith("OFF"))
637                         target.setConsoleLoggingLevel(Level.OFF);
638                     else {
639                         handler.sendClientMsg("-ERR Bad Level "+param[2]);
640                         return;
641                     }
642                 } else if(param[1].equals("loggingLevel")) { /* v1.3.1 */
643                     if(param[2].endsWith("SEVERE"))
644                         target.setLoggingLevel(Level.SEVERE);
645                     else if(param[2].endsWith("WARNING"))
646                         target.setLoggingLevel(Level.WARNING);
647                     else if(param[2].endsWith("INFO"))
648                         target.setLoggingLevel(Level.INFO);
649                     else if(param[2].endsWith("CONFIG"))
650                         target.setLoggingLevel(Level.CONFIG);
651                     else if(param[2].endsWith("FINE"))
652                         target.setLoggingLevel(Level.FINE);
653                     else if(param[2].endsWith("FINER"))
654                         target.setLoggingLevel(Level.FINER);
655                     else if(param[2].endsWith("FINEST"))
656                         target.setLoggingLevel(Level.FINEST);
657                     else if(param[2].endsWith("ALL"))
658                         target.setLoggingLevel(Level.ALL);
659                     else if(param[2].endsWith("OFF"))
660                         target.setLoggingLevel(Level.OFF);
661                     else {
662                         handler.sendClientMsg("-ERR Bad Level "+param[2]);
663                         return;
664                     }
665                 } else if(param[1].equals("communicationLogging")) {
666                     if(param[2].equals("true"))/* v1.3.2 */
667                         target.setCommunicationLogging(true);
668                     else
669                         target.setCommunicationLogging(false);
670                 } else if(param[1].equals("objectPoolConfig-maxActive")) {
671                     int no = Integer.parseInt(param[2]);
672                     target.getConfig().getObjectPoolConfig().setMaxActive(no);
673                 } else if(param[1].equals("objectPoolConfig-maxIdle")) {
674                     int no = Integer.parseInt(param[2]);
675                     target.getConfig().getObjectPoolConfig().setMaxIdle(no);
676                 } else if(param[1].equals("objectPoolConfig-initSize")) {
677                     int no = Integer.parseInt(param[2]);
678                     target.getConfig().getObjectPoolConfig().setInitSize(no);
679                 } else {
680                     handler.sendClientMsg("-ERR Bad Set Key : "+param[1]);
681                     return;
682                 }
683                 handler.sendClientMsg("+OK Set");
684             } catch(Exception JavaDoc e) {
685                 handler.sendClientMsg("-ERR "+e);
686             }
687             return;
688         } else if(cmd.equals("get")) {
689             if(param.length < 2)/*target,key*/ {
690                 handler.sendClientMsg("-ERR "+"insufficient param");
691                 return;
692             }
693             try {
694                 if(param[1].equals("maxClient")) {
695                     long no = target.getMaxConnection();
696                     handler.sendClientMsg("+OK "+no);
697                 } else if(param[1].equals("maxClientMsg")) {
698                     String JavaDoc msg = target.getMaxConnectionMsg();
699                     msg = MyString.replaceAll(msg, "\n", "\\n");
700                     handler.sendClientMsg("+OK "+msg);
701                 } else if(param[1].equals("port")) {
702                     long no = target.getPort();
703                     handler.sendClientMsg("+OK "+no);
704                 } else if(param[1].equals("maxAuthTry")) {
705                     int no = target.getMaxAuthTry();
706                     handler.sendClientMsg("+OK "+no);
707                 } else if(param[1].equals("maxAuthTryMsg")) {
708                     String JavaDoc msg=target.getMaxAuthTryMsg();
709                     msg = MyString.replaceAll(msg, "\n", "\\n");
710                     handler.sendClientMsg("+OK "+msg);
711                 } else if(param[1].equals("clientEventHandler")) { /*v1.4.6*/
712                     String JavaDoc msg=target.getClientEventHandler();
713                     handler.sendClientMsg("+OK "+msg);
714                 } else if(param[1].equals("clientCommandHandler")) {
715                     String JavaDoc msg=target.getClientCommandHandler();
716                     handler.sendClientMsg("+OK "+msg);
717                 } else if(param[1].equals("clientWriteHandler")) { /*v1.4.6*/
718                     String JavaDoc msg=target.getClientWriteHandler();
719                     handler.sendClientMsg("+OK "+msg);
720                 } else if(param[1].equals("clientObjectHandler")) {
721                     String JavaDoc msg=target.getClientObjectHandler();
722                     handler.sendClientMsg("+OK "+msg);
723                 } else if(param[1].equals("clientAuthenticationHandler")) {
724                     String JavaDoc msg=target.getClientAuthenticationHandler();
725                     handler.sendClientMsg("+OK "+msg);
726                 } else if(param[1].equals("clientData")) {
727                     String JavaDoc msg=target.getClientData();
728                     handler.sendClientMsg("+OK "+msg);
729                 } else if(param[1].equals("clientExtendedEventHandler")) { /*v1.4.6*/
730                     String JavaDoc msg=target.getClientExtendedEventHandler();
731                     handler.sendClientMsg("+OK "+msg);
732                 } else if(param[1].equals("timeout")) {
733                     String JavaDoc msg=""+target.getTimeout();
734                     handler.sendClientMsg("+OK "+msg);
735                 } else if(param[1].equals("timeoutMsg")) {
736                     String JavaDoc msg=""+target.getTimeoutMsg();
737                     msg = MyString.replaceAll(msg, "\n", "\\n");
738                     handler.sendClientMsg("+OK "+msg);
739                 } else if(param[1].equals("plugin")) /* v1.2*/{
740                     if(param[0].equals("self")) {
741                         String JavaDoc msg = adminServer.getCommandPlugin();
742                         handler.sendClientMsg("+OK "+msg);
743                     } else {
744                         handler.sendClientMsg("-ERR Bad target : "+param[0]+" self is only allowed.");
745                     }
746                 } else if(param[1].equals("consoleLoggingFormatter")) {
747                     String JavaDoc msg=""+target.getConsoleLoggingFormatter(); /* v1.3 */
748                     handler.sendClientMsg("+OK "+msg);
749                 } else if(param[1].equals("consoleLoggingLevel")) { /* v1.3 */
750                     String JavaDoc msg=""+target.getConsoleLoggingLevel();
751                     handler.sendClientMsg("+OK "+msg);
752                 } else if(param[1].equals("serviceState")) {
753                     int state=target.getServiceState(); /*v1.3*/
754                     if(state==org.quickserver.net.Service.INIT)
755                         handler.sendClientMsg("+OK INIT");
756                     else if(state==org.quickserver.net.Service.RUNNING)
757                         handler.sendClientMsg("+OK RUNNING");
758                     else if(state==org.quickserver.net.Service.STOPPED)
759                         handler.sendClientMsg("+OK STOPPED");
760                     else if(state==org.quickserver.net.Service.SUSPENDED)
761                         handler.sendClientMsg("+OK SUSPENDED");
762                     else
763                         handler.sendClientMsg("+OK UNKNOWN");
764                 } else if(param[1].equals("communicationLogging")) {
765                     String JavaDoc msg=""+target.getCommunicationLogging();
766                     handler.sendClientMsg("+OK "+msg);
767                 } else if(param[1].equals("objectPoolConfig-maxActive")) {
768                     String JavaDoc msg=""+target.getConfig().getObjectPoolConfig().getMaxActive();
769                     handler.sendClientMsg("+OK "+msg);
770                 } else if(param[1].equals("objectPoolConfig-maxIdle")) {
771                     String JavaDoc msg=""+target.getConfig().getObjectPoolConfig().getMaxIdle();
772                     handler.sendClientMsg("+OK "+msg);
773                 } else if(param[1].equals("objectPoolConfig-initSize")) {
774                     String JavaDoc msg=""+target.getConfig().getObjectPoolConfig().getInitSize();
775                     handler.sendClientMsg("+OK "+msg);
776                 } else {
777                     handler.sendClientMsg("-ERR Bad Get Key : "+param[1]);
778                 }
779             } catch(Exception JavaDoc e) {
780                 handler.sendClientMsg("-ERR "+e);
781             }
782             return;
783         } else {
784             handler.sendClientMsg("-ERR Bad Command : "+cmd);
785         }
786         return;
787     }
788 }
789
Popular Tags