airavata-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chath...@apache.org
Subject svn commit: r1413788 [2/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...
Date Mon, 26 Nov 2012 19:16:36 GMT
Modified: airavata/trunk/modules/rest/service/src/main/java/org/apache/airavata/services/registry/rest/resources/ExperimentRegistryResource.java
URL: http://svn.apache.org/viewvc/airavata/trunk/modules/rest/service/src/main/java/org/apache/airavata/services/registry/rest/resources/ExperimentRegistryResource.java?rev=1413788&r1=1413787&r2=1413788&view=diff
==============================================================================
--- airavata/trunk/modules/rest/service/src/main/java/org/apache/airavata/services/registry/rest/resources/ExperimentRegistryResource.java (original)
+++ airavata/trunk/modules/rest/service/src/main/java/org/apache/airavata/services/registry/rest/resources/ExperimentRegistryResource.java Mon Nov 26 19:16:30 2012
@@ -31,6 +31,7 @@ import org.apache.airavata.registry.api.
 import org.apache.airavata.rest.mappings.resourcemappings.ExperimentList;
 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.*;
@@ -49,7 +50,6 @@ import java.util.List;
  */
 @Path(ResourcePathConstants.ExperimentResourcePathConstants.EXP_RESOURCE_PATH)
 public class ExperimentRegistryResource {
-    private AiravataRegistry2 airavataRegistry;
 
     @Context
     ServletContext context;
@@ -60,14 +60,15 @@ public class ExperimentRegistryResource 
 
     /**
      * This method will delete an experiment with given experiment ID
-     * @param experimentId  experiment ID
+     *
+     * @param experimentId experiment ID
      * @return HTTP response
      */
     @DELETE
     @Path(ResourcePathConstants.ExperimentResourcePathConstants.DELETE_EXP)
     @Produces(MediaType.TEXT_PLAIN)
     public Response removeExperiment(@QueryParam("experimentId") String experimentId) {
-        airavataRegistry = (AiravataRegistry2) context.getAttribute(RestServicesConstants.AIRAVATA_REGISTRY);
+        AiravataRegistry2 airavataRegistry = RegPoolUtils.acquireRegistry();
         try {
             airavataRegistry.removeExperiment(experimentId);
             Response.ResponseBuilder builder = Response.status(Response.Status.OK);
@@ -77,19 +78,23 @@ public class ExperimentRegistryResource 
             Response.ResponseBuilder builder = Response.status(Response.Status.NOT_FOUND);
             builder.entity(e.getMessage());
             return builder.build();
+        } finally {
+            if (airavataRegistry != null) {
+                RegPoolUtils.releaseRegistry(airavataRegistry);
+            }
         }
     }
 
     /**
      * This method will return all the experiments available
-     * @return HTTP response
      *
+     * @return HTTP response
      */
     @GET
     @Path(ResourcePathConstants.ExperimentResourcePathConstants.GET_ALL_EXPS)
     @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
-    public Response getExperiments(){
-        airavataRegistry = (AiravataRegistry2) context.getAttribute(RestServicesConstants.AIRAVATA_REGISTRY);
+    public Response getExperiments() {
+        AiravataRegistry2 airavataRegistry = RegPoolUtils.acquireRegistry();
         try {
             List<AiravataExperiment> airavataExperimentList = airavataRegistry.getExperiments();
             ExperimentList experimentList = new ExperimentList();
@@ -111,11 +116,16 @@ public class ExperimentRegistryResource 
             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 experiments for a given project
+     *
      * @param projectName project name
      * @return HTTP response
      */
@@ -123,7 +133,7 @@ public class ExperimentRegistryResource 
     @Path(ResourcePathConstants.ExperimentResourcePathConstants.GET_EXPS_BY_PROJECT)
     @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
     public Response getExperimentsByProject(@QueryParam("projectName") String projectName) {
-        airavataRegistry = (AiravataRegistry2) context.getAttribute(RestServicesConstants.AIRAVATA_REGISTRY);
+        AiravataRegistry2 airavataRegistry = RegPoolUtils.acquireRegistry();
         try {
             List<AiravataExperiment> airavataExperimentList = airavataRegistry.getExperiments(projectName);
             ExperimentList experimentList = new ExperimentList();
@@ -145,14 +155,19 @@ public class ExperimentRegistryResource 
             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 experiments in a given period of time
+     *
      * @param fromDate starting date
-     * @param toDate end date
-     * @return  HTTP response
+     * @param toDate   end date
+     * @return HTTP response
      */
     @GET
     @Path(ResourcePathConstants.ExperimentResourcePathConstants.GET_EXPS_BY_DATE)
@@ -160,7 +175,7 @@ public class ExperimentRegistryResource 
     @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
     public Response getExperimentsByDate(@QueryParam("fromDate") String fromDate,
                                          @QueryParam("toDate") String toDate) {
-        airavataRegistry = (AiravataRegistry2) context.getAttribute(RestServicesConstants.AIRAVATA_REGISTRY);
+        AiravataRegistry2 airavataRegistry = RegPoolUtils.acquireRegistry();
         try {
             DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
             Date formattedFromDate = dateFormat.parse(fromDate);
@@ -189,14 +204,19 @@ public class ExperimentRegistryResource 
             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 experiments for a given project in a given period of time
+     *
      * @param projectName project name
-     * @param fromDate starting date
-     * @param toDate end date
+     * @param fromDate    starting date
+     * @param toDate      end date
      * @return HTTP response
      */
     @GET
@@ -206,7 +226,7 @@ public class ExperimentRegistryResource 
     public Response getExperimentsByProjectDate(@QueryParam("projectName") String projectName,
                                                 @QueryParam("fromDate") String fromDate,
                                                 @QueryParam("toDate") String toDate) {
-        airavataRegistry = (AiravataRegistry2) context.getAttribute(RestServicesConstants.AIRAVATA_REGISTRY);
+        AiravataRegistry2 airavataRegistry = RegPoolUtils.acquireRegistry();
         try {
             DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
             Date formattedFromDate = dateFormat.parse(fromDate);
@@ -235,13 +255,18 @@ public class ExperimentRegistryResource 
             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 experiment
-     * @param projectName project name
-     * @param experimentID experiment ID
+     *
+     * @param projectName   project name
+     * @param experimentID  experiment ID
      * @param submittedDate submitted date
      * @return HTTP response
      */
@@ -252,7 +277,7 @@ public class ExperimentRegistryResource 
     public Response addExperiment(@FormParam("projectName") String projectName,
                                   @FormParam("experimentID") String experimentID,
                                   @FormParam("submittedDate") String submittedDate) {
-        airavataRegistry = (AiravataRegistry2) context.getAttribute(RestServicesConstants.AIRAVATA_REGISTRY);
+        AiravataRegistry2 airavataRegistry = RegPoolUtils.acquireRegistry();
         try {
             AiravataExperiment experiment = new AiravataExperiment();
             experiment.setExperimentId(experimentID);
@@ -283,12 +308,17 @@ public class ExperimentRegistryResource 
             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 check whether the given experiment ID exists
+     *
      * @param experimentId experiment ID
      * @return HTTP response
      */
@@ -296,7 +326,7 @@ public class ExperimentRegistryResource 
     @Path(ResourcePathConstants.ExperimentResourcePathConstants.EXP_EXISTS)
     @Produces(MediaType.TEXT_PLAIN)
     public Response isExperimentExists(@QueryParam("experimentId") String experimentId) {
-        airavataRegistry = (AiravataRegistry2) context.getAttribute(RestServicesConstants.AIRAVATA_REGISTRY);
+        AiravataRegistry2 airavataRegistry = RegPoolUtils.acquireRegistry();
         try {
             airavataRegistry.isExperimentExists(experimentId);
             Response.ResponseBuilder builder = Response.status(Response.Status.NO_CONTENT);
@@ -310,14 +340,19 @@ public class ExperimentRegistryResource 
             Response.ResponseBuilder builder = Response.status(Response.Status.NOT_FOUND);
             builder.entity("Exprtiment does not exist...");
             return builder.build();
+        } finally {
+            if (airavataRegistry != null) {
+                RegPoolUtils.releaseRegistry(airavataRegistry);
+            }
         }
     }
 
     /**
      * This method will check whether an experiment exist and create if not exists according to the
      * createIfNotPresent flag
-     * @param experimentId  experiment ID
-     * @param createIfNotPresent  flag to check whether to create a new experiment or not
+     *
+     * @param experimentId       experiment ID
+     * @param createIfNotPresent flag to check whether to create a new experiment or not
      * @return HTTP response
      */
     @POST
@@ -329,7 +364,7 @@ public class ExperimentRegistryResource 
         if (createIfNotPresent.equals("true")) {
             createIfNotPresentStatus = true;
         }
-        airavataRegistry = (AiravataRegistry2) context.getAttribute(RestServicesConstants.AIRAVATA_REGISTRY);
+        AiravataRegistry2 airavataRegistry = RegPoolUtils.acquireRegistry();
         try {
             airavataRegistry.isExperimentExists(experimentId, createIfNotPresentStatus);
             Response.ResponseBuilder builder = Response.status(Response.Status.NO_CONTENT);
@@ -339,6 +374,10 @@ public class ExperimentRegistryResource 
             Response.ResponseBuilder builder = Response.status(Response.Status.NOT_FOUND);
             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/ProjectRegistryResource.java
URL: http://svn.apache.org/viewvc/airavata/trunk/modules/rest/service/src/main/java/org/apache/airavata/services/registry/rest/resources/ProjectRegistryResource.java?rev=1413788&r1=1413787&r2=1413788&view=diff
==============================================================================
--- airavata/trunk/modules/rest/service/src/main/java/org/apache/airavata/services/registry/rest/resources/ProjectRegistryResource.java (original)
+++ airavata/trunk/modules/rest/service/src/main/java/org/apache/airavata/services/registry/rest/resources/ProjectRegistryResource.java Mon Nov 26 19:16:30 2012
@@ -28,7 +28,7 @@ import org.apache.airavata.registry.api.
 import org.apache.airavata.registry.api.exception.worker.WorkspaceProjectDoesNotExistsException;
 import org.apache.airavata.rest.mappings.resourcemappings.WorkspaceProjectList;
 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.*;
@@ -43,7 +43,6 @@ import java.util.List;
  */
 @Path(ResourcePathConstants.ProjectResourcePathConstants.REGISTRY_API_PROJECTREGISTRY)
 public class ProjectRegistryResource {
-    private AiravataRegistry2 airavataRegistry;
 
     @Context
     ServletContext context;
@@ -61,7 +60,7 @@ public class ProjectRegistryResource {
     @Path(ResourcePathConstants.ProjectResourcePathConstants.PROJECT_EXIST)
     @Produces(MediaType.TEXT_PLAIN)
     public Response isWorkspaceProjectExists(@QueryParam("projectName") String projectName) {
-        airavataRegistry = (AiravataRegistry2) context.getAttribute(RestServicesConstants.AIRAVATA_REGISTRY);
+        AiravataRegistry2 airavataRegistry = RegPoolUtils.acquireRegistry();
         try {
             boolean result = airavataRegistry.isWorkspaceProjectExists(projectName);
             if (result) {
@@ -77,6 +76,10 @@ public class ProjectRegistryResource {
             Response.ResponseBuilder builder = Response.status(Response.Status.INTERNAL_SERVER_ERROR);
             builder.entity(e.getMessage());
             return builder.build();
+        } finally {
+            if (airavataRegistry != null) {
+                RegPoolUtils.releaseRegistry(airavataRegistry);
+            }
         }
     }
 
@@ -96,7 +99,7 @@ public class ProjectRegistryResource {
         if (createIfNotExists.equals("true")) {
             createIfNotExistStatus = true;
         }
-        airavataRegistry = (AiravataRegistry2) context.getAttribute(RestServicesConstants.AIRAVATA_REGISTRY);
+        AiravataRegistry2 airavataRegistry = RegPoolUtils.acquireRegistry();
         try {
             boolean result = airavataRegistry.isWorkspaceProjectExists(projectName, createIfNotExistStatus);
             if (result) {
@@ -112,6 +115,10 @@ public class ProjectRegistryResource {
             Response.ResponseBuilder builder = Response.status(Response.Status.INTERNAL_SERVER_ERROR);
             builder.entity(e.getMessage());
             return builder.build();
+        }finally {
+            if (airavataRegistry != null) {
+                RegPoolUtils.releaseRegistry(airavataRegistry);
+            }
         }
     }
 
@@ -124,7 +131,7 @@ public class ProjectRegistryResource {
     @Path(ResourcePathConstants.ProjectResourcePathConstants.ADD_PROJECT)
     @Produces(MediaType.TEXT_PLAIN)
     public Response addWorkspaceProject(@FormParam("projectName") String projectName) {
-        airavataRegistry = (AiravataRegistry2) context.getAttribute(RestServicesConstants.AIRAVATA_REGISTRY);
+        AiravataRegistry2 airavataRegistry = RegPoolUtils.acquireRegistry();
         try {
             WorkspaceProject workspaceProject = new WorkspaceProject(projectName, airavataRegistry);
             airavataRegistry.addWorkspaceProject(workspaceProject);
@@ -139,6 +146,10 @@ public class ProjectRegistryResource {
             Response.ResponseBuilder builder = Response.status(Response.Status.INTERNAL_SERVER_ERROR);
             builder.entity(e.getMessage());
             return builder.build();
+        } finally {
+            if (airavataRegistry != null) {
+                RegPoolUtils.releaseRegistry(airavataRegistry);
+            }
         }
     }
 
@@ -151,7 +162,7 @@ public class ProjectRegistryResource {
     @Path(ResourcePathConstants.ProjectResourcePathConstants.UPDATE_PROJECT)
     @Produces(MediaType.TEXT_PLAIN)
     public Response updateWorkspaceProject(@FormParam("projectName") String projectName) {
-        airavataRegistry = (AiravataRegistry2) context.getAttribute(RestServicesConstants.AIRAVATA_REGISTRY);
+        AiravataRegistry2 airavataRegistry = RegPoolUtils.acquireRegistry();
         try {
             WorkspaceProject workspaceProject = new WorkspaceProject(projectName, airavataRegistry);
             airavataRegistry.updateWorkspaceProject(workspaceProject);
@@ -166,6 +177,10 @@ public class ProjectRegistryResource {
             Response.ResponseBuilder builder = Response.status(Response.Status.INTERNAL_SERVER_ERROR);
             builder.entity(e.getMessage());
             return builder.build();
+        }  finally {
+            if (airavataRegistry != null) {
+                RegPoolUtils.releaseRegistry(airavataRegistry);
+            }
         }
     }
 
@@ -178,7 +193,7 @@ public class ProjectRegistryResource {
     @Path(ResourcePathConstants.ProjectResourcePathConstants.DELETE_PROJECT)
     @Produces(MediaType.TEXT_PLAIN)
     public Response deleteWorkspaceProject(@QueryParam("projectName") String projectName) {
-        airavataRegistry = (AiravataRegistry2) context.getAttribute(RestServicesConstants.AIRAVATA_REGISTRY);
+        AiravataRegistry2 airavataRegistry = RegPoolUtils.acquireRegistry();
         try {
             airavataRegistry.deleteWorkspaceProject(projectName);
             Response.ResponseBuilder builder = Response.status(Response.Status.OK);
@@ -192,6 +207,10 @@ public class ProjectRegistryResource {
             Response.ResponseBuilder builder = Response.status(Response.Status.INTERNAL_SERVER_ERROR);
             builder.entity(e.getMessage());
             return builder.build();
+        }  finally {
+            if (airavataRegistry != null) {
+                RegPoolUtils.releaseRegistry(airavataRegistry);
+            }
         }
     }
 
@@ -204,7 +223,7 @@ public class ProjectRegistryResource {
     @Path(ResourcePathConstants.ProjectResourcePathConstants.GET_PROJECT)
     @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
     public Response getWorkspaceProject(@QueryParam("projectName") String projectName) {
-        airavataRegistry = (AiravataRegistry2) context.getAttribute(RestServicesConstants.AIRAVATA_REGISTRY);
+        AiravataRegistry2 airavataRegistry = RegPoolUtils.acquireRegistry();
         try {
             WorkspaceProject workspaceProject = airavataRegistry.getWorkspaceProject(projectName);
             if (workspaceProject != null) {
@@ -224,6 +243,10 @@ public class ProjectRegistryResource {
             Response.ResponseBuilder builder = Response.status(Response.Status.INTERNAL_SERVER_ERROR);
             builder.entity(e.getMessage());
             return builder.build();
+        } finally {
+            if (airavataRegistry != null) {
+                RegPoolUtils.releaseRegistry(airavataRegistry);
+            }
         }
     }
 
@@ -235,7 +258,7 @@ public class ProjectRegistryResource {
     @Path(ResourcePathConstants.ProjectResourcePathConstants.GET_PROJECTS)
     @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
     public Response getWorkspaceProjects() {
-        airavataRegistry = (AiravataRegistry2) context.getAttribute(RestServicesConstants.AIRAVATA_REGISTRY);
+        AiravataRegistry2 airavataRegistry = RegPoolUtils.acquireRegistry();
         try {
             List<WorkspaceProject> workspaceProjects = airavataRegistry.getWorkspaceProjects();
             WorkspaceProjectList workspaceProjectList = new WorkspaceProjectList();
@@ -257,6 +280,10 @@ public class ProjectRegistryResource {
             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/ProvenanceRegistryResource.java
URL: http://svn.apache.org/viewvc/airavata/trunk/modules/rest/service/src/main/java/org/apache/airavata/services/registry/rest/resources/ProvenanceRegistryResource.java?rev=1413788&r1=1413787&r2=1413788&view=diff
==============================================================================
--- airavata/trunk/modules/rest/service/src/main/java/org/apache/airavata/services/registry/rest/resources/ProvenanceRegistryResource.java (original)
+++ airavata/trunk/modules/rest/service/src/main/java/org/apache/airavata/services/registry/rest/resources/ProvenanceRegistryResource.java Mon Nov 26 19:16:30 2012
@@ -29,7 +29,7 @@ import org.apache.airavata.rest.mappings
 import org.apache.airavata.rest.mappings.resourcemappings.ExperimentIDList;
 import org.apache.airavata.rest.mappings.resourcemappings.WorkflowInstancesList;
 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.*;
@@ -49,7 +49,6 @@ import java.util.List;
  */
 @Path(ResourcePathConstants.ProvenanceResourcePathConstants.REGISTRY_API_PROVENANCEREGISTRY)
 public class ProvenanceRegistryResource {
-    private AiravataRegistry2 airavataRegistry;
 
     @Context
     ServletContext context;
@@ -60,8 +59,9 @@ public class ProvenanceRegistryResource 
 
     /**
      * This method will update the experiment execution user
+     *
      * @param experimentId experiment ID
-     * @param user experiment execution user
+     * @param user         experiment execution user
      * @return HTTP response
      */
     @POST
@@ -69,7 +69,7 @@ public class ProvenanceRegistryResource 
     @Produces(MediaType.TEXT_PLAIN)
     public Response updateExperimentExecutionUser(@FormParam("experimentId") String experimentId,
                                                   @FormParam("user") String user) {
-        airavataRegistry = (AiravataRegistry2) context.getAttribute(RestServicesConstants.AIRAVATA_REGISTRY);
+        AiravataRegistry2 airavataRegistry = RegPoolUtils.acquireRegistry();
         try {
             airavataRegistry.updateExperimentExecutionUser(experimentId, user);
             Response.ResponseBuilder builder = Response.status(Response.Status.OK);
@@ -79,19 +79,24 @@ public class ProvenanceRegistryResource 
             Response.ResponseBuilder builder = Response.status(Response.Status.NOT_FOUND);
             builder.entity(e.getMessage());
             return builder.build();
+        } finally {
+            if (airavataRegistry != null) {
+                RegPoolUtils.releaseRegistry(airavataRegistry);
+            }
         }
     }
 
     /**
      * This method will retrieve experiment execution user
-     * @param experimentId  experiment ID
+     *
+     * @param experimentId experiment ID
      * @return HTTP response
      */
     @GET
     @Path(ResourcePathConstants.ProvenanceResourcePathConstants.GET_EXPERIMENT_EXECUTIONUSER)
     @Produces(MediaType.TEXT_PLAIN)
     public Response getExperimentExecutionUser(@QueryParam("experimentId") String experimentId) {
-        airavataRegistry = (AiravataRegistry2) context.getAttribute(RestServicesConstants.AIRAVATA_REGISTRY);
+        AiravataRegistry2 airavataRegistry = RegPoolUtils.acquireRegistry();
         try {
             String user = airavataRegistry.getExperimentExecutionUser(experimentId);
             if (user != null) {
@@ -107,19 +112,24 @@ public class ProvenanceRegistryResource 
             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 retrieve the experiment name for a given experiment ID
-     * @param experimentId  experiment ID
+     *
+     * @param experimentId experiment ID
      * @return HTTP response
      */
     @GET
     @Path(ResourcePathConstants.ProvenanceResourcePathConstants.GET_EXPERIMENT_NAME)
     @Produces(MediaType.TEXT_PLAIN)
     public Response getExperimentName(@QueryParam("experimentId") String experimentId) {
-        airavataRegistry = (AiravataRegistry2) context.getAttribute(RestServicesConstants.AIRAVATA_REGISTRY);
+        AiravataRegistry2 airavataRegistry = RegPoolUtils.acquireRegistry();
         try {
             String result = airavataRegistry.getExperimentName(experimentId);
             if (result != null) {
@@ -135,12 +145,17 @@ public class ProvenanceRegistryResource 
             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 experiment name
-     * @param experimentId experiment ID
+     *
+     * @param experimentId   experiment ID
      * @param experimentName experiment name
      * @return HTTP response
      */
@@ -149,7 +164,7 @@ public class ProvenanceRegistryResource 
     @Produces(MediaType.TEXT_PLAIN)
     public Response updateExperimentName(@FormParam("experimentId") String experimentId,
                                          @FormParam("experimentName") String experimentName) {
-        airavataRegistry = (AiravataRegistry2) context.getAttribute(RestServicesConstants.AIRAVATA_REGISTRY);
+        AiravataRegistry2 airavataRegistry = RegPoolUtils.acquireRegistry();
         try {
             airavataRegistry.updateExperimentName(experimentId, experimentName);
             Response.ResponseBuilder builder = Response.status(Response.Status.OK);
@@ -159,11 +174,16 @@ public class ProvenanceRegistryResource 
             Response.ResponseBuilder builder = Response.status(Response.Status.NOT_FOUND);
             builder.entity(e.getMessage());
             return builder.build();
+        } finally {
+            if (airavataRegistry != null) {
+                RegPoolUtils.releaseRegistry(airavataRegistry);
+            }
         }
     }
 
     /**
      * This method will retrieve the experiment metadata
+     *
      * @param experimentId experiment ID
      * @return HTTP response
      */
@@ -171,7 +191,7 @@ public class ProvenanceRegistryResource 
     @Path(ResourcePathConstants.ProvenanceResourcePathConstants.GET_EXPERIMENTMETADATA)
     @Produces(MediaType.TEXT_PLAIN)
     public Response getExperimentMetadata(@QueryParam("experimentId") String experimentId) {
-        airavataRegistry = (AiravataRegistry2) context.getAttribute(RestServicesConstants.AIRAVATA_REGISTRY);
+        AiravataRegistry2 airavataRegistry = RegPoolUtils.acquireRegistry();
         try {
             String result = airavataRegistry.getExperimentMetadata(experimentId);
             if (result != null) {
@@ -187,13 +207,18 @@ public class ProvenanceRegistryResource 
             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 experiment metadata
+     *
      * @param experimentId experiment ID
-     * @param metadata experiment metadata
+     * @param metadata     experiment metadata
      * @return HTTP response
      */
     @POST
@@ -201,7 +226,7 @@ public class ProvenanceRegistryResource 
     @Produces(MediaType.TEXT_PLAIN)
     public Response updateExperimentMetadata(@FormParam("experimentId") String experimentId,
                                              @FormParam("metadata") String metadata) {
-        airavataRegistry = (AiravataRegistry2) context.getAttribute(RestServicesConstants.AIRAVATA_REGISTRY);
+        AiravataRegistry2 airavataRegistry = RegPoolUtils.acquireRegistry();
         try {
             airavataRegistry.updateExperimentMetadata(experimentId, metadata);
             Response.ResponseBuilder builder = Response.status(Response.Status.OK);
@@ -211,12 +236,17 @@ public class ProvenanceRegistryResource 
             Response.ResponseBuilder builder = Response.status(Response.Status.NOT_FOUND);
             builder.entity(e.getMessage());
             return builder.build();
+        } finally {
+            if (airavataRegistry != null) {
+                RegPoolUtils.releaseRegistry(airavataRegistry);
+            }
         }
     }
 
 
     /**
      * This method will retrieve workflow execution name
+     *
      * @param workflowInstanceId workflow instance ID
      * @return HTTP response
      */
@@ -224,7 +254,7 @@ public class ProvenanceRegistryResource 
     @Path(ResourcePathConstants.ProvenanceResourcePathConstants.GET_WORKFLOWTEMPLATENAME)
     @Produces(MediaType.TEXT_PLAIN)
     public Response getWorkflowExecutionTemplateName(@QueryParam("workflowInstanceId") String workflowInstanceId) {
-        airavataRegistry = (AiravataRegistry2) context.getAttribute(RestServicesConstants.AIRAVATA_REGISTRY);
+        AiravataRegistry2 airavataRegistry = RegPoolUtils.acquireRegistry();
         try {
             String result = airavataRegistry.getWorkflowExecutionTemplateName(workflowInstanceId);
             if (result != null) {
@@ -240,13 +270,18 @@ public class ProvenanceRegistryResource 
             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 set the workflow instance template name
+     *
      * @param workflowInstanceId workflow instance id
-     * @param templateName template name
+     * @param templateName       template name
      * @return HTTP response
      */
     @POST
@@ -254,7 +289,7 @@ public class ProvenanceRegistryResource 
     @Produces(MediaType.TEXT_PLAIN)
     public Response setWorkflowInstanceTemplateName(@FormParam("workflowInstanceId") String workflowInstanceId,
                                                     @FormParam("templateName") String templateName) {
-        airavataRegistry = (AiravataRegistry2) context.getAttribute(RestServicesConstants.AIRAVATA_REGISTRY);
+        AiravataRegistry2 airavataRegistry = RegPoolUtils.acquireRegistry();
         try {
             airavataRegistry.setWorkflowInstanceTemplateName(workflowInstanceId, templateName);
             Response.ResponseBuilder builder = Response.status(Response.Status.OK);
@@ -264,11 +299,16 @@ public class ProvenanceRegistryResource 
             Response.ResponseBuilder builder = Response.status(Response.Status.NOT_FOUND);
             builder.entity(e.getMessage());
             return builder.build();
+        } finally {
+            if (airavataRegistry != null) {
+                RegPoolUtils.releaseRegistry(airavataRegistry);
+            }
         }
     }
 
     /**
      * This method will get experiment workflow instances for a given experiment ID
+     *
      * @param experimentId experiment ID
      * @return HTTP response
      */
@@ -276,7 +316,7 @@ public class ProvenanceRegistryResource 
     @Path(ResourcePathConstants.ProvenanceResourcePathConstants.GET_EXPERIMENTWORKFLOWINSTANCES)
     @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
     public Response getExperimentWorkflowInstances(@QueryParam("experimentId") String experimentId) {
-        airavataRegistry = (AiravataRegistry2) context.getAttribute(RestServicesConstants.AIRAVATA_REGISTRY);
+        AiravataRegistry2 airavataRegistry = RegPoolUtils.acquireRegistry();
         try {
             List<WorkflowInstance> experimentWorkflowInstances = airavataRegistry.getExperimentWorkflowInstances(experimentId);
             WorkflowInstancesList workflowInstancesList = new WorkflowInstancesList();
@@ -298,11 +338,16 @@ public class ProvenanceRegistryResource 
             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 check whether a workflow instance exists
+     *
      * @param instanceId workflow instance ID
      * @return HTTP response
      */
@@ -310,7 +355,7 @@ public class ProvenanceRegistryResource 
     @Path(ResourcePathConstants.ProvenanceResourcePathConstants.WORKFLOWINSTANCE_EXIST_CHECK)
     @Produces(MediaType.TEXT_PLAIN)
     public Response isWorkflowInstanceExists(@QueryParam("instanceId") String instanceId) {
-        airavataRegistry = (AiravataRegistry2) context.getAttribute(RestServicesConstants.AIRAVATA_REGISTRY);
+        AiravataRegistry2 airavataRegistry = RegPoolUtils.acquireRegistry();
         try {
             Boolean result = airavataRegistry.isWorkflowInstanceExists(instanceId);
             if (result) {
@@ -326,6 +371,10 @@ public class ProvenanceRegistryResource 
             Response.ResponseBuilder builder = Response.status(Response.Status.NOT_FOUND);
             builder.entity(e.getMessage());
             return builder.build();
+        } finally {
+            if (airavataRegistry != null) {
+                RegPoolUtils.releaseRegistry(airavataRegistry);
+            }
         }
 
     }
@@ -333,7 +382,8 @@ public class ProvenanceRegistryResource 
     /**
      * This method will check whether a workflow instance exist and create the workflow instance
      * according to createIfNotPresent flag
-     * @param instanceId workflow instance ID
+     *
+     * @param instanceId         workflow instance ID
      * @param createIfNotPresent flag whether to create a new workflow instance or not
      * @return HTTP response
      */
@@ -342,7 +392,7 @@ public class ProvenanceRegistryResource 
     @Produces(MediaType.TEXT_PLAIN)
     public Response isWorkflowInstanceExistsThenCreate(@FormParam("instanceId") String instanceId,
                                                        @FormParam("createIfNotPresent") String createIfNotPresent) {
-        airavataRegistry = (AiravataRegistry2) context.getAttribute(RestServicesConstants.AIRAVATA_REGISTRY);
+        AiravataRegistry2 airavataRegistry = RegPoolUtils.acquireRegistry();
         try {
             Boolean result = airavataRegistry.isWorkflowInstanceExists(instanceId, Boolean.valueOf(createIfNotPresent));
             if (result) {
@@ -358,12 +408,17 @@ public class ProvenanceRegistryResource 
             Response.ResponseBuilder builder = Response.status(Response.Status.NOT_FOUND);
             builder.entity(e.getMessage());
             return builder.build();
+        } finally {
+            if (airavataRegistry != null) {
+                RegPoolUtils.releaseRegistry(airavataRegistry);
+            }
         }
     }
 
     /**
      * This method will update workflow instance status
-     * @param instanceId  workflow instance ID
+     *
+     * @param instanceId      workflow instance ID
      * @param executionStatus workflow execution status
      * @return HTTP response
      */
@@ -372,7 +427,7 @@ public class ProvenanceRegistryResource 
     @Produces(MediaType.TEXT_PLAIN)
     public Response updateWorkflowInstanceStatusByInstance(@FormParam("instanceId") String instanceId,
                                                            @FormParam("executionStatus") String executionStatus) {
-        airavataRegistry = (AiravataRegistry2) context.getAttribute(RestServicesConstants.AIRAVATA_REGISTRY);
+        AiravataRegistry2 airavataRegistry = RegPoolUtils.acquireRegistry();
         try {
             WorkflowInstanceStatus.ExecutionStatus status = WorkflowInstanceStatus.ExecutionStatus.valueOf(executionStatus);
             airavataRegistry.updateWorkflowInstanceStatus(instanceId, status);
@@ -383,14 +438,19 @@ public class ProvenanceRegistryResource 
             Response.ResponseBuilder builder = Response.status(Response.Status.NOT_FOUND);
             builder.entity(e.getMessage());
             return builder.build();
+        } finally {
+            if (airavataRegistry != null) {
+                RegPoolUtils.releaseRegistry(airavataRegistry);
+            }
         }
     }
 
     /**
      * This method will update the workflow instance status
-     * @param workflowInstanceId  workflow instance ID
-     * @param executionStatus workflow execution status
-     * @param statusUpdateTime workflow status update time
+     *
+     * @param workflowInstanceId workflow instance ID
+     * @param executionStatus    workflow execution status
+     * @param statusUpdateTime   workflow status update time
      * @return HTTP response
      */
     @POST
@@ -399,7 +459,7 @@ public class ProvenanceRegistryResource 
     public Response updateWorkflowInstanceStatus(@FormParam("workflowInstanceId") String workflowInstanceId,
                                                  @FormParam("executionStatus") String executionStatus,
                                                  @FormParam("statusUpdateTime") String statusUpdateTime) {
-        airavataRegistry = (AiravataRegistry2) context.getAttribute(RestServicesConstants.AIRAVATA_REGISTRY);
+        AiravataRegistry2 airavataRegistry = RegPoolUtils.acquireRegistry();
         try {
             DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
             Date formattedDate = dateFormat.parse(statusUpdateTime);
@@ -418,11 +478,16 @@ public class ProvenanceRegistryResource 
             Response.ResponseBuilder builder = Response.status(Response.Status.NOT_FOUND);
             builder.entity(e.getMessage());
             return builder.build();
+        } finally {
+            if (airavataRegistry != null) {
+                RegPoolUtils.releaseRegistry(airavataRegistry);
+            }
         }
     }
 
     /**
      * This method will retrieve workflow instance statuse for a given workflow instance ID
+     *
      * @param instanceId workflow instance ID
      * @return HTTP response
      */
@@ -430,7 +495,7 @@ public class ProvenanceRegistryResource 
     @Path(ResourcePathConstants.ProvenanceResourcePathConstants.GET_WORKFLOWINSTANCESTATUS)
     @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
     public Response getWorkflowInstanceStatus(@QueryParam("instanceId") String instanceId) {
-        airavataRegistry = (AiravataRegistry2) context.getAttribute(RestServicesConstants.AIRAVATA_REGISTRY);
+        AiravataRegistry2 airavataRegistry = RegPoolUtils.acquireRegistry();
         try {
             WorkflowInstanceStatus workflowInstanceStatus = airavataRegistry.getWorkflowInstanceStatus(instanceId);
             if (workflowInstanceStatus != null) {
@@ -446,15 +511,20 @@ public class ProvenanceRegistryResource 
             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 workflowNodeInput
-     * @param nodeID workflow node ID
-     * @param workflowInstanceID  workflow instance ID
-     * @param data input data
-     * @return  HTTP response
+     *
+     * @param nodeID             workflow node ID
+     * @param workflowInstanceID workflow instance ID
+     * @param data               input data
+     * @return HTTP response
      */
     @POST
     @Path(ResourcePathConstants.ProvenanceResourcePathConstants.UPDATE_WORKFLOWNODEINPUT)
@@ -462,7 +532,7 @@ public class ProvenanceRegistryResource 
     public Response updateWorkflowNodeInput(@FormParam("nodeID") String nodeID,
                                             @FormParam("workflowInstanceId") String workflowInstanceID,
                                             @FormParam("data") String data) {
-        airavataRegistry = (AiravataRegistry2) context.getAttribute(RestServicesConstants.AIRAVATA_REGISTRY);
+        AiravataRegistry2 airavataRegistry = RegPoolUtils.acquireRegistry();
         try {
             WorkflowInstanceData workflowInstanceData = airavataRegistry.getWorkflowInstanceData(workflowInstanceID);
             WorkflowInstanceNode workflowInstanceNode = workflowInstanceData.getNodeData(nodeID).getWorkflowInstanceNode();
@@ -474,15 +544,20 @@ public class ProvenanceRegistryResource 
             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 workflow node output
-     * @param nodeID workflow node ID
+     *
+     * @param nodeID             workflow node ID
      * @param workflowInstanceID workflow instance ID
-     * @param data workflow node output data
+     * @param data               workflow node output data
      * @return HTTP response
      */
     @POST
@@ -491,7 +566,7 @@ public class ProvenanceRegistryResource 
     public Response updateWorkflowNodeOutput(@FormParam("nodeID") String nodeID,
                                              @FormParam("workflowInstanceId") String workflowInstanceID,
                                              @FormParam("data") String data) {
-        airavataRegistry = (AiravataRegistry2) context.getAttribute(RestServicesConstants.AIRAVATA_REGISTRY);
+        AiravataRegistry2 airavataRegistry = RegPoolUtils.acquireRegistry();
         try {
             WorkflowInstanceData workflowInstanceData = airavataRegistry.getWorkflowInstanceData(workflowInstanceID);
             WorkflowInstanceNode workflowInstanceNode = workflowInstanceData.getNodeData(nodeID).getWorkflowInstanceNode();
@@ -503,6 +578,10 @@ public class ProvenanceRegistryResource 
             Response.ResponseBuilder builder = Response.status(Response.Status.INTERNAL_SERVER_ERROR);
             builder.entity(e.getMessage());
             return builder.build();
+        } finally {
+            if (airavataRegistry != null) {
+                RegPoolUtils.releaseRegistry(airavataRegistry);
+            }
         }
     }
 
@@ -513,7 +592,7 @@ public class ProvenanceRegistryResource 
     public Response searchWorkflowInstanceNodeInput(@QueryParam("experimentIdRegEx") String experimentIdRegEx,
                                                     @QueryParam("workflowNameRegEx") String workflowNameRegEx,
                                                     @QueryParam("nodeNameRegEx") String nodeNameRegEx) {
-        airavataRegistry = (AiravataRegistry2) context.getAttribute(RestServicesConstants.AIRAVATA_REGISTRY);
+        AiravataRegistry2 airavataRegistry = RegPoolUtils.acquireRegistry();
         try {
             List<WorkflowNodeIOData> workflowNodeIODataList = airavataRegistry.searchWorkflowInstanceNodeInput(experimentIdRegEx, workflowNameRegEx, nodeNameRegEx);
             WorkflowNodeIODataMapping[] workflowNodeIODataCollection = new WorkflowNodeIODataMapping[workflowNodeIODataList.size()];
@@ -541,6 +620,10 @@ public class ProvenanceRegistryResource 
         } catch (RegistryException e) {
             Response.ResponseBuilder builder = Response.status(Response.Status.INTERNAL_SERVER_ERROR);
             return builder.build();
+        } finally {
+            if (airavataRegistry != null) {
+                RegPoolUtils.releaseRegistry(airavataRegistry);
+            }
         }
     }
 
@@ -550,7 +633,7 @@ public class ProvenanceRegistryResource 
     public Response searchWorkflowInstanceNodeOutput(@QueryParam("experimentIdRegEx") String experimentIdRegEx,
                                                      @QueryParam("workflowNameRegEx") String workflowNameRegEx,
                                                      @QueryParam("nodeNameRegEx") String nodeNameRegEx) {
-        airavataRegistry = (AiravataRegistry2) context.getAttribute(RestServicesConstants.AIRAVATA_REGISTRY);
+        AiravataRegistry2 airavataRegistry = RegPoolUtils.acquireRegistry();
         try {
             List<WorkflowNodeIOData> workflowNodeIODataList = airavataRegistry.searchWorkflowInstanceNodeOutput(experimentIdRegEx, workflowNameRegEx, nodeNameRegEx);
             WorkflowNodeIODataMapping[] workflowNodeIODataCollection = new WorkflowNodeIODataMapping[workflowNodeIODataList.size()];
@@ -578,6 +661,10 @@ public class ProvenanceRegistryResource 
         } catch (RegistryException e) {
             Response.ResponseBuilder builder = Response.status(Response.Status.INTERNAL_SERVER_ERROR);
             return builder.build();
+        }finally {
+            if (airavataRegistry != null) {
+                RegPoolUtils.releaseRegistry(airavataRegistry);
+            }
         }
     }
 
@@ -587,7 +674,7 @@ public class ProvenanceRegistryResource 
     public Response getWorkflowInstanceNodeInput(@QueryParam("workflowInstanceId") String workflowInstanceId,
                                                  @QueryParam("nodeType") String nodeType) {
         // Airavata JPA Registry method returns null at the moment
-        airavataRegistry = (AiravataRegistry2) context.getAttribute(RestServicesConstants.AIRAVATA_REGISTRY);
+        AiravataRegistry2 airavataRegistry = RegPoolUtils.acquireRegistry();
         try {
             List<WorkflowNodeIOData> workflowNodeIODataList = airavataRegistry.getWorkflowInstanceNodeInput(workflowInstanceId, nodeType);
             WorkflowNodeIODataMapping[] workflowNodeIODataCollection = new WorkflowNodeIODataMapping[workflowNodeIODataList.size()];
@@ -615,6 +702,10 @@ public class ProvenanceRegistryResource 
         } catch (RegistryException e) {
             Response.ResponseBuilder builder = Response.status(Response.Status.INTERNAL_SERVER_ERROR);
             return builder.build();
+        }  finally {
+            if (airavataRegistry != null) {
+                RegPoolUtils.releaseRegistry(airavataRegistry);
+            }
         }
     }
 
@@ -623,7 +714,7 @@ public class ProvenanceRegistryResource 
     @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
     public Response getWorkflowInstanceNodeOutput(@QueryParam("workflowInstanceId") String workflowInstanceId,
                                                   @QueryParam("nodeType") String nodeType) {
-        airavataRegistry = (AiravataRegistry2) context.getAttribute(RestServicesConstants.AIRAVATA_REGISTRY);
+        AiravataRegistry2 airavataRegistry = RegPoolUtils.acquireRegistry();
         try {
             List<WorkflowNodeIOData> workflowNodeIODataList = airavataRegistry.getWorkflowInstanceNodeOutput(workflowInstanceId, nodeType);
             WorkflowNodeIODataMapping[] workflowNodeIODataCollection = new WorkflowNodeIODataMapping[workflowNodeIODataList.size()];
@@ -651,6 +742,10 @@ public class ProvenanceRegistryResource 
         } catch (RegistryException e) {
             Response.ResponseBuilder builder = Response.status(Response.Status.INTERNAL_SERVER_ERROR);
             return builder.build();
+        }finally {
+            if (airavataRegistry != null) {
+                RegPoolUtils.releaseRegistry(airavataRegistry);
+            }
         }
     }
     */
@@ -658,6 +753,7 @@ public class ProvenanceRegistryResource 
     /**
      * This method will return all the data related to a given experiment. This will include workflow
      * status, input values, output values to the workflow, node statuses etc.
+     *
      * @param experimentId experiment ID
      * @return HTTP response
      */
@@ -665,10 +761,10 @@ public class ProvenanceRegistryResource 
     @Path(ResourcePathConstants.ProvenanceResourcePathConstants.GET_EXPERIMENT)
     @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
     public Response getExperiment(@QueryParam("experimentId") String experimentId) {
-        airavataRegistry = (AiravataRegistry2) context.getAttribute(RestServicesConstants.AIRAVATA_REGISTRY);
-        try{
-            ExperimentDataImpl experimentData = (ExperimentDataImpl)airavataRegistry.getExperiment(experimentId);
-            if (experimentData != null){
+        AiravataRegistry2 airavataRegistry = RegPoolUtils.acquireRegistry();
+        try {
+            ExperimentDataImpl experimentData = (ExperimentDataImpl) airavataRegistry.getExperiment(experimentId);
+            if (experimentData != null) {
                 Response.ResponseBuilder builder = Response.status(Response.Status.OK);
                 builder.entity(experimentData);
                 return builder.build();
@@ -681,11 +777,16 @@ public class ProvenanceRegistryResource 
             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 experiment IDs for a given user
+     *
      * @param username experiment execution user
      * @return HTTP response
      */
@@ -693,12 +794,12 @@ public class ProvenanceRegistryResource 
     @Path(ResourcePathConstants.ProvenanceResourcePathConstants.GET_EXPERIMENT_ID_USER)
     @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
     public Response getExperimentIdByUser(@QueryParam("username") String username) {
-        airavataRegistry = (AiravataRegistry2) context.getAttribute(RestServicesConstants.AIRAVATA_REGISTRY);
-        try{
-            ArrayList<String> experiments = (ArrayList)airavataRegistry.getExperimentIdByUser(username);
+        AiravataRegistry2 airavataRegistry = RegPoolUtils.acquireRegistry();
+        try {
+            ArrayList<String> experiments = (ArrayList) airavataRegistry.getExperimentIdByUser(username);
             ExperimentIDList experimentIDList = new ExperimentIDList();
             experimentIDList.setExperimentIDList(experiments);
-            if (experiments.size() != 0){
+            if (experiments.size() != 0) {
                 Response.ResponseBuilder builder = Response.status(Response.Status.OK);
                 builder.entity(experimentIDList);
                 return builder.build();
@@ -711,26 +812,30 @@ public class ProvenanceRegistryResource 
             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 experiments for a given user
-     * @param username experiment execution user
-     * @return  HTTP response
      *
+     * @param username experiment execution user
+     * @return HTTP response
      */
     @GET
     @Path(ResourcePathConstants.ProvenanceResourcePathConstants.GET_EXPERIMENT_USER)
     @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
-    public Response getExperimentByUser(@QueryParam("username") String username){
-        airavataRegistry = (AiravataRegistry2) context.getAttribute(RestServicesConstants.AIRAVATA_REGISTRY);
-        try{
+    public Response getExperimentByUser(@QueryParam("username") String username) {
+        AiravataRegistry2 airavataRegistry = RegPoolUtils.acquireRegistry();
+        try {
             List<ExperimentData> experimentDataList = airavataRegistry.getExperimentByUser(username);
             ExperimentDataList experimentData = new ExperimentDataList();
             List<ExperimentDataImpl> experimentDatas = new ArrayList<ExperimentDataImpl>();
-            for (int i = 0; i < experimentDataList.size(); i ++){
-                experimentDatas.add((ExperimentDataImpl)experimentDataList.get(i));
+            for (int i = 0; i < experimentDataList.size(); i++) {
+                experimentDatas.add((ExperimentDataImpl) experimentDataList.get(i));
             }
             experimentData.setExperimentDataList(experimentDatas);
             if (experimentDataList.size() != 0) {
@@ -746,14 +851,19 @@ public class ProvenanceRegistryResource 
             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 node status
-     * @param workflowInstanceId  workflow instance ID
-     * @param nodeId  node ID
-     * @param executionStatus node execution status
+     *
+     * @param workflowInstanceId workflow instance ID
+     * @param nodeId             node ID
+     * @param executionStatus    node execution status
      * @return HTTP response
      */
     @POST
@@ -762,8 +872,8 @@ public class ProvenanceRegistryResource 
     public Response updateWorkflowNodeStatus(@FormParam("workflowInstanceId") String workflowInstanceId,
                                              @FormParam("nodeId") String nodeId,
                                              @FormParam("executionStatus") String executionStatus) {
-        airavataRegistry = (AiravataRegistry2) context.getAttribute(RestServicesConstants.AIRAVATA_REGISTRY);
-        try{
+        AiravataRegistry2 airavataRegistry = RegPoolUtils.acquireRegistry();
+        try {
             WorkflowInstanceStatus.ExecutionStatus status = WorkflowInstanceStatus.ExecutionStatus.valueOf(executionStatus);
             airavataRegistry.updateWorkflowNodeStatus(workflowInstanceId, nodeId, status);
             Response.ResponseBuilder builder = Response.status(Response.Status.OK);
@@ -773,26 +883,31 @@ public class ProvenanceRegistryResource 
             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 retrieve workflow status for a given workflow instance and node
+     *
      * @param workflowInstanceId workflow instance ID
-     * @param nodeId node ID
+     * @param nodeId             node ID
      * @return HTTP response
      */
     @GET
     @Path(ResourcePathConstants.ProvenanceResourcePathConstants.GET_WORKFLOWNODE_STATUS)
     @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
     public Response getWorkflowNodeStatus(@QueryParam("workflowInstanceId") String workflowInstanceId,
-                                          @QueryParam("nodeId") String nodeId){
-        airavataRegistry = (AiravataRegistry2) context.getAttribute(RestServicesConstants.AIRAVATA_REGISTRY);
-        try{
+                                          @QueryParam("nodeId") String nodeId) {
+        AiravataRegistry2 airavataRegistry = RegPoolUtils.acquireRegistry();
+        try {
             WorkflowInstanceData workflowInstanceData = airavataRegistry.getWorkflowInstanceData(workflowInstanceId);
             WorkflowInstanceNode workflowInstanceNode = workflowInstanceData.getNodeData(nodeId).getWorkflowInstanceNode();
             WorkflowInstanceNodeStatus workflowNodeStatus = airavataRegistry.getWorkflowNodeStatus(workflowInstanceNode);
-            if(workflowNodeStatus != null){
+            if (workflowNodeStatus != null) {
                 Response.ResponseBuilder builder = Response.status(Response.Status.OK);
                 builder.entity(workflowNodeStatus);
                 return builder.build();
@@ -805,26 +920,31 @@ public class ProvenanceRegistryResource 
             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 retrieve workflow node started time
+     *
      * @param workflowInstanceId workflow instance ID
-     * @param nodeId node ID
-     * @return  HTTP response
+     * @param nodeId             node ID
+     * @return HTTP response
      */
     @GET
     @Path(ResourcePathConstants.ProvenanceResourcePathConstants.GET_WORKFLOWNODE_STARTTIME)
     @Produces(MediaType.TEXT_PLAIN)
     public Response getWorkflowNodeStartTime(@QueryParam("workflowInstanceId") String workflowInstanceId,
                                              @QueryParam("nodeId") String nodeId) {
-        airavataRegistry = (AiravataRegistry2) context.getAttribute(RestServicesConstants.AIRAVATA_REGISTRY);
-        try{
+        AiravataRegistry2 airavataRegistry = RegPoolUtils.acquireRegistry();
+        try {
             WorkflowInstanceData workflowInstanceData = airavataRegistry.getWorkflowInstanceData(workflowInstanceId);
             WorkflowInstanceNode workflowInstanceNode = workflowInstanceData.getNodeData(nodeId).getWorkflowInstanceNode();
             Date workflowNodeStartTime = airavataRegistry.getWorkflowNodeStartTime(workflowInstanceNode);
-            if(workflowNodeStartTime != null){
+            if (workflowNodeStartTime != null) {
                 Response.ResponseBuilder builder = Response.status(Response.Status.OK);
                 builder.entity(workflowNodeStartTime.toString());
                 return builder.build();
@@ -837,11 +957,16 @@ public class ProvenanceRegistryResource 
             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 workflow started time
+     *
      * @param workflowInstanceId workflow instance ID
      * @return HTTP response
      */
@@ -849,12 +974,12 @@ public class ProvenanceRegistryResource 
     @Path(ResourcePathConstants.ProvenanceResourcePathConstants.GET_WORKFLOW_STARTTIME)
     @Produces(MediaType.TEXT_PLAIN)
     public Response getWorkflowStartTime(@QueryParam("workflowInstanceId") String workflowInstanceId) {
-        airavataRegistry = (AiravataRegistry2) context.getAttribute(RestServicesConstants.AIRAVATA_REGISTRY);
-        try{
+        AiravataRegistry2 airavataRegistry = RegPoolUtils.acquireRegistry();
+        try {
             WorkflowInstanceData workflowInstanceData = airavataRegistry.getWorkflowInstanceData(workflowInstanceId);
             WorkflowInstance workflowInstance = workflowInstanceData.getWorkflowInstance();
             Date workflowStartTime = airavataRegistry.getWorkflowStartTime(workflowInstance);
-            if(workflowStartTime != null){
+            if (workflowStartTime != null) {
                 Response.ResponseBuilder builder = Response.status(Response.Status.OK);
                 builder.entity(workflowStartTime.toString());
                 return builder.build();
@@ -867,11 +992,16 @@ public class ProvenanceRegistryResource 
             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 workflow node Gram data
+     *
      * @param workflowNodeGramData workflow node gram data object as a JSON input
      * @return HTTP response
      */
@@ -880,8 +1010,8 @@ public class ProvenanceRegistryResource 
     @Consumes({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
     @Produces(MediaType.TEXT_PLAIN)
     public Response updateWorkflowNodeGramData(WorkflowNodeGramData workflowNodeGramData) {
-        airavataRegistry = (AiravataRegistry2) context.getAttribute(RestServicesConstants.AIRAVATA_REGISTRY);
-        try{
+        AiravataRegistry2 airavataRegistry = RegPoolUtils.acquireRegistry();
+        try {
             airavataRegistry.updateWorkflowNodeGramData(workflowNodeGramData);
             Response.ResponseBuilder builder = Response.status(Response.Status.OK);
             builder.entity("Workflow node Gram data updated successfully...");
@@ -890,12 +1020,17 @@ public class ProvenanceRegistryResource 
             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 information regarding a workflow instance
+     *
      * @param workflowInstanceId workflow instance ID
      * @return HTTP response
      */
@@ -903,10 +1038,10 @@ public class ProvenanceRegistryResource 
     @Path(ResourcePathConstants.ProvenanceResourcePathConstants.GET_WORKFLOWINSTANCEDATA)
     @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
     public Response getWorkflowInstanceData(@QueryParam("workflowInstanceId") String workflowInstanceId) {
-        airavataRegistry = (AiravataRegistry2) context.getAttribute(RestServicesConstants.AIRAVATA_REGISTRY);
-        try{
+        AiravataRegistry2 airavataRegistry = RegPoolUtils.acquireRegistry();
+        try {
             WorkflowInstanceData workflowInstanceData = airavataRegistry.getWorkflowInstanceData(workflowInstanceId);
-            if (workflowInstanceData != null){
+            if (workflowInstanceData != null) {
                 Response.ResponseBuilder builder = Response.status(Response.Status.OK);
                 builder.entity(workflowInstanceData);
                 return builder.build();
@@ -919,24 +1054,29 @@ public class ProvenanceRegistryResource 
             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 wil check whether a workflow node present
+     *
      * @param workflowInstanceId workflow instance ID
-     * @param nodeId node ID
+     * @param nodeId             node ID
      * @return HTTP response
      */
     @GET
     @Path(ResourcePathConstants.ProvenanceResourcePathConstants.WORKFLOWINSTANCE_NODE_EXIST)
     @Produces(MediaType.TEXT_PLAIN)
     public Response isWorkflowInstanceNodePresent(@QueryParam("workflowInstanceId") String workflowInstanceId,
-                                                  @QueryParam("nodeId") String nodeId){
-        airavataRegistry = (AiravataRegistry2) context.getAttribute(RestServicesConstants.AIRAVATA_REGISTRY);
-        try{
+                                                  @QueryParam("nodeId") String nodeId) {
+        AiravataRegistry2 airavataRegistry = RegPoolUtils.acquireRegistry();
+        try {
             boolean workflowInstanceNodePresent = airavataRegistry.isWorkflowInstanceNodePresent(workflowInstanceId, nodeId);
-            if (workflowInstanceNodePresent){
+            if (workflowInstanceNodePresent) {
                 Response.ResponseBuilder builder = Response.status(Response.Status.OK);
                 builder.entity("Workflow instance node exists...");
                 return builder.build();
@@ -949,6 +1089,10 @@ public class ProvenanceRegistryResource 
             Response.ResponseBuilder builder = Response.status(Response.Status.INTERNAL_SERVER_ERROR);
             builder.entity(e.getMessage());
             return builder.build();
+        } finally {
+            if (airavataRegistry != null) {
+                RegPoolUtils.releaseRegistry(airavataRegistry);
+            }
         }
 
     }
@@ -956,9 +1100,10 @@ public class ProvenanceRegistryResource 
     /**
      * This method wil check whether a workflow node present and create a new workflow node according
      * to createIfNotPresent flag
+     *
      * @param workflowInstanceId workflow instance Id
-     * @param nodeId  node Id
-     * @param createIfNotPresent  flag whether to create a new node or not
+     * @param nodeId             node Id
+     * @param createIfNotPresent flag whether to create a new node or not
      * @return HTTP response
      */
     @POST
@@ -966,11 +1111,11 @@ public class ProvenanceRegistryResource 
     @Produces(MediaType.TEXT_PLAIN)
     public Response isWorkflowInstanceNodePresentCreate(@FormParam("workflowInstanceId") String workflowInstanceId,
                                                         @FormParam("nodeId") String nodeId,
-                                                        @FormParam("createIfNotPresent") String createIfNotPresent){
-        airavataRegistry = (AiravataRegistry2) context.getAttribute(RestServicesConstants.AIRAVATA_REGISTRY);
-        try{
+                                                        @FormParam("createIfNotPresent") String createIfNotPresent) {
+        AiravataRegistry2 airavataRegistry = RegPoolUtils.acquireRegistry();
+        try {
             boolean workflowInstanceNodePresent = airavataRegistry.isWorkflowInstanceNodePresent(workflowInstanceId, nodeId, Boolean.getBoolean(createIfNotPresent));
-            if (workflowInstanceNodePresent){
+            if (workflowInstanceNodePresent) {
                 Response.ResponseBuilder builder = Response.status(Response.Status.OK);
                 builder.entity("Workflow instance node exists...");
                 return builder.build();
@@ -983,6 +1128,10 @@ public class ProvenanceRegistryResource 
             Response.ResponseBuilder builder = Response.status(Response.Status.INTERNAL_SERVER_ERROR);
             builder.entity(e.getMessage());
             return builder.build();
+        } finally {
+            if (airavataRegistry != null) {
+                RegPoolUtils.releaseRegistry(airavataRegistry);
+            }
         }
 
     }
@@ -990,8 +1139,9 @@ public class ProvenanceRegistryResource 
 
     /**
      * This method will return data related to the workflow instance node
+     *
      * @param workflowInstanceId workflow instance ID
-     * @param nodeId node ID
+     * @param nodeId             node ID
      * @return HTTP response
      */
     @GET
@@ -999,14 +1149,14 @@ public class ProvenanceRegistryResource 
     @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
     public Response getWorkflowInstanceNodeData(@QueryParam("workflowInstanceId") String workflowInstanceId,
                                                 @QueryParam("nodeId") String nodeId) {
-        airavataRegistry = (AiravataRegistry2) context.getAttribute(RestServicesConstants.AIRAVATA_REGISTRY);
-        try{
+        AiravataRegistry2 airavataRegistry = RegPoolUtils.acquireRegistry();
+        try {
             WorkflowInstanceNodeData workflowInstanceNodeData = airavataRegistry.getWorkflowInstanceNodeData(workflowInstanceId, nodeId);
-            if (workflowInstanceNodeData != null){
+            if (workflowInstanceNodeData != null) {
                 Response.ResponseBuilder builder = Response.status(Response.Status.OK);
                 builder.entity(workflowInstanceNodeData);
                 return builder.build();
-            }  else {
+            } else {
                 Response.ResponseBuilder builder = Response.status(Response.Status.NO_CONTENT);
                 builder.entity("Could not retrieve workflow instance node data...");
                 return builder.build();
@@ -1015,16 +1165,21 @@ public class ProvenanceRegistryResource 
             Response.ResponseBuilder builder = Response.status(Response.Status.NO_CONTENT);
             builder.entity(e.getMessage());
             return builder.build();
+        } finally {
+            if (airavataRegistry != null) {
+                RegPoolUtils.releaseRegistry(airavataRegistry);
+            }
         }
 
     }
 
     /**
      * This method will add a workflow instance
-     * @param experimentId experiment ID
-     * @param workflowInstanceId  workflow instance ID
-     * @param templateName workflow template name
-     * @return  HTTP response
+     *
+     * @param experimentId       experiment ID
+     * @param workflowInstanceId workflow instance ID
+     * @param templateName       workflow template name
+     * @return HTTP response
      */
     @POST
     @Path(ResourcePathConstants.ProvenanceResourcePathConstants.ADD_WORKFLOWINSTANCE)
@@ -1032,8 +1187,8 @@ public class ProvenanceRegistryResource 
     public Response addWorkflowInstance(@FormParam("experimentId") String experimentId,
                                         @FormParam("workflowInstanceId") String workflowInstanceId,
                                         @FormParam("templateName") String templateName) {
-        airavataRegistry = (AiravataRegistry2) context.getAttribute(RestServicesConstants.AIRAVATA_REGISTRY);
-        try{
+        AiravataRegistry2 airavataRegistry = RegPoolUtils.acquireRegistry();
+        try {
             airavataRegistry.addWorkflowInstance(experimentId, workflowInstanceId, templateName);
             Response.ResponseBuilder builder = Response.status(Response.Status.OK);
             builder.entity("Workflow instance added successfully...");
@@ -1042,15 +1197,20 @@ public class ProvenanceRegistryResource 
             Response.ResponseBuilder builder = Response.status(Response.Status.NO_CONTENT);
             builder.entity(e.getMessage());
             return builder.build();
+        } finally {
+            if (airavataRegistry != null) {
+                RegPoolUtils.releaseRegistry(airavataRegistry);
+            }
         }
     }
 
     /**
      * This method will update the workflow node type
+     *
      * @param workflowInstanceId workflow instance ID
-     * @param nodeId node ID
-     * @param nodeType node type
-     * @return  HTTP response
+     * @param nodeId             node ID
+     * @param nodeType           node type
+     * @return HTTP response
      */
     @POST
     @Path(ResourcePathConstants.ProvenanceResourcePathConstants.UPDATE_WORKFLOWNODETYPE)
@@ -1058,8 +1218,8 @@ public class ProvenanceRegistryResource 
     public Response updateWorkflowNodeType(@FormParam("workflowInstanceId") String workflowInstanceId,
                                            @FormParam("nodeId") String nodeId,
                                            @FormParam("nodeType") String nodeType) {
-        airavataRegistry = (AiravataRegistry2) context.getAttribute(RestServicesConstants.AIRAVATA_REGISTRY);
-        try{
+        AiravataRegistry2 airavataRegistry = RegPoolUtils.acquireRegistry();
+        try {
             WorkflowInstanceNodeData workflowInstanceNodeData = airavataRegistry.getWorkflowInstanceData(workflowInstanceId).getNodeData(nodeId);
             WorkflowInstanceNode workflowInstanceNode = workflowInstanceNodeData.getWorkflowInstanceNode();
             WorkflowNodeType workflowNodeType = new WorkflowNodeType();
@@ -1075,23 +1235,28 @@ public class ProvenanceRegistryResource 
             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 node to workflow instance
+     *
      * @param workflowInstanceId workflow instance ID
-     * @param nodeId  node ID
-     * @return  HTTP response
+     * @param nodeId             node ID
+     * @return HTTP response
      */
     @POST
     @Path(ResourcePathConstants.ProvenanceResourcePathConstants.ADD_WORKFLOWINSTANCENODE)
     @Produces(MediaType.TEXT_PLAIN)
     public Response addWorkflowInstanceNode(@FormParam("workflowInstanceId") String workflowInstanceId,
                                             @FormParam("nodeId") String nodeId) {
-        airavataRegistry = (AiravataRegistry2) context.getAttribute(RestServicesConstants.AIRAVATA_REGISTRY);
-        try{
+        AiravataRegistry2 airavataRegistry = RegPoolUtils.acquireRegistry();
+        try {
             airavataRegistry.addWorkflowInstanceNode(workflowInstanceId, nodeId);
             Response.ResponseBuilder builder = Response.status(Response.Status.OK);
             builder.entity("Workflow instance node added successfully...");
@@ -1100,23 +1265,28 @@ public class ProvenanceRegistryResource 
             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 wil check whether the experiment name exists
+     *
      * @param experimentName experiment name
      * @return HTTP response
      */
     @GET
     @Path(ResourcePathConstants.ProvenanceResourcePathConstants.EXPERIMENTNAME_EXISTS)
     @Produces(MediaType.TEXT_PLAIN)
-    public Response isExperimentNameExist(@QueryParam("experimentName") String experimentName){
-        airavataRegistry = (AiravataRegistry2) context.getAttribute(RestServicesConstants.AIRAVATA_REGISTRY);
-        try{
+    public Response isExperimentNameExist(@QueryParam("experimentName") String experimentName) {
+        AiravataRegistry2 airavataRegistry = RegPoolUtils.acquireRegistry();
+        try {
             boolean experimentNameExist = airavataRegistry.isExperimentNameExist(experimentName);
-            if (experimentNameExist){
+            if (experimentNameExist) {
                 Response.ResponseBuilder builder = Response.status(Response.Status.OK);
                 builder.entity("Experiment name exists...");
                 return builder.build();
@@ -1130,6 +1300,10 @@ public class ProvenanceRegistryResource 
             Response.ResponseBuilder builder = Response.status(Response.Status.INTERNAL_SERVER_ERROR);
             builder.entity(e.getMessage());
             return builder.build();
+        } finally {
+            if (airavataRegistry != null) {
+                RegPoolUtils.releaseRegistry(airavataRegistry);
+            }
         }
 
     }
@@ -1137,17 +1311,18 @@ public class ProvenanceRegistryResource 
     /**
      * This method will return only information regarding to the experiment. Node information will
      * not be retrieved
+     *
      * @param experimentId experiment ID
      * @return HTTP response
      */
     @GET
     @Path(ResourcePathConstants.ProvenanceResourcePathConstants.GET_EXPERIMENT_METAINFORMATION)
     @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
-    public Response getExperimentMetaInformation(@QueryParam("experimentId") String experimentId){
-        airavataRegistry = (AiravataRegistry2) context.getAttribute(RestServicesConstants.AIRAVATA_REGISTRY);
-        try{
-            ExperimentDataImpl experimentMetaInformation = (ExperimentDataImpl)airavataRegistry.getExperimentMetaInformation(experimentId);
-            if (experimentMetaInformation != null){
+    public Response getExperimentMetaInformation(@QueryParam("experimentId") String experimentId) {
+        AiravataRegistry2 airavataRegistry = RegPoolUtils.acquireRegistry();
+        try {
+            ExperimentDataImpl experimentMetaInformation = (ExperimentDataImpl) airavataRegistry.getExperimentMetaInformation(experimentId);
+            if (experimentMetaInformation != null) {
                 Response.ResponseBuilder builder = Response.status(Response.Status.OK);
                 builder.entity(experimentMetaInformation);
                 return builder.build();
@@ -1160,28 +1335,33 @@ public class ProvenanceRegistryResource 
             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 meta information for all the experiments
+     *
      * @param user experiment execution user
      * @return HTTP response
      */
     @GET
     @Path(ResourcePathConstants.ProvenanceResourcePathConstants.GET_ALL_EXPERIMENT_METAINFORMATION)
     @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
-    public Response getAllExperimentMetaInformation(@QueryParam("user") String user){
-        airavataRegistry = (AiravataRegistry2) context.getAttribute(RestServicesConstants.AIRAVATA_REGISTRY);
-        try{
+    public Response getAllExperimentMetaInformation(@QueryParam("user") String user) {
+        AiravataRegistry2 airavataRegistry = RegPoolUtils.acquireRegistry();
+        try {
             List<ExperimentData> allExperimentMetaInformation = airavataRegistry.getAllExperimentMetaInformation(user);
             ExperimentDataList experimentDataList = new ExperimentDataList();
             List<ExperimentDataImpl> experimentDatas = new ArrayList<ExperimentDataImpl>();
-            for (ExperimentData experimentData : allExperimentMetaInformation){
-                experimentDatas.add((ExperimentDataImpl)experimentData);
+            for (ExperimentData experimentData : allExperimentMetaInformation) {
+                experimentDatas.add((ExperimentDataImpl) experimentData);
             }
             experimentDataList.setExperimentDataList(experimentDatas);
-            if (allExperimentMetaInformation.size() != 0){
+            if (allExperimentMetaInformation.size() != 0) {
                 Response.ResponseBuilder builder = Response.status(Response.Status.OK);
                 builder.entity(experimentDataList);
                 return builder.build();
@@ -1194,31 +1374,36 @@ public class ProvenanceRegistryResource 
             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 search all the experiments which has the name like given experiment name for
      * a given experiment execution user
-     * @param user experiment execution user
+     *
+     * @param user                experiment execution user
      * @param experimentNameRegex experiment name
-     * @return  HTTP response
+     * @return HTTP response
      */
     @GET
     @Path(ResourcePathConstants.ProvenanceResourcePathConstants.SEARCH_EXPERIMENTS)
     @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
     public Response searchExperiments(@QueryParam("user") String user,
-                                      @QueryParam("experimentNameRegex") String experimentNameRegex){
-        airavataRegistry = (AiravataRegistry2) context.getAttribute(RestServicesConstants.AIRAVATA_REGISTRY);
-        try{
+                                      @QueryParam("experimentNameRegex") String experimentNameRegex) {
+        AiravataRegistry2 airavataRegistry = RegPoolUtils.acquireRegistry();
+        try {
             List<ExperimentData> experimentDataList = airavataRegistry.searchExperiments(user, experimentNameRegex);
             ExperimentDataList experimentData = new ExperimentDataList();
             List<ExperimentDataImpl> experimentDatas = new ArrayList<ExperimentDataImpl>();
-            for (ExperimentData experimentData1 : experimentDataList){
-                experimentDatas.add((ExperimentDataImpl)experimentData1);
+            for (ExperimentData experimentData1 : experimentDataList) {
+                experimentDatas.add((ExperimentDataImpl) experimentData1);
             }
             experimentData.setExperimentDataList(experimentDatas);
-            if (experimentDataList.size() != 0){
+            if (experimentDataList.size() != 0) {
                 Response.ResponseBuilder builder = Response.status(Response.Status.OK);
                 builder.entity(experimentData);
                 return builder.build();
@@ -1231,6 +1416,10 @@ public class ProvenanceRegistryResource 
             Response.ResponseBuilder builder = Response.status(Response.Status.INTERNAL_SERVER_ERROR);
             builder.entity(e.getMessage());
             return builder.build();
+        } finally {
+            if (airavataRegistry != null) {
+                RegPoolUtils.releaseRegistry(airavataRegistry);
+            }
         }
 
     }



Mime
View raw message