Github user michaelarusso commented on a diff in the pull request:
https://github.com/apache/usergrid/pull/524#discussion_r64041172
--- Diff:
stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java
---
@@ -142,12 +141,66 @@ public CpEntityManagerFactory( final CassandraService
cassandraService, final Co
this.connectionService = injector.getInstance(
ConnectionService.class );
this.indexSchemaCacheFactory = injector.getInstance(
IndexSchemaCacheFactory.class );
- //this line always needs to be last due to the temporary cicular
dependency until spring is removed
+ // this line always needs to be last due to the temporary circular
dependency until spring is removed
this.applicationIdCache =
injector.getInstance(ApplicationIdCacheFactory.class).getInstance(
getManagementEntityManager() );
+ 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");
--- End diff --
Exception is caught above when calling _getEntityManager in the case that
it returns null and NPE would be thrown on getApplication(). At this point, it
seems like we'd be returning a null value to the cache's load() method. Is
this intended behavior?
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---