StringTokenizer st = new StringTokenizer(command," ");
String cmd = null;
cmd = st.nextToken().toLowerCase();
String param[] = new String[st.countTokens()];
QuickServer target = null;
for (int i=0;st.hasMoreTokens();i++)
param[i] = st.nextToken();
if(command.equals("start console")) { /*v1.4.5*/
QSAdminShell.getInstance(
(QuickServer) handler.getServer().getStoreObjects()[0], null);
handler.sendClientMsg("+OK QSAdminShell is started.");
return;
} else if(command.equals("stop console")) { /*v1.4.5*/
QSAdminShell shell = QSAdminShell.getInstance(null, null);
if(shell!=null) {
try {
shell.stopShell();
} catch(Exception err) {
handler.sendClientMsg("-ERR Error stopping QSAdminShell: "+err);
}
handler.sendClientMsg("+OK QSAdminShell is stopped.");
} else {
handler.sendClientMsg("-ERR QSAdminShell is not running.");
}
return;
}
if(param.length > 0) {
if( param[0].equals("server") )
target = (QuickServer) handler.getServer().getStoreObjects()[0];
else if( param[0].equals("self") )
target = handler.getServer();
else {
handler.sendClientMsg("-ERR Bad <<target>> : "+param[0]);
return;
}
}
if(cmd.equals("help")) {
handler.sendClientMsg("+OK info follows"+"\r\n"+
"Refer Api Docs for org.quickserver.net.qsadmin.CommandHandler");
handler.sendClientMsg(".");
return;
} else if(cmd.equals("quit")) {
handler.sendClientMsg("+OK Bye ;-)");
handler.closeConnection();
return;
} else if(cmd.equals("shutdown")) {
try {
QuickServer controlServer =
(QuickServer) handler.getServer().getStoreObjects()[0];
if(controlServer!=null && controlServer.isClosed()==false) {
controlServer.stopServer();
}
if(handler.getServer()!=null && handler.getServer().isClosed()==false) {
handler.getServer().stopServer();
}
QSAdminShell shell = QSAdminShell.getInstance(null, null);
if(shell!=null) {
try {
shell.stopShell();
} catch(Exception err) {
logger.warning("Error stoping shell: "+err);
}
}
handler.sendClientMsg("+OK Done");
} catch (AppException e) {
handler.sendClientMsg("-ERR "+e);
}
return;
} else if(cmd.equals("version")) {
handler.sendClientMsg("+OK "+QuickServer.getVersion());
return;
} else if(cmd.equals("kill") || cmd.equals("exit")) /*v1.3,v1.3.2*/{
StringBuilder errBuf = new StringBuilder();
QuickServer controlServer =
(QuickServer) handler.getServer().getStoreObjects()[0];
int exitCode = 0;
if(param.length!=0) {
try {
exitCode = Integer.parseInt(param[0]);
} catch(Exception nfe) {/*ignore*/}
}
try {
if(controlServer!=null && controlServer.isClosed()==false) {
try {
controlServer.stopServer();
} catch(AppException ae) {
errBuf.append(ae.toString());
}
}
if(handler.getServer()!=null && handler.getServer().isClosed()==false) {
try {
handler.getServer().stopServer();
} catch(AppException ae) {
errBuf.append(ae.toString());
}
}
QSAdminShell shell = QSAdminShell.getInstance(null, null);
if(shell!=null) {
try {
shell.stopShell();
} catch(Exception err) {
errBuf.append(err.toString());
}
}
if(errBuf.length()==0)
handler.sendClientMsg("+OK Done");
else
handler.sendClientMsg("+OK Done, Errors: "+errBuf.toString());
} catch (Exception e) {
handler.sendClientMsg("-ERR Exception : "+e+"\r\n"+errBuf.toString());
if(exitCode==0) exitCode = 1;
} finally {
try {
if(controlServer!=null)
controlServer.closeAllPools();
if(handler.getServer()!=null)
handler.getServer().closeAllPools();
} catch(Exception er) {
logger.warning("Error closing pools: "+er);
}