Source Code Cross Referenced for CommandHandler.java in  » Net » QuickServer » org » quickserver » net » qsadmin » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Net » QuickServer » org.quickserver.net.qsadmin 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * This file is part of the QuickServer library 
003:         * Copyright (C) QuickServer.org
004:         *
005:         * Use, modification, copying and distribution of this software is subject to
006:         * the terms and conditions of the GNU Lesser General Public License. 
007:         * You should have received a copy of the GNU LGP License along with this 
008:         * library; if not, you can download a copy from <http://www.quickserver.org/>.
009:         *
010:         * For questions, suggestions, bug-reports, enhancement-requests etc.
011:         * visit http://www.quickserver.org
012:         *
013:         */
014:
015:        package org.quickserver.net.qsadmin;
016:
017:        import java.net.*;
018:        import java.io.*;
019:        import java.util.StringTokenizer;
020:
021:        import org.quickserver.net.server.ClientCommandHandler;
022:        import org.quickserver.net.server.ClientEventHandler;
023:        import org.quickserver.net.server.ClientHandler;
024:        import org.quickserver.net.server.QuickServer;
025:        import org.quickserver.net.AppException;
026:
027:        import java.util.logging.*;
028:
029:        import org.quickserver.util.*;
030:        import org.quickserver.util.pool.thread.*;
031:        import java.util.*;
032:        import org.quickserver.util.pool.*;
033:        import org.apache.commons.pool.ObjectPool;
034:        import org.quickserver.net.server.ClientIdentifier;
035:
036:        /**
037:         * ClientCommandHandler for QSAdminServer.
038:         * <p>
039:         * = Protocol =<br>
040:         * Each response starts with a status.
041:         * <ul>
042:         *  <li>+OK = Success
043:         *  <li>-ERR = Failed
044:         * </ul>
045:         * If response if one lined then it follows the status.
046:         * Else You will get "info follows" as the first line
047:         * followed by with many lines of response ending by a 
048:         * dot in a line by itself. i.e.,  &lt;CR&gt;&lt;LF&gt;.&lt;CR&gt;&lt;LF&gt;<br>
049:         * Command supported are give below .. [ Note: &lt;&lt;target&gt;&gt; = server|self ]
050:         * <br>&nbsp;<br>
051:         * <table align="center" border=1>
052:         * <tr><th>Command</th><th>Param</th><th>Effect</th></tr>
053:         * <tr><td>start</td><td>&lt;&lt;target&gt;&gt;</td><td>Starts target.</td></tr>
054:         * <tr><td>stop</td><td>&lt;&lt;target&gt;&gt;</td><td>Stops target.</td></tr>
055:         * <tr><td>restart</td><td>&lt;&lt;target&gt;&gt;</td><td>=stop+start command</td></tr>
056:         * <tr><td>shutdown</td><td>&nbsp;</td><td>Stops server and self. </td></tr>
057:         * <tr><td>kill or exit</td><td>&nbsp;</td><td>Stops server and self and kill all threads. </td></tr>
058:         * <tr><td>info</td><td>&lt;&lt;target&gt;&gt;</td><td>Information about target.</td></tr>
059:         * <tr><td>noclient</td><td>&lt;&lt;target&gt;&gt;</td><td>No Client connected to the target.</td></tr>
060:         * <tr><td>running</td><td>&lt;&lt;target&gt;&gt;</td><td>Checks if target is running.</td></tr>
061:         * <tr><td>get</td><td>&lt;&lt;target&gt;&gt; maxClient</td><td>Gets max no of client for the target.</td></tr>
062:         * <tr><td>get</td><td>&lt;&lt;target&gt;&gt; port</td><td>Gets port for the target.</td></tr>
063:         * <tr><td>get</td><td>&lt;&lt;target&gt;&gt; maxAuthTryMsg</td><td>Gets maxAuthTryMsg for the target. </td></tr>
064:         * <tr><td>get</td><td>&lt;&lt;target&gt;&gt; clientCommandHandler</td><td>Gets ClientCommandHandler class for the target.</td></tr>
065:         * <tr><td>get</td><td>&lt;&lt;target&gt;&gt; clientAuthenticationHandler</td><td>Gets ClientAuthenticationHandler class for the target.</td></tr>
066:         * <tr><td>get</td><td>&lt;&lt;target&gt;&gt; clientData</td><td>Gets ClientData class for the target.</td></tr>
067:         * <tr><td>get</td><td>&lt;&lt;target&gt;&gt; timeout</td><td>Gets timeout set for clients for the target.</td></tr>
068:         * <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>
069:         * <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>
070:         * <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>
071:         * <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>
072:         * <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>
073:         * <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>
074:         * <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>
075:         * <tr><td>version</td><td>&nbsp;</td><td>Gets the version of the QuickServer library used.</td></tr>
076:         * <tr><td>quit</td><td>&nbsp;</td><td>Close session.</td></tr>
077:         * <tr><td colspan=3>New Command in v1.2 </td></tr>
078:         * <tr><td>get</td><td>self plugin</td><td>Gets pluggable command handler for QsAdminServer. *</td></tr>
079:         * <tr><td>set</td><td>self plugin &lt;&lt;full class name&gt;&gt;</td><td>Sets Pluggable command handler for QsAdminServer. *</td></tr>
080:         * <tr><td colspan=3>New Command in v1.3 </td></tr>
081:         * <tr><td>suspendService</td><td>&lt;&lt;target&gt;&gt;</td><td>Suspends target.</td></tr>
082:         * <tr><td>resumeService</td><td>&lt;&lt;target&gt;&gt;</td><td>Resume target.</td></tr>
083:         * <tr><td>get</td><td>&lt;&lt;target&gt;&gt; maxAuthTry</td><td>Gets maxAuthTry for the target.</td></tr>
084:         * <tr><td>set</td><td>&lt;&lt;target&gt;&gt; maxAuthTry</td><td>Sets maxAuthTry for the target.*</td></tr>
085:         * <tr><td>get</td><td>&lt;&lt;target&gt;&gt; clientObjectHandler</td><td>Gets ClientObjectHandler class for the target.</td></tr>
086:         * <tr><td>set</td><td>&lt;&lt;target&gt;&gt; clientObjectHandler</td><td>Sets ClientObjectHandler class for the target.*</td></tr>
087:         * <tr><td>get</td><td>&lt;&lt;target&gt;&gt; timeoutMsg</td><td>Gets timeout Message for the target.</td></tr>
088:         * <tr><td>set</td><td>&lt;&lt;target&gt;&gt; timeoutMsg</td><td>Sets timeout Message for the target.*</td></tr>
089:         * <tr><td>get</td><td>&lt;&lt;target&gt;&gt; serviceState</td><td>Gets Service State for the target.</td></tr>
090:         * <tr><td>get</td><td>&lt;&lt;target&gt;&gt; consoleLoggingFormatter</td><td>Sets consoleLoggingFormatter for the target.</td></tr>
091:         * <tr><td>set</td><td>&lt;&lt;target&gt;&gt; consoleLoggingFormatter</td><td>Sets consoleLoggingFormatter for the target.</td></tr>
092:         * <tr><td>get</td><td>&lt;&lt;target&gt;&gt; consoleLoggingLevel</td><td>Sets consoleLoggingLevel for the target. <br>
093:         * <tr><td>set</td><td>&lt;&lt;target&gt;&gt; consoleLoggingLevel</td><td>Sets consoleLoggingLevel for the target. <br>
094:         * [<code>SEVERE|WARNING|INFO|CONFIG|FINE|FINER|FINEST<code>]</td></tr>
095:         * <tr><td>set</td><td>&lt;&lt;target&gt;&gt; maxClientMsg</td><td>Sets maxClientMsg for the target.</td></tr>
096:         * <tr><td>get</td><td>&lt;&lt;target&gt;&gt; maxClientMsg</td><td>Gets maxClientMsg for the target.</td></tr>
097:         * <tr><td colspan=3>New Command in v1.3.1 </td></tr>
098:         * <tr><td>set</td><td>&lt;&lt;target&gt;&gt; loggingLevel</td><td>Sets LoggingLevel for the target. <br>
099:         * [<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,
152:                ClientEventHandler {
153:            private static Logger logger = Logger
154:                    .getLogger(CommandHandler.class.getName());
155:
156:            private CommandPlugin plugin;
157:            private Runtime runtime;
158:            StringBuffer temp = new StringBuffer();
159:
160:            //-- ClientEventHandler
161:            public void gotConnected(ClientHandler handler)
162:                    throws SocketTimeoutException, IOException {
163:                logger.fine("Connection opened : " + handler.getHostAddress());
164:
165:                handler.sendClientMsg("+OK +++++++++++++++++++++++++++++++++");
166:                handler.sendClientMsg("+OK   Welcome to QsAdminServer v 1.0 ");
167:                handler.sendClientMsg("+OK +++++++++++++++++++++++++++++++++");
168:
169:                //v.2
170:                if (plugin == null || runtime == null) {
171:                    plugin = (CommandPlugin) handler.getServer()
172:                            .getStoreObjects()[1];
173:                    //v1.3.2
174:                    runtime = Runtime.getRuntime();
175:                }
176:            }
177:
178:            public void lostConnection(ClientHandler handler)
179:                    throws IOException {
180:                logger.fine("Connection lost : " + handler.getHostAddress());
181:            }
182:
183:            public void closingConnection(ClientHandler handler)
184:                    throws IOException {
185:                logger.fine("Connection closing : " + handler.getHostAddress());
186:            }
187:
188:            //-- ClientEventHandler
189:
190:            public void handleCommand(ClientHandler handler, String command)
191:                    throws SocketTimeoutException, IOException {
192:                if (command == null || command.trim().equals("")) {
193:                    handler.sendClientMsg("-ERR No command");
194:                    return;
195:                }
196:
197:                //v1.2 - plugin
198:                if (plugin != null && plugin.handleCommand(handler, command)) {
199:                    logger.fine("Handled by plugin.");
200:                    return;
201:                }
202:                QSAdminServer adminServer = (QSAdminServer) handler.getServer()
203:                        .getStoreObjects()[2];
204:
205:                StringTokenizer st = new StringTokenizer(command, " ");
206:                String cmd = null;
207:                cmd = st.nextToken().toLowerCase();
208:                String param[] = new String[st.countTokens()];
209:
210:                QuickServer target = null;
211:                for (int i = 0; st.hasMoreTokens(); i++)
212:                    param[i] = st.nextToken();
213:
214:                if (command.equals("start console")) { /*v1.4.5*/
215:                    QSAdminShell.getInstance((QuickServer) handler.getServer()
216:                            .getStoreObjects()[0], null);
217:                    handler.sendClientMsg("+OK QSAdminShell is started.");
218:                    return;
219:                } else if (command.equals("stop console")) { /*v1.4.5*/
220:                    QSAdminShell shell = QSAdminShell.getInstance(null, null);
221:                    if (shell != null) {
222:                        try {
223:                            shell.stopShell();
224:                        } catch (Exception err) {
225:                            handler
226:                                    .sendClientMsg("-ERR Error stopping QSAdminShell: "
227:                                            + err);
228:                        }
229:                        handler.sendClientMsg("+OK QSAdminShell is stopped.");
230:                    } else {
231:                        handler
232:                                .sendClientMsg("-ERR QSAdminShell is not running.");
233:                    }
234:                    return;
235:                }
236:
237:                if (param.length > 0) {
238:                    if (param[0].equals("server"))
239:                        target = (QuickServer) handler.getServer()
240:                                .getStoreObjects()[0];
241:                    else if (param[0].equals("self"))
242:                        target = handler.getServer();
243:                    else {
244:                        handler.sendClientMsg("-ERR Bad <<target>> : "
245:                                + param[0]);
246:                        return;
247:                    }
248:                }
249:
250:                if (cmd.equals("help")) {
251:                    handler
252:                            .sendClientMsg("+OK info follows"
253:                                    + "\r\n"
254:                                    + "Refer Api Docs for org.quickserver.net.qsadmin.CommandHandler");
255:                    handler.sendClientMsg(".");
256:                    return;
257:                } else if (cmd.equals("quit")) {
258:                    handler.sendClientMsg("+OK Bye ;-)");
259:                    handler.closeConnection();
260:                    return;
261:                } else if (cmd.equals("shutdown")) {
262:                    try {
263:                        QuickServer controlServer = (QuickServer) handler
264:                                .getServer().getStoreObjects()[0];
265:                        if (controlServer != null
266:                                && controlServer.isClosed() == false) {
267:                            controlServer.stopServer();
268:                        }
269:                        if (handler.getServer() != null
270:                                && handler.getServer().isClosed() == false) {
271:                            handler.getServer().stopServer();
272:                        }
273:
274:                        QSAdminShell shell = QSAdminShell.getInstance(null,
275:                                null);
276:                        if (shell != null) {
277:                            try {
278:                                shell.stopShell();
279:                            } catch (Exception err) {
280:                                logger.warning("Error stoping shell: " + err);
281:                            }
282:                        }
283:
284:                        handler.sendClientMsg("+OK Done");
285:                    } catch (AppException e) {
286:                        handler.sendClientMsg("-ERR " + e);
287:                    }
288:                    return;
289:                } else if (cmd.equals("version")) {
290:                    handler.sendClientMsg("+OK " + QuickServer.getVersion());
291:                    return;
292:                } else if (cmd.equals("kill") || cmd.equals("exit")) /*v1.3,v1.3.2*/{
293:                    StringBuffer errBuf = new StringBuffer();
294:                    QuickServer controlServer = (QuickServer) handler
295:                            .getServer().getStoreObjects()[0];
296:                    int exitCode = 0;
297:
298:                    if (param.length != 0) {
299:                        try {
300:                            exitCode = Integer.parseInt(param[0]);
301:                        } catch (Exception nfe) {/*ignore*/
302:                        }
303:                    }
304:
305:                    try {
306:                        if (controlServer != null
307:                                && controlServer.isClosed() == false) {
308:                            try {
309:                                controlServer.stopServer();
310:                            } catch (AppException ae) {
311:                                errBuf.append(ae.toString());
312:                            }
313:                        }
314:                        if (handler.getServer() != null
315:                                && handler.getServer().isClosed() == false) {
316:                            try {
317:                                handler.getServer().stopServer();
318:                            } catch (AppException ae) {
319:                                errBuf.append(ae.toString());
320:                            }
321:                        }
322:
323:                        QSAdminShell shell = QSAdminShell.getInstance(null,
324:                                null);
325:                        if (shell != null) {
326:                            try {
327:                                shell.stopShell();
328:                            } catch (Exception err) {
329:                                errBuf.append(err.toString());
330:                            }
331:                        }
332:
333:                        if (errBuf.length() == 0)
334:                            handler.sendClientMsg("+OK Done");
335:                        else
336:                            handler.sendClientMsg("+OK Done, Errors: "
337:                                    + errBuf.toString());
338:                    } catch (Exception e) {
339:                        handler.sendClientMsg("-ERR Exception : " + e + "\r\n"
340:                                + errBuf.toString());
341:                        if (exitCode == 0)
342:                            exitCode = 1;
343:                    } finally {
344:                        try {
345:                            if (controlServer != null)
346:                                controlServer.closeAllPools();
347:                            if (handler.getServer() != null)
348:                                handler.getServer().closeAllPools();
349:                        } catch (Exception er) {
350:                            logger.warning("Error closing pools: " + er);
351:                        }
352:                        System.exit(exitCode);
353:                    }
354:                    return;
355:                } else if (cmd.equals("memoryinfo")) { /*v1.3.2*/
356:                    //Padding : Total:Used:Max
357:                    float totalMemory = (float) runtime.totalMemory();
358:                    float usedMemory = totalMemory
359:                            - (float) runtime.freeMemory();
360:                    float maxMemory = (float) runtime.maxMemory();
361:                    handler.sendClientMsg("+OK " + totalMemory + ":"
362:                            + usedMemory + ":" + maxMemory);
363:                    return;
364:                } else if (cmd.equals("systeminfo")) { /*v1.4.5*/
365:                    handler.sendClientMsg("+OK info follows");
366:                    handler.sendClientMsg(MyString.getSystemInfo(target
367:                            .getVersion()));
368:                    handler.sendClientMsg(".");
369:                    return;
370:                } else if (param.length == 0) {
371:                    handler.sendClientMsg("-ERR Bad Command or No Param : ->"
372:                            + cmd + "<-");
373:                    return;
374:                }
375:
376:                if (cmd.equals("start")) {
377:                    try {
378:                        target.startServer();
379:                        handler.sendClientMsg("+OK Server Started");
380:                    } catch (AppException e) {
381:                        handler.sendClientMsg("-ERR " + e);
382:                    }
383:                    return;
384:                } else if (cmd.equals("stop")) {
385:                    try {
386:                        target.stopServer();
387:                        handler.sendClientMsg("+OK Server Stopped");
388:                    } catch (AppException e) {
389:                        handler.sendClientMsg("-ERR " + e);
390:                    }
391:                    return;
392:                } else if (cmd.equals("restart")) {
393:                    try {
394:                        target.stopServer();
395:                        target.startServer();
396:                        handler.sendClientMsg("+OK Server Restarted");
397:                    } catch (AppException e) {
398:                        handler.sendClientMsg("-ERR " + e);
399:                    }
400:                    return;
401:                } else if (cmd.equals("info")) {
402:                    handler.sendClientMsg("+OK info follows");
403:                    handler.sendClientMsg("" + target);
404:                    handler.sendClientMsg("Running : " + !target.isClosed());
405:                    handler.sendClientMsg("Max Client Allowed  : "
406:                            + target.getMaxConnection());
407:                    handler.sendClientMsg("No Client Connected : "
408:                            + target.getClientCount());
409:                    if (target.isRunningSecure() == true) {
410:                        handler.sendClientMsg("Running in secure mode : "
411:                                + target.getSecure().getProtocol());
412:                    } else {
413:                        handler.sendClientMsg("Running in non-secure mode");
414:                    }
415:                    handler.sendClientMsg("Server Mode : "
416:                            + target.getBasicConfig().getServerMode());
417:                    handler.sendClientMsg(".");
418:                    return;
419:                } else if (cmd.equals("noclient")) {
420:                    handler.sendClientMsg("+OK " + target.getClientCount());
421:                    return;
422:                } else if (cmd.equals("running")) {
423:                    handler.sendClientMsg("+OK " + !target.isClosed());
424:                    return;
425:                } else if (cmd.equals("suspendservice")) {
426:                    handler.sendClientMsg("+OK " + target.suspendService());
427:                    return;
428:                } else if (cmd.equals("resumeservice")) {
429:                    handler.sendClientMsg("+OK " + target.resumeService());
430:                    return;
431:                } else if (cmd.equals("client-thread-pool-info")) /*v1.3.2*/{
432:                    temp.setLength(0);//used:idle
433:                    if (PoolHelper.isPoolOpen(target.getClientPool()
434:                            .getObjectPool()) == true) {
435:                        temp.append(target.getClientPool().getNumActive());
436:                        temp.append(':');
437:                        temp.append(target.getClientPool().getNumIdle());
438:                    } else {
439:                        temp.append("0:0");
440:                    }
441:                    handler.sendClientMsg("+OK " + temp.toString());
442:                    return;
443:                } else if (cmd.equals("client-thread-pool-dump")) /*v1.4.5*/{
444:                    if (PoolHelper.isPoolOpen(target.getClientPool()
445:                            .getObjectPool()) == true) {
446:                        handler.sendClientMsg("+OK info follows");
447:                        ClientThread ct = null;
448:                        synchronized (target.getClientPool()
449:                                .getObjectToSynchronize()) {
450:                            Iterator iterator = target.getClientPool()
451:                                    .getAllClientThread();
452:                            while (iterator.hasNext()) {
453:                                ct = (ClientThread) iterator.next();
454:                                handler.sendClientMsg(ct.toString());
455:                            }
456:                        }
457:                        handler.sendClientMsg(".");
458:                    } else {
459:                        handler.sendClientMsg("-ERR Pool Closed");
460:                    }
461:                    return;
462:                } else if (cmd.equals("client-handler-pool-dump")) /*v1.4.6*/{
463:
464:                    ObjectPool objectPool = target.getClientHandlerPool();
465:
466:                    if (PoolHelper.isPoolOpen(objectPool) == true) {
467:                        if (QSObjectPool.class.isInstance(objectPool) == false) {
468:                            handler.sendClientMsg("-ERR System Error!");
469:                        }
470:
471:                        ClientIdentifier clientIdentifier = target
472:                                .getClientIdentifier();
473:                        ClientHandler foundClientHandler = null;
474:                        synchronized (clientIdentifier.getObjectToSynchronize()) {
475:                            Iterator iterator = clientIdentifier
476:                                    .findAllClient();
477:                            handler.sendClientMsg("+OK info follows");
478:                            while (iterator.hasNext()) {
479:                                foundClientHandler = (ClientHandler) iterator
480:                                        .next();
481:                                handler
482:                                        .sendClientMsg(foundClientHandler
483:                                                .info());
484:                            }
485:                        }
486:                        handler.sendClientMsg(".");
487:                    } else {
488:                        handler.sendClientMsg("-ERR Pool Closed");
489:                    }
490:                    return;
491:                } else if (cmd.equals("client-data-pool-info")) /*v1.3.2*/{
492:                    temp.setLength(0);//used:idle
493:                    if (target.getClientDataPool() != null) {
494:                        if (PoolHelper.isPoolOpen(target.getClientDataPool()) == true) {
495:                            temp.append(target.getClientDataPool()
496:                                    .getNumActive());
497:                            temp.append(':');
498:                            temp
499:                                    .append(target.getClientDataPool()
500:                                            .getNumIdle());
501:                            handler.sendClientMsg("+OK " + temp.toString());
502:                        } else {
503:                            handler
504:                                    .sendClientMsg("-ERR Client Data Pool Closed");
505:                        }
506:                    } else {
507:                        handler.sendClientMsg("-ERR No Client Data Pool");
508:                    }
509:                    return;
510:                }
511:                if (cmd.equals("byte-buffer-pool-info")) /*v1.4.6*/{
512:                    temp.setLength(0);//used:idle
513:                    if (target.getByteBufferPool() != null) {
514:                        if (PoolHelper.isPoolOpen(target.getByteBufferPool()) == true) {
515:                            temp.append(target.getByteBufferPool()
516:                                    .getNumActive());
517:                            temp.append(':');
518:                            temp
519:                                    .append(target.getByteBufferPool()
520:                                            .getNumIdle());
521:                            handler.sendClientMsg("+OK " + temp.toString());
522:                        } else {
523:                            handler
524:                                    .sendClientMsg("-ERR ByteBuffer Pool Closed");
525:                        }
526:                    } else {
527:                        handler.sendClientMsg("-ERR No ByteBuffer Pool");
528:                    }
529:                    return;
530:                } else if (cmd.equals("all-pool-info")) /*v1.4.5*/{
531:                    handler.sendClientMsg("+OK info follows");
532:                    temp.setLength(0);//used:idle
533:
534:                    if (PoolHelper.isPoolOpen(target.getClientPool()
535:                            .getObjectPool()) == true) {
536:                        temp.append("Client Thread Pool - ");
537:                        temp.append("Num Active: ");
538:                        temp.append(target.getClientPool().getNumActive());
539:                        temp.append(", Num Idle: ");
540:                        temp.append(target.getClientPool().getNumIdle());
541:                        temp.append(", Max Idle: ");
542:                        temp.append(target.getClientPool().getPoolConfig()
543:                                .getMaxIdle());
544:                        temp.append(", Max Active: ");
545:                        temp.append(target.getClientPool().getPoolConfig()
546:                                .getMaxActive());
547:                    } else {
548:                        temp.append("Byte Buffer Pool - Closed");
549:                    }
550:                    handler.sendClientMsg(temp.toString());
551:                    temp.setLength(0);
552:
553:                    if (PoolHelper.isPoolOpen(target.getClientHandlerPool()) == true) {
554:                        temp.append("Client Handler Pool - ");
555:                        temp.append("Num Active: ");
556:                        temp.append(target.getClientHandlerPool()
557:                                .getNumActive());
558:                        temp.append(", Num Idle: ");
559:                        temp.append(target.getClientHandlerPool().getNumIdle());
560:                        temp.append(", Max Idle: ");
561:                        temp.append(target.getBasicConfig()
562:                                .getObjectPoolConfig()
563:                                .getClientHandlerObjectPoolConfig()
564:                                .getMaxIdle());
565:                        temp.append(", Max Active: ");
566:                        temp.append(target.getBasicConfig()
567:                                .getObjectPoolConfig()
568:                                .getClientHandlerObjectPoolConfig()
569:                                .getMaxActive());
570:                    } else {
571:                        temp.append("Client Handler Pool - Closed");
572:                    }
573:                    handler.sendClientMsg(temp.toString());
574:                    temp.setLength(0);
575:
576:                    if (target.getByteBufferPool() != null) {
577:                        if (PoolHelper.isPoolOpen(target.getByteBufferPool()) == true) {
578:                            temp.append("ByteBuffer Pool - ");
579:                            temp.append("Num Active: ");
580:                            temp.append(target.getByteBufferPool()
581:                                    .getNumActive());
582:                            temp.append(", Num Idle: ");
583:                            temp
584:                                    .append(target.getByteBufferPool()
585:                                            .getNumIdle());
586:                            temp.append(", Max Idle: ");
587:                            temp.append(target.getBasicConfig()
588:                                    .getObjectPoolConfig()
589:                                    .getByteBufferObjectPoolConfig()
590:                                    .getMaxIdle());
591:                            temp.append(", Max Active: ");
592:                            temp.append(target.getBasicConfig()
593:                                    .getObjectPoolConfig()
594:                                    .getByteBufferObjectPoolConfig()
595:                                    .getMaxActive());
596:                        } else {
597:                            temp.append("Byte Buffer Pool - Closed");
598:                        }
599:                    } else {
600:                        temp.append("Byte Buffer Pool - Not Used");
601:                    }
602:                    handler.sendClientMsg(temp.toString());
603:                    temp.setLength(0);
604:
605:                    if (target.getClientDataPool() != null) {
606:                        if (PoolHelper.isPoolOpen(target.getClientDataPool()) == true) {
607:                            temp.append("Client Data Pool - ");
608:                            temp.append("Num Active: ");
609:                            temp.append(target.getClientDataPool()
610:                                    .getNumActive());
611:                            temp.append(", Num Idle: ");
612:                            temp
613:                                    .append(target.getClientDataPool()
614:                                            .getNumIdle());
615:                            temp.append(", Max Idle: ");
616:                            temp.append(target.getBasicConfig()
617:                                    .getObjectPoolConfig()
618:                                    .getClientDataObjectPoolConfig()
619:                                    .getMaxIdle());
620:                            temp.append(", Max Active: ");
621:                            temp.append(target.getBasicConfig()
622:                                    .getObjectPoolConfig()
623:                                    .getClientDataObjectPoolConfig()
624:                                    .getMaxActive());
625:                        } else {
626:                            temp.append("Client Data Pool - Closed");
627:                        }
628:                    } else {
629:                        temp.append("Client Data Pool - Not Used");
630:                    }
631:                    handler.sendClientMsg(temp.toString());
632:                    temp.setLength(0);
633:
634:                    handler.sendClientMsg(".");
635:                    return;
636:                } else if (cmd.equals("set")) {
637:                    if (param.length < 3)/*target,key,value*/{
638:                        handler.sendClientMsg("-ERR " + "insufficient param");
639:                        return;
640:                    }
641:                    if (param[2].equals("null"))
642:                        param[2] = null;
643:                    try {
644:                        if (param[1].equals("maxClient")) {
645:                            long no = Long.parseLong(param[2]);
646:                            target.setMaxConnection(no);
647:                        } else if (param[1].equals("maxClientMsg")) {
648:                            target.setMaxConnectionMsg(param[2]);
649:                        } else if (param[1].equals("port")) {
650:                            long no = Long.parseLong(param[2]);
651:                            target.setPort((int) no);
652:                        } else if (param[1].equals("port")) {
653:                            long no = Long.parseLong(param[2]);
654:                            target.setPort((int) no);
655:                        } else if (param[1].equals("maxAuthTry")) {
656:                            int no = Integer.parseInt(param[2]);
657:                            target.setMaxAuthTry(no);
658:                        } else if (param[1].equals("maxAuthTryMsg")) {
659:                            target.setMaxAuthTryMsg(param[2]);
660:                        } else if (param[1].equals("clientEventHandler")) { /*v1.4.6*/
661:                            target.setClientEventHandler(param[2]);
662:                        } else if (param[1].equals("clientCommandHandler")) {
663:                            target.setClientCommandHandler(param[2]);
664:                        } else if (param[1].equals("clientWriteHandler")) { /*v1.4.6*/
665:                            target.setClientWriteHandler(param[2]);
666:                        } else if (param[1].equals("clientObjectHandler")) {
667:                            target.setClientObjectHandler(param[2]); /*v1.3*/
668:                        } else if (param[1]
669:                                .equals("clientAuthenticationHandler")) {
670:                            target.setClientAuthenticationHandler(param[2]);
671:                        } else if (param[1].equals("clientData")) {
672:                            target.setClientData(param[2]);
673:                        } else if (param[1]
674:                                .equals("clientExtendedEventHandler")) { /*v1.4.6*/
675:                            target.setClientExtendedEventHandler(param[2]);
676:                        } else if (param[1].equals("timeout")) {
677:                            long no = Long.parseLong(param[2]);
678:                            target.setTimeout((int) no);
679:                        } else if (param[1].equals("timeoutMsg")) {
680:                            target.setTimeoutMsg(param[2]); /* v1.3 */
681:                        } else if (param[1].equals("plugin")) /* v1.2*/{
682:                            if (param[0].equals("self")) {
683:                                try {
684:                                    adminServer.setCommandPlugin(param[2]);
685:                                } catch (Exception e) {
686:                                    handler
687:                                            .sendClientMsg("-ERR not set : "
688:                                                    + e);
689:                                    return;
690:                                }
691:                            } else {
692:                                handler.sendClientMsg("-ERR Bad target : "
693:                                        + param[0] + " self is only allowed.");
694:                                return;
695:                            }
696:                        } else if (param[1].equals("consoleLoggingFormatter")) {
697:                            target.setConsoleLoggingFormatter(param[2]); /* v1.3 */
698:                        } else if (param[1].equals("consoleLoggingLevel")) { /* v1.3 */
699:                            if (param[2].endsWith("SEVERE"))
700:                                target.setConsoleLoggingLevel(Level.SEVERE);
701:                            else if (param[2].endsWith("WARNING"))
702:                                target.setConsoleLoggingLevel(Level.WARNING);
703:                            else if (param[2].endsWith("INFO"))
704:                                target.setConsoleLoggingLevel(Level.INFO);
705:                            else if (param[2].endsWith("CONFIG"))
706:                                target.setConsoleLoggingLevel(Level.CONFIG);
707:                            else if (param[2].endsWith("FINE"))
708:                                target.setConsoleLoggingLevel(Level.FINE);
709:                            else if (param[2].endsWith("FINER"))
710:                                target.setConsoleLoggingLevel(Level.FINER);
711:                            else if (param[2].endsWith("FINEST"))
712:                                target.setConsoleLoggingLevel(Level.FINEST);
713:                            else if (param[2].endsWith("ALL"))
714:                                target.setConsoleLoggingLevel(Level.ALL);
715:                            else if (param[2].endsWith("OFF"))
716:                                target.setConsoleLoggingLevel(Level.OFF);
717:                            else {
718:                                handler.sendClientMsg("-ERR Bad Level "
719:                                        + param[2]);
720:                                return;
721:                            }
722:                        } else if (param[1].equals("loggingLevel")) { /* v1.3.1 */
723:                            if (param[2].endsWith("SEVERE"))
724:                                target.setLoggingLevel(Level.SEVERE);
725:                            else if (param[2].endsWith("WARNING"))
726:                                target.setLoggingLevel(Level.WARNING);
727:                            else if (param[2].endsWith("INFO"))
728:                                target.setLoggingLevel(Level.INFO);
729:                            else if (param[2].endsWith("CONFIG"))
730:                                target.setLoggingLevel(Level.CONFIG);
731:                            else if (param[2].endsWith("FINE"))
732:                                target.setLoggingLevel(Level.FINE);
733:                            else if (param[2].endsWith("FINER"))
734:                                target.setLoggingLevel(Level.FINER);
735:                            else if (param[2].endsWith("FINEST"))
736:                                target.setLoggingLevel(Level.FINEST);
737:                            else if (param[2].endsWith("ALL"))
738:                                target.setLoggingLevel(Level.ALL);
739:                            else if (param[2].endsWith("OFF"))
740:                                target.setLoggingLevel(Level.OFF);
741:                            else {
742:                                handler.sendClientMsg("-ERR Bad Level "
743:                                        + param[2]);
744:                                return;
745:                            }
746:                        } else if (param[1].equals("communicationLogging")) {
747:                            if (param[2].equals("true"))/* v1.3.2 */
748:                                target.setCommunicationLogging(true);
749:                            else
750:                                target.setCommunicationLogging(false);
751:                        } else if (param[1]
752:                                .equals("objectPoolConfig-maxActive")) {
753:                            int no = Integer.parseInt(param[2]);
754:                            target.getConfig().getObjectPoolConfig()
755:                                    .setMaxActive(no);
756:                        } else if (param[1].equals("objectPoolConfig-maxIdle")) {
757:                            int no = Integer.parseInt(param[2]);
758:                            target.getConfig().getObjectPoolConfig()
759:                                    .setMaxIdle(no);
760:                        } else if (param[1].equals("objectPoolConfig-initSize")) {
761:                            int no = Integer.parseInt(param[2]);
762:                            target.getConfig().getObjectPoolConfig()
763:                                    .setInitSize(no);
764:                        } else {
765:                            handler.sendClientMsg("-ERR Bad Set Key : "
766:                                    + param[1]);
767:                            return;
768:                        }
769:                        handler.sendClientMsg("+OK Set");
770:                    } catch (Exception e) {
771:                        handler.sendClientMsg("-ERR " + e);
772:                    }
773:                    return;
774:                } else if (cmd.equals("get")) {
775:                    if (param.length < 2)/*target,key*/{
776:                        handler.sendClientMsg("-ERR " + "insufficient param");
777:                        return;
778:                    }
779:                    try {
780:                        if (param[1].equals("maxClient")) {
781:                            long no = target.getMaxConnection();
782:                            handler.sendClientMsg("+OK " + no);
783:                        } else if (param[1].equals("maxClientMsg")) {
784:                            String msg = target.getMaxConnectionMsg();
785:                            msg = MyString.replaceAll(msg, "\n", "\\n");
786:                            handler.sendClientMsg("+OK " + msg);
787:                        } else if (param[1].equals("port")) {
788:                            long no = target.getPort();
789:                            handler.sendClientMsg("+OK " + no);
790:                        } else if (param[1].equals("maxAuthTry")) {
791:                            int no = target.getMaxAuthTry();
792:                            handler.sendClientMsg("+OK " + no);
793:                        } else if (param[1].equals("maxAuthTryMsg")) {
794:                            String msg = target.getMaxAuthTryMsg();
795:                            msg = MyString.replaceAll(msg, "\n", "\\n");
796:                            handler.sendClientMsg("+OK " + msg);
797:                        } else if (param[1].equals("clientEventHandler")) { /*v1.4.6*/
798:                            String msg = target.getClientEventHandler();
799:                            handler.sendClientMsg("+OK " + msg);
800:                        } else if (param[1].equals("clientCommandHandler")) {
801:                            String msg = target.getClientCommandHandler();
802:                            handler.sendClientMsg("+OK " + msg);
803:                        } else if (param[1].equals("clientWriteHandler")) { /*v1.4.6*/
804:                            String msg = target.getClientWriteHandler();
805:                            handler.sendClientMsg("+OK " + msg);
806:                        } else if (param[1].equals("clientObjectHandler")) {
807:                            String msg = target.getClientObjectHandler();
808:                            handler.sendClientMsg("+OK " + msg);
809:                        } else if (param[1]
810:                                .equals("clientAuthenticationHandler")) {
811:                            String msg = target
812:                                    .getClientAuthenticationHandler();
813:                            handler.sendClientMsg("+OK " + msg);
814:                        } else if (param[1].equals("clientData")) {
815:                            String msg = target.getClientData();
816:                            handler.sendClientMsg("+OK " + msg);
817:                        } else if (param[1]
818:                                .equals("clientExtendedEventHandler")) { /*v1.4.6*/
819:                            String msg = target.getClientExtendedEventHandler();
820:                            handler.sendClientMsg("+OK " + msg);
821:                        } else if (param[1].equals("timeout")) {
822:                            String msg = "" + target.getTimeout();
823:                            handler.sendClientMsg("+OK " + msg);
824:                        } else if (param[1].equals("timeoutMsg")) {
825:                            String msg = "" + target.getTimeoutMsg();
826:                            msg = MyString.replaceAll(msg, "\n", "\\n");
827:                            handler.sendClientMsg("+OK " + msg);
828:                        } else if (param[1].equals("plugin")) /* v1.2*/{
829:                            if (param[0].equals("self")) {
830:                                String msg = adminServer.getCommandPlugin();
831:                                handler.sendClientMsg("+OK " + msg);
832:                            } else {
833:                                handler.sendClientMsg("-ERR Bad target : "
834:                                        + param[0] + " self is only allowed.");
835:                            }
836:                        } else if (param[1].equals("consoleLoggingFormatter")) {
837:                            String msg = ""
838:                                    + target.getConsoleLoggingFormatter(); /* v1.3 */
839:                            handler.sendClientMsg("+OK " + msg);
840:                        } else if (param[1].equals("consoleLoggingLevel")) { /* v1.3 */
841:                            String msg = "" + target.getConsoleLoggingLevel();
842:                            handler.sendClientMsg("+OK " + msg);
843:                        } else if (param[1].equals("serviceState")) {
844:                            int state = target.getServiceState(); /*v1.3*/
845:                            if (state == org.quickserver.net.Service.INIT)
846:                                handler.sendClientMsg("+OK INIT");
847:                            else if (state == org.quickserver.net.Service.RUNNING)
848:                                handler.sendClientMsg("+OK RUNNING");
849:                            else if (state == org.quickserver.net.Service.STOPPED)
850:                                handler.sendClientMsg("+OK STOPPED");
851:                            else if (state == org.quickserver.net.Service.SUSPENDED)
852:                                handler.sendClientMsg("+OK SUSPENDED");
853:                            else
854:                                handler.sendClientMsg("+OK UNKNOWN");
855:                        } else if (param[1].equals("communicationLogging")) {
856:                            String msg = "" + target.getCommunicationLogging();
857:                            handler.sendClientMsg("+OK " + msg);
858:                        } else if (param[1]
859:                                .equals("objectPoolConfig-maxActive")) {
860:                            String msg = ""
861:                                    + target.getConfig().getObjectPoolConfig()
862:                                            .getMaxActive();
863:                            handler.sendClientMsg("+OK " + msg);
864:                        } else if (param[1].equals("objectPoolConfig-maxIdle")) {
865:                            String msg = ""
866:                                    + target.getConfig().getObjectPoolConfig()
867:                                            .getMaxIdle();
868:                            handler.sendClientMsg("+OK " + msg);
869:                        } else if (param[1].equals("objectPoolConfig-initSize")) {
870:                            String msg = ""
871:                                    + target.getConfig().getObjectPoolConfig()
872:                                            .getInitSize();
873:                            handler.sendClientMsg("+OK " + msg);
874:                        } else {
875:                            handler.sendClientMsg("-ERR Bad Get Key : "
876:                                    + param[1]);
877:                        }
878:                    } catch (Exception e) {
879:                        handler.sendClientMsg("-ERR " + e);
880:                    }
881:                    return;
882:                } else {
883:                    handler.sendClientMsg("-ERR Bad Command : " + cmd);
884:                }
885:                return;
886:            }
887:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.