You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@usergrid.apache.org by sn...@apache.org on 2015/05/27 21:35:35 UTC

[46/50] [abbrv] incubator-usergrid git commit: Only synchronize initialization code, not whole method.

Only synchronize initialization code, not whole method.


Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/5079d473
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/5079d473
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/5079d473

Branch: refs/heads/two-dot-o
Commit: 5079d4737cfdb960665692e4b16bf59ea61d5dd5
Parents: c6289d5
Author: Dave Johnson <dm...@apigee.com>
Authored: Mon May 18 13:45:28 2015 -0400
Committer: Dave Johnson <dm...@apigee.com>
Committed: Mon May 18 13:45:28 2015 -0400

----------------------------------------------------------------------
 .../rest/management/ManagementResource.java     | 60 +++++++++++---------
 1 file changed, 32 insertions(+), 28 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/5079d473/stack/rest/src/main/java/org/apache/usergrid/rest/management/ManagementResource.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/main/java/org/apache/usergrid/rest/management/ManagementResource.java b/stack/rest/src/main/java/org/apache/usergrid/rest/management/ManagementResource.java
index ad604d5..46d6d6b 100644
--- a/stack/rest/src/main/java/org/apache/usergrid/rest/management/ManagementResource.java
+++ b/stack/rest/src/main/java/org/apache/usergrid/rest/management/ManagementResource.java
@@ -710,44 +710,48 @@ public class ManagementResource extends AbstractContextResource {
     }
 
 
-    synchronized Client getJerseyClient() {
+    private Client getJerseyClient() {
 
         if ( jerseyClient == null ) {
 
-            // create HTTPClient and with configured connection pool
+            synchronized ( this ) {
 
-            int poolSize = 100; // connections
-            final String poolSizeStr = properties.getProperty( CENTRAL_CONNECTION_POOL_SIZE );
-            if ( poolSizeStr != null ) {
-                poolSize = Integer.parseInt( poolSizeStr );
-            }
+                // create HTTPClient and with configured connection pool
 
-            MultiThreadedHttpConnectionManager cm = new MultiThreadedHttpConnectionManager();
-            HttpConnectionManagerParams cmParams = cm.getParams();
-            cmParams.setMaxTotalConnections( poolSize );
-            HttpClient httpClient = new HttpClient( cm );
+                int poolSize = 100; // connections
+                final String poolSizeStr = properties.getProperty( CENTRAL_CONNECTION_POOL_SIZE );
+                if ( poolSizeStr != null ) {
+                    poolSize = Integer.parseInt( poolSizeStr );
+                }
 
-            // create Jersey Client using that HTTPClient and with configured timeouts
+                MultiThreadedHttpConnectionManager cm = new MultiThreadedHttpConnectionManager();
+                HttpConnectionManagerParams cmParams = cm.getParams();
+                cmParams.setMaxTotalConnections( poolSize );
+                HttpClient httpClient = new HttpClient( cm );
 
-            int timeout = 20000; // ms
-            final String timeoutStr = properties.getProperty( CENTRAL_CONNECTION_TIMEOUT );
-            if ( timeoutStr != null ) {
-                timeout = Integer.parseInt( timeoutStr );
-            }
+                // create Jersey Client using that HTTPClient and with configured timeouts
 
-            int readTimeout = 20000; // ms
-            final String readTimeoutStr = properties.getProperty( CENTRAL_READ_TIMEOUT );
-            if ( readTimeoutStr != null ) {
-                readTimeout = Integer.parseInt( readTimeoutStr );
-            }
+                int timeout = 20000; // ms
+                final String timeoutStr = properties.getProperty( CENTRAL_CONNECTION_TIMEOUT );
+                if ( timeoutStr != null ) {
+                    timeout = Integer.parseInt( timeoutStr );
+                }
 
-            ClientConfig clientConfig = new DefaultClientConfig();
-            clientConfig.getFeatures().put( JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE );
-            clientConfig.getProperties().put( ClientConfig.PROPERTY_CONNECT_TIMEOUT, timeout ); // ms
-            clientConfig.getProperties().put( ClientConfig.PROPERTY_READ_TIMEOUT, readTimeout ); // ms
+                int readTimeout = 20000; // ms
+                final String readTimeoutStr = properties.getProperty( CENTRAL_READ_TIMEOUT );
+                if ( readTimeoutStr != null ) {
+                    readTimeout = Integer.parseInt( readTimeoutStr );
+                }
+
+                ClientConfig clientConfig = new DefaultClientConfig();
+                clientConfig.getFeatures().put( JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE );
+                clientConfig.getProperties().put( ClientConfig.PROPERTY_CONNECT_TIMEOUT, timeout ); // ms
+                clientConfig.getProperties().put( ClientConfig.PROPERTY_READ_TIMEOUT, readTimeout ); // ms
 
-            ApacheHttpClientHandler handler = new ApacheHttpClientHandler( httpClient, clientConfig );
-            jerseyClient = new ApacheHttpClient( handler );
+                ApacheHttpClientHandler handler = new ApacheHttpClientHandler( httpClient, clientConfig );
+                jerseyClient = new ApacheHttpClient( handler );
+
+            }
         }
 
         return jerseyClient;