You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airavata.apache.org by ch...@apache.org on 2012/11/26 20:16:36 UTC

svn commit: r1413788 [3/3] - in /airavata/trunk/modules: airavata-client/src/main/java/org/apache/airavata/client/ gfac-axis2/src/main/java/org/apache/airavata/services/gfac/axis2/ gfac-core/src/main/java/org/apache/airavata/core/gfac/services/impl/ re...

Modified: airavata/trunk/modules/rest/service/src/main/java/org/apache/airavata/services/registry/rest/resources/PublishWorkflowRegistryResource.java
URL: http://svn.apache.org/viewvc/airavata/trunk/modules/rest/service/src/main/java/org/apache/airavata/services/registry/rest/resources/PublishWorkflowRegistryResource.java?rev=1413788&r1=1413787&r2=1413788&view=diff
==============================================================================
--- airavata/trunk/modules/rest/service/src/main/java/org/apache/airavata/services/registry/rest/resources/PublishWorkflowRegistryResource.java (original)
+++ airavata/trunk/modules/rest/service/src/main/java/org/apache/airavata/services/registry/rest/resources/PublishWorkflowRegistryResource.java Mon Nov 26 19:16:30 2012
@@ -30,7 +30,7 @@ import org.apache.airavata.rest.mappings
 import org.apache.airavata.rest.mappings.resourcemappings.Workflow;
 import org.apache.airavata.rest.mappings.resourcemappings.WorkflowList;
 import org.apache.airavata.rest.mappings.utils.ResourcePathConstants;
-import org.apache.airavata.rest.mappings.utils.RestServicesConstants;
+import org.apache.airavata.services.registry.rest.utils.RegPoolUtils;
 
 import javax.servlet.ServletContext;
 import javax.ws.rs.*;
@@ -47,7 +47,6 @@ import java.util.Map;
  */
 @Path(ResourcePathConstants.PublishedWFConstants.REGISTRY_API_PUBLISHWFREGISTRY)
 public class PublishWorkflowRegistryResource {
-    private AiravataRegistry2 airavataRegistry;
 
     @Context
     ServletContext context;
@@ -56,6 +55,7 @@ public class PublishWorkflowRegistryReso
 
     /**
      * This method will check whether a given published workflow name already exists
+     *
      * @param workflowname publish workflow name
      * @return HTTP response
      */
@@ -63,14 +63,14 @@ public class PublishWorkflowRegistryReso
     @Path(ResourcePathConstants.PublishedWFConstants.PUBLISHWF_EXIST)
     @Produces(MediaType.TEXT_PLAIN)
     public Response isPublishedWorkflowExists(@QueryParam("workflowname") String workflowname) {
-        airavataRegistry = (AiravataRegistry2) context.getAttribute(RestServicesConstants.AIRAVATA_REGISTRY);
-        try{
+        AiravataRegistry2 airavataRegistry = RegPoolUtils.acquireRegistry();
+        try {
             boolean workflowExists = airavataRegistry.isPublishedWorkflowExists(workflowname);
-            if (workflowExists){
+            if (workflowExists) {
                 Response.ResponseBuilder builder = Response.status(Response.Status.OK);
                 builder.entity("Publish workflow exists...");
                 return builder.build();
-            }else {
+            } else {
                 Response.ResponseBuilder builder = Response.status(Response.Status.NO_CONTENT);
                 builder.entity("Publish workflow does not exists...");
                 return builder.build();
@@ -79,12 +79,17 @@ public class PublishWorkflowRegistryReso
             Response.ResponseBuilder builder = Response.status(Response.Status.INTERNAL_SERVER_ERROR);
             builder.entity(e.getMessage());
             return builder.build();
+        } finally {
+            if (airavataRegistry != null) {
+                RegPoolUtils.releaseRegistry(airavataRegistry);
+            }
         }
     }
 
     /**
      * This method will make a user workflow as a published workflow with the given name
-     * @param workflowName user workflow name
+     *
+     * @param workflowName        user workflow name
      * @param publishWorkflowName name need to save the published workflow as
      * @return HTTP response
      */
@@ -92,9 +97,9 @@ public class PublishWorkflowRegistryReso
     @Path(ResourcePathConstants.PublishedWFConstants.PUBLISH_WORKFLOW)
     @Produces(MediaType.TEXT_PLAIN)
     public Response publishWorkflow(@FormParam("workflowName") String workflowName,
-                                    @FormParam("publishWorkflowName") String publishWorkflowName)  {
-        airavataRegistry = (AiravataRegistry2) context.getAttribute(RestServicesConstants.AIRAVATA_REGISTRY);
-        try{
+                                    @FormParam("publishWorkflowName") String publishWorkflowName) {
+        AiravataRegistry2 airavataRegistry = RegPoolUtils.acquireRegistry();
+        try {
             airavataRegistry.publishWorkflow(workflowName, publishWorkflowName);
             Response.ResponseBuilder builder = Response.status(Response.Status.OK);
             builder.entity("Workflow published successfully...");
@@ -111,20 +116,25 @@ public class PublishWorkflowRegistryReso
             Response.ResponseBuilder builder = Response.status(Response.Status.INTERNAL_SERVER_ERROR);
             builder.entity(e.getMessage());
             return builder.build();
+        } finally {
+            if (airavataRegistry != null) {
+                RegPoolUtils.releaseRegistry(airavataRegistry);
+            }
         }
     }
 
     /**
      * This method will publish a workflow with the default workflow name
+     *
      * @param workflowName workflow name
      * @return HTTP response
      */
     @POST
     @Path(ResourcePathConstants.PublishedWFConstants.PUBLISH_DEFAULT_WORKFLOW)
     @Produces(MediaType.TEXT_PLAIN)
-    public Response publishWorkflow(@FormParam("workflowName") String workflowName){
-        airavataRegistry = (AiravataRegistry2) context.getAttribute(RestServicesConstants.AIRAVATA_REGISTRY);
-        try{
+    public Response publishWorkflow(@FormParam("workflowName") String workflowName) {
+        AiravataRegistry2 airavataRegistry = RegPoolUtils.acquireRegistry();
+        try {
             airavataRegistry.publishWorkflow(workflowName);
             Response.ResponseBuilder builder = Response.status(Response.Status.OK);
             builder.entity("Workflow published successfully...");
@@ -141,11 +151,16 @@ public class PublishWorkflowRegistryReso
             Response.ResponseBuilder builder = Response.status(Response.Status.INTERNAL_SERVER_ERROR);
             builder.entity(e.getMessage());
             return builder.build();
+        } finally {
+            if (airavataRegistry != null) {
+                RegPoolUtils.releaseRegistry(airavataRegistry);
+            }
         }
     }
 
     /**
      * This method will return the worklflow graph
+     *
      * @param workflowName workflow name
      * @return HTTP response
      */
@@ -153,14 +168,14 @@ public class PublishWorkflowRegistryReso
     @Path(ResourcePathConstants.PublishedWFConstants.GET_PUBLISHWORKFLOWGRAPH)
     @Produces(MediaType.APPLICATION_FORM_URLENCODED)
     public Response getPublishedWorkflowGraphXML(@QueryParam("workflowName") String workflowName) {
-        airavataRegistry = (AiravataRegistry2) context.getAttribute(RestServicesConstants.AIRAVATA_REGISTRY);
-        try{
+        AiravataRegistry2 airavataRegistry = RegPoolUtils.acquireRegistry();
+        try {
             String publishedWorkflowGraphXML = airavataRegistry.getPublishedWorkflowGraphXML(workflowName);
-            if (publishedWorkflowGraphXML !=null){
+            if (publishedWorkflowGraphXML != null) {
                 Response.ResponseBuilder builder = Response.status(Response.Status.OK);
                 builder.entity(publishedWorkflowGraphXML);
                 return builder.build();
-            }else {
+            } else {
                 Response.ResponseBuilder builder = Response.status(Response.Status.NO_CONTENT);
                 builder.entity("Could not find workflow graph...");
                 return builder.build();
@@ -173,23 +188,28 @@ public class PublishWorkflowRegistryReso
             Response.ResponseBuilder builder = Response.status(Response.Status.INTERNAL_SERVER_ERROR);
             builder.entity(e.getMessage());
             return builder.build();
+        } finally {
+            if (airavataRegistry != null) {
+                RegPoolUtils.releaseRegistry(airavataRegistry);
+            }
         }
     }
 
     /**
      * This method will return all the published workflow names
+     *
      * @return HTTP response
      */
     @GET
     @Path(ResourcePathConstants.PublishedWFConstants.GET_PUBLISHWORKFLOWNAMES)
     @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
     public Response getPublishedWorkflowNames() {
-        airavataRegistry = (AiravataRegistry2) context.getAttribute(RestServicesConstants.AIRAVATA_REGISTRY);
-        try{
+        AiravataRegistry2 airavataRegistry = RegPoolUtils.acquireRegistry();
+        try {
             List<String> publishedWorkflowNames = airavataRegistry.getPublishedWorkflowNames();
             PublishWorkflowNamesList publishWorkflowNamesList = new PublishWorkflowNamesList();
             publishWorkflowNamesList.setPublishWorkflowNames(publishedWorkflowNames);
-            if (publishedWorkflowNames.size() != 0){
+            if (publishedWorkflowNames.size() != 0) {
                 Response.ResponseBuilder builder = Response.status(Response.Status.OK);
                 builder.entity(publishWorkflowNamesList);
                 return builder.build();
@@ -202,30 +222,35 @@ public class PublishWorkflowRegistryReso
             Response.ResponseBuilder builder = Response.status(Response.Status.INTERNAL_SERVER_ERROR);
             builder.entity(e.getMessage());
             return builder.build();
+        } finally {
+            if (airavataRegistry != null) {
+                RegPoolUtils.releaseRegistry(airavataRegistry);
+            }
         }
     }
 
     /**
      * This method will return all the published workflows
+     *
      * @return HTTP response
      */
     @GET
     @Path(ResourcePathConstants.PublishedWFConstants.GET_PUBLISHWORKFLOWS)
     @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
     public Response getPublishedWorkflows() {
-        airavataRegistry = (AiravataRegistry2) context.getAttribute(RestServicesConstants.AIRAVATA_REGISTRY);
-        try{
+        AiravataRegistry2 airavataRegistry = RegPoolUtils.acquireRegistry();
+        try {
             Map<String, String> publishedWorkflows = airavataRegistry.getPublishedWorkflows();
             WorkflowList workflowList = new WorkflowList();
             List<Workflow> workflowsModels = new ArrayList<Workflow>();
-            for (String workflowName : publishedWorkflows.keySet()){
+            for (String workflowName : publishedWorkflows.keySet()) {
                 Workflow workflow = new Workflow();
                 workflow.setWorkflowName(workflowName);
                 workflow.setWorkflowGraph(publishedWorkflows.get(workflowName));
                 workflowsModels.add(workflow);
             }
             workflowList.setWorkflowList(workflowsModels);
-            if(publishedWorkflows.size() != 0 ){
+            if (publishedWorkflows.size() != 0) {
                 Response.ResponseBuilder builder = Response.status(Response.Status.OK);
                 builder.entity(workflowList);
                 return builder.build();
@@ -239,11 +264,16 @@ public class PublishWorkflowRegistryReso
             Response.ResponseBuilder builder = Response.status(Response.Status.INTERNAL_SERVER_ERROR);
             builder.entity(e.getMessage());
             return builder.build();
+        } finally {
+            if (airavataRegistry != null) {
+                RegPoolUtils.releaseRegistry(airavataRegistry);
+            }
         }
     }
 
     /**
      * This method will delete a published workflow with the given published workflow name
+     *
      * @param workflowName published workflow name
      * @return HTTP response
      */
@@ -251,8 +281,8 @@ public class PublishWorkflowRegistryReso
     @Path(ResourcePathConstants.PublishedWFConstants.REMOVE_PUBLISHWORKFLOW)
     @Produces(MediaType.TEXT_PLAIN)
     public Response removePublishedWorkflow(@QueryParam("workflowName") String workflowName) {
-        airavataRegistry = (AiravataRegistry2) context.getAttribute(RestServicesConstants.AIRAVATA_REGISTRY);
-        try{
+        AiravataRegistry2 airavataRegistry = RegPoolUtils.acquireRegistry();
+        try {
             airavataRegistry.removePublishedWorkflow(workflowName);
             Response.ResponseBuilder builder = Response.status(Response.Status.OK);
             builder.entity("Publish workflow removed successfully...");
@@ -265,6 +295,10 @@ public class PublishWorkflowRegistryReso
             Response.ResponseBuilder builder = Response.status(Response.Status.INTERNAL_SERVER_ERROR);
             builder.entity(e.getMessage());
             return builder.build();
+        } finally {
+            if (airavataRegistry != null) {
+                RegPoolUtils.releaseRegistry(airavataRegistry);
+            }
         }
     }
 }

Modified: airavata/trunk/modules/rest/service/src/main/java/org/apache/airavata/services/registry/rest/resources/UserWorkflowRegistryResource.java
URL: http://svn.apache.org/viewvc/airavata/trunk/modules/rest/service/src/main/java/org/apache/airavata/services/registry/rest/resources/UserWorkflowRegistryResource.java?rev=1413788&r1=1413787&r2=1413788&view=diff
==============================================================================
--- airavata/trunk/modules/rest/service/src/main/java/org/apache/airavata/services/registry/rest/resources/UserWorkflowRegistryResource.java (original)
+++ airavata/trunk/modules/rest/service/src/main/java/org/apache/airavata/services/registry/rest/resources/UserWorkflowRegistryResource.java Mon Nov 26 19:16:30 2012
@@ -28,7 +28,7 @@ import org.apache.airavata.registry.api.
 import org.apache.airavata.rest.mappings.resourcemappings.Workflow;
 import org.apache.airavata.rest.mappings.resourcemappings.WorkflowList;
 import org.apache.airavata.rest.mappings.utils.ResourcePathConstants;
-import org.apache.airavata.rest.mappings.utils.RestServicesConstants;
+import org.apache.airavata.services.registry.rest.utils.RegPoolUtils;
 
 import javax.servlet.ServletContext;
 import javax.ws.rs.*;
@@ -45,7 +45,6 @@ import java.util.Map;
  */
 @Path(ResourcePathConstants.UserWFConstants.REGISTRY_API_USERWFREGISTRY)
 public class UserWorkflowRegistryResource {
-    private AiravataRegistry2 airavataRegistry;
 
     @Context
     ServletContext context;
@@ -54,21 +53,22 @@ public class UserWorkflowRegistryResourc
 
     /**
      * This method will check whether a given user workflow name already exists
+     *
      * @param workflowName workflow name
      * @return HTTP response
      */
     @GET
     @Path(ResourcePathConstants.UserWFConstants.WORKFLOW_EXIST)
     @Produces(MediaType.TEXT_PLAIN)
-    public Response isWorkflowExists(@QueryParam("workflowName") String workflowName){
-        airavataRegistry = (AiravataRegistry2) context.getAttribute(RestServicesConstants.AIRAVATA_REGISTRY);
-        try{
+    public Response isWorkflowExists(@QueryParam("workflowName") String workflowName) {
+        AiravataRegistry2 airavataRegistry = RegPoolUtils.acquireRegistry();
+        try {
             boolean workflowExists = airavataRegistry.isWorkflowExists(workflowName);
-            if (workflowExists){
+            if (workflowExists) {
                 Response.ResponseBuilder builder = Response.status(Response.Status.OK);
                 builder.entity("User workflow exists...");
                 return builder.build();
-            }else {
+            } else {
                 Response.ResponseBuilder builder = Response.status(Response.Status.NO_CONTENT);
                 builder.entity("User workflow does not exists...");
                 return builder.build();
@@ -77,12 +77,17 @@ public class UserWorkflowRegistryResourc
             Response.ResponseBuilder builder = Response.status(Response.Status.INTERNAL_SERVER_ERROR);
             builder.entity(e.getMessage());
             return builder.build();
+        } finally {
+            if (airavataRegistry != null) {
+                RegPoolUtils.releaseRegistry(airavataRegistry);
+            }
         }
     }
 
     /**
      * This method will add a new workflow
-     * @param workflowName workflow name
+     *
+     * @param workflowName     workflow name
      * @param workflowGraphXml workflow content
      * @return HTTP response
      */
@@ -92,8 +97,8 @@ public class UserWorkflowRegistryResourc
     @Produces(MediaType.TEXT_PLAIN)
     public Response addWorkflow(@FormParam("workflowName") String workflowName,
                                 @FormParam("workflowGraphXml") String workflowGraphXml) {
-        airavataRegistry = (AiravataRegistry2) context.getAttribute(RestServicesConstants.AIRAVATA_REGISTRY);
-        try{
+        AiravataRegistry2 airavataRegistry = RegPoolUtils.acquireRegistry();
+        try {
             airavataRegistry.addWorkflow(workflowName, workflowGraphXml);
             Response.ResponseBuilder builder = Response.status(Response.Status.OK);
             builder.entity("Workflow added successfully...");
@@ -106,12 +111,17 @@ public class UserWorkflowRegistryResourc
             Response.ResponseBuilder builder = Response.status(Response.Status.INTERNAL_SERVER_ERROR);
             builder.entity(e.getMessage());
             return builder.build();
+        } finally {
+            if (airavataRegistry != null) {
+                RegPoolUtils.releaseRegistry(airavataRegistry);
+            }
         }
     }
 
     /**
      * This method will update the workflow
-     * @param workflowName workflow name
+     *
+     * @param workflowName     workflow name
      * @param workflowGraphXml workflow content
      * @return HTTP response
      */
@@ -120,9 +130,9 @@ public class UserWorkflowRegistryResourc
     @Consumes(MediaType.APPLICATION_FORM_URLENCODED)
     @Produces(MediaType.TEXT_PLAIN)
     public Response updateWorkflow(@FormParam("workflowName") String workflowName,
-                                   @FormParam("workflowGraphXml") String workflowGraphXml){
-        airavataRegistry = (AiravataRegistry2) context.getAttribute(RestServicesConstants.AIRAVATA_REGISTRY);
-        try{
+                                   @FormParam("workflowGraphXml") String workflowGraphXml) {
+        AiravataRegistry2 airavataRegistry = RegPoolUtils.acquireRegistry();
+        try {
             airavataRegistry.updateWorkflow(workflowName, workflowGraphXml);
             Response.ResponseBuilder builder = Response.status(Response.Status.OK);
             builder.entity("Workflow updated successfully...");
@@ -135,11 +145,16 @@ public class UserWorkflowRegistryResourc
             Response.ResponseBuilder builder = Response.status(Response.Status.INTERNAL_SERVER_ERROR);
             builder.entity(e.getMessage());
             return builder.build();
+        } finally {
+            if (airavataRegistry != null) {
+                RegPoolUtils.releaseRegistry(airavataRegistry);
+            }
         }
     }
 
     /**
      * This method will return the content of the given workflow
+     *
      * @param workflowName workflow name
      * @return HTTP response
      */
@@ -147,14 +162,14 @@ public class UserWorkflowRegistryResourc
     @Path(ResourcePathConstants.UserWFConstants.GET_WORKFLOWGRAPH)
     @Produces(MediaType.APPLICATION_FORM_URLENCODED)
     public Response getWorkflowGraphXML(@QueryParam("workflowName") String workflowName) {
-        airavataRegistry = (AiravataRegistry2) context.getAttribute(RestServicesConstants.AIRAVATA_REGISTRY);
-        try{
+        AiravataRegistry2 airavataRegistry = RegPoolUtils.acquireRegistry();
+        try {
             String workflowGraphXML = airavataRegistry.getWorkflowGraphXML(workflowName);
-            if (workflowGraphXML != null){
+            if (workflowGraphXML != null) {
                 Response.ResponseBuilder builder = Response.status(Response.Status.OK);
                 builder.entity(workflowGraphXML);
                 return builder.build();
-            }else {
+            } else {
                 Response.ResponseBuilder builder = Response.status(Response.Status.NO_CONTENT);
                 builder.entity("Could not get workflow graph...");
                 return builder.build();
@@ -167,30 +182,35 @@ public class UserWorkflowRegistryResourc
             Response.ResponseBuilder builder = Response.status(Response.Status.INTERNAL_SERVER_ERROR);
             builder.entity(e.getMessage());
             return builder.build();
+        } finally {
+            if (airavataRegistry != null) {
+                RegPoolUtils.releaseRegistry(airavataRegistry);
+            }
         }
     }
 
     /**
      * This method will return all the user workflows
+     *
      * @return HTTP response
      */
     @GET
     @Path(ResourcePathConstants.UserWFConstants.GET_WORKFLOWS)
     @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
-    public Response getWorkflows()  {
-        airavataRegistry = (AiravataRegistry2) context.getAttribute(RestServicesConstants.AIRAVATA_REGISTRY);
-        try{
+    public Response getWorkflows() {
+        AiravataRegistry2 airavataRegistry = RegPoolUtils.acquireRegistry();
+        try {
             Map<String, String> workflows = airavataRegistry.getWorkflows();
             WorkflowList workflowList = new WorkflowList();
             List<Workflow> workflowsModels = new ArrayList<Workflow>();
-            for (String workflowName : workflows.keySet()){
+            for (String workflowName : workflows.keySet()) {
                 Workflow workflow = new Workflow();
                 workflow.setWorkflowName(workflowName);
                 workflow.setWorkflowGraph(workflows.get(workflowName));
                 workflowsModels.add(workflow);
             }
             workflowList.setWorkflowList(workflowsModels);
-            if(workflows.size() != 0 ){
+            if (workflows.size() != 0) {
                 Response.ResponseBuilder builder = Response.status(Response.Status.OK);
                 builder.entity(workflowList);
                 return builder.build();
@@ -204,11 +224,16 @@ public class UserWorkflowRegistryResourc
             Response.ResponseBuilder builder = Response.status(Response.Status.INTERNAL_SERVER_ERROR);
             builder.entity(e.getMessage());
             return builder.build();
+        } finally {
+            if (airavataRegistry != null) {
+                RegPoolUtils.releaseRegistry(airavataRegistry);
+            }
         }
     }
 
     /**
      * This method will delete a user workflow with the given user workflow name
+     *
      * @param workflowName user workflow name
      * @return HTTP response
      */
@@ -216,8 +241,8 @@ public class UserWorkflowRegistryResourc
     @Path(ResourcePathConstants.UserWFConstants.REMOVE_WORKFLOW)
     @Produces(MediaType.TEXT_PLAIN)
     public Response removeWorkflow(@QueryParam("workflowName") String workflowName) {
-        airavataRegistry = (AiravataRegistry2) context.getAttribute(RestServicesConstants.AIRAVATA_REGISTRY);
-        try{
+        AiravataRegistry2 airavataRegistry = RegPoolUtils.acquireRegistry();
+        try {
             airavataRegistry.removeWorkflow(workflowName);
             Response.ResponseBuilder builder = Response.status(Response.Status.OK);
             builder.entity("Workflow removed successfully...");
@@ -230,6 +255,10 @@ public class UserWorkflowRegistryResourc
             Response.ResponseBuilder builder = Response.status(Response.Status.INTERNAL_SERVER_ERROR);
             builder.entity(e.getMessage());
             return builder.build();
+        } finally {
+            if (airavataRegistry != null) {
+                RegPoolUtils.releaseRegistry(airavataRegistry);
+            }
         }
     }
 }

Added: airavata/trunk/modules/rest/service/src/main/java/org/apache/airavata/services/registry/rest/utils/RegIdentifier.java
URL: http://svn.apache.org/viewvc/airavata/trunk/modules/rest/service/src/main/java/org/apache/airavata/services/registry/rest/utils/RegIdentifier.java?rev=1413788&view=auto
==============================================================================
--- airavata/trunk/modules/rest/service/src/main/java/org/apache/airavata/services/registry/rest/utils/RegIdentifier.java (added)
+++ airavata/trunk/modules/rest/service/src/main/java/org/apache/airavata/services/registry/rest/utils/RegIdentifier.java Mon Nov 26 19:16:30 2012
@@ -0,0 +1,40 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.airavata.services.registry.rest.utils;
+
+public class RegIdentifier {
+    private String user;
+    private String gateway;
+
+    public RegIdentifier(String user, String gateway) {
+        this.user = user;
+        this.gateway = gateway;
+    }
+
+    public String getUser() {
+        return user;
+    }
+
+    public String getGateway() {
+        return gateway;
+    }
+}

Added: airavata/trunk/modules/rest/service/src/main/java/org/apache/airavata/services/registry/rest/utils/RegPoolUtils.java
URL: http://svn.apache.org/viewvc/airavata/trunk/modules/rest/service/src/main/java/org/apache/airavata/services/registry/rest/utils/RegPoolUtils.java?rev=1413788&view=auto
==============================================================================
--- airavata/trunk/modules/rest/service/src/main/java/org/apache/airavata/services/registry/rest/utils/RegPoolUtils.java (added)
+++ airavata/trunk/modules/rest/service/src/main/java/org/apache/airavata/services/registry/rest/utils/RegPoolUtils.java Mon Nov 26 19:16:30 2012
@@ -0,0 +1,98 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.airavata.services.registry.rest.utils;
+
+import org.apache.airavata.common.context.RequestContext;
+import org.apache.airavata.common.context.WorkflowContext;
+import org.apache.airavata.common.exception.AiravataConfigurationException;
+import org.apache.airavata.registry.api.AiravataRegistry2;
+import org.apache.airavata.registry.api.AiravataRegistryFactory;
+import org.apache.airavata.registry.api.AiravataUser;
+import org.apache.airavata.registry.api.Gateway;
+import org.apache.airavata.registry.api.exception.RegistryAccessorInstantiateException;
+import org.apache.airavata.registry.api.exception.RegistryAccessorInvalidException;
+import org.apache.airavata.registry.api.exception.RegistryAccessorNotFoundException;
+import org.apache.airavata.registry.api.exception.RegistryAccessorUndefinedException;
+import org.apache.airavata.rest.mappings.utils.RestServicesConstants;
+
+import javax.servlet.ServletContext;
+import javax.ws.rs.core.Context;
+import java.util.Map;
+
+
+public class RegPoolUtils {
+
+    @Context
+    static ServletContext context;
+
+
+    public static AiravataRegistry2 acquireRegistry() {
+        AiravataRegistry2 airavataRegistry=null;
+        RequestContext requestContext = WorkflowContext.get();
+        String user = requestContext.getUserIdentity();
+        Gateway gateway = (Gateway)context.getAttribute(RestServicesConstants.GATEWAY);
+        AiravataUser airavataUser = new AiravataUser(user);
+
+        RegistryInstancesPool registryInstancesPool = (RegistryInstancesPool) context.getAttribute(RestServicesConstants.AIRAVATA_REGISTRY_POOL);
+        Map<RegIdentifier,AiravataRegistry2> registryMap = registryInstancesPool.getRegistryInstancesList();
+        boolean foundReg=false;
+        try{
+            while(!foundReg){
+                synchronized (registryMap){
+                    RegIdentifier identifier = new RegIdentifier(user, gateway.getGatewayName());
+                    if (registryMap.size()==0){
+                        registryMap.put(identifier, AiravataRegistryFactory.getRegistry(gateway, airavataUser));
+                    }else {
+                        airavataRegistry = registryMap.get(identifier);
+                        if (airavataRegistry == null){
+                            registryMap.put(identifier, AiravataRegistryFactory.getRegistry(gateway, airavataUser));
+                        }
+                    }
+                    airavataRegistry=registryMap.get(identifier);
+                    registryMap.remove(identifier);
+                    foundReg=true;
+                }
+            }
+        }catch (RegistryAccessorInvalidException e) {
+            e.printStackTrace();
+        } catch (RegistryAccessorInstantiateException e) {
+            e.printStackTrace();
+        } catch (RegistryAccessorUndefinedException e) {
+            e.printStackTrace();
+        } catch (RegistryAccessorNotFoundException e) {
+            e.printStackTrace();
+        } catch (AiravataConfigurationException e) {
+            e.printStackTrace();
+        }
+        return airavataRegistry;
+    }
+
+    public static void releaseRegistry(AiravataRegistry2 airavataRegistry) {
+        RegistryInstancesPool registryInstancesPool = (RegistryInstancesPool)context.getAttribute(RestServicesConstants.AIRAVATA_REGISTRY_POOL);
+        Map<RegIdentifier, AiravataRegistry2> registryInstancesList = registryInstancesPool.getRegistryInstancesList();
+        synchronized (registryInstancesList){
+            RegIdentifier regIdentifier = new RegIdentifier(airavataRegistry.getUser().getUserName(), airavataRegistry.getGateway().getGatewayName());
+            registryInstancesList.put(regIdentifier, airavataRegistry);
+        }
+    }
+
+}

Added: airavata/trunk/modules/rest/service/src/main/java/org/apache/airavata/services/registry/rest/utils/RegistryInstancesPool.java
URL: http://svn.apache.org/viewvc/airavata/trunk/modules/rest/service/src/main/java/org/apache/airavata/services/registry/rest/utils/RegistryInstancesPool.java?rev=1413788&view=auto
==============================================================================
--- airavata/trunk/modules/rest/service/src/main/java/org/apache/airavata/services/registry/rest/utils/RegistryInstancesPool.java (added)
+++ airavata/trunk/modules/rest/service/src/main/java/org/apache/airavata/services/registry/rest/utils/RegistryInstancesPool.java Mon Nov 26 19:16:30 2012
@@ -0,0 +1,50 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.airavata.services.registry.rest.utils;
+
+import org.apache.airavata.registry.api.AiravataRegistry2;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class RegistryInstancesPool {
+    private Map<RegIdentifier, AiravataRegistry2> registryInstancesList = new HashMap<RegIdentifier, AiravataRegistry2>();
+    private int maxSize;
+
+    public RegistryInstancesPool(int maxSize) {
+        this.maxSize = maxSize;
+    }
+
+    public int getMaxSize() {
+        return maxSize;
+    }
+
+    public Map<RegIdentifier, AiravataRegistry2> getRegistryInstancesList() {
+        return registryInstancesList;
+    }
+
+    public void setRegistryInstancesList(Map<RegIdentifier, AiravataRegistry2> registryInstancesList) {
+        this.registryInstancesList = registryInstancesList;
+    }
+
+
+}

Modified: airavata/trunk/modules/rest/service/src/main/java/org/apache/airavata/services/registry/rest/utils/RegistryListener.java
URL: http://svn.apache.org/viewvc/airavata/trunk/modules/rest/service/src/main/java/org/apache/airavata/services/registry/rest/utils/RegistryListener.java?rev=1413788&r1=1413787&r2=1413788&view=diff
==============================================================================
--- airavata/trunk/modules/rest/service/src/main/java/org/apache/airavata/services/registry/rest/utils/RegistryListener.java (original)
+++ airavata/trunk/modules/rest/service/src/main/java/org/apache/airavata/services/registry/rest/utils/RegistryListener.java Mon Nov 26 19:16:30 2012
@@ -21,16 +21,9 @@
 
 package org.apache.airavata.services.registry.rest.utils;
 
-import org.apache.airavata.registry.api.AiravataRegistry2;
-import org.apache.airavata.registry.api.AiravataRegistryFactory;
-import org.apache.airavata.registry.api.AiravataUser;
 import org.apache.airavata.registry.api.Gateway;
 import org.apache.airavata.rest.mappings.utils.RestServicesConstants;
 
-//import org.apache.airavata.client.AiravataClient;
-//import org.apache.airavata.client.AiravataClientUtils;
-//import org.apache.airavata.client.api.AiravataAPI;
-
 import javax.servlet.ServletContext;
 import javax.servlet.ServletContextEvent;
 import javax.servlet.ServletContextListener;
@@ -39,7 +32,6 @@ import java.net.URL;
 import java.util.Properties;
 
 public class RegistryListener implements ServletContextListener {
-    private static AiravataRegistry2 airavataRegistry;
 
     public void contextInitialized(ServletContextEvent servletContextEvent) {
         try {
@@ -54,17 +46,10 @@ public class RegistryListener implements
                 e.printStackTrace();
             }
             String gatewayID = properties.getProperty(RestServicesConstants.GATEWAY_ID);
-            String registryUser = properties.getProperty(RestServicesConstants.REGISTRY_USERNAME);
             Gateway gateway =  new Gateway(gatewayID);
-            AiravataUser airavataUser = new AiravataUser(registryUser) ;
 
-            airavataRegistry = AiravataRegistryFactory.getRegistry(gateway, airavataUser);
-            servletContext.setAttribute(RestServicesConstants.AIRAVATA_REGISTRY, airavataRegistry);
             servletContext.setAttribute(RestServicesConstants.GATEWAY, gateway);
-            servletContext.setAttribute(RestServicesConstants.REGISTRY_USER, airavataUser);
-
-//            AiravataAPI airavataAPI = AiravataClientUtils.getAPI(url.getPath());
-//            servletContext.setAttribute(RestServicesConstants.AIRAVATA_API, airavataAPI);
+            servletContext.setAttribute(RestServicesConstants.AIRAVATA_REGISTRY_POOL,new RegistryInstancesPool(100));
         } catch (Exception e) {
             e.printStackTrace();
         }

Modified: airavata/trunk/modules/ws-messenger/messagebox/src/main/java/org/apache/airavata/wsmg/msgbox/MsgBoxServiceLifeCycle.java
URL: http://svn.apache.org/viewvc/airavata/trunk/modules/ws-messenger/messagebox/src/main/java/org/apache/airavata/wsmg/msgbox/MsgBoxServiceLifeCycle.java?rev=1413788&r1=1413787&r2=1413788&view=diff
==============================================================================
--- airavata/trunk/modules/ws-messenger/messagebox/src/main/java/org/apache/airavata/wsmg/msgbox/MsgBoxServiceLifeCycle.java (original)
+++ airavata/trunk/modules/ws-messenger/messagebox/src/main/java/org/apache/airavata/wsmg/msgbox/MsgBoxServiceLifeCycle.java Mon Nov 26 19:16:30 2012
@@ -32,8 +32,6 @@ import org.apache.airavata.client.api.Ai
 import org.apache.airavata.client.api.AiravataAPIInvocationException;
 import org.apache.airavata.common.utils.ServiceUtils;
 import org.apache.airavata.client.tools.PeriodicExecutorThread;
-//import org.apache.airavata.registry.api.AiravataRegistry2;
-//import org.apache.airavata.registry.api.util.RegistryUtils;
 import org.apache.airavata.wsmg.commons.config.ConfigurationManager;
 import org.apache.airavata.wsmg.commons.util.Axis2Utils;
 import org.apache.airavata.wsmg.msgbox.Storage.MsgBoxStorage;
@@ -116,11 +114,9 @@ public class MsgBoxServiceLifeCycle impl
 					}
 
                     String userName = properties.getProperty("registry.user");
-                    String password = properties.getProperty("registry.password");
-                    String regURL = properties.getProperty("registry.jdbc.url");
-                    URI baseUri = new URI(regURL);
+                    String gateway = properties.getProperty("gateway.id");
 
-                    AiravataAPI airavataAPI = AiravataAPIFactory.getAPI(baseUri, userName, password);
+                    AiravataAPI airavataAPI = AiravataAPIFactory.getAPI(gateway, userName);
 					String localAddress = ServiceUtils.generateServiceURLFromConfigurationContext(context, MESSAGE_BOX_SERVICE_NAME);
 					logger.debug("MESSAGE BOX SERVICE_ADDRESS:" + localAddress);
                     context.setProperty(SERVICE_URL,new URI(localAddress));

Modified: airavata/trunk/modules/ws-messenger/messagebroker/src/main/java/org/apache/airavata/wsmg/broker/BrokerServiceLifeCycle.java
URL: http://svn.apache.org/viewvc/airavata/trunk/modules/ws-messenger/messagebroker/src/main/java/org/apache/airavata/wsmg/broker/BrokerServiceLifeCycle.java?rev=1413788&r1=1413787&r2=1413788&view=diff
==============================================================================
--- airavata/trunk/modules/ws-messenger/messagebroker/src/main/java/org/apache/airavata/wsmg/broker/BrokerServiceLifeCycle.java (original)
+++ airavata/trunk/modules/ws-messenger/messagebroker/src/main/java/org/apache/airavata/wsmg/broker/BrokerServiceLifeCycle.java Mon Nov 26 19:16:30 2012
@@ -21,7 +21,6 @@
 
 package org.apache.airavata.wsmg.broker;
 
-import java.io.File;
 import java.lang.reflect.Constructor;
 import java.net.URI;
 import java.net.URL;
@@ -34,8 +33,6 @@ import org.apache.airavata.client.api.Ai
 import org.apache.airavata.client.api.AiravataAPIInvocationException;
 import org.apache.airavata.client.tools.PeriodicExecutorThread;
 import org.apache.airavata.common.utils.ServiceUtils;
-//import org.apache.airavata.registry.api.AiravataRegistry2;
-//import org.apache.airavata.registry.api.util.RegistryUtils;
 import org.apache.airavata.wsmg.broker.handler.PublishedMessageHandler;
 import org.apache.airavata.wsmg.broker.subscription.SubscriptionManager;
 import org.apache.airavata.wsmg.commons.WsmgCommonConstants;
@@ -156,11 +153,9 @@ public class BrokerServiceLifeCycle impl
                             }
 
                             String userName = properties.getProperty("registry.user");
-                            String password = properties.getProperty("registry.password");
-                            String regURL = properties.getProperty("registry.jdbc.url");
-                            URI baseUri = new URI(regURL);
+                            String gateway = properties.getProperty("gateway.id");
 
-                            AiravataAPI airavataAPI = AiravataAPIFactory.getAPI(baseUri, userName, password);
+                            AiravataAPI airavataAPI = AiravataAPIFactory.getAPI(gateway, userName);
                             String localAddress = ServiceUtils
                                     .generateServiceURLFromConfigurationContext(
                                             context,