jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dpfis...@apache.org
Subject svn commit: r1177652 - in /jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/server: FileServlet.java HttpProcessor.java MicroKernelServlet.java Response.java Server.java
Date Fri, 30 Sep 2011 13:34:08 GMT
Author: dpfister
Date: Fri Sep 30 13:34:07 2011
New Revision: 1177652

URL: http://svn.apache.org/viewvc?rev=1177652&view=rev
Log:
HTTP interface to microkernel
- simplify "servlets"
- use logical && instead of &

Modified:
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/server/FileServlet.java
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/server/HttpProcessor.java
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/server/MicroKernelServlet.java
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/server/Response.java
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/server/Server.java

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/server/FileServlet.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/server/FileServlet.java?rev=1177652&r1=1177651&r2=1177652&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/server/FileServlet.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/server/FileServlet.java
Fri Sep 30 13:34:07 2011
@@ -26,6 +26,12 @@ import org.apache.jackrabbit.mk.util.IOU
  * File servlet that will deliver static resources.
  */
 class FileServlet implements Servlet {
+    
+    /** The one and only instance of this servlet. */
+    public static FileServlet INSTANCE = new FileServlet();
+    
+    /** Just one instance, no need to make constructor public */
+    private FileServlet() {}
 
     public void service(Request request, Response response) throws IOException {
         String file = request.getFile();

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/server/HttpProcessor.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/server/HttpProcessor.java?rev=1177652&r1=1177651&r2=1177652&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/server/HttpProcessor.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/server/HttpProcessor.java
Fri Sep 30 13:34:07 2011
@@ -105,8 +105,8 @@ class HttpProcessor {
             throw e;
         }
         try {
-            boolean keepAlive = request.isKeepAlive();
-            keepAlive &= (requestNum + 1 < MAX_KEEP_ALIVE_REQUESTS);
+            boolean keepAlive = request.isKeepAlive() &&
+                    (requestNum + 1 < MAX_KEEP_ALIVE_REQUESTS);
             response = new Response(socketOut, keepAlive);
             servlet.service(request, response);
             return keepAlive;

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/server/MicroKernelServlet.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/server/MicroKernelServlet.java?rev=1177652&r1=1177651&r2=1177652&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/server/MicroKernelServlet.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/server/MicroKernelServlet.java
Fri Sep 30 13:34:07 2011
@@ -22,7 +22,6 @@ import java.io.InputStream;
 import java.io.OutputStream;
 import java.util.HashMap;
 import java.util.Map;
-import java.util.concurrent.atomic.AtomicReference;
 
 import org.apache.jackrabbit.mk.api.MicroKernel;
 import org.apache.jackrabbit.mk.api.MicroKernelException;
@@ -33,37 +32,34 @@ import org.apache.jackrabbit.mk.util.IOU
 /**
  * Servlet handling requests directed at a <code>MicroKernel</code> instance.

  */
-class MicroKernelServlet implements Servlet {
+class MicroKernelServlet {
     
-    private final AtomicReference<MicroKernel> mkref;
+    /** The one and only instance of this servlet. */
+    public static MicroKernelServlet INSTANCE = new MicroKernelServlet();
     
-    public MicroKernelServlet(AtomicReference<MicroKernel> mkref) {
-        this.mkref = mkref;
-    }
+    /** Just one instance, no need to make constructor public */
+    private MicroKernelServlet() {}
     
-    public void service(Request request, Response response) throws IOException {
+    public void service(MicroKernel mk, Request request, Response response) throws IOException
{
         String file = request.getFile();
         int dotIndex = file.indexOf('.');
         if (dotIndex == -1) {
             dotIndex = file.length();
         }
         Command command = COMMANDS.get(file.substring(1, dotIndex));
-        if (command != null) {
-            MicroKernel mk = mkref.get();
-            if (mk != null) {
-                try {
-                    command.execute(mk, request, response);
-                } catch (MicroKernelException e) {
-                    response.setStatusCode(500);
-                    response.setContentType("text/plain");
-                    e.printStackTrace(new PrintStream(response.getOutputStream()));
-                } catch (Throwable e) {
-                    response.setStatusCode(500);
-                    response.setContentType("text/plain");
-                    e.printStackTrace(new PrintStream(response.getOutputStream()));
-                }
-                return;
+        if (command != null && mk != null) {
+            try {
+                command.execute(mk, request, response);
+            } catch (MicroKernelException e) {
+                response.setStatusCode(500);
+                response.setContentType("text/plain");
+                e.printStackTrace(new PrintStream(response.getOutputStream()));
+            } catch (Throwable e) {
+                response.setStatusCode(500);
+                response.setContentType("text/plain");
+                e.printStackTrace(new PrintStream(response.getOutputStream()));
             }
+            return;
         }
         response.setStatusCode(404);
     }
@@ -89,7 +85,7 @@ class MicroKernelServlet implements Serv
         COMMANDS.put("write", new Write());
     }
     
-    static class GetHeadRevision implements Command {
+    private static class GetHeadRevision implements Command {
         
         public void execute(MicroKernel mk, Request request, Response response)
                 throws IOException, MicroKernelException {
@@ -99,7 +95,7 @@ class MicroKernelServlet implements Serv
         }        
     }
 
-    static class GetRevisions implements Command {
+    private static class GetRevisions implements Command {
         
         public void execute(MicroKernel mk, Request request, Response response)
                 throws IOException, MicroKernelException {
@@ -116,7 +112,7 @@ class MicroKernelServlet implements Serv
         }        
     }
     
-    static class WaitForCommit implements Command {
+    private static class WaitForCommit implements Command {
 
         public void execute(MicroKernel mk, Request request, Response response)
                 throws IOException, MicroKernelException {
@@ -139,7 +135,7 @@ class MicroKernelServlet implements Serv
         }
     }
 
-    static class GetJournal implements Command {
+    private static class GetJournal implements Command {
 
         public void execute(MicroKernel mk, Request request, Response response)
                 throws IOException, MicroKernelException {
@@ -158,7 +154,7 @@ class MicroKernelServlet implements Serv
         }        
     }
 
-    static class NodeExists implements Command {
+    private static class NodeExists implements Command {
 
         public void execute(MicroKernel mk, Request request, Response response)
                 throws IOException, MicroKernelException {
@@ -173,7 +169,7 @@ class MicroKernelServlet implements Serv
         }
     }
 
-    static class GetNodes implements Command {
+    private static class GetNodes implements Command {
 
         public void execute(MicroKernel mk, Request request, Response response)
                 throws IOException, MicroKernelException {
@@ -195,7 +191,7 @@ class MicroKernelServlet implements Serv
         }        
     }
 
-    static class Commit implements Command {
+    private static class Commit implements Command {
 
         public void execute(MicroKernel mk, Request request, Response response)
                 throws IOException, MicroKernelException {
@@ -214,7 +210,7 @@ class MicroKernelServlet implements Serv
         }        
     }
 
-    static class GetLength implements Command {
+    private static class GetLength implements Command {
 
         public void execute(MicroKernel mk, Request request, Response response)
                 throws IOException, MicroKernelException {
@@ -227,7 +223,7 @@ class MicroKernelServlet implements Serv
         }
     }
 
-    static class Read implements Command {
+    private static class Read implements Command {
 
         public void execute(MicroKernel mk, Request request, Response response)
                 throws IOException, MicroKernelException {
@@ -252,7 +248,7 @@ class MicroKernelServlet implements Serv
         }
     }
 
-    static class Write implements Command {
+    private static class Write implements Command {
 
         public void execute(MicroKernel mk, Request request, Response response)
                 throws IOException, MicroKernelException {

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/server/Response.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/server/Response.java?rev=1177652&r1=1177651&r2=1177652&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/server/Response.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/server/Response.java
Fri Sep 30 13:34:07 2011
@@ -211,7 +211,7 @@ class Response implements Closeable {
     private class BodyOutputStream extends OutputStream {
         
         /**
-         * Buffer size chosen intentionally to need exceed maximum chunk
+         * Buffer size chosen intentionally to not exceed maximum chunk
          * size we'd like to transmit.
          */
         private final byte[] buf = new byte[0xFFFF];

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/server/Server.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/server/Server.java?rev=1177652&r1=1177651&r2=1177652&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/server/Server.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/server/Server.java
Fri Sep 30 13:34:07 2011
@@ -36,8 +36,6 @@ public class Server {
 
     private AtomicReference<MicroKernel> mkref;
     
-    private MicroKernelServlet mkServlet;
-    
     private AtomicBoolean started = new AtomicBoolean();
     
     private AtomicBoolean stopped = new AtomicBoolean();
@@ -55,8 +53,6 @@ public class Server {
      */
     public Server(MicroKernel mk) {
         this.mkref = new AtomicReference<MicroKernel>(mk);
-        
-        mkServlet = new MicroKernelServlet(mkref);
     }
 
     /**
@@ -141,15 +137,13 @@ public class Server {
      */
     class ServletImpl implements Servlet {
 
-        private final Servlet fileServlet = new FileServlet();
-
         public void service(Request request, Response response)
                 throws IOException {
 
             if (request.getMethod().equals("POST")) {
-                mkServlet.service(request, response);
+                MicroKernelServlet.INSTANCE.service(mkref.get(), request, response);
             } else {
-                fileServlet.service(request, response);
+                FileServlet.INSTANCE.service(request, response);
             }
         }
     }



Mime
View raw message