You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@usergrid.apache.org by mr...@apache.org on 2016/06/03 14:45:53 UTC

[03/26] usergrid git commit: Merge branch 'usergrid-1283-service-mgr-init' into usegrid-1283-mgmt-app-init

Merge branch 'usergrid-1283-service-mgr-init' into usegrid-1283-mgmt-app-init

Conflicts:
	stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java


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

Branch: refs/heads/release-2.1.1
Commit: de6de6629903f57df4faf5c3f20f5cea63f2bcec
Parents: e0c0c87 5f46341
Author: Dave Johnson <sn...@apache.org>
Authored: Wed May 18 09:23:54 2016 -0400
Committer: Dave Johnson <sn...@apache.org>
Committed: Wed May 18 09:23:54 2016 -0400

----------------------------------------------------------------------
 .../corepersistence/CpEntityManagerFactory.java | 66 +++++++++++++++++---
 1 file changed, 59 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/usergrid/blob/de6de662/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java
----------------------------------------------------------------------
diff --cc stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java
index b61be01,4028875..e057210
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java
@@@ -98,14 -102,15 +98,12 @@@ public class CpEntityManagerFactory imp
  
      private Setup setup = null;
  
+     EntityManager managementAppEntityManager = null;
+ 
      // cache of already instantiated entity managers
-     private LoadingCache<UUID, EntityManager> entityManagers
-         = CacheBuilder.newBuilder().maximumSize(100).build(new CacheLoader<UUID, EntityManager>() {
-             public EntityManager load(UUID appId) { // no checked exception
-                 return _getEntityManager(appId);
-             }
-         });
+     private final String ENTITY_MANAGER_CACHE_SIZE = "entity.manager.cache.size";
+     private final LoadingCache<UUID, EntityManager> entityManagers;
  
 -
 -
 -
      private final ApplicationIdCache applicationIdCache;
      //private final IndexSchemaCache indexSchemaCache;
  
@@@ -148,7 -148,62 +146,61 @@@
          this.applicationIdCache = injector.getInstance(ApplicationIdCacheFactory.class).getInstance(
              getManagementEntityManager() );
  
-         initMgmtAppInternal();
 -
+         int entityManagerCacheSize = 100;
+         try {
+             entityManagerCacheSize = Integer.parseInt(
+                 cassandraService.getProperties().getProperty( ENTITY_MANAGER_CACHE_SIZE, "100" ));
+         } catch ( Exception e ) {
+             logger.error("Error parsing " + ENTITY_MANAGER_CACHE_SIZE + " using " + entityManagerCacheSize, e );
+         }
+ 
+         entityManagers = CacheBuilder.newBuilder()
+             .maximumSize(entityManagerCacheSize)
+             .build(new CacheLoader<UUID, EntityManager>() {
+ 
+             public EntityManager load( UUID appId ) { // no checked exception
+ 
+                 // get entity manager and ensure it can get its own application
+ 
+                 EntityManager entityManager = _getEntityManager( appId );
+                 Application app = null;
+                 Exception exception = null;
+                 try {
+                     app = entityManager.getApplication();
+                 } catch (Exception e) {
+                     exception = e;
+                 }
+ 
+                 // the management app is a special case
+ 
+                 if ( CpNamingUtils.MANAGEMENT_APPLICATION_ID.equals( appId ) ) {
+ 
+                     if ( app != null ) {
+ 
+                         // we successfully fetched up the management app, cache it for a rainy day
+                         managementAppEntityManager = entityManager;
+ 
+                     } else if ( managementAppEntityManager != null ) {
+ 
+                         // failed to fetch management app, use cached one
+                         entityManager = managementAppEntityManager;
+ 
+                     } else {
+ 
+                         // fetch failed and we have nothing cached, we must be bootstrapping
+                         logger.info("managementAppEntityManager is null, bootstrapping in progress");
+                     }
+ 
+                 } else { // not the management app, so blow up if app cannot be fetched
+ 
+                     if (app == null) {
+                         throw new RuntimeException( "Error getting application " + appId, exception );
+                     }
+                 }
+ 
+                 return entityManager;
+             }
+         });
      }