geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pivotalsa...@apache.org
Subject [geode] branch develop updated: GEODE-3966: Avoid singletons by passing distributed system and cache. (#1366)
Date Mon, 05 Feb 2018 16:14:53 GMT
This is an automated email from the ASF dual-hosted git repository.

pivotalsarge pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/geode.git


The following commit(s) were added to refs/heads/develop by this push:
     new 40a2ca0  GEODE-3966: Avoid singletons by passing distributed system and cache. (#1366)
40a2ca0 is described below

commit 40a2ca0041e575cd3c21f9fba80f523ce44bc3c1
Author: Michael "Sarge" Dodge <mdodge@pivotal.io>
AuthorDate: Mon Feb 5 08:14:48 2018 -0800

    GEODE-3966: Avoid singletons by passing distributed system and cache. (#1366)
---
 .../geode/cache/client/internal/PoolImpl.java      | 89 +++++++++++++---------
 .../org/apache/geode/cache/query/QueryService.java | 13 +++-
 .../geode/internal/cache/PoolFactoryImpl.java      |  5 +-
 .../geode/internal/i18n/LocalizedStrings.java      |  2 +
 4 files changed, 71 insertions(+), 38 deletions(-)

diff --git a/geode-core/src/main/java/org/apache/geode/cache/client/internal/PoolImpl.java
b/geode-core/src/main/java/org/apache/geode/cache/client/internal/PoolImpl.java
index c266b8b..ec2c091 100644
--- a/geode-core/src/main/java/org/apache/geode/cache/client/internal/PoolImpl.java
+++ b/geode-core/src/main/java/org/apache/geode/cache/client/internal/PoolImpl.java
@@ -37,9 +37,7 @@ import org.apache.geode.CancelCriterion;
 import org.apache.geode.CancelException;
 import org.apache.geode.StatisticsFactory;
 import org.apache.geode.SystemFailure;
-import org.apache.geode.cache.Cache;
 import org.apache.geode.cache.CacheClosedException;
-import org.apache.geode.cache.CacheFactory;
 import org.apache.geode.cache.NoSubscriptionServersAvailableException;
 import org.apache.geode.cache.Region;
 import org.apache.geode.cache.RegionService;
@@ -59,7 +57,6 @@ import org.apache.geode.distributed.internal.membership.gms.membership.HostAddre
 import org.apache.geode.internal.ScheduledThreadPoolExecutorWithKeepAlive;
 import org.apache.geode.internal.admin.ClientStatsManager;
 import org.apache.geode.internal.cache.EventID;
-import org.apache.geode.internal.cache.GemFireCacheImpl;
 import org.apache.geode.internal.cache.InternalCache;
 import org.apache.geode.internal.cache.PoolFactoryImpl;
 import org.apache.geode.internal.cache.PoolManagerImpl;
@@ -136,6 +133,7 @@ public class PoolImpl implements InternalPool {
   private final OpExecutorImpl executor;
   private final RegisterInterestTracker riTracker = new RegisterInterestTracker();
   private final InternalDistributedSystem dsys;
+  private InternalCache cache;
 
   private final ClientProxyMembershipID proxyId;
   protected final CancelCriterion cancelCriterion;
@@ -153,8 +151,9 @@ public class PoolImpl implements InternalPool {
   private AtomicInteger primaryQueueSize = new AtomicInteger(PRIMARY_QUEUE_NOT_AVAILABLE);
 
   public static PoolImpl create(PoolManagerImpl pm, String name, Pool attributes,
-      List<HostAddress> locatorAddresses) {
-    PoolImpl pool = new PoolImpl(pm, name, attributes, locatorAddresses);
+      List<HostAddress> locatorAddresses, InternalDistributedSystem distributedSystem,
+      InternalCache cache) {
+    PoolImpl pool = new PoolImpl(pm, name, attributes, locatorAddresses, distributedSystem,
cache);
     pool.finishCreate(pm);
     return pool;
   }
@@ -181,7 +180,8 @@ public class PoolImpl implements InternalPool {
   }
 
   protected PoolImpl(PoolManagerImpl pm, String name, Pool attributes,
-      List<HostAddress> locAddresses) {
+      List<HostAddress> locAddresses, InternalDistributedSystem distributedSystem,
+      InternalCache cache) {
     this.pm = pm;
     this.name = name;
     this.socketConnectTimeout = attributes.getSocketConnectTimeout();
@@ -210,46 +210,42 @@ public class PoolImpl implements InternalPool {
         ((PoolFactoryImpl.PoolAttributes) attributes).startDisabled || !pm.isNormal();
     this.usedByGateway = ((PoolFactoryImpl.PoolAttributes) attributes).isGateway();
     this.gatewaySender = ((PoolFactoryImpl.PoolAttributes) attributes).getGatewaySender();
-    // if (this.subscriptionEnabled && this.multiuserSecureModeEnabled) {
-    // throw new IllegalStateException(
-    // "subscription-enabled and multiuser-authentication both cannot be true.");
-    // }
-    InternalDistributedSystem ds = InternalDistributedSystem.getAnyInstance();
-    if (ds == null) {
+    this.dsys = distributedSystem;
+    if (this.dsys == null) {
       throw new IllegalStateException(
           LocalizedStrings.PoolImpl_DISTRIBUTED_SYSTEM_MUST_BE_CREATED_BEFORE_CREATING_POOL
               .toLocalizedString());
     }
-    this.securityLogWriter = ds.getSecurityInternalLogWriter();
-    if (!ds.getConfig().getStatisticSamplingEnabled() && this.statisticInterval >
0) {
+    this.cache = cache;
+    this.securityLogWriter = this.dsys.getSecurityInternalLogWriter();
+    if (!this.dsys.getConfig().getStatisticSamplingEnabled() && this.statisticInterval
> 0) {
       logger.info(LocalizedMessage.create(
           LocalizedStrings.PoolImpl_STATISTIC_SAMPLING_MUST_BE_ENABLED_FOR_SAMPLING_RATE_OF_0_TO_TAKE_AFFECT,
           this.statisticInterval));
     }
-    this.dsys = ds;
     this.cancelCriterion = new Stopper();
     if (Boolean.getBoolean(DistributionConfig.GEMFIRE_PREFIX + "SPECIAL_DURABLE")) {
       ClientProxyMembershipID.setPoolName(name);
-      this.proxyId = ClientProxyMembershipID.getNewProxyMembership(ds);
+      this.proxyId = ClientProxyMembershipID.getNewProxyMembership(this.dsys);
       ClientProxyMembershipID.setPoolName(null);
     } else {
-      this.proxyId = ClientProxyMembershipID.getNewProxyMembership(ds);
+      this.proxyId = ClientProxyMembershipID.getNewProxyMembership(this.dsys);
     }
     StatisticsFactory statFactory = null;
     if (this.gatewaySender != null) {
       statFactory = new DummyStatisticsFactory();
     } else {
-      statFactory = ds;
+      statFactory = this.dsys;
     }
     this.stats = this.startDisabled ? null
         : new PoolStats(statFactory, getName() + "->"
             + (isEmpty(serverGroup) ? "[any servers]" : "[" + getServerGroup() + "]"));
 
     source = getSourceImpl(((PoolFactoryImpl.PoolAttributes) attributes).locatorCallback);
-    endpointManager = new EndpointManagerImpl(name, ds, this.cancelCriterion, this.stats);
-    connectionFactory = new ConnectionFactoryImpl(source, endpointManager, ds, socketBufferSize,
-        socketConnectTimeout, readTimeout, proxyId, this.cancelCriterion, usedByGateway,
-        gatewaySender, pingInterval, multiuserSecureModeEnabled, this);
+    endpointManager = new EndpointManagerImpl(name, this.dsys, this.cancelCriterion, this.stats);
+    connectionFactory = new ConnectionFactoryImpl(source, endpointManager, this.dsys,
+        socketBufferSize, socketConnectTimeout, readTimeout, proxyId, this.cancelCriterion,
+        usedByGateway, gatewaySender, pingInterval, multiuserSecureModeEnabled, this);
     if (subscriptionEnabled) {
       queueManager = new QueueManagerImpl(this, endpointManager, source, connectionFactory,
           subscriptionRedundancyLevel, pingInterval, securityLogWriter, proxyId);
@@ -510,9 +506,16 @@ public class PoolImpl implements InternalPool {
       if (SPECIAL_DURABLE) {
         synchronized (simpleLock) {
           try {
-            if (!CacheFactory.getAnyInstance().isClosed()
-                && this.getPoolOrCacheCancelInProgress() == null) {
-              Set<Region<?, ?>> regions = CacheFactory.getInstance(dsys).rootRegions();
+            if (cache == null && dsys != null) {
+              cache = dsys.getCache();
+              if (cache == null) {
+                throw new IllegalStateException(
+                    LocalizedStrings.PoolImpl_CACHE_MUST_BE_CREATED_BEFORE_CREATING_POOL
+                        .toLocalizedString());
+              }
+            }
+            if (!cache.isClosed() && this.getPoolOrCacheCancelInProgress() == null)
{
+              Set<Region<?, ?>> regions = cache.rootRegions();
               for (Region<?, ?> roots : regions) {
                 Set<Region<?, ?>> subregions = roots.subregions(true);
                 for (Region<?, ?> subroots : subregions) {
@@ -1005,8 +1008,7 @@ public class PoolImpl implements InternalPool {
 
   public boolean isDurableClient() {
     boolean isDurable = false;
-    InternalDistributedSystem system = InternalDistributedSystem.getAnyInstance();
-    DistributionConfig config = system.getConfig();
+    DistributionConfig config = dsys.getConfig();
     String durableClientId = config.getDurableClientId();
     isDurable = durableClientId != null && durableClientId.length() > 0;
     return isDurable;
@@ -1405,8 +1407,7 @@ public class PoolImpl implements InternalPool {
    * @return the QueryService
    */
   public QueryService getQueryService() {
-    Cache cache = CacheFactory.getInstance(InternalDistributedSystem.getAnyInstance());
-    DefaultQueryService queryService = new DefaultQueryService((InternalCache) cache);
+    DefaultQueryService queryService = new DefaultQueryService(cache);
     queryService.setPool(this);
     return queryService;
   }
@@ -1419,13 +1420,20 @@ public class PoolImpl implements InternalPool {
     if (properties == null || properties.isEmpty()) {
       throw new IllegalArgumentException("Security properties cannot be empty.");
     }
-    Cache cache = CacheFactory.getInstance(InternalDistributedSystem.getAnyInstance());
 
     Properties props = new Properties();
     for (Entry<Object, Object> entry : properties.entrySet()) {
       props.setProperty((String) entry.getKey(), (String) entry.getValue());
     }
-    ProxyCache proxy = new ProxyCache(props, (InternalCache) cache, this);
+    if (cache == null && dsys != null) {
+      cache = dsys.getCache();
+      if (cache == null) {
+        throw new IllegalStateException(
+            LocalizedStrings.PoolImpl_CACHE_MUST_BE_CREATED_BEFORE_CREATING_POOL
+                .toLocalizedString());
+      }
+    }
+    ProxyCache proxy = new ProxyCache(props, cache, this);
     synchronized (this.proxyCacheList) {
       this.proxyCacheList.add(proxy);
     }
@@ -1439,12 +1447,19 @@ public class PoolImpl implements InternalPool {
     if (re != null) {
       return re;
     }
-    InternalCache cache = GemFireCacheImpl.getInstance();
     if (cache == null) {
       if (cacheCriterion != null) {
         return cacheCriterion.generateCancelledException(e);
       }
     } else {
+      if (cache == null && dsys != null) {
+        cache = dsys.getCache();
+        if (cache == null) {
+          throw new IllegalStateException(
+              LocalizedStrings.PoolImpl_CACHE_MUST_BE_CREATED_BEFORE_CREATING_POOL
+                  .toLocalizedString());
+        }
+      }
       if (cacheCriterion == null || cacheCriterion != cache.getCancelCriterion()) {
         cacheCriterion = cache.getCancelCriterion();
       }
@@ -1460,13 +1475,20 @@ public class PoolImpl implements InternalPool {
       if (reason != null) {
         return reason;
       }
-      InternalCache cache = GemFireCacheImpl.getInstance();
       if (cache == null) {
         if (cacheCriterion != null) {
           return cacheCriterion.cancelInProgress();
         }
         return null;
       } else {
+        if (cache == null && dsys != null) {
+          cache = dsys.getCache();
+          if (cache == null) {
+            throw new IllegalStateException(
+                LocalizedStrings.PoolImpl_CACHE_MUST_BE_CREATED_BEFORE_CREATING_POOL
+                    .toLocalizedString());
+          }
+        }
         if (cacheCriterion == null) {
           cacheCriterion = cache.getCancelCriterion();
         } else if (cacheCriterion != cache.getCancelCriterion()) {
@@ -1489,7 +1511,6 @@ public class PoolImpl implements InternalPool {
   }
 
   public boolean getKeepAlive() {
-    InternalCache cache = GemFireCacheImpl.getInstance();
     if (cache == null) {
       return keepAlive;
     }
diff --git a/geode-core/src/main/java/org/apache/geode/cache/query/QueryService.java b/geode-core/src/main/java/org/apache/geode/cache/query/QueryService.java
index b9996f3..93fefce 100644
--- a/geode-core/src/main/java/org/apache/geode/cache/query/QueryService.java
+++ b/geode-core/src/main/java/org/apache/geode/cache/query/QueryService.java
@@ -25,9 +25,16 @@ import org.apache.geode.cache.query.internal.Undefined;
  * Interface for the query service, which is used for instantiating queries, creating and
destroying
  * indexes, creating CQs and operating on CQs.
  *
- * Creating an index on an employee's age using QueryService in region "employeeRegion",
- * QueryService queryService = cache.getQueryService(); queryService.createIndex ("SampleIndex",
- * //IndexName "e.age" //indexExpression "/employeeRegion e", //regionPath );
+ * Creating an index on an employee's age using QueryService in region "employeeRegion":
+ *
+ * <pre>
+ *   <code>
+ *     QueryService queryService = cache.getQueryService();
+ *     queryService.createIndex ("SampleIndex",        // indexName
+ *                               "e.age",              // indexedExpression
+ *                               "/employeeRegion e"); //regionPath
+ *   </code>
+ * </pre>
  *
  * The CQs work on the server regions, the client can use the CQ methods supported in this
class to
  * create/operate CQs on the server. The CQ obtains the Server connection from the corresponding
diff --git a/geode-core/src/main/java/org/apache/geode/internal/cache/PoolFactoryImpl.java
b/geode-core/src/main/java/org/apache/geode/internal/cache/PoolFactoryImpl.java
index 8bf1dac..f63784f 100644
--- a/geode-core/src/main/java/org/apache/geode/internal/cache/PoolFactoryImpl.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/cache/PoolFactoryImpl.java
@@ -37,6 +37,7 @@ import org.apache.geode.cache.client.internal.LocatorDiscoveryCallback;
 import org.apache.geode.cache.client.internal.PoolImpl;
 import org.apache.geode.cache.query.QueryService;
 import org.apache.geode.cache.wan.GatewaySender;
+import org.apache.geode.distributed.internal.InternalDistributedSystem;
 import org.apache.geode.distributed.internal.membership.gms.membership.HostAddress;
 import org.apache.geode.internal.i18n.LocalizedStrings;
 import org.apache.geode.internal.logging.LogService;
@@ -328,6 +329,7 @@ public class PoolFactoryImpl implements PoolFactory {
    * @since GemFire 5.7
    */
   public Pool create(String name) throws CacheException {
+    InternalDistributedSystem distributedSystem = InternalDistributedSystem.getAnyInstance();
     InternalCache cache = GemFireCacheImpl.getInstance();
     if (cache != null) {
       TypeRegistry registry = cache.getPdxRegistry();
@@ -335,7 +337,8 @@ public class PoolFactoryImpl implements PoolFactory {
         registry.creatingPool();
       }
     }
-    return PoolImpl.create(this.pm, name, this.attributes, this.locatorAddresses);
+    return PoolImpl.create(this.pm, name, this.attributes, this.locatorAddresses, distributedSystem,
+        cache);
   }
 
   /**
diff --git a/geode-core/src/main/java/org/apache/geode/internal/i18n/LocalizedStrings.java
b/geode-core/src/main/java/org/apache/geode/internal/i18n/LocalizedStrings.java
index c48deb7..905086a 100755
--- a/geode-core/src/main/java/org/apache/geode/internal/i18n/LocalizedStrings.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/i18n/LocalizedStrings.java
@@ -7711,6 +7711,8 @@ public class LocalizedStrings {
       new StringId(6664, "{0}: Providing synchronization event for key={1}; timestamp={2}:
{3}");
   public static final StringId AbstractGatewaySender_ENQUEUEING_SYNCHRONIZATION_EVENT =
       new StringId(6665, "{0}: Enqueueing synchronization event: {1}");
+  public static final StringId PoolImpl_CACHE_MUST_BE_CREATED_BEFORE_CREATING_POOL =
+      new StringId(6666, "Cache must be created before creating pool");
 
   /** Testing strings, messageId 90000-99999 **/
 

-- 
To stop receiving notification emails like this one, please contact
pivotalsarge@apache.org.

Mime
View raw message