[ARVADOS] updated: 84c471b1cfb20116b2d7d26215c2517cb57ba53f

git at public.curoverse.com git at public.curoverse.com
Tue Apr 29 08:20:31 EDT 2014


Summary of changes:
 .gitignore                                         |    1 +
 .../main/java/org/arvados/sdk/java/Arvados.java    |  117 +++++++++++---------
 2 files changed, 64 insertions(+), 54 deletions(-)

       via  84c471b1cfb20116b2d7d26215c2517cb57ba53f (commit)
       via  a5034fccf4a829a36d6e2670a9f62e4f7a545f2f (commit)
      from  72c312b352a88740a44fba9e274d72bbabb489a7 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.


commit 84c471b1cfb20116b2d7d26215c2517cb57ba53f
Author: radhika <radhika at radhika>
Date:   Tue Apr 29 08:20:04 2014 -0400

    2525: Address multithreading concerns in the sdk.

diff --git a/sdk/java/src/main/java/org/arvados/sdk/java/Arvados.java b/sdk/java/src/main/java/org/arvados/sdk/java/Arvados.java
index cf73712..69bb623 100644
--- a/sdk/java/src/main/java/org/arvados/sdk/java/Arvados.java
+++ b/sdk/java/src/main/java/org/arvados/sdk/java/Arvados.java
@@ -31,9 +31,9 @@ import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
 public class Arvados {
+  // HttpTransport and JsonFactory are thread-safe. So, use global instances. 
   private static HttpTransport HTTP_TRANSPORT;
   private static final JsonFactory JSON_FACTORY = JacksonFactory.getDefaultInstance();
-  private static Discovery DISCOVERY_CLIENT;
 
   private static final Pattern METHOD_PATTERN = Pattern.compile("((\\w+)\\.)*(\\w+)");
 
@@ -139,17 +139,50 @@ public class Arvados {
       NetHttpTransport.Builder builder = new NetHttpTransport.Builder();
       builder.doNotValidateCertificate();
       HTTP_TRANSPORT = builder.build();
-
-      // Create DISCOVERY_CLIENT object
-      Discovery.Builder discoveryBuilder = new Discovery.Builder(HTTP_TRANSPORT, JSON_FACTORY, null);
-
-      discoveryBuilder.setRootUrl(ARVADOS_ROOT_URL);
-      discoveryBuilder.setApplicationName(apiName);
-      DISCOVERY_CLIENT = discoveryBuilder.build();
     } catch (Throwable t) {
       t.printStackTrace();
     }
   }
+  
+  public RestDescription discover(List<String> params) throws Exception {
+    if (params.size() == 1) {
+      error("call", "missing api name");
+    } else if (params.size() == 2) {
+      error("call", "missing api version");
+    } 
+
+    RestDescription restDescription = loadArvadosApi(params.get(1), params.get(2));
+
+    // compute method details
+    ArrayList<MethodDetails> result = Lists.newArrayList();
+    String resourceName = "";
+    processResources(result, resourceName, restDescription.getResources());
+
+    // display method details
+    Collections.sort(result);
+    for (MethodDetails methodDetail : result) {
+      System.out.println();
+      System.out.print("Arvados call " + params.get(1) + " " + params.get(2) + " " + methodDetail.name);
+      for (String param : methodDetail.requiredParameters) {
+        System.out.print(" <" + param + ">");
+      }
+      if (methodDetail.hasContent) {
+        System.out.print(" contentFile");
+      }
+      if (methodDetail.optionalParameters.isEmpty() && !methodDetail.hasContent) {
+        System.out.println();
+      } else {
+        System.out.println(" [optional parameters...]");
+        System.out.println("  --contentType <value> (default is \"application/json\")");
+        for (String param : methodDetail.optionalParameters) {
+          System.out.println("  --" + param + " <value>");
+        }
+      }
+    }
+
+    return (restDescription);
+  }
+
   public String call(List<String> callParams) throws Exception {
     if (callParams.size() == 1) {
       error("call", "missing api name");
@@ -264,7 +297,7 @@ public class Arvados {
       requestFactory = HTTP_TRANSPORT.createRequestFactory();
 
       HttpRequest request = requestFactory.buildRequest(method.getHttpMethod(), url, content);
-      //request.getp
+
       List<String> authHeader = new ArrayList<String>();
       authHeader.add("OAuth2 " + ARVADOS_API_TOKEN);
       request.getHeaders().put("Authorization", authHeader);
@@ -277,57 +310,33 @@ public class Arvados {
     }
   }
 
-  public RestDescription discover(List<String> params) throws Exception {
-    if (params.size() == 1) {
-      error("call", "missing api name");
-    } else if (params.size() == 2) {
-      error("call", "missing api version");
-    } 
-
-    RestDescription restDescription = loadArvadosApi(params.get(1), params.get(2));
-
-    // compute method details
-    ArrayList<MethodDetails> result = Lists.newArrayList();
-    String resourceName = "";
-    processResources(result, resourceName, restDescription.getResources());
-
-
-    // display method details
-    Collections.sort(result);
-    for (MethodDetails methodDetail : result) {
-      System.out.println();
-      System.out.print("Arvados call " + params.get(1) + " " + params.get(2) + " " + methodDetail.name);
-      for (String param : methodDetail.requiredParameters) {
-        System.out.print(" <" + param + ">");
-      }
-      if (methodDetail.hasContent) {
-        System.out.print(" contentFile");
-      }
-      if (methodDetail.optionalParameters.isEmpty() && !methodDetail.hasContent) {
-        System.out.println();
-      } else {
-        System.out.println(" [optional parameters...]");
-        System.out.println("  --contentType <value> (default is \"application/json\")");
-        for (String param : methodDetail.optionalParameters) {
-          System.out.println("  --" + param + " <value>");
-        }
-      }
-    }
-
-    return (restDescription);
-  }
-
-  private RestDescription loadArvadosApi(String appName, String appVersion)
+  /**
+   * Not thread-safe. So, create for each request.
+   * @param apiName
+   * @param apiVersion
+   * @return
+   * @throws Exception
+   */
+  private RestDescription loadArvadosApi(String apiName, String apiVersion)
       throws Exception {
     try {
-      return DISCOVERY_CLIENT.apis().getRest(appName, appVersion).execute();
+      Discovery discovery;
+      
+      Discovery.Builder discoveryBuilder = new Discovery.Builder(HTTP_TRANSPORT, JSON_FACTORY, null);
+
+      discoveryBuilder.setRootUrl(ARVADOS_ROOT_URL);
+      discoveryBuilder.setApplicationName(apiName);
+      
+      discovery = discoveryBuilder.build();
+
+      return discovery.apis().getRest(apiName, apiVersion).execute();
     } catch (Exception e) {
       e.printStackTrace();
       throw e;
     }
   }
 
-  private static void processMethods(
+  private void processMethods(
       ArrayList<MethodDetails> result, String resourceName, Map<String, RestMethod> methodMap) {
     if (methodMap == null) {
       return;
@@ -363,7 +372,7 @@ public class Arvados {
     }
   }
 
-  private static void processResources(
+  private void processResources(
       ArrayList<MethodDetails> result, String resourceName, Map<String, RestResource> resourceMap) {
     if (resourceMap == null) {
       return;
@@ -376,7 +385,7 @@ public class Arvados {
     }
   }
 
-  private static void putParameter(String argName, Map<String, Object> parameters,
+  private void putParameter(String argName, Map<String, Object> parameters,
       String parameterName, JsonSchema parameter, String parameterValue) throws Exception {
     Object value = parameterValue;
     if (parameter != null) {

commit a5034fccf4a829a36d6e2670a9f62e4f7a545f2f
Author: radhika <radhika at radhika>
Date:   Tue Apr 29 07:50:57 2014 -0400

    2525: Add sdk/java/target to gitignore list

diff --git a/.gitignore b/.gitignore
index 2156fdf..c1b7c20 100644
--- a/.gitignore
+++ b/.gitignore
@@ -14,3 +14,4 @@ sdk/perl/pm_to_blib
 services/keep/bin
 services/keep/pkg
 services/keep/src/github.com
+sdk/java/target

-----------------------------------------------------------------------


hooks/post-receive
-- 




More information about the arvados-commits mailing list