Author: doogie
Date: Tue Apr 17 19:58:03 2012 New Revision: 1327256 URL: http://svn.apache.org/viewvc?rev=1327256&view=rev Log: OPTIMIZE: Add a new FAIL Control, and move the processing into a method on the enum. Modified: ofbiz/trunk/framework/start/src/org/ofbiz/base/start/Start.java Modified: ofbiz/trunk/framework/start/src/org/ofbiz/base/start/Start.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/start/src/org/ofbiz/base/start/Start.java?rev=1327256&r1=1327255&r2=1327256&view=diff ============================================================================== --- ofbiz/trunk/framework/start/src/org/ofbiz/base/start/Start.java (original) +++ ofbiz/trunk/framework/start/src/org/ofbiz/base/start/Start.java Tue Apr 17 19:58:03 2012 @@ -40,7 +40,27 @@ import java.util.concurrent.atomic.Atomi public class Start { private enum Control { - SHUTDOWN, STATUS + SHUTDOWN { + void processRequest(Start start, PrintWriter writer) { + if (start.serverState.get() == ServerState.STOPPING) { + writer.println("IN-PROGRESS"); + } else { + writer.println("OK"); + writer.flush(); + start.stopServer(); + } + } + }, STATUS { + void processRequest(Start start, PrintWriter writer) { + writer.println(start.serverState.get()); + } + }, FAIL { + void processRequest(Start start, PrintWriter writer) { + writer.println("FAIL"); + } + }; + + abstract void processRequest(Start start, PrintWriter writer); } private static void help(PrintStream out) { @@ -361,26 +381,21 @@ public class Start { reader = new BufferedReader(new InputStreamReader(client.getInputStream())); String request = reader.readLine(); writer = new PrintWriter(client.getOutputStream(), true); + Control control; if (request != null && !request.isEmpty() && request.contains(":")) { String key = request.substring(0, request.indexOf(':')); - Control control = Control.valueOf(request.substring(request.indexOf(':') + 1)); if (key.equals(config.adminKey)) { - if (control == Control.SHUTDOWN) { - if (Start.this.serverState.get() == ServerState.STOPPING) { - writer.println("IN-PROGRESS"); - } else { - writer.println("OK"); - writer.flush(); - stopServer(); - } - return; - } else if (control == Control.STATUS) { - writer.println(Start.this.serverState.get()); - return; + control = Control.valueOf(request.substring(request.indexOf(':') + 1)); + if (control == null) { + control = Control.FAIL; } + } else { + control = Control.FAIL; } + } else { + control = Control.FAIL; } - writer.println("FAIL"); + control.processRequest(Start.this, writer); } finally { if (reader != null) { reader.close(); |
Free forum by Nabble | Edit this page |