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/07/14 20:21:08 UTC
[2/2] usergrid git commit: Clean up some naming around collection
settings.
Clean up some naming around collection settings.
Project: http://git-wip-us.apache.org/repos/asf/usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/usergrid/commit/3b6eb07f
Tree: http://git-wip-us.apache.org/repos/asf/usergrid/tree/3b6eb07f
Diff: http://git-wip-us.apache.org/repos/asf/usergrid/diff/3b6eb07f
Branch: refs/heads/release-2.1.1
Commit: 3b6eb07fd47f78086a6f89afd0fb1ab6af274e86
Parents: b11b397
Author: Michael Russo <mr...@apigee.com>
Authored: Thu Jul 14 13:18:54 2016 -0700
Committer: Michael Russo <mr...@apigee.com>
Committed: Thu Jul 14 13:18:54 2016 -0700
----------------------------------------------------------------------
.../corepersistence/CpEntityManager.java | 40 ++++++++++----------
.../index/CollectionSettingsCache.java | 4 +-
.../index/CollectionSettingsFactory.java | 18 +--------
.../index/ReIndexServiceImpl.java | 12 +++---
4 files changed, 28 insertions(+), 46 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/usergrid/blob/3b6eb07f/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManager.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManager.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManager.java
index d80969c..fcda5b5 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManager.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManager.java
@@ -554,13 +554,13 @@ public class CpEntityManager implements EntityManager {
String collectionName = Schema.defaultCollectionName( type );
- CollectionSettings collectionSettingsCache = collectionSettingsFactory
+ CollectionSettings collectionSettings = collectionSettingsFactory
.getInstance( new CollectionSettingsScopeImpl(getAppIdObject(), collectionName) );
- Optional<Map<String, Object>> collectionSettings =
- collectionSettingsCache.getCollectionSettings( collectionName );
+ Optional<Map<String, Object>> existingSettings =
+ collectionSettings.getCollectionSettings( collectionName );
- if ( collectionSettings.isPresent()) {
- Map jsonMapData = collectionSettings.get();
+ if ( existingSettings.isPresent()) {
+ Map jsonMapData = existingSettings.get();
Object fields = jsonMapData.get("fields");
if ( fields != null && "none".equalsIgnoreCase( fields.toString() ) ) {
skipIndexing = true;
@@ -1124,12 +1124,12 @@ public class CpEntityManager implements EntityManager {
String region = null;
String collectionName = Schema.defaultCollectionName( entityRef.getType() );
- CollectionSettings collectionSettingsCache = collectionSettingsFactory
+ CollectionSettings collectionSettings = collectionSettingsFactory
.getInstance( new CollectionSettingsScopeImpl( getAppIdObject(), collectionName) );
- Optional<Map<String, Object>> collectionSettings =
- collectionSettingsCache.getCollectionSettings( collectionName );
- if ( collectionSettings.isPresent() ) {
- region = collectionSettings.get().get("region").toString();
+ Optional<Map<String, Object>> existingSettings =
+ collectionSettings.getCollectionSettings( collectionName );
+ if ( existingSettings.isPresent() ) {
+ region = existingSettings.get().get("region").toString();
}
//TODO: does this call and others like it need a graphite reporter?
@@ -1774,10 +1774,10 @@ public class CpEntityManager implements EntityManager {
// Possible values are app credentials, org credentials, or the user email(Admin tokens).
updatedSettings.put( "lastUpdateBy", owner );
- CollectionSettings collectionSettingsCache = collectionSettingsFactory
+ CollectionSettings collectionSettings = collectionSettingsFactory
.getInstance( new CollectionSettingsScopeImpl( getAppIdObject(), collectionName) );
Optional<Map<String, Object>> existingSettings =
- collectionSettingsCache.getCollectionSettings( collectionName );
+ collectionSettings.getCollectionSettings( collectionName );
// If there is an existing schema then take the lastReindexed time and keep it around.
// Otherwise initialize to 0.
@@ -1811,7 +1811,7 @@ public class CpEntityManager implements EntityManager {
}
}
- collectionSettingsCache.putCollectionSettings( collectionName, JsonUtils.mapToJsonString( updatedSettings ) );
+ collectionSettings.putCollectionSettings( collectionName, JsonUtils.mapToJsonString( updatedSettings ) );
return updatedSettings;
}
@@ -1819,11 +1819,11 @@ public class CpEntityManager implements EntityManager {
@Override
public void deleteCollectionSettings( String collectionName ){
- CollectionSettings collectionSettingsCache = collectionSettingsFactory
+ CollectionSettings collectionSettings = collectionSettingsFactory
.getInstance( new CollectionSettingsScopeImpl( getAppIdObject(), collectionName) );
- collectionSettingsCache.deleteCollectionSettings( collectionName );
+ collectionSettings.deleteCollectionSettings( collectionName );
}
@@ -3118,14 +3118,14 @@ public class CpEntityManager implements EntityManager {
// get collection settings for type
- CollectionSettings collectionSettingsCache = collectionSettingsFactory
+ CollectionSettings collectionSettings = collectionSettingsFactory
.getInstance( new CollectionSettingsScopeImpl( getAppIdObject(), collectionName) );
- Optional<Map<String, Object>> collectionSettings =
- collectionSettingsCache.getCollectionSettings( collectionName );
+ Optional<Map<String, Object>> existingSettings =
+ collectionSettings.getCollectionSettings( collectionName );
- if ( collectionSettings.isPresent() && collectionSettings.get().get("region") != null ) {
- region = collectionSettings.get().get("region").toString();
+ if ( existingSettings.isPresent() && existingSettings.get().get("region") != null ) {
+ region = existingSettings.get().get("region").toString();
}
return region;
http://git-wip-us.apache.org/repos/asf/usergrid/blob/3b6eb07f/stack/core/src/main/java/org/apache/usergrid/corepersistence/index/CollectionSettingsCache.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/index/CollectionSettingsCache.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/index/CollectionSettingsCache.java
index 1ff718e..aad274b 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/index/CollectionSettingsCache.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/index/CollectionSettingsCache.java
@@ -27,15 +27,13 @@ import java.util.concurrent.TimeUnit;
@Singleton
public class CollectionSettingsCache {
- private final CollectionSettingsCacheFig fig;
private final Cache<CollectionSettingsScope,String> cache;
@Inject
public CollectionSettingsCache( CollectionSettingsCacheFig fig ) {
- this.fig = fig;
this.cache = CacheBuilder.newBuilder()
- .maximumSize(Math.min(1000, fig.getCacheSize()))
+ .maximumSize(fig.getCacheSize())
.expireAfterWrite(fig.getCacheTimeout(), TimeUnit.SECONDS).build();
}
http://git-wip-us.apache.org/repos/asf/usergrid/blob/3b6eb07f/stack/core/src/main/java/org/apache/usergrid/corepersistence/index/CollectionSettingsFactory.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/index/CollectionSettingsFactory.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/index/CollectionSettingsFactory.java
index af4ae40..df38c86 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/index/CollectionSettingsFactory.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/index/CollectionSettingsFactory.java
@@ -18,7 +18,6 @@
package org.apache.usergrid.corepersistence.index;
-import com.google.common.base.Optional;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
@@ -28,36 +27,21 @@ import org.apache.usergrid.persistence.map.MapManager;
import com.google.inject.Inject;
import com.google.inject.Singleton;
import org.apache.usergrid.persistence.map.MapManagerFactory;
-import org.apache.usergrid.persistence.model.entity.Id;
-import java.util.Map;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
-/**
- * This can only be implemented after we have the impl for the application cache.
- */
@Singleton
public class CollectionSettingsFactory {
- private final CollectionSettingsCacheFig fig;
-
- private final MapManagerFactory mapManagerFactory;
-
-
private final LoadingCache<CollectionSettingsScope,CollectionSettings> indexSchemaCache;
- private final CollectionSettingsCache collectionSettingsCache;
-
-
@Inject
public CollectionSettingsFactory( final CollectionSettingsCacheFig fig,
final MapManagerFactory mapManagerFactory,
final CollectionSettingsCache collectionSettingsCache ){
- this.fig = fig;
- this.mapManagerFactory = mapManagerFactory;
- this.collectionSettingsCache = collectionSettingsCache;
+
indexSchemaCache = CacheBuilder.newBuilder()
.maximumSize( fig.getCacheSize() )
http://git-wip-us.apache.org/repos/asf/usergrid/blob/3b6eb07f/stack/core/src/main/java/org/apache/usergrid/corepersistence/index/ReIndexServiceImpl.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/index/ReIndexServiceImpl.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/index/ReIndexServiceImpl.java
index 1093f3c..e3b179d 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/index/ReIndexServiceImpl.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/index/ReIndexServiceImpl.java
@@ -141,21 +141,21 @@ public class ReIndexServiceImpl implements ReIndexService {
String collectionName = InflectionUtils.pluralize(
CpNamingUtils.getNameFromEdgeType(reIndexRequestBuilder.getCollectionName().get() ));
- CollectionSettings collectionSettingsCache =
+ CollectionSettings collectionSettings =
collectionSettingsFactory.getInstance( new CollectionSettingsScopeImpl(appId.get().getApplication(), collectionName) );
- Optional<Map<String, Object>> collectionSettings =
- collectionSettingsCache.getCollectionSettings( collectionName );
+ Optional<Map<String, Object>> existingSettings =
+ collectionSettings.getCollectionSettings( collectionName );
// If we do have a schema then parse it and add it to a list of properties we want to keep.Otherwise return.
- if ( collectionSettings.isPresent() ) {
+ if ( existingSettings.isPresent() ) {
- Map jsonMapData = collectionSettings.get();
+ Map jsonMapData = existingSettings.get();
jsonMapData.put( "lastReindexed", Instant.now().toEpochMilli() );
// should probably roll this into the cache.
- collectionSettingsCache.putCollectionSettings(
+ collectionSettings.putCollectionSettings(
collectionName, JsonUtils.mapToJsonString(jsonMapData ) );
}