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 2016/06/14 17:14:51 UTC
[12/44] usergrid git commit: Revert changes to initMgmtApp() and add
null-pointer check.
Revert changes to initMgmtApp() and add null-pointer check.
Project: http://git-wip-us.apache.org/repos/asf/usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/usergrid/commit/12743f3e
Tree: http://git-wip-us.apache.org/repos/asf/usergrid/tree/12743f3e
Diff: http://git-wip-us.apache.org/repos/asf/usergrid/diff/12743f3e
Branch: refs/heads/usergrid-1268-akka-211
Commit: 12743f3e221f80df7eab89fda08325e9775f7ae9
Parents: de6de66
Author: Dave Johnson <sn...@apache.org>
Authored: Fri May 20 14:03:53 2016 -0400
Committer: Dave Johnson <sn...@apache.org>
Committed: Fri May 20 14:03:53 2016 -0400
----------------------------------------------------------------------
.../corepersistence/CpEntityManagerFactory.java | 49 +++++---------------
1 file changed, 12 insertions(+), 37 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/usergrid/blob/12743f3e/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java
index e057210..924dd10 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java
@@ -175,12 +175,12 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
if ( CpNamingUtils.MANAGEMENT_APPLICATION_ID.equals( appId ) ) {
- if ( app != null ) {
+ if ( app != null && entityManager != null ) {
// we successfully fetched up the management app, cache it for a rainy day
managementAppEntityManager = entityManager;
- } else if ( managementAppEntityManager != null ) {
+ } else if ( entityManager == null && managementAppEntityManager != null ) {
// failed to fetch management app, use cached one
entityManager = managementAppEntityManager;
@@ -214,47 +214,22 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
}
-
private void initMgmtAppInternal() {
- Properties properties = cassandraService.getProperties();
-
- Integer maxRetries;
- try {
- Object maxRetriesObject = properties.get( MANAGEMENT_APP_MAX_RETRIES ).toString();
- maxRetries = Integer.parseInt( maxRetriesObject.toString() );
- } catch ( NumberFormatException nfe ) {
- maxRetries = 20;
- }
-
EntityManager em = getEntityManager(getManagementAppId());
+ indexService.queueInitializeApplicationIndex(CpNamingUtils.getApplicationScope(getManagementAppId()));
- int retryCount = 0;
-
- while ( managementApp != null && retryCount++ <= maxRetries ) {
-
- try {
- managementApp = em.getApplication();
-
- if ( managementApp == null ) {
-
- logger.warn( "Management application not found, attempting creation" );
-
- Map mgmtAppProps = new HashMap<String, Object>();
- mgmtAppProps.put( PROPERTY_NAME, CassandraService.MANAGEMENT_APPLICATION );
- em.create( getManagementAppId(), TYPE_APPLICATION, mgmtAppProps );
- managementApp = em.getApplication();
- }
-
- } catch ( Throwable t ) {
- logger.warn("Error getting or creating management application after " + retryCount + " retries", t);
+ try {
+ if ( em.getApplication() == null ) {
+ logger.info("Creating management application");
+ Map mgmtAppProps = new HashMap<String, Object>();
+ mgmtAppProps.put(PROPERTY_NAME, CassandraService.MANAGEMENT_APPLICATION);
+ em.create( getManagementAppId(), TYPE_APPLICATION, mgmtAppProps);
+ em.getApplication();
}
- }
-
- indexService.queueInitializeApplicationIndex(CpNamingUtils.getApplicationScope(getManagementAppId()));
- if ( managementApp == null ) {
- throw new RuntimeException("FATAL ERROR: Failed to get or create management app");
+ } catch (Exception ex) {
+ throw new RuntimeException("Fatal error creating management application", ex);
}
}