From acf6b17d7bc1ebb65111436f1fde9b9dc1335bf2 Mon Sep 17 00:00:00 2001 From: John Blum Date: Tue, 24 Apr 2018 14:42:55 -0700 Subject: [PATCH] SGF-738 - Avoid Pool Already Exists Exception on Spring container initialization. --- .../data/gemfire/client/PoolFactoryBean.java | 64 ++++++++++--------- 1 file changed, 35 insertions(+), 29 deletions(-) diff --git a/src/main/java/org/springframework/data/gemfire/client/PoolFactoryBean.java b/src/main/java/org/springframework/data/gemfire/client/PoolFactoryBean.java index a8d6244e..08e08cb2 100644 --- a/src/main/java/org/springframework/data/gemfire/client/PoolFactoryBean.java +++ b/src/main/java/org/springframework/data/gemfire/client/PoolFactoryBean.java @@ -164,45 +164,51 @@ public class PoolFactoryBean implements FactoryBean, InitializingBean, Dis } } - /* (non-Javadoc) */ @Override public Pool getObject() throws Exception { + if (this.pool == null) { + eagerlyInitializeClientCacheIfNotPresent(); - PoolFactory poolFactory = createPoolFactory(); + this.pool = PoolManager.find(getName()); - poolFactory.setFreeConnectionTimeout(freeConnectionTimeout); - poolFactory.setIdleTimeout(idleTimeout); - poolFactory.setLoadConditioningInterval(loadConditioningInterval); - poolFactory.setMaxConnections(maxConnections); - poolFactory.setMinConnections(minConnections); - poolFactory.setMultiuserAuthentication(multiUserAuthentication); - poolFactory.setPingInterval(pingInterval); - poolFactory.setPRSingleHopEnabled(prSingleHopEnabled); - poolFactory.setReadTimeout(readTimeout); - poolFactory.setRetryAttempts(retryAttempts); - poolFactory.setServerGroup(serverGroup); - poolFactory.setSocketBufferSize(socketBufferSize); - poolFactory.setStatisticInterval(statisticInterval); - poolFactory.setSubscriptionAckInterval(subscriptionAckInterval); - poolFactory.setSubscriptionEnabled(subscriptionEnabled); - poolFactory.setSubscriptionMessageTrackingTimeout(subscriptionMessageTrackingTimeout); - poolFactory.setSubscriptionRedundancy(subscriptionRedundancy); - poolFactory.setThreadLocalConnections(threadLocalConnections); + if (this.pool == null) { - for (ConnectionEndpoint locator : this.locators) { - poolFactory.addLocator(locator.getHost(), locator.getPort()); + PoolFactory poolFactory = createPoolFactory(); + + poolFactory.setFreeConnectionTimeout(freeConnectionTimeout); + poolFactory.setIdleTimeout(idleTimeout); + poolFactory.setLoadConditioningInterval(loadConditioningInterval); + poolFactory.setMaxConnections(maxConnections); + poolFactory.setMinConnections(minConnections); + poolFactory.setMultiuserAuthentication(multiUserAuthentication); + poolFactory.setPingInterval(pingInterval); + poolFactory.setPRSingleHopEnabled(prSingleHopEnabled); + poolFactory.setReadTimeout(readTimeout); + poolFactory.setRetryAttempts(retryAttempts); + poolFactory.setServerGroup(serverGroup); + poolFactory.setSocketBufferSize(socketBufferSize); + poolFactory.setStatisticInterval(statisticInterval); + poolFactory.setSubscriptionAckInterval(subscriptionAckInterval); + poolFactory.setSubscriptionEnabled(subscriptionEnabled); + poolFactory.setSubscriptionMessageTrackingTimeout(subscriptionMessageTrackingTimeout); + poolFactory.setSubscriptionRedundancy(subscriptionRedundancy); + poolFactory.setThreadLocalConnections(threadLocalConnections); + + for (ConnectionEndpoint locator : this.locators) { + poolFactory.addLocator(locator.getHost(), locator.getPort()); + } + + for (ConnectionEndpoint server : this.servers) { + poolFactory.addServer(server.getHost(), server.getPort()); + } + + this.pool = poolFactory.create(name); } - - for (ConnectionEndpoint server : this.servers) { - poolFactory.addServer(server.getHost(), server.getPort()); - } - - pool = poolFactory.create(name); } - return pool; + return this.pool; } /**