You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airavata.apache.org by sc...@apache.org on 2017/02/17 17:34:48 UTC

[2/3] airavata git commit: using client pools for thrift clients in API server

http://git-wip-us.apache.org/repos/asf/airavata/blob/a286f622/airavata-api/airavata-api-server/src/main/java/org/apache/airavata/api/server/handler/AiravataServerHandler.java
----------------------------------------------------------------------
diff --git a/airavata-api/airavata-api-server/src/main/java/org/apache/airavata/api/server/handler/AiravataServerHandler.java b/airavata-api/airavata-api-server/src/main/java/org/apache/airavata/api/server/handler/AiravataServerHandler.java
index f7c2380..6ae5fad 100644
--- a/airavata-api/airavata-api-server/src/main/java/org/apache/airavata/api/server/handler/AiravataServerHandler.java
+++ b/airavata-api/airavata-api-server/src/main/java/org/apache/airavata/api/server/handler/AiravataServerHandler.java
@@ -24,14 +24,13 @@ package org.apache.airavata.api.server.handler;
 import org.apache.airavata.api.Airavata;
 import org.apache.airavata.api.airavata_apiConstants;
 import org.apache.airavata.api.server.security.interceptor.SecurityCheck;
+import org.apache.airavata.api.server.util.ThriftClientPool;
 import org.apache.airavata.common.exception.AiravataException;
 import org.apache.airavata.common.exception.ApplicationSettingsException;
 import org.apache.airavata.common.utils.AiravataUtils;
 import org.apache.airavata.common.utils.Constants;
 import org.apache.airavata.common.utils.ServerSettings;
-import org.apache.airavata.credential.store.client.CredentialStoreClientFactory;
 import org.apache.airavata.credential.store.cpi.CredentialStoreService;
-import org.apache.airavata.credential.store.exception.CredentialStoreException;
 import org.apache.airavata.messaging.core.MessageContext;
 import org.apache.airavata.messaging.core.MessagingFactory;
 import org.apache.airavata.messaging.core.Publisher;
@@ -75,11 +74,10 @@ import org.apache.airavata.model.workspace.Gateway;
 import org.apache.airavata.model.workspace.Notification;
 import org.apache.airavata.model.workspace.Project;
 import org.apache.airavata.registry.api.RegistryService;
-import org.apache.airavata.registry.api.client.RegistryServiceClientFactory;
 import org.apache.airavata.registry.api.exception.RegistryServiceException;
-import org.apache.airavata.sharing.registry.client.SharingRegistryServiceClientFactory;
 import org.apache.airavata.sharing.registry.models.*;
 import org.apache.airavata.sharing.registry.service.cpi.SharingRegistryService;
+import org.apache.commons.pool.impl.GenericObjectPool;
 import org.apache.thrift.TException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -90,13 +88,35 @@ public class AiravataServerHandler implements Airavata.Iface {
     private static final Logger logger = LoggerFactory.getLogger(AiravataServerHandler.class);
     private Publisher statusPublisher;
     private Publisher experimentPublisher;
-    private CredentialStoreService.Client csClient;
+
+    private ThriftClientPool<SharingRegistryService.Client> sharingClientPool;
+    private ThriftClientPool<RegistryService.Client> registryClientPool;
+    private ThriftClientPool<CredentialStoreService.Client> csClientPool;
 
     public AiravataServerHandler() {
         try {
             statusPublisher = MessagingFactory.getPublisher(Type.STATUS);
             experimentPublisher = MessagingFactory.getPublisher(Type.EXPERIMENT_LAUNCH);
 
+            GenericObjectPool.Config poolConfig = new GenericObjectPool.Config();
+            poolConfig.maxActive = 100;
+            poolConfig.minIdle = 5;
+            poolConfig.whenExhaustedAction = GenericObjectPool.WHEN_EXHAUSTED_BLOCK;
+            poolConfig.testOnBorrow = true;
+            poolConfig.testWhileIdle = true;
+            poolConfig.numTestsPerEvictionRun = 10;
+            poolConfig.maxWait = 3000;
+
+            sharingClientPool = new ThriftClientPool<>(
+                    tProtocol -> new SharingRegistryService.Client(tProtocol), poolConfig, ServerSettings.getSharingRegistryHost(),
+                    Integer.parseInt(ServerSettings.getSharingRegistryPort()));
+            registryClientPool = new ThriftClientPool<>(
+                    tProtocol -> new RegistryService.Client(tProtocol), poolConfig, ServerSettings.getRegistryServerHost(),
+                    Integer.parseInt(ServerSettings.getRegistryServerPort()));
+            csClientPool = new ThriftClientPool<>(
+                    tProtocol -> new CredentialStoreService.Client(tProtocol), poolConfig, ServerSettings.getCredentialStoreServerHost(),
+                    Integer.parseInt(ServerSettings.getCredentialStoreServerPort()));
+
             initSharingRegistry();
         } catch (ApplicationSettingsException e) {
             logger.error("Error occured while reading airavata-server properties..", e);
@@ -108,55 +128,62 @@ public class AiravataServerHandler implements Airavata.Iface {
     }
 
     private void initSharingRegistry() throws ApplicationSettingsException, TException {
-        if (getSharingRegistryServiceClient().getDomain(ServerSettings.getDefaultUserGateway()) == null) {
-            Domain domain = new Domain();
-            domain.setDomainId(ServerSettings.getDefaultUserGateway());
-            domain.setName(ServerSettings.getDefaultUserGateway());
-            domain.setDescription("Domain entry for " + domain.name);
-            getSharingRegistryServiceClient().createDomain(domain);
-
-            User user = new User();
-            user.setDomainId(domain.domainId);
-            user.setUserId(ServerSettings.getDefaultUser()+"@"+ServerSettings.getDefaultUserGateway());
-            user.setUserName(ServerSettings.getDefaultUser());
-            getSharingRegistryServiceClient().createUser(user);
-
-            //Creating Entity Types for each domain
-            EntityType entityType = new EntityType();
-            entityType.setEntityTypeId(domain.domainId+":PROJECT");
-            entityType.setDomainId(domain.domainId);
-            entityType.setName("PROJECT");
-            entityType.setDescription("Project entity type");
-            getSharingRegistryServiceClient().createEntityType(entityType);
-
-            entityType = new EntityType();
-            entityType.setEntityTypeId(domain.domainId+":EXPERIMENT");
-            entityType.setDomainId(domain.domainId);
-            entityType.setName("EXPERIMENT");
-            entityType.setDescription("Experiment entity type");
-            getSharingRegistryServiceClient().createEntityType(entityType);
-
-            entityType = new EntityType();
-            entityType.setEntityTypeId(domain.domainId+":FILE");
-            entityType.setDomainId(domain.domainId);
-            entityType.setName("FILE");
-            entityType.setDescription("File entity type");
-            getSharingRegistryServiceClient().createEntityType(entityType);
-
-            //Creating Permission Types for each domain
-            PermissionType permissionType = new PermissionType();
-            permissionType.setPermissionTypeId(domain.domainId+":READ");
-            permissionType.setDomainId(domain.domainId);
-            permissionType.setName("READ");
-            permissionType.setDescription("Read permission type");
-            getSharingRegistryServiceClient().createPermissionType(permissionType);
-
-            permissionType = new PermissionType();
-            permissionType.setPermissionTypeId(domain.domainId+":WRITE");
-            permissionType.setDomainId(domain.domainId);
-            permissionType.setName("WRITE");
-            permissionType.setDescription("Write permission type");
-            getSharingRegistryServiceClient().createPermissionType(permissionType);
+        SharingRegistryService.Client client = sharingClientPool.getResource();
+        try {
+            if (client.getDomain(ServerSettings.getDefaultUserGateway()) == null) {
+                Domain domain = new Domain();
+                domain.setDomainId(ServerSettings.getDefaultUserGateway());
+                domain.setName(ServerSettings.getDefaultUserGateway());
+                domain.setDescription("Domain entry for " + domain.name);
+                client.createDomain(domain);
+
+                User user = new User();
+                user.setDomainId(domain.domainId);
+                user.setUserId(ServerSettings.getDefaultUser() + "@" + ServerSettings.getDefaultUserGateway());
+                user.setUserName(ServerSettings.getDefaultUser());
+                client.createUser(user);
+
+                //Creating Entity Types for each domain
+                EntityType entityType = new EntityType();
+                entityType.setEntityTypeId(domain.domainId + ":PROJECT");
+                entityType.setDomainId(domain.domainId);
+                entityType.setName("PROJECT");
+                entityType.setDescription("Project entity type");
+                client.createEntityType(entityType);
+
+                entityType = new EntityType();
+                entityType.setEntityTypeId(domain.domainId + ":EXPERIMENT");
+                entityType.setDomainId(domain.domainId);
+                entityType.setName("EXPERIMENT");
+                entityType.setDescription("Experiment entity type");
+                client.createEntityType(entityType);
+
+                entityType = new EntityType();
+                entityType.setEntityTypeId(domain.domainId + ":FILE");
+                entityType.setDomainId(domain.domainId);
+                entityType.setName("FILE");
+                entityType.setDescription("File entity type");
+                client.createEntityType(entityType);
+
+                //Creating Permission Types for each domain
+                PermissionType permissionType = new PermissionType();
+                permissionType.setPermissionTypeId(domain.domainId + ":READ");
+                permissionType.setDomainId(domain.domainId);
+                permissionType.setName("READ");
+                permissionType.setDescription("Read permission type");
+                client.createPermissionType(permissionType);
+
+                permissionType = new PermissionType();
+                permissionType.setPermissionTypeId(domain.domainId + ":WRITE");
+                permissionType.setDomainId(domain.domainId);
+                permissionType.setName("WRITE");
+                permissionType.setDescription("Write permission type");
+                client.createPermissionType(permissionType);
+            }
+            sharingClientPool.returnResource(client);
+        } catch (Exception ex) {
+            sharingClientPool.returnBrokenResource(client);
+            throw ex;
         }
     }
 
@@ -182,13 +209,17 @@ public class AiravataServerHandler implements Airavata.Iface {
     @Override
     public boolean isUserExists(AuthzToken authzToken, String gatewayId, String userName) throws InvalidRequestException,
             AiravataClientException, AiravataSystemException, AuthorizationException, TException {
+        RegistryService.Client client = registryClientPool.getResource();
         try {
-            return getRegistryServiceClient().isUserExists(gatewayId, userName);
-        } catch (ApplicationSettingsException | RegistryServiceException e) {
+            boolean isExists = client.isUserExists(gatewayId, userName);
+            registryClientPool.returnResource(client);
+            return isExists;
+        } catch (Exception e) {
             logger.error("Error while verifying user", e);
             AiravataSystemException exception = new AiravataSystemException();
             exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR);
             exception.setMessage("Error while verifying user. More info : " + e.getMessage());
+            registryClientPool.returnBrokenResource(client);
             throw exception;
         }
     }
@@ -197,13 +228,15 @@ public class AiravataServerHandler implements Airavata.Iface {
     @SecurityCheck
     public String addGateway(AuthzToken authzToken, Gateway gateway) throws InvalidRequestException,
             AiravataClientException, AiravataSystemException, AuthorizationException, TException {
+        SharingRegistryService.Client sharingClient = sharingClientPool.getResource();
+        RegistryService.Client registryClient = registryClientPool.getResource();
         try {
-            String gatewayId = getRegistryServiceClient().addGateway(gateway);
+            String gatewayId = registryClient.addGateway(gateway);
             Domain domain = new Domain();
             domain.setDomainId(gateway.getGatewayId());
             domain.setName(gateway.getGatewayName());
             domain.setDescription("Domain entry for " + domain.name);
-            getSharingRegistryServiceClient().createDomain(domain);
+            sharingClient.createDomain(domain);
 
             //Creating Entity Types for each domain
             EntityType entityType = new EntityType();
@@ -211,21 +244,21 @@ public class AiravataServerHandler implements Airavata.Iface {
             entityType.setDomainId(domain.domainId);
             entityType.setName("PROJECT");
             entityType.setDescription("Project entity type");
-            getSharingRegistryServiceClient().createEntityType(entityType);
+            sharingClient.createEntityType(entityType);
 
             entityType = new EntityType();
             entityType.setEntityTypeId(domain.domainId+":EXPERIMENT");
             entityType.setDomainId(domain.domainId);
             entityType.setName("EXPERIMENT");
             entityType.setDescription("Experiment entity type");
-            getSharingRegistryServiceClient().createEntityType(entityType);
+            sharingClient.createEntityType(entityType);
 
             entityType = new EntityType();
             entityType.setEntityTypeId(domain.domainId+":FILE");
             entityType.setDomainId(domain.domainId);
             entityType.setName("FILE");
             entityType.setDescription("File entity type");
-            getSharingRegistryServiceClient().createEntityType(entityType);
+            sharingClient.createEntityType(entityType);
 
             //Creating Permission Types for each domain
             PermissionType permissionType = new PermissionType();
@@ -233,21 +266,26 @@ public class AiravataServerHandler implements Airavata.Iface {
             permissionType.setDomainId(domain.domainId);
             permissionType.setName("READ");
             permissionType.setDescription("Read permission type");
-            getSharingRegistryServiceClient().createPermissionType(permissionType);
+            sharingClient.createPermissionType(permissionType);
 
             permissionType = new PermissionType();
             permissionType.setPermissionTypeId(domain.domainId+":WRITE");
             permissionType.setDomainId(domain.domainId);
             permissionType.setName("WRITE");
             permissionType.setDescription("Write permission type");
-            getSharingRegistryServiceClient().createPermissionType(permissionType);
+            sharingClient.createPermissionType(permissionType);
+
+            registryClientPool.returnResource(registryClient);
+            sharingClientPool.returnResource(sharingClient);
 
             return gatewayId;
-        } catch (ApplicationSettingsException | RegistryServiceException e) {
+        } catch (Exception e) {
             logger.error("Error while adding gateway", e);
             AiravataSystemException exception = new AiravataSystemException();
             exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR);
             exception.setMessage("Error while adding gateway. More info : " + e.getMessage());
+            sharingClientPool.returnBrokenResource(sharingClient);
+            registryClientPool.returnBrokenResource(registryClient);
             throw exception;
         }
     }
@@ -263,13 +301,17 @@ public class AiravataServerHandler implements Airavata.Iface {
     @Override
     public List<String> getAllUsersInGateway(AuthzToken authzToken, String gatewayId) throws InvalidRequestException,
             AiravataClientException, AiravataSystemException, AuthorizationException, TException {
+        RegistryService.Client regClient = registryClientPool.getResource();
         try {
-            return getRegistryServiceClient().getAllUsersInGateway(gatewayId);
-        } catch (ApplicationSettingsException | RegistryServiceException e) {
+            List<String> result = regClient.getAllUsersInGateway(gatewayId);
+            registryClientPool.returnResource(regClient);
+            return result;
+        } catch (Exception e) {
             logger.error("Error while retrieving users", e);
             AiravataSystemException exception = new AiravataSystemException();
             exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR);
             exception.setMessage("Error while retrieving users. More info : " + e.getMessage());
+            registryClientPool.returnBrokenResource(regClient);
             throw exception;
         }
     }
@@ -279,13 +321,17 @@ public class AiravataServerHandler implements Airavata.Iface {
     public boolean updateGateway(AuthzToken authzToken, String gatewayId, Gateway updatedGateway)
             throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException {
 
+        RegistryService.Client regClient = registryClientPool.getResource();
         try {
-            return getRegistryServiceClient().updateGateway(gatewayId, updatedGateway);
-        } catch (ApplicationSettingsException | RegistryServiceException e) {
+            boolean result = regClient.updateGateway(gatewayId, updatedGateway);
+            registryClientPool.returnResource(regClient);
+            return result;
+        } catch (Exception e) {
             logger.error("Error while updating the gateway", e);
             AiravataSystemException exception = new AiravataSystemException();
             exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR);
             exception.setMessage("Error while updating the gateway. More info : " + e.getMessage());
+            registryClientPool.returnBrokenResource(regClient);
             throw exception;
         }
     }
@@ -295,13 +341,17 @@ public class AiravataServerHandler implements Airavata.Iface {
     public Gateway getGateway(AuthzToken authzToken, String gatewayId) throws InvalidRequestException,
             AiravataClientException, AiravataSystemException, AuthorizationException, TException {
 
+        RegistryService.Client regClient = registryClientPool.getResource();
         try {
-            return getRegistryServiceClient().getGateway(gatewayId);
-        } catch (ApplicationSettingsException | RegistryServiceException e) {
+            Gateway result = regClient.getGateway(gatewayId);
+            registryClientPool.returnResource(regClient);
+            return result;
+        } catch (Exception e) {
             logger.error("Error while getting the gateway", e);
             AiravataSystemException exception = new AiravataSystemException();
             exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR);
             exception.setMessage("Error while getting the gateway. More info : " + e.getMessage());
+            registryClientPool.returnBrokenResource(regClient);
             throw exception;
         }
     }
@@ -310,13 +360,17 @@ public class AiravataServerHandler implements Airavata.Iface {
     @SecurityCheck
     public boolean deleteGateway(AuthzToken authzToken, String gatewayId) throws InvalidRequestException,
             AiravataClientException, AiravataSystemException, AuthorizationException, TException {
+        RegistryService.Client regClient = registryClientPool.getResource();
         try {
-            return getRegistryServiceClient().deleteGateway(gatewayId);
-        } catch (ApplicationSettingsException | RegistryServiceException e) {
+            boolean result = regClient.deleteGateway(gatewayId);
+            registryClientPool.returnResource(regClient);
+            return result;
+        } catch (Exception e) {
             logger.error("Error while deleting the gateway", e);
             AiravataSystemException exception = new AiravataSystemException();
             exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR);
             exception.setMessage("Error while deleting the gateway. More info : " + e.getMessage());
+            registryClientPool.returnBrokenResource(regClient);
             throw exception;
         }
     }
@@ -325,13 +379,17 @@ public class AiravataServerHandler implements Airavata.Iface {
     @SecurityCheck
     public List<Gateway> getAllGateways(AuthzToken authzToken) throws InvalidRequestException, AiravataClientException,
             AiravataSystemException, AuthorizationException, TException {
+        RegistryService.Client regClient = registryClientPool.getResource();
         try {
-            return getRegistryServiceClient().getAllGateways();
-        } catch (ApplicationSettingsException | RegistryServiceException e) {
+            List<Gateway> result = regClient.getAllGateways();
+            registryClientPool.returnResource(regClient);
+            return result;
+        } catch (Exception e) {
             logger.error("Error while getting all the gateways", e);
             AiravataSystemException exception = new AiravataSystemException();
             exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR);
             exception.setMessage("Error while getting all the gateways. More info : " + e.getMessage());
+            registryClientPool.returnBrokenResource(regClient);
             throw exception;
         }
     }
@@ -340,14 +398,17 @@ public class AiravataServerHandler implements Airavata.Iface {
     @SecurityCheck
     public boolean isGatewayExist(AuthzToken authzToken, String gatewayId) throws InvalidRequestException,
             AiravataClientException, AiravataSystemException, AuthorizationException, TException {
-
+        RegistryService.Client regClient = registryClientPool.getResource();
         try {
-            return getRegistryServiceClient().isGatewayExist(gatewayId);
-        } catch (ApplicationSettingsException | RegistryServiceException e) {
+            boolean result = regClient.isGatewayExist(gatewayId);
+            registryClientPool.returnResource(regClient);
+            return result;
+        } catch (Exception e) {
             logger.error("Error while getting gateway", e);
             AiravataSystemException exception = new AiravataSystemException();
             exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR);
             exception.setMessage("Error while getting gateway. More info : " + e.getMessage());
+            registryClientPool.returnBrokenResource(regClient);
             throw exception;
         }
     }
@@ -363,13 +424,17 @@ public class AiravataServerHandler implements Airavata.Iface {
     @SecurityCheck
     public String createNotification(AuthzToken authzToken, Notification notification) throws InvalidRequestException,
             AiravataClientException, AiravataSystemException, AuthorizationException, TException {
+        RegistryService.Client regClient = registryClientPool.getResource();
         try {
-            return getRegistryServiceClient().createNotification(notification);
-        } catch (ApplicationSettingsException | RegistryServiceException e) {
+            String result = regClient.createNotification(notification);
+            registryClientPool.returnResource(regClient);
+            return result;
+        } catch (Exception e) {
             logger.error("Error while creating notification", e);
             AiravataSystemException exception = new AiravataSystemException();
             exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR);
             exception.setMessage("Error while creating notification. More info : " + e.getMessage());
+            registryClientPool.returnBrokenResource(regClient);
             throw exception;
         }
     }
@@ -378,13 +443,17 @@ public class AiravataServerHandler implements Airavata.Iface {
     @SecurityCheck
     public boolean updateNotification(AuthzToken authzToken, Notification notification) throws InvalidRequestException,
             AiravataClientException, AiravataSystemException, AuthorizationException, TException {
+        RegistryService.Client regClient = registryClientPool.getResource();
         try {
-            return getRegistryServiceClient().updateNotification(notification);
-        } catch (ApplicationSettingsException | RegistryServiceException e) {
+            boolean result = regClient.updateNotification(notification);
+            registryClientPool.returnResource(regClient);
+            return result;
+        } catch (Exception e) {
             logger.error("Error while updating notification", e);
             AiravataSystemException exception = new AiravataSystemException();
             exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR);
             exception.setMessage("Error while getting gateway. More info : " + e.getMessage());
+            registryClientPool.returnBrokenResource(regClient);
             throw exception;
         }
     }
@@ -393,28 +462,36 @@ public class AiravataServerHandler implements Airavata.Iface {
     @SecurityCheck
     public boolean deleteNotification(AuthzToken authzToken, String gatewayId, String notificationId) throws InvalidRequestException,
             AiravataClientException, AiravataSystemException, AuthorizationException, TException {
+        RegistryService.Client regClient = registryClientPool.getResource();
         try {
-            return getRegistryServiceClient().deleteNotification(gatewayId, notificationId);
-        } catch (ApplicationSettingsException | RegistryServiceException e) {
+            boolean result = regClient.deleteNotification(gatewayId, notificationId);
+            registryClientPool.returnResource(regClient);
+            return result;
+        } catch (Exception e) {
             logger.error("Error while deleting notification", e);
             AiravataSystemException exception = new AiravataSystemException();
             exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR);
             exception.setMessage("Error while deleting notification. More info : " + e.getMessage());
+            registryClientPool.returnBrokenResource(regClient);
             throw exception;
         }
     }
 
+    // No security check
     @Override
-    @SecurityCheck
     public Notification getNotification(AuthzToken authzToken, String gatewayId, String notificationId) throws InvalidRequestException,
             AiravataClientException, AiravataSystemException, AuthorizationException, TException {
+        RegistryService.Client regClient = registryClientPool.getResource();
         try {
-            return getRegistryServiceClient().getNotification(gatewayId, notificationId);
-        } catch (RegistryServiceException | ApplicationSettingsException e) {
+            Notification result = regClient.getNotification(gatewayId, notificationId);
+            registryClientPool.returnResource(regClient);
+            return result;
+        } catch (Exception e) {
             logger.error("Error while retrieving notification", e);
             AiravataSystemException exception = new AiravataSystemException();
             exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR);
             exception.setMessage("Error while retreiving notification. More info : " + e.getMessage());
+            registryClientPool.returnBrokenResource(regClient);
             throw exception;
         }
     }
@@ -423,13 +500,17 @@ public class AiravataServerHandler implements Airavata.Iface {
     @Override
     public List<Notification> getAllNotifications(AuthzToken authzToken, String gatewayId) throws InvalidRequestException,
             AiravataClientException, AiravataSystemException, AuthorizationException, TException {
+        RegistryService.Client regClient = registryClientPool.getResource();
         try {
-            return getRegistryServiceClient().getAllNotifications(gatewayId);
-        } catch (ApplicationSettingsException | RegistryServiceException e) {
+            List<Notification> result = regClient.getAllNotifications(gatewayId);
+            registryClientPool.returnResource(regClient);
+            return result;
+        } catch (Exception e) {
             logger.error("Error while getting all notifications", e);
             AiravataSystemException exception = new AiravataSystemException();
             exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR);
             exception.setMessage("Error while getting all notifications. More info : " + e.getMessage());
+            registryClientPool.returnBrokenResource(regClient);
             throw exception;
         }
     }
@@ -437,10 +518,8 @@ public class AiravataServerHandler implements Airavata.Iface {
     @Override
     @SecurityCheck
     public String generateAndRegisterSSHKeys(AuthzToken authzToken, String gatewayId, String userName, String description, CredentialOwnerType credentialOwnerType) throws InvalidRequestException, AiravataClientException, AiravataSystemException, TException {
+        CredentialStoreService.Client csClient = csClientPool.getResource();
         try {
-            if (csClient == null){
-                csClient = getCredentialStoreServiceClient();
-            }
             SSHCredential sshCredential = new SSHCredential();
             sshCredential.setUsername(userName);
             sshCredential.setGatewayId(gatewayId);
@@ -450,12 +529,14 @@ public class AiravataServerHandler implements Airavata.Iface {
             }
             String key = csClient.addSSHCredential(sshCredential);
             logger.debug("Airavata generated SSH keys for gateway : " + gatewayId + " and for user : " + userName);
+            csClientPool.returnResource(csClient);
             return key;
         }catch (Exception e){
             logger.error("Error occurred while registering SSH Credential", e);
             AiravataSystemException exception = new AiravataSystemException();
             exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR);
             exception.setMessage("Error occurred while registering SSH Credential. More info : " + e.getMessage());
+            csClientPool.returnBrokenResource(csClient);
             throw exception;
         }
     }
@@ -476,10 +557,8 @@ public class AiravataServerHandler implements Airavata.Iface {
     @SecurityCheck
     public String registerPwdCredential(AuthzToken authzToken, String gatewayId, String portalUserName,
                                         String loginUserName, String password, String description) throws InvalidRequestException, AiravataClientException, AiravataSystemException, TException {
+        CredentialStoreService.Client csClient = csClientPool.getResource();
         try {
-            if (csClient == null){
-                csClient = getCredentialStoreServiceClient();
-            }
             PasswordCredential pwdCredential = new PasswordCredential();
             pwdCredential.setPortalUserName(portalUserName);
             pwdCredential.setLoginUserName(loginUserName);
@@ -488,12 +567,14 @@ public class AiravataServerHandler implements Airavata.Iface {
             pwdCredential.setGatewayId(gatewayId);
             String key = csClient.addPasswordCredential(pwdCredential);
             logger.debug("Airavata generated PWD credential for gateway : " + gatewayId + " and for user : " + loginUserName);
+            csClientPool.returnResource(csClient);
             return key;
         }catch (Exception e){
             logger.error("Error occurred while registering PWD Credential", e);
             AiravataSystemException exception = new AiravataSystemException();
             exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR);
             exception.setMessage("Error occurred while registering PWD Credential. More info : " + e.getMessage());
+            csClientPool.returnBrokenResource(csClient);
             throw exception;
         }
     }
@@ -501,18 +582,18 @@ public class AiravataServerHandler implements Airavata.Iface {
     @Override
     @SecurityCheck
     public String getSSHPubKey(AuthzToken authzToken, String airavataCredStoreToken, String gatewayId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, TException {
+        CredentialStoreService.Client csClient = csClientPool.getResource();
         try {
-            if (csClient == null){
-                csClient = getCredentialStoreServiceClient();
-            }
             SSHCredential sshCredential = csClient.getSSHCredential(airavataCredStoreToken, gatewayId);
             logger.debug("Airavata retrieved SSH pub key for gateway id : " + gatewayId + " and for token : " + airavataCredStoreToken);
+            csClientPool.returnResource(csClient);
             return sshCredential.getPublicKey();
         }catch (Exception e){
             logger.error("Error occurred while retrieving SSH credential", e);
             AiravataSystemException exception = new AiravataSystemException();
             exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR);
             exception.setMessage("Error occurred while retrieving SSH credential. More info : " + e.getMessage());
+            csClientPool.returnBrokenResource(csClient);
             throw exception;
         }
     }
@@ -521,18 +602,18 @@ public class AiravataServerHandler implements Airavata.Iface {
     @Override
     @SecurityCheck
     public Map<String, String> getAllGatewaySSHPubKeys(AuthzToken authzToken, String gatewayId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, TException {
+        CredentialStoreService.Client csClient = csClientPool.getResource();
         try {
-            if (csClient == null){
-                csClient = getCredentialStoreServiceClient();
-            }
             Map<String, String> allSSHKeysForGateway = csClient.getAllSSHKeysForGateway(gatewayId);
             logger.debug("Airavata retrieved all SSH pub keys for gateway Id : " + gatewayId);
+            csClientPool.returnResource(csClient);
             return allSSHKeysForGateway;
         }catch (Exception e){
             logger.error("Error occurred while retrieving SSH public keys for gateway : " + gatewayId , e);
             AiravataSystemException exception = new AiravataSystemException();
             exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR);
             exception.setMessage("Error occurred while retrieving SSH public keys for gateway : " + gatewayId + ". More info : " + e.getMessage());
+            csClientPool.returnBrokenResource(csClient);
             throw exception;
         }
     }
@@ -540,18 +621,19 @@ public class AiravataServerHandler implements Airavata.Iface {
     @Override
     @SecurityCheck
     public List<CredentialSummary> getAllCredentialSummaryForGateway(AuthzToken authzToken, SummaryType type, String gatewayId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, TException {
+        CredentialStoreService.Client csClient = csClientPool.getResource();
         try {
             if(type.equals(SummaryType.SSH)){
-                if (csClient == null){
-                    csClient = getCredentialStoreServiceClient();
-                }
                 logger.debug("Airavata will retrieve all SSH pub keys summaries for gateway Id : " + gatewayId);
-                return csClient.getAllCredentialSummaryForGateway(type, gatewayId);
+                List<CredentialSummary> result = csClient.getAllCredentialSummaryForGateway(type, gatewayId);
+                csClientPool.returnResource(csClient);
+                return result;
             } else {
                 logger.info("Summay Type"+ type.toString() + " not supported by Airavata");
                 AiravataSystemException ex = new AiravataSystemException();
                 ex.setAiravataErrorType(AiravataErrorType.UNSUPPORTED_OPERATION);
                 ex.setMessage("Summay Type"+ type.toString() + " not supported by Airavata");
+                csClientPool.returnResource(csClient);
                 throw ex;
             }
         }catch (Exception e){
@@ -559,6 +641,7 @@ public class AiravataServerHandler implements Airavata.Iface {
             AiravataSystemException exception = new AiravataSystemException();
             exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR);
             exception.setMessage("Error occurred while retrieving SSH public keys summaries for gateway : " + gatewayId + ". More info : " + e.getMessage());
+            csClientPool.returnBrokenResource(csClient);
             throw exception;
         }
     }
@@ -566,18 +649,19 @@ public class AiravataServerHandler implements Airavata.Iface {
     @Override
     @SecurityCheck
     public List<CredentialSummary> getAllCredentialSummaryForUsersInGateway(AuthzToken authzToken,SummaryType type, String gatewayId, String userId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, TException {
+        CredentialStoreService.Client csClient = csClientPool.getResource();
         try {
             if(type.equals(SummaryType.SSH)){
-                if (csClient == null){
-                    csClient = getCredentialStoreServiceClient();
-                }
                 logger.debug("Airavata will retrieve all SSH pub keys summaries for gateway Id : " + gatewayId);
-                return csClient.getAllCredentialSummaryForUserInGateway(type, gatewayId, userId);
+                List<CredentialSummary> result = csClient.getAllCredentialSummaryForUserInGateway(type, gatewayId, userId);
+                csClientPool.returnResource(csClient);
+                return result;
             } else {
                 logger.info("Summay Type"+ type.toString() + " not supported by Airavata");
                 AiravataSystemException ex = new AiravataSystemException();
                 ex.setAiravataErrorType(AiravataErrorType.UNSUPPORTED_OPERATION);
                 ex.setMessage("Summay Type"+ type.toString() + " not supported by Airavata");
+                csClientPool.returnResource(csClient);
                 throw ex;
             }
         }catch (Exception e){
@@ -585,6 +669,7 @@ public class AiravataServerHandler implements Airavata.Iface {
             AiravataSystemException exception = new AiravataSystemException();
             exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR);
             exception.setMessage("Error occurred while retrieving SSH public keys summaries for user : " + userId + ". More info : " + e.getMessage());
+            csClientPool.returnBrokenResource(csClient);
             throw exception;
         }
     }
@@ -592,18 +677,18 @@ public class AiravataServerHandler implements Airavata.Iface {
     @Override
     @SecurityCheck
     public Map<String, String> getAllGatewayPWDCredentials(AuthzToken authzToken, String gatewayId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, TException {
+        CredentialStoreService.Client csClient = csClientPool.getResource();
         try {
-            if (csClient == null){
-                csClient = getCredentialStoreServiceClient();
-            }
             Map<String, String> allPwdCredentials = csClient.getAllPWDCredentialsForGateway(gatewayId);
             logger.debug("Airavata retrieved all PWD Credentials for gateway Id : " + gatewayId);
+            csClientPool.returnResource(csClient);
             return allPwdCredentials;
         }catch (Exception e){
             logger.error("Error occurred while retrieving PWD Credentials for gateway : " + gatewayId , e);
             AiravataSystemException exception = new AiravataSystemException();
             exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR);
             exception.setMessage("Error occurred while retrieving PWD Credentials for gateway : " + gatewayId + ". More info : " + e.getMessage());
+            csClientPool.returnBrokenResource(csClient);
             throw exception;
         }
     }
@@ -611,17 +696,18 @@ public class AiravataServerHandler implements Airavata.Iface {
     @Override
     @SecurityCheck
     public boolean deleteSSHPubKey(AuthzToken authzToken, String airavataCredStoreToken, String gatewayId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, TException {
+        CredentialStoreService.Client csClient = csClientPool.getResource();
         try {
-            if (csClient == null){
-                csClient = getCredentialStoreServiceClient();
-            }
             logger.debug("Airavata deleted SSH pub key for gateway Id : " + gatewayId + " and with token id : " + airavataCredStoreToken);
-            return csClient.deleteSSHCredential(airavataCredStoreToken, gatewayId);
+            boolean result = csClient.deleteSSHCredential(airavataCredStoreToken, gatewayId);
+            csClientPool.returnResource(csClient);
+            return result;
         }catch (Exception e){
             logger.error("Error occurred while deleting SSH credential", e);
             AiravataSystemException exception = new AiravataSystemException();
             exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR);
             exception.setMessage("Error occurred while deleting SSH credential. More info : " + e.getMessage());
+            csClientPool.returnBrokenResource(csClient);
             throw exception;
         }
     }
@@ -629,17 +715,18 @@ public class AiravataServerHandler implements Airavata.Iface {
     @Override
     @SecurityCheck
     public boolean deletePWDCredential(AuthzToken authzToken, String airavataCredStoreToken, String gatewayId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, TException {
+        CredentialStoreService.Client csClient = csClientPool.getResource();
         try {
-            if (csClient == null){
-                csClient = getCredentialStoreServiceClient();
-            }
             logger.debug("Airavata deleted PWD credential for gateway Id : " + gatewayId + " and with token id : " + airavataCredStoreToken);
-            return csClient.deletePWDCredential(airavataCredStoreToken, gatewayId);
+            boolean result = csClient.deletePWDCredential(airavataCredStoreToken, gatewayId);
+            csClientPool.returnResource(csClient);
+            return result;
         }catch (Exception e){
             logger.error("Error occurred while deleting PWD credential", e);
             AiravataSystemException exception = new AiravataSystemException();
             exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR);
             exception.setMessage("Error occurred while deleting PWD credential. More info : " + e.getMessage());
+            csClientPool.returnBrokenResource(csClient);
             throw exception;
         }
     }
@@ -653,10 +740,10 @@ public class AiravataServerHandler implements Airavata.Iface {
     @SecurityCheck
     public String createProject(AuthzToken authzToken, String gatewayId, Project project) throws InvalidRequestException,
             AiravataClientException, AiravataSystemException, AuthorizationException, TException {
-
+        RegistryService.Client regClient = registryClientPool.getResource();
+        SharingRegistryService.Client sharingClient = sharingClientPool.getResource();
         try {
-            String projectId = getRegistryServiceClient().createProject(gatewayId, project);
-
+            String projectId = regClient.createProject(gatewayId, project);
             if(ServerSettings.isEnableSharing()){
                 try {
                     Entity entity = new Entity();
@@ -666,26 +753,27 @@ public class AiravataServerHandler implements Airavata.Iface {
                     entity.setOwnerId(project.getOwner() + "@" + project.getGatewayId());
                     entity.setName(project.getName());
                     entity.setDescription(project.getDescription());
-
-                    getSharingRegistryServiceClient().createEntity(entity);
+                    sharingClient.createEntity(entity);
                 } catch (Exception ex) {
                     logger.error(ex.getMessage(), ex);
                     logger.error("Rolling back project creation Proj ID : " + projectId);
-                    getRegistryServiceClient().deleteProject(projectId);
+                    regClient.deleteProject(projectId);
                     AiravataSystemException ase = new AiravataSystemException();
                     ase.setMessage("Failed to create entry for project in Sharing Registry");
                     throw ase;
                 }
-
             }
-
             logger.debug("Airavata created project with project Id : " + projectId + " for gateway Id : " + gatewayId);
+            registryClientPool.returnResource(regClient);
+            sharingClientPool.returnResource(sharingClient);
             return projectId;
         } catch (Exception e) {
             logger.error("Error while creating the project", e);
             AiravataSystemException exception = new AiravataSystemException();
             exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR);
             exception.setMessage("Error while creating the project. More info : " + e.getMessage());
+            registryClientPool.returnBrokenResource(regClient);
+            sharingClientPool.returnBrokenResource(sharingClient);
             throw exception;
         }
     }
@@ -694,15 +782,16 @@ public class AiravataServerHandler implements Airavata.Iface {
     @SecurityCheck
     public void updateProject(AuthzToken authzToken, String projectId, Project updatedProject) throws InvalidRequestException,
             AiravataClientException, AiravataSystemException, ProjectNotFoundException, AuthorizationException, TException {
+        RegistryService.Client regClient = registryClientPool.getResource();
+        SharingRegistryService.Client sharingClient = sharingClientPool.getResource();
         try {
-            RegistryService.Client regClient = getRegistryServiceClient();
             Project existingProject = regClient.getProject(projectId);
             if(ServerSettings.isEnableSharing() && !authzToken.getClaimsMap().get(org.apache.airavata.common.utils.Constants.USER_NAME).equals(existingProject.getOwner())
                     || !authzToken.getClaimsMap().get(org.apache.airavata.common.utils.Constants.GATEWAY_ID).equals(existingProject.getGatewayId())){
                 try {
                     String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID);
                     String userId = authzToken.getClaimsMap().get(Constants.USER_NAME);
-                    if (!getSharingRegistryServiceClient().userHasAccess(gatewayId, userId + "@" + gatewayId,
+                    if (!sharingClient.userHasAccess(gatewayId, userId + "@" + gatewayId,
                             projectId, gatewayId + ":WRITE")){
                         throw new AuthorizationException("User does not have permission to access this resource");
                     }
@@ -718,11 +807,15 @@ public class AiravataServerHandler implements Airavata.Iface {
             }
             regClient.updateProject(projectId, updatedProject);
             logger.debug("Airavata updated project with project Id : " + projectId );
-        } catch (RegistryServiceException | ApplicationSettingsException e) {
+            registryClientPool.returnResource(regClient);
+            sharingClientPool.returnResource(sharingClient);
+        } catch (Exception e) {
             logger.error("Error while updating the project", e);
             AiravataSystemException exception = new AiravataSystemException();
             exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR);
             exception.setMessage("Error while updating the project. More info : " + e.getMessage());
+            registryClientPool.returnBrokenResource(regClient);
+            sharingClientPool.returnBrokenResource(sharingClient);
             throw exception;
         }
     }
@@ -731,15 +824,16 @@ public class AiravataServerHandler implements Airavata.Iface {
     @SecurityCheck
     public boolean deleteProject(AuthzToken authzToken, String projectId) throws InvalidRequestException,
             AiravataClientException, AiravataSystemException, ProjectNotFoundException, AuthorizationException, TException {
+        RegistryService.Client regClient = registryClientPool.getResource();
+        SharingRegistryService.Client sharingClient = sharingClientPool.getResource();
         try {
-            RegistryService.Client regClient = getRegistryServiceClient();
             Project existingProject = regClient.getProject(projectId);
             if(ServerSettings.isEnableSharing() && !authzToken.getClaimsMap().get(org.apache.airavata.common.utils.Constants.USER_NAME).equals(existingProject.getOwner())
                     || !authzToken.getClaimsMap().get(org.apache.airavata.common.utils.Constants.GATEWAY_ID).equals(existingProject.getGatewayId())){
                 try {
                     String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID);
                     String userId = authzToken.getClaimsMap().get(Constants.USER_NAME);
-                    if (!getSharingRegistryServiceClient().userHasAccess(gatewayId, userId + "@" + gatewayId,
+                    if (!sharingClient.userHasAccess(gatewayId, userId + "@" + gatewayId,
                             projectId, gatewayId + ":WRITE")){
                         throw new AuthorizationException("User does not have permission to access this resource");
                     }
@@ -749,11 +843,15 @@ public class AiravataServerHandler implements Airavata.Iface {
             }
             boolean ret = regClient.deleteProject(projectId);
             logger.debug("Airavata deleted project with project Id : " + projectId );
+            registryClientPool.returnResource(regClient);
+            sharingClientPool.returnResource(sharingClient);
             return ret;
-        } catch (ApplicationSettingsException | RegistryServiceException e) {
+        } catch (Exception e) {
             logger.error("Error while removing the project", e);
             ProjectNotFoundException exception = new ProjectNotFoundException();
             exception.setMessage("Error while removing the project. More info : " + e.getMessage());
+            registryClientPool.returnBrokenResource(regClient);
+            sharingClientPool.returnBrokenResource(sharingClient);
             throw exception;
         }
     }
@@ -775,29 +873,40 @@ public class AiravataServerHandler implements Airavata.Iface {
     @SecurityCheck
     public Project getProject(AuthzToken authzToken, String projectId) throws InvalidRequestException,
             AiravataClientException, AiravataSystemException, ProjectNotFoundException, AuthorizationException, TException {
+        RegistryService.Client regClient = registryClientPool.getResource();
+        SharingRegistryService.Client sharingClient = sharingClientPool.getResource();
         try {
-            Project project = getRegistryServiceClient().getProject(projectId);
+            Project project = regClient.getProject(projectId);
             if(authzToken.getClaimsMap().get(org.apache.airavata.common.utils.Constants.USER_NAME).equals(project.getOwner())
                     && authzToken.getClaimsMap().get(org.apache.airavata.common.utils.Constants.GATEWAY_ID).equals(project.getGatewayId())){
+                registryClientPool.returnResource(regClient);
+                sharingClientPool.returnResource(sharingClient);
                 return project;
             }else if (ServerSettings.isEnableSharing()){
                 try {
                     String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID);
                     String userId = authzToken.getClaimsMap().get(Constants.USER_NAME);
-                    if (!getSharingRegistryServiceClient().userHasAccess(gatewayId, userId + "@" + gatewayId,
+                    if (!sharingClient.userHasAccess(gatewayId, userId + "@" + gatewayId,
                             projectId, gatewayId + ":READ")){
                         throw new AuthorizationException("User does not have permission to access this resource");
                     }
+                    registryClientPool.returnResource(regClient);
+                    sharingClientPool.returnResource(sharingClient);
                     return project;
                 } catch (Exception e) {
                     throw new AuthorizationException("User does not have permission to access this resource");
                 }
-            }else
+            } else {
+                registryClientPool.returnResource(regClient);
+                sharingClientPool.returnResource(sharingClient);
                 return null;
-        } catch (ApplicationSettingsException | RegistryServiceException e) {
+            }
+        } catch (Exception e) {
             logger.error("Error while retrieving the project", e);
             ProjectNotFoundException exception = new ProjectNotFoundException();
             exception.setMessage("Error while retrieving the project. More info : " + e.getMessage());
+            registryClientPool.returnBrokenResource(regClient);
+            sharingClientPool.returnBrokenResource(sharingClient);
             throw exception;
         }
     }
@@ -821,6 +930,8 @@ public class AiravataServerHandler implements Airavata.Iface {
     public List<Project> getUserProjects(AuthzToken authzToken, String gatewayId, String userName,
                                          int limit, int offset)
             throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException {
+        RegistryService.Client regClient = registryClientPool.getResource();
+        SharingRegistryService.Client sharingClient = sharingClientPool.getResource();
         try {
             if (ServerSettings.isEnableSharing()){
                 // user projects + user accessible projects
@@ -831,18 +942,26 @@ public class AiravataServerHandler implements Airavata.Iface {
                 searchCriteria.setSearchCondition(SearchCondition.EQUAL);
                 searchCriteria.setValue(gatewayId + ":PROJECT");
                 filters.add(searchCriteria);
-                getSharingRegistryServiceClient().searchEntities(authzToken.getClaimsMap().get(Constants.GATEWAY_ID),
+                sharingClient.searchEntities(authzToken.getClaimsMap().get(Constants.GATEWAY_ID),
                         userName + "@" + gatewayId, filters, offset, limit).stream().forEach(p -> accessibleProjectIds.add(p.entityId));
-                return getRegistryServiceClient().searchProjects(gatewayId, userName, accessibleProjectIds, new HashMap<>(), limit, offset);
+                List<Project> result = regClient.searchProjects(gatewayId, userName, accessibleProjectIds, new HashMap<>(), limit, offset);
+                registryClientPool.returnResource(regClient);
+                sharingClientPool.returnResource(sharingClient);
+                return result;
             }else{
-                return getRegistryServiceClient().getUserProjects(gatewayId, userName, limit, offset);
+                List<Project> result = regClient.getUserProjects(gatewayId, userName, limit, offset);
+                registryClientPool.returnResource(regClient);
+                sharingClientPool.returnResource(sharingClient);
+                return result;
             }
 
-        } catch (ApplicationSettingsException | RegistryServiceException e) {
+        } catch (Exception e) {
             logger.error("Error while retrieving projects", e);
             AiravataSystemException exception = new AiravataSystemException();
             exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR);
             exception.setMessage("Error while retrieving projects. More info : " + e.getMessage());
+            registryClientPool.returnBrokenResource(regClient);
+            sharingClientPool.returnBrokenResource(sharingClient);
             throw exception;
         }
     }
@@ -872,6 +991,8 @@ public class AiravataServerHandler implements Airavata.Iface {
     @Override
     public List<Project> searchProjects(AuthzToken authzToken, String gatewayId, String userName, Map<ProjectSearchFields,
             String> filters, int limit, int offset) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException {
+        RegistryService.Client regClient = registryClientPool.getResource();
+        SharingRegistryService.Client sharingClient = sharingClientPool.getResource();
         try {
             List<String> accessibleProjIds  = new ArrayList<>();
 
@@ -882,15 +1003,20 @@ public class AiravataServerHandler implements Airavata.Iface {
                 searchCriteria.setSearchCondition(SearchCondition.EQUAL);
                 searchCriteria.setValue(gatewayId + ":PROJECT");
                 sharingFilters.add(searchCriteria);
-                getSharingRegistryServiceClient().searchEntities(authzToken.getClaimsMap().get(Constants.GATEWAY_ID),
+                sharingClient.searchEntities(authzToken.getClaimsMap().get(Constants.GATEWAY_ID),
                         userName + "@" + gatewayId, sharingFilters, 0, -1).stream().forEach(e -> accessibleProjIds.add(e.entityId));
             }
-            return getRegistryServiceClient().searchProjects(gatewayId, userName, accessibleProjIds, filters, limit, offset);
+            List<Project> result = regClient.searchProjects(gatewayId, userName, accessibleProjIds, filters, limit, offset);
+            registryClientPool.returnResource(regClient);
+            sharingClientPool.returnResource(sharingClient);
+            return result;
         }catch (Exception e) {
             logger.error("Error while retrieving projects", e);
             AiravataSystemException exception = new AiravataSystemException();
             exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR);
             exception.setMessage("Error while retrieving projects. More info : " + e.getMessage());
+            registryClientPool.returnBrokenResource(regClient);
+            sharingClientPool.returnBrokenResource(sharingClient);
             throw exception;
         }
     }
@@ -916,6 +1042,8 @@ public class AiravataServerHandler implements Airavata.Iface {
     public List<ExperimentSummaryModel> searchExperiments(AuthzToken authzToken, String gatewayId, String userName, Map<ExperimentSearchFields,
             String> filters, int limit, int offset)
             throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException {
+        RegistryService.Client regClient = registryClientPool.getResource();
+        SharingRegistryService.Client sharingClient = sharingClientPool.getResource();
         try {
             List<String> accessibleExpIds = new ArrayList<>();
             if (ServerSettings.isEnableSharing()) {
@@ -925,15 +1053,20 @@ public class AiravataServerHandler implements Airavata.Iface {
                 searchCriteria.setSearchCondition(SearchCondition.EQUAL);
                 searchCriteria.setValue(gatewayId + ":EXPERIMENT");
                 sharingFilters.add(searchCriteria);
-                getSharingRegistryServiceClient().searchEntities(authzToken.getClaimsMap().get(Constants.GATEWAY_ID),
+                sharingClient.searchEntities(authzToken.getClaimsMap().get(Constants.GATEWAY_ID),
                         userName + "@" + gatewayId, sharingFilters, 0, -1).forEach(e -> accessibleExpIds.add(e.entityId));
             }
-            return getRegistryServiceClient().searchExperiments(gatewayId, userName, accessibleExpIds, filters, limit, offset);
+            List<ExperimentSummaryModel> result = regClient.searchExperiments(gatewayId, userName, accessibleExpIds, filters, limit, offset);
+            registryClientPool.returnResource(regClient);
+            sharingClientPool.returnResource(sharingClient);
+            return result;
         }catch (Exception e) {
             logger.error("Error while retrieving experiments", e);
             AiravataSystemException exception = new AiravataSystemException();
             exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR);
             exception.setMessage("Error while retrieving experiments. More info : " + e.getMessage());
+            registryClientPool.returnBrokenResource(regClient);
+            sharingClientPool.returnBrokenResource(sharingClient);
             throw exception;
         }
     }
@@ -956,13 +1089,20 @@ public class AiravataServerHandler implements Airavata.Iface {
     public ExperimentStatistics getExperimentStatistics(AuthzToken authzToken, String gatewayId, long fromTime, long toTime,
                                                         String userName, String applicationName, String resourceHostName)
             throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException {
+        RegistryService.Client regClient = registryClientPool.getResource();
+        SharingRegistryService.Client sharingClient = sharingClientPool.getResource();
         try {
-            return getRegistryServiceClient().getExperimentStatistics(gatewayId, fromTime, toTime, userName, applicationName, resourceHostName);
+            ExperimentStatistics result = regClient.getExperimentStatistics(gatewayId, fromTime, toTime, userName, applicationName, resourceHostName);
+            registryClientPool.returnResource(regClient);
+            sharingClientPool.returnResource(sharingClient);
+            return result;
         }catch (Exception e) {
             logger.error("Error while retrieving experiments", e);
             AiravataSystemException exception = new AiravataSystemException();
             exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR);
             exception.setMessage("Error while retrieving experiments. More info : " + e.getMessage());
+            registryClientPool.returnBrokenResource(regClient);
+            sharingClientPool.returnBrokenResource(sharingClient);
             throw exception;
         }
     }
@@ -983,8 +1123,9 @@ public class AiravataServerHandler implements Airavata.Iface {
     public List<ExperimentModel> getExperimentsInProject(AuthzToken authzToken, String projectId, int limit, int offset)
             throws InvalidRequestException, AiravataClientException, AiravataSystemException, ProjectNotFoundException,
             AuthorizationException, TException {
+        RegistryService.Client regClient = registryClientPool.getResource();
+        SharingRegistryService.Client sharingClient = sharingClientPool.getResource();
         try {
-            RegistryService.Client regClient  = getRegistryServiceClient();
             Project project = regClient.getProject(projectId);
 
             if(ServerSettings.isEnableSharing() && !authzToken.getClaimsMap().get(org.apache.airavata.common.utils.Constants.USER_NAME).equals(project.getOwner())
@@ -992,7 +1133,7 @@ public class AiravataServerHandler implements Airavata.Iface {
                 try {
                     String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID);
                     String userId = authzToken.getClaimsMap().get(Constants.USER_NAME);
-                    if (!getSharingRegistryServiceClient().userHasAccess(gatewayId, userId + "@" + gatewayId,
+                    if (!sharingClient.userHasAccess(gatewayId, userId + "@" + gatewayId,
                             projectId, gatewayId + ":READ")){
                         throw new AuthorizationException("User does not have permission to access this resource");
                     }
@@ -1000,12 +1141,17 @@ public class AiravataServerHandler implements Airavata.Iface {
                     throw new AuthorizationException("User does not have permission to access this resource");
                 }
             }
-            return regClient.getExperimentsInProject(projectId, limit, offset);
+            List<ExperimentModel> result = regClient.getExperimentsInProject(projectId, limit, offset);
+            registryClientPool.returnResource(regClient);
+            sharingClientPool.returnResource(sharingClient);
+            return result;
         } catch (Exception e) {
             logger.error("Error while retrieving the experiments", e);
             AiravataSystemException exception = new AiravataSystemException();
             exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR);
             exception.setMessage("Error while retrieving the experiments. More info : " + e.getMessage());
+            registryClientPool.returnBrokenResource(regClient);
+            sharingClientPool.returnBrokenResource(sharingClient);
             throw exception;
         }
     }
@@ -1028,13 +1174,20 @@ public class AiravataServerHandler implements Airavata.Iface {
     public List<ExperimentModel> getUserExperiments(AuthzToken authzToken, String gatewayId, String userName, int limit,
                                                     int offset) throws InvalidRequestException,
             AiravataClientException, AiravataSystemException, AuthorizationException, TException {
+        RegistryService.Client regClient = registryClientPool.getResource();
+        SharingRegistryService.Client sharingClient = sharingClientPool.getResource();
         try {
-            return getRegistryServiceClient().getUserExperiments(gatewayId, userName, limit, offset);
+            List<ExperimentModel> result = regClient.getUserExperiments(gatewayId, userName, limit, offset);
+            registryClientPool.returnResource(regClient);
+            sharingClientPool.returnResource(sharingClient);
+            return result;
         } catch (Exception e) {
             logger.error("Error while retrieving the experiments", e);
             AiravataSystemException exception = new AiravataSystemException();
             exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR);
             exception.setMessage("Error while retrieving the experiments. More info : " + e.getMessage());
+            registryClientPool.returnBrokenResource(regClient);
+            sharingClientPool.returnBrokenResource(sharingClient);
             throw exception;
         }
     }
@@ -1065,8 +1218,10 @@ public class AiravataServerHandler implements Airavata.Iface {
     @SecurityCheck
     public String createExperiment(AuthzToken authzToken, String gatewayId, ExperimentModel experiment) throws InvalidRequestException,
             AiravataClientException, AiravataSystemException, AuthorizationException, TException {
+        RegistryService.Client regClient = registryClientPool.getResource();
+        SharingRegistryService.Client sharingClient = sharingClientPool.getResource();
         try {
-            String experimentId = getRegistryServiceClient().createExperiment(gatewayId, experiment);
+            String experimentId = regClient.createExperiment(gatewayId, experiment);
 
             if(ServerSettings.isEnableSharing()) {
                 try {
@@ -1079,11 +1234,11 @@ public class AiravataServerHandler implements Airavata.Iface {
                     entity.setDescription(experiment.getDescription());
                     entity.setParentEntityId(experiment.getProjectId());
 
-                    getSharingRegistryServiceClient().createEntity(entity);
+                    sharingClient.createEntity(entity);
                 } catch (Exception ex) {
                     logger.error(ex.getMessage(), ex);
                     logger.error("Rolling back experiment creation Exp ID : " + experimentId);
-                    getRegistryServiceClient().deleteExperiment(experimentId);
+                    regClient.deleteExperiment(experimentId);
                     AiravataSystemException ase = new AiravataSystemException();
                     ase.setMessage("Failed to create sharing registry record");
                     throw ase;
@@ -1100,12 +1255,16 @@ public class AiravataServerHandler implements Airavata.Iface {
                 statusPublisher.publish(messageContext);
             }
             logger.debug(experimentId, "Created new experiment with experiment name {}", experiment.getExperimentName());
+            registryClientPool.returnResource(regClient);
+            sharingClientPool.returnResource(sharingClient);
             return experimentId;
         } catch (Exception e) {
             logger.error("Error while creating the experiment with experiment name {}", experiment.getExperimentName());
             AiravataSystemException exception = new AiravataSystemException();
             exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR);
             exception.setMessage("Error while creating the experiment. More info : " + e.getMessage());
+            registryClientPool.returnBrokenResource(regClient);
+            sharingClientPool.returnBrokenResource(sharingClient);
             throw exception;
         }
     }
@@ -1124,8 +1283,9 @@ public class AiravataServerHandler implements Airavata.Iface {
     @Override
     @SecurityCheck
     public boolean deleteExperiment(AuthzToken authzToken, String experimentId) throws InvalidRequestException, AiravataClientException, AiravataSystemException, AuthorizationException, TException {
+        RegistryService.Client regClient = registryClientPool.getResource();
+        SharingRegistryService.Client sharingClient = sharingClientPool.getResource();
         try {
-            RegistryService.Client regClient  = getRegistryServiceClient();
             ExperimentModel experimentModel = regClient.getExperiment(experimentId);
 
             if(ServerSettings.isEnableSharing() && !authzToken.getClaimsMap().get(org.apache.airavata.common.utils.Constants.USER_NAME).equals(experimentModel.getUserName())
@@ -1133,7 +1293,7 @@ public class AiravataServerHandler implements Airavata.Iface {
                 try {
                     String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID);
                     String userId = authzToken.getClaimsMap().get(Constants.USER_NAME);
-                    if (!getSharingRegistryServiceClient().userHasAccess(gatewayId, userId + "@" + gatewayId,
+                    if (!sharingClient.userHasAccess(gatewayId, userId + "@" + gatewayId,
                             experimentId, gatewayId + ":WRITE")){
                         throw new AuthorizationException("User does not have permission to access this resource");
                     }
@@ -1146,12 +1306,17 @@ public class AiravataServerHandler implements Airavata.Iface {
                 logger.error("Error while deleting the experiment");
                 throw new RegistryServiceException("Experiment is not in CREATED state. Hence cannot deleted. ID:"+ experimentId);
             }
-            return regClient.deleteExperiment(experimentId);
+            boolean result = regClient.deleteExperiment(experimentId);
+            registryClientPool.returnResource(regClient);
+            sharingClientPool.returnResource(sharingClient);
+            return result;
         } catch (Exception e) {
             logger.error("Error while deleting the experiment", e);
             AiravataSystemException exception = new AiravataSystemException();
             exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR);
             exception.setMessage("Error while deleting the experiment. More info : " + e.getMessage());
+            registryClientPool.returnBrokenResource(regClient);
+            sharingClientPool.returnBrokenResource(sharingClient);
             throw exception;
         }
     }
@@ -1182,32 +1347,42 @@ public class AiravataServerHandler implements Airavata.Iface {
     @SecurityCheck
     public ExperimentModel getExperiment(AuthzToken authzToken, String airavataExperimentId) throws InvalidRequestException,
             ExperimentNotFoundException, AiravataClientException, AiravataSystemException, AuthorizationException, TException {
+        RegistryService.Client regClient = registryClientPool.getResource();
+        SharingRegistryService.Client sharingClient = sharingClientPool.getResource();
         ExperimentModel experimentModel = null;
         try {
-            experimentModel = getRegistryServiceClient().getExperiment(airavataExperimentId);
+            experimentModel = regClient.getExperiment(airavataExperimentId);
             if(authzToken.getClaimsMap().get(org.apache.airavata.common.utils.Constants.USER_NAME).equals(experimentModel.getUserName())
                     && authzToken.getClaimsMap().get(org.apache.airavata.common.utils.Constants.GATEWAY_ID).equals(experimentModel.getGatewayId())){
+                registryClientPool.returnResource(regClient);
+                sharingClientPool.returnResource(sharingClient);
                 return experimentModel;
             }else if(ServerSettings.isEnableSharing()){
                 try {
                     String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID);
                     String userId = authzToken.getClaimsMap().get(Constants.USER_NAME);
-                    if (!getSharingRegistryServiceClient().userHasAccess(gatewayId, userId + "@" + gatewayId,
+                    if (!sharingClient.userHasAccess(gatewayId, userId + "@" + gatewayId,
                             airavataExperimentId, gatewayId + ":READ")){
                         throw new AuthorizationException("User does not have permission to access this resource");
                     }
+                    registryClientPool.returnResource(regClient);
+                    sharingClientPool.returnResource(sharingClient);
                     return experimentModel;
                 } catch (Exception e) {
                     throw new AuthorizationException("User does not have permission to access this resource");
                 }
             }else{
+                registryClientPool.returnResource(regClient);
+                sharingClientPool.returnResource(sharingClient);
                 return null;
             }
-        } catch (ApplicationSettingsException e) {
+        } catch (Exception e) {
             logger.error("Error while getting the experiment", e);
             AiravataSystemException exception = new AiravataSystemException();
             exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR);
             exception.setMessage("Error while getting the experiment. More info : " + e.getMessage());
+            registryClientPool.returnBrokenResource(regClient);
+            sharingClientPool.returnBrokenResource(sharingClient);
             throw exception;
         }
     }
@@ -1216,21 +1391,23 @@ public class AiravataServerHandler implements Airavata.Iface {
     @SecurityCheck
     public ExperimentModel getExperimentByAdmin(AuthzToken authzToken, String airavataExperimentId)
             throws InvalidRequestException, ExperimentNotFoundException, AiravataClientException, AiravataSystemException, AuthorizationException, TException {
-
+        RegistryService.Client regClient = registryClientPool.getResource();
         ExperimentModel experimentModel = null;
         try {
             String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID);
-            experimentModel = getRegistryServiceClient().getExperiment(airavataExperimentId);
+            experimentModel = regClient.getExperiment(airavataExperimentId);
+            registryClientPool.returnResource(regClient);
             if(gatewayId.equals(experimentModel.getGatewayId())){
                 return experimentModel;
             } else {
                 throw new AuthorizationException("User does not have permission to access this resource");
             }
-        } catch (ApplicationSettingsException e) {
+        } catch (Exception e) {
             logger.error("Error while getting the experiment", e);
             AiravataSystemException exception = new AiravataSystemException();
             exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR);
             exception.setMessage("Error while getting the experiment. More info : " + e.getMessage());
+            registryClientPool.returnBrokenResource(regClient);
             throw exception;
         }
     }
@@ -1262,13 +1439,20 @@ public class AiravataServerHandler implements Airavata.Iface {
     @SecurityCheck
     public ExperimentModel getDetailedExperimentTree(AuthzToken authzToken, String airavataExperimentId) throws InvalidRequestException,
             ExperimentNotFoundException, AiravataClientException, AiravataSystemException, AuthorizationException, TException {
+        RegistryService.Client regClient = registryClientPool.getResource();
+        SharingRegistryService.Client sharingClient = sharingClientPool.getResource();
         try {
-            return getRegistryServiceClient().getDetailedExperimentTree(airavataExperimentId);
+            ExperimentModel result = regClient.getDetailedExperimentTree(airavataExperimentId);
+            registryClientPool.returnResource(regClient);
+            sharingClientPool.returnResource(sharingClient);
+            return result;
         } catch (Exception e) {
             logger.error("Error while retrieving the experiment", e);
             AiravataSystemException exception = new AiravataSystemException();
             exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR);
             exception.setMessage("Error while retrieving the experiment. More info : " + e.getMessage());
+            registryClientPool.returnBrokenResource(regClient);
+            sharingClientPool.returnBrokenResource(sharingClient);
             throw exception;
         }
     }
@@ -1302,15 +1486,16 @@ public class AiravataServerHandler implements Airavata.Iface {
     public void updateExperiment(AuthzToken authzToken, String airavataExperimentId, ExperimentModel experiment)
             throws InvalidRequestException, ExperimentNotFoundException, AiravataClientException, AiravataSystemException,
             AuthorizationException, TException {
+        RegistryService.Client regClient = registryClientPool.getResource();
+        SharingRegistryService.Client sharingClient = sharingClientPool.getResource();
         try {
-            RegistryService.Client regClient = getRegistryServiceClient();
             ExperimentModel experimentModel = regClient.getExperiment(airavataExperimentId);
             if(ServerSettings.isEnableSharing() && !authzToken.getClaimsMap().get(org.apache.airavata.common.utils.Constants.USER_NAME).equals(experimentModel.getUserName())
                     || !authzToken.getClaimsMap().get(org.apache.airavata.common.utils.Constants.GATEWAY_ID).equals(experimentModel.getGatewayId())){
                 try {
                     String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID);
                     String userId = authzToken.getClaimsMap().get(Constants.USER_NAME);
-                    if (!getSharingRegistryServiceClient().userHasAccess(gatewayId, userId + "@" + gatewayId,
+                    if (!sharingClient.userHasAccess(gatewayId, userId + "@" + gatewayId,
                             airavataExperimentId, gatewayId + ":WRITE")){
                         throw new AuthorizationException("User does not have permission to access this resource");
                     }
@@ -1320,11 +1505,15 @@ public class AiravataServerHandler implements Airavata.Iface {
             }
 
             regClient.updateExperiment(airavataExperimentId, experiment);
-        } catch (ApplicationSettingsException | RegistryServiceException e) {
+            registryClientPool.returnResource(regClient);
+            sharingClientPool.returnResource(sharingClient);
+        } catch (Exception e) {
             logger.error(airavataExperimentId, "Error while updating experiment", e);
             AiravataSystemException exception = new AiravataSystemException();
             exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR);
             exception.setMessage("Error while updating experiment. More info : " + e.getMessage());
+            registryClientPool.returnBrokenResource(regClient);
+            sharingClientPool.returnBrokenResource(sharingClient);
             throw exception;
         }
     }
@@ -1333,8 +1522,10 @@ public class AiravataServerHandler implements Airavata.Iface {
     @SecurityCheck
     public void updateExperimentConfiguration(AuthzToken authzToken, String airavataExperimentId, UserConfigurationDataModel userConfiguration)
             throws AuthorizationException, TException {
+        RegistryService.Client regClient = registryClientPool.getResource();
         try {
-            getRegistryServiceClient().send_updateExperimentConfiguration(airavataExperimentId, userConfiguration);
+            regClient.send_updateExperimentConfiguration(airavataExperimentId, userConfiguration);
+            registryClientPool.returnResource(regClient);
         } catch (Exception e) {
             logger.error(airavataExperimentId, "Error while updating user configuration", e);
             AiravataSystemException exception = new AiravataSystemException();
@@ -1343,6 +1534,7 @@ public class AiravataServerHandler implements Airavata.Iface {
                     "Update experiment is only valid for experiments " +
                     "with status CREATED, VALIDATED, CANCELLED, FAILED and UNKNOWN. Make sure the given " +
                     "experiment is in one of above statuses...  " + e.getMessage());
+            registryClientPool.returnBrokenResource(regClient);
             throw exception;
         }
     }
@@ -1351,8 +1543,10 @@ public class AiravataServerHandler implements Airavata.Iface {
     @SecurityCheck
     public void updateResourceScheduleing(AuthzToken authzToken, String airavataExperimentId,
                                           ComputationalResourceSchedulingModel resourceScheduling) throws AuthorizationException, TException {
+        RegistryService.Client regClient = registryClientPool.getResource();
         try {
-            getRegistryServiceClient().updateResourceScheduleing(airavataExperimentId, resourceScheduling);
+            regClient.updateResourceScheduleing(airavataExperimentId, resourceScheduling);
+            registryClientPool.returnResource(regClient);
         } catch (Exception e) {
             logger.error(airavataExperimentId, "Error while updating scheduling info", e);
             AiravataSystemException exception = new AiravataSystemException();
@@ -1361,6 +1555,7 @@ public class AiravataServerHandler implements Airavata.Iface {
                     "Update experiment is only valid for experiments " +
                     "with status CREATED, VALIDATED, CANCELLED, FAILED and UNKNOWN. Make sure the given " +
                     "experiment is in one of above statuses...  " + e.getMessage());
+            registryClientPool.returnBrokenResource(regClient);
             throw exception;
         }
     }
@@ -1381,7 +1576,7 @@ public class AiravataServerHandler implements Airavata.Iface {
     public boolean validateExperiment(AuthzToken authzToken, String airavataExperimentId) throws TException {
         // TODO - call validation module and validate experiment
 /*     	try {
-            ExperimentModel experimentModel = getRegistryServiceClient().getExperiment(airavataExperimentId);
+            ExperimentModel experimentModel = regClient.getExperiment(airavataExperimentId);
  			if (experimentModel == null) {
                 logger.error(airavataExperimentId, "Experiment validation failed , experiment {} doesn't exist.", airavataExperimentId);
                 throw new ExperimentNotFoundException("Requested experiment id " + airavataExperimentId + " does not exist in the system..");
@@ -1437,11 +1632,15 @@ public class AiravataServerHandler implements Airavata.Iface {
     @Override
     @SecurityCheck
     public ExperimentStatus getExperimentStatus(AuthzToken authzToken, String airavataExperimentId) throws TException {
+        RegistryService.Client regClient = registryClientPool.getResource();
         try {
-            return getRegistryServiceClient().getExperimentStatus(airavataExperimentId);
-        } catch (ApplicationSettingsException e) {
+            ExperimentStatus result = regClient.getExperimentStatus(airavataExperimentId);
+            registryClientPool.returnResource(regClient);
+            return result;
+        } catch (Exception e) {
             AiravataSystemException exception = new AiravataSystemException();
             exception.setMessage(e.getMessage());
+            registryClientPool.returnBrokenResource(regClient);
             throw exception;
         }
     }
@@ -1451,13 +1650,17 @@ public class AiravataServerHandler implements Airavata.Iface {
     @SecurityCheck
     public List<OutputDataObjectType> getExperimentOutputs(AuthzToken authzToken, String airavataExperimentId)
             throws AuthorizationException, TException {
+        RegistryService.Client regClient = registryClientPool.getResource();
         try {
-            return getRegistryServiceClient().getExperimentOutputs(airavataExperimentId);
+            List<OutputDataObjectType> result = regClient.getExperimentOutputs(airavataExperimentId);
+            registryClientPool.returnResource(regClient);
+            return result;
         } catch (Exception e) {
             logger.error(airavataExperimentId, "Error while retrieving the experiment outputs", e);
             AiravataSystemException exception = new AiravataSystemException();
             exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR);
             exception.setMessage("Error while retrieving the experiment outputs. More info : " + e.getMessage());
+            registryClientPool.returnBrokenResource(regClient);
             throw exception;
         }
     }
@@ -1472,13 +1675,17 @@ public class AiravataServerHandler implements Airavata.Iface {
     @SecurityCheck
     public Map<String, JobStatus> getJobStatuses(AuthzToken authzToken, String airavataExperimentId)
             throws AuthorizationException, TException {
+        RegistryService.Client regClient = registryClientPool.getResource();
         try {
-            return getRegistryServiceClient().getJobStatuses(airavataExperimentId);
+            Map<String, JobStatus> result = regClient.getJobStatuses(airavataExperimentId);
+            registryClientPool.returnResource(regClient);
+            return result;
         } catch (Exception e) {
             logger.error(airavataExperimentId, "Error while retrieving the job statuses", e);
             AiravataSystemException exception = new AiravataSystemException();
             exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR);
             exception.setMessage("Error while retrieving the job statuses. More info : " + e.getMessage());
+            registryClientPool.returnBrokenResource(regClient);
             throw exception;
         }
     }
@@ -1487,13 +1694,17 @@ public class AiravataServerHandler implements Airavata.Iface {
     @SecurityCheck
     public List<JobModel> getJobDetails(AuthzToken authzToken, String airavataExperimentId) throws InvalidRequestException,
             ExperimentNotFoundException, AiravataClientException, AiravataSystemException, AuthorizationException, TException {
+        RegistryService.Client regClient = registryClientPool.getResource();
         try {
-            return getRegistryServiceClient().getJobDetails(airavataExperimentId);
+            List<JobModel> result = regClient.getJobDetails(airavataExperimentId);
+            registryClientPool.returnResource(regClient);
+            return result;
         } catch (Exception e) {
             logger.error(airavataExperimentId, "Error while retrieving the job details", e);
             AiravataSystemException exception = new AiravataSystemException();
             exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR);
             exception.setMessage("Error while retrieving the job details. More info : " + e.getMessage());
+            registryClientPool.returnBrokenResource(regClient);
             throw exception;
         }
     }
@@ -1530,22 +1741,22 @@ public class AiravataServerHandler implements Airavata.Iface {
     @SecurityCheck
     public void launchExperiment(AuthzToken authzTo

<TRUNCATED>