Java HTTP gateway, docs
authorBill Erickson <berick@esilibrary.com>
Tue, 28 Feb 2012 13:19:30 +0000 (08:19 -0500)
committerBill Erickson <berick@esilibrary.com>
Thu, 15 Mar 2012 20:23:51 +0000 (16:23 -0400)
Signed-off-by: Bill Erickson <berick@esilibrary.com>
src/java/org/opensrf/net/http/GatewayConnection.java
src/java/org/opensrf/net/http/GatewayRequestHandler.java

index beab024..ac62169 100644 (file)
@@ -1,22 +1,34 @@
 package org.opensrf.net.http;
 
-import org.opensrf.*;
-import org.opensrf.util.*;
-
 import java.net.URL;
 import java.net.MalformedURLException;
 import java.util.Queue;
 import java.util.concurrent.ConcurrentLinkedQueue;
+import org.opensrf.*;
+import org.opensrf.util.*;
+
+
+/**
+ * Manages connection parameters and thread limiting for opensrf json gateway connections.
+ */
 
 public class GatewayConnection {
 
-    private String proto; /* http, https */
+    /** http or https */
+    private String proto;
+    /** server name */
     private String host;
+    /** URL path to the gateway, defaults to defaultPath */
     private String path;
+    /** Compiled URL object */
     private URL url;
+    /** Number of threads currently communicating with the server */
     protected int activeThreads;
+    /** Queue of pending async requests */
     protected Queue<GatewayRequest> pendingThreadQueue;
+    /** maximum number of actively communicating threads allowed */
     protected int maxThreads = 10;
+    /** URL path for the gateway */
     public static final String defaultPath = "/osrf-gateway-v1";
 
     public GatewayConnection(String proto, String host) {
@@ -36,11 +48,14 @@ public class GatewayConnection {
         return maxThreads;
     }
 
+    /** 
+     * Set the maximum number of actively communicating threads allowed 
+     */
     public void setMaxThreads(int max) {
         maxThreads = max;
     }
 
-    public URL getUrl() throws java.net.MalformedURLException {
+    protected URL getUrl() throws java.net.MalformedURLException {
         try {
             if (url == null) {
                 url = new URL(proto + "://" + host + path);
@@ -55,6 +70,19 @@ public class GatewayConnection {
         return new GatewayRequest(this, service, method);
     }
 
+    /**
+     * Launches or queues an asynchronous request.
+     *
+     * If the maximum active thread count has not been reached,
+     * start a new thread and use it to send and receive the request.
+     * The response is passed to the request's GatewayRequestHandler
+     * onComplete().  After complete, if the number of active threads
+     * is still lower than the max, one request will be pulled (if 
+     * present) from the async queue and fired.
+     *
+     * If there are too many active threads, the main request is
+     * pushed onto the async queue for later processing
+     */
     protected void manageAsyncRequest(final GatewayRequest request) {
 
         if (activeThreads >= maxThreads) {
@@ -64,10 +92,8 @@ public class GatewayConnection {
 
         activeThreads++;
 
-        /*
-         * Send the request receive the response, fire off the next 
-         * thread if necessary, then pass the result to the handler
-         */
+         //Send the request receive the response, fire off the next 
+         //thread if necessary, then pass the result to the handler
         Runnable r = new Runnable() {
             public void run() {
 
index 3a62769..48ceeda 100644 (file)
@@ -1,5 +1,9 @@
 package org.opensrf.net.http;
 
+/*
+ * Handler for async gateway request responses
+ */
+
 public interface GatewayRequestHandler {
     public void onComplete(Object payload);
 }