This is an automated email from the ASF dual-hosted git repository. jbarrett 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 4303144 GEODE-6588: Cleanup static analyzer warnings. (#3570) 4303144 is described below commit 43031449443b22e087066fed7516a3b98170c1ea Author: Jacob Barrett <jbarr...@pivotal.io> AuthorDate: Tue May 14 07:34:26 2019 -0700 GEODE-6588: Cleanup static analyzer warnings. (#3570) --- .../apache/geode/modules/util/RegionHelper.java | 36 +- .../apache/geode/cache30/CacheXml66DUnitTest.java | 3 +- .../apache/geode/cache30/ReconnectDUnitTest.java | 3 +- .../cache/client/ClientCacheFactoryJUnitTest.java | 64 +-- .../membership/gms/mgr/GMSMembershipManager.java | 3 +- .../internal/cache/xmlcache/CacheXmlGenerator.java | 562 +++++++++------------ .../internal/cache/xmlcache/XmlGenerator.java | 11 - .../cli/functions/ExportConfigFunction.java | 9 +- .../internal/configuration/domain/XmlEntity.java | 149 +++--- ...uceneIndexXmlGeneratorIntegrationJUnitTest.java | 10 +- ...ipleReceiversDefinedInClusterConfiguration.java | 19 +- 11 files changed, 361 insertions(+), 508 deletions(-) diff --git a/extensions/geode-modules/src/main/java/org/apache/geode/modules/util/RegionHelper.java b/extensions/geode-modules/src/main/java/org/apache/geode/modules/util/RegionHelper.java index 1961849..6028dc9 100644 --- a/extensions/geode-modules/src/main/java/org/apache/geode/modules/util/RegionHelper.java +++ b/extensions/geode-modules/src/main/java/org/apache/geode/modules/util/RegionHelper.java @@ -12,11 +12,11 @@ * or implied. See the License for the specific language governing permissions and limitations under * the License. */ + package org.apache.geode.modules.util; import java.io.PrintWriter; import java.io.StringWriter; -import java.util.HashSet; import java.util.Set; import java.util.concurrent.CancellationException; @@ -34,7 +34,6 @@ import org.apache.geode.cache.control.RebalanceResults; import org.apache.geode.cache.control.ResourceManager; import org.apache.geode.cache.partition.PartitionMemberInfo; import org.apache.geode.cache.partition.PartitionRebalanceInfo; -import org.apache.geode.cache.partition.PartitionRegionHelper; import org.apache.geode.internal.cache.xmlcache.CacheXmlGenerator; import org.apache.geode.internal.cache.xmlcache.RegionAttributesCreation; import org.apache.geode.modules.gatewaydelta.GatewayDeltaForwarderCacheListener; @@ -76,28 +75,6 @@ public class RegionHelper { existingRACreation.sameAs(requestedRegionAttributes); } - public static RebalanceResults rebalanceRegion(Region region) - throws CancellationException, InterruptedException { - String regionName = region.getName(); // FilterByName only looks at name and not full path - if (!PartitionRegionHelper.isPartitionedRegion(region)) { - StringBuilder builder = new StringBuilder(); - builder.append("Region ").append(regionName).append(" is not partitioned. Instead, it is ") - .append(region.getAttributes().getDataPolicy()).append(". It can't be rebalanced."); - throw new IllegalArgumentException(builder.toString()); - } - - // Rebalance the region - ResourceManager resourceManager = region.getCache().getResourceManager(); - RebalanceFactory rebalanceFactory = resourceManager.createRebalanceFactory(); - Set<String> regionsToRebalance = new HashSet<String>(); - regionsToRebalance.add(regionName); - rebalanceFactory.includeRegions(regionsToRebalance); - RebalanceOperation rebalanceOperation = rebalanceFactory.start(); - - // Return the results - return rebalanceOperation.getResults(); - } - public static RebalanceResults rebalanceCache(GemFireCache cache) throws CancellationException, InterruptedException { ResourceManager resourceManager = cache.getResourceManager(); @@ -110,7 +87,7 @@ public class RegionHelper { try { StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw, true); - CacheXmlGenerator.generate(cache, pw, true, false); + CacheXmlGenerator.generate(cache, pw, false); pw.close(); return sw.toString(); } catch (Exception ex) { @@ -118,8 +95,7 @@ public class RegionHelper { } } - public static RegionAttributes getRegionAttributes(Cache cache, - RegionConfiguration configuration) { + static RegionAttributes getRegionAttributes(Cache cache, RegionConfiguration configuration) { // Create the requested attributes RegionAttributes baseRequestedAttributes = cache.getRegionAttributes(configuration.getRegionAttributesId()); @@ -166,11 +142,7 @@ public class RegionHelper { CacheWriter writer = (CacheWriter) Class.forName(configuration.getCacheWriterName()).newInstance(); requestedFactory.setCacheWriter(writer); - } catch (InstantiationException e) { - throw new RuntimeException("Could not set a cacheWriter for the region", e); - } catch (IllegalAccessException e) { - throw new RuntimeException("Could not set a cacheWriter for the region", e); - } catch (ClassNotFoundException e) { + } catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) { throw new RuntimeException("Could not set a cacheWriter for the region", e); } } diff --git a/geode-core/src/distributedTest/java/org/apache/geode/cache30/CacheXml66DUnitTest.java b/geode-core/src/distributedTest/java/org/apache/geode/cache30/CacheXml66DUnitTest.java index 4954dd7..f6b5d31 100644 --- a/geode-core/src/distributedTest/java/org/apache/geode/cache30/CacheXml66DUnitTest.java +++ b/geode-core/src/distributedTest/java/org/apache/geode/cache30/CacheXml66DUnitTest.java @@ -3449,11 +3449,10 @@ public abstract class CacheXml66DUnitTest extends CacheXmlTestCase { public InputStream generate(CacheCreation creation) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); - final boolean useSchema = getUseSchema(); final String version = getGemFireVersion(); PrintWriter pw = new PrintWriter(new OutputStreamWriter(baos), true); - CacheXmlGenerator.generate(creation, pw, useSchema, version); + CacheXmlGenerator.generate(creation, pw, getUseSchema(), version); pw.close(); byte[] bytes = baos.toByteArray(); diff --git a/geode-core/src/distributedTest/java/org/apache/geode/cache30/ReconnectDUnitTest.java b/geode-core/src/distributedTest/java/org/apache/geode/cache30/ReconnectDUnitTest.java index 232d729..b93e234 100755 --- a/geode-core/src/distributedTest/java/org/apache/geode/cache30/ReconnectDUnitTest.java +++ b/geode-core/src/distributedTest/java/org/apache/geode/cache30/ReconnectDUnitTest.java @@ -37,7 +37,6 @@ import static org.apache.geode.distributed.ConfigurationProperties.SECURITY_MANA import static org.apache.geode.distributed.ConfigurationProperties.START_LOCATOR; import static org.apache.geode.distributed.Locator.getLocator; import static org.apache.geode.distributed.internal.membership.gms.MembershipManagerHelper.getMembershipManager; -import static org.apache.geode.internal.cache.xmlcache.CacheXmlGenerator.generate; import static org.apache.geode.test.awaitility.GeodeAwaitility.await; import static org.apache.geode.test.awaitility.GeodeAwaitility.getTimeout; import static org.apache.geode.test.dunit.Host.getHost; @@ -852,7 +851,7 @@ public class ReconnectDUnitTest extends JUnit4CacheTestCase { File file = new File("RoleRegained.xml"); try { PrintWriter pw = new PrintWriter(new FileWriter(file), true); - generate(getCache(), pw); + CacheXmlGenerator.generate(getCache(), pw); pw.close(); } catch (IOException ex) { Assert.fail("IOException during cache.xml generation to " + file, ex); diff --git a/geode-core/src/integrationTest/java/org/apache/geode/cache/client/ClientCacheFactoryJUnitTest.java b/geode-core/src/integrationTest/java/org/apache/geode/cache/client/ClientCacheFactoryJUnitTest.java index 6ca4488..9439552 100644 --- a/geode-core/src/integrationTest/java/org/apache/geode/cache/client/ClientCacheFactoryJUnitTest.java +++ b/geode-core/src/integrationTest/java/org/apache/geode/cache/client/ClientCacheFactoryJUnitTest.java @@ -86,7 +86,7 @@ public class ClientCacheFactoryJUnitTest { @After public void tearDown() throws Exception { - if (this.clientCache != null && !this.clientCache.isClosed()) { + if (clientCache != null && !clientCache.isClosed()) { clientCache.close(); } } @@ -101,11 +101,11 @@ public class ClientCacheFactoryJUnitTest { @Test public void test000Defaults() throws Exception { - this.clientCache = new ClientCacheFactory().create(); - GemFireCacheImpl gfc = (GemFireCacheImpl) this.clientCache; + clientCache = new ClientCacheFactory().create(); + GemFireCacheImpl gfc = (GemFireCacheImpl) clientCache; assertThat(gfc.isClient()).isTrue(); - Properties dsProps = this.clientCache.getDistributedSystem().getProperties(); + Properties dsProps = clientCache.getDistributedSystem().getProperties(); assertThat(dsProps.getProperty(MCAST_PORT)).isEqualTo("0"); assertThat(dsProps.getProperty(LOCATORS)).isEqualTo(""); @@ -118,8 +118,8 @@ public class ClientCacheFactoryJUnitTest { new InetSocketAddress(InetAddress.getLocalHost(), CacheServer.DEFAULT_PORT))); ClientCache cc2 = new ClientCacheFactory().create(); - assertThat(cc2).as("expected cc2 and cc to be == " + cc2 + this.clientCache) - .isSameAs(this.clientCache); + assertThat(cc2).as("expected cc2 and cc to be == " + cc2 + clientCache) + .isSameAs(clientCache); assertThatThrownBy(() -> new ClientCacheFactory().set(LOG_LEVEL, "severe").create()) .isInstanceOf(IllegalStateException.class); assertThatThrownBy(() -> new ClientCacheFactory().addPoolLocator("127.0.0.1", 36666).create()) @@ -133,12 +133,12 @@ public class ClientCacheFactoryJUnitTest { .getResource("ClientCacheFactoryJUnitTest_single_pool.xml"); FileUtils.copyFile(new File(url.getFile()), cacheXmlFile); - this.clientCache = + clientCache = new ClientCacheFactory().set(CACHE_XML_FILE, cacheXmlFile.getAbsolutePath()).create(); - GemFireCacheImpl gfc = (GemFireCacheImpl) this.clientCache; + GemFireCacheImpl gfc = (GemFireCacheImpl) clientCache; assertThat(gfc.isClient()).isTrue(); - Properties dsProps = this.clientCache.getDistributedSystem().getProperties(); + Properties dsProps = clientCache.getDistributedSystem().getProperties(); assertThat(dsProps.getProperty(MCAST_PORT)).isEqualTo("0"); assertThat(dsProps.getProperty(LOCATORS)).isEqualTo(""); @@ -162,8 +162,8 @@ public class ClientCacheFactoryJUnitTest { Pool p = PoolManager.createFactory().addServer(InetAddress.getLocalHost().getHostName(), 7777) .setSocketConnectTimeout(1400).create("singlePool"); - this.clientCache = new ClientCacheFactory().create(); - GemFireCacheImpl gfc = (GemFireCacheImpl) this.clientCache; + clientCache = new ClientCacheFactory().create(); + GemFireCacheImpl gfc = (GemFireCacheImpl) clientCache; assertThat(gfc.isClient()).isTrue(); Pool defPool = gfc.getDefaultPool(); @@ -174,14 +174,14 @@ public class ClientCacheFactoryJUnitTest { // enabled Properties suProps = new Properties(); suProps.setProperty("user", "foo"); - assertThatThrownBy(() -> this.clientCache.createAuthenticatedView(suProps)) + assertThatThrownBy(() -> clientCache.createAuthenticatedView(suProps)) .isInstanceOf(IllegalStateException.class); // however we should be to to create it by configuring a pool Pool pool = PoolManager.createFactory() .addServer(InetAddress.getLocalHost().getHostName(), CacheServer.DEFAULT_PORT) .setMultiuserAuthentication(true).setSocketConnectTimeout(2345).create("pool1"); - RegionService cc = this.clientCache.createAuthenticatedView(suProps, pool.getName()); + RegionService cc = clientCache.createAuthenticatedView(suProps, pool.getName()); ProxyCache pc = (ProxyCache) cc; UserAttributes ua = pc.getUserAttributes(); Pool proxyDefPool = ua.getPool(); @@ -204,8 +204,8 @@ public class ClientCacheFactoryJUnitTest { PoolManager.createFactory().addServer(InetAddress.getLocalHost().getHostName(), 6666) .setSocketConnectTimeout(5200).create("p6"); - this.clientCache = new ClientCacheFactory().create(); - GemFireCacheImpl gfc = (GemFireCacheImpl) this.clientCache; + clientCache = new ClientCacheFactory().create(); + GemFireCacheImpl gfc = (GemFireCacheImpl) clientCache; assertThat(gfc.isClient()).isTrue(); Pool defPool = gfc.getDefaultPool(); @@ -217,14 +217,14 @@ public class ClientCacheFactoryJUnitTest { // multiuser enabled Properties suProps = new Properties(); suProps.setProperty("user", "foo"); - assertThatThrownBy(() -> this.clientCache.createAuthenticatedView(suProps)) + assertThatThrownBy(() -> clientCache.createAuthenticatedView(suProps)) .isInstanceOf(IllegalStateException.class); // however we should be to to create it by configuring a pool Pool pool = PoolManager.createFactory() .addServer(InetAddress.getLocalHost().getHostName(), CacheServer.DEFAULT_PORT) .setMultiuserAuthentication(true).create("pool1"); - RegionService cc = this.clientCache.createAuthenticatedView(suProps, pool.getName()); + RegionService cc = clientCache.createAuthenticatedView(suProps, pool.getName()); ProxyCache pc = (ProxyCache) cc; UserAttributes ua = pc.getUserAttributes(); Pool proxyDefPool = ua.getPool(); @@ -237,16 +237,16 @@ public class ClientCacheFactoryJUnitTest { @Test public void test004SetMethod() { - this.clientCache = + clientCache = new ClientCacheFactory().set(LOG_LEVEL, "severe").setPoolSocketConnectTimeout(0).create(); - GemFireCacheImpl gfc = (GemFireCacheImpl) this.clientCache; + GemFireCacheImpl gfc = (GemFireCacheImpl) clientCache; assertThat(gfc.isClient()).isTrue(); - Properties dsProps = this.clientCache.getDistributedSystem().getProperties(); + Properties dsProps = clientCache.getDistributedSystem().getProperties(); assertThat(dsProps.getProperty(MCAST_PORT)).isEqualTo("0"); assertThat(dsProps.getProperty(LOCATORS)).isEqualTo(""); assertThat(dsProps.getProperty(LOG_LEVEL)).isEqualTo("severe"); - assertThat(this.clientCache.getDefaultPool().getSocketConnectTimeout()).isEqualTo(0); + assertThat(clientCache.getDefaultPool().getSocketConnectTimeout()).isEqualTo(0); assertThatThrownBy(() -> new ClientCacheFactory().setPoolSocketConnectTimeout(-1).create()) .isInstanceOf(IllegalArgumentException.class); @@ -258,11 +258,11 @@ public class ClientCacheFactoryJUnitTest { suProps.setProperty("user", "foo"); GemFireCacheImpl gfc = (GemFireCacheImpl) new ClientCacheFactory().setPoolMultiuserAuthentication(true).create(); - this.clientCache = gfc; + clientCache = gfc; - RegionService cc1 = this.clientCache.createAuthenticatedView(suProps); + RegionService cc1 = clientCache.createAuthenticatedView(suProps); assertThat(gfc.isClient()).isTrue(); - Properties dsProps = this.clientCache.getDistributedSystem().getProperties(); + Properties dsProps = clientCache.getDistributedSystem().getProperties(); assertThat(dsProps.getProperty(MCAST_PORT)).isEqualTo("0"); assertThat(dsProps.getProperty(LOCATORS)).isEqualTo(""); @@ -274,7 +274,7 @@ public class ClientCacheFactoryJUnitTest { new InetSocketAddress(InetAddress.getLocalHost(), CacheServer.DEFAULT_PORT))); // make sure we can create another secure user cache - RegionService cc2 = this.clientCache.createAuthenticatedView(suProps); + RegionService cc2 = clientCache.createAuthenticatedView(suProps); assertThat(gfc.isClient()).isTrue(); assertThat(dsProps.getProperty(MCAST_PORT)).isEqualTo("0"); assertThat(dsProps.getProperty(LOCATORS)).isEqualTo(""); @@ -291,12 +291,12 @@ public class ClientCacheFactoryJUnitTest { @Test public void test006NonDefaultPool() throws Exception { - this.clientCache = new ClientCacheFactory() + clientCache = new ClientCacheFactory() .addPoolServer(InetAddress.getLocalHost().getHostName(), 55555).create(); - GemFireCacheImpl gfc = (GemFireCacheImpl) this.clientCache; + GemFireCacheImpl gfc = (GemFireCacheImpl) clientCache; assertThat(gfc.isClient()).isTrue(); - Properties dsProps = this.clientCache.getDistributedSystem().getProperties(); + Properties dsProps = clientCache.getDistributedSystem().getProperties(); assertThat(dsProps.getProperty(LOCATORS)).isEqualTo(""); assertThat(dsProps.getProperty(MCAST_PORT)).isEqualTo("0"); @@ -306,10 +306,10 @@ public class ClientCacheFactoryJUnitTest { assertThat(defPool.getServers()).isEqualTo( Collections.singletonList(new InetSocketAddress(InetAddress.getLocalHost(), 55555))); - gfc = (GemFireCacheImpl) this.clientCache; + gfc = (GemFireCacheImpl) clientCache; assertThat(gfc.isClient()).isTrue(); - dsProps = this.clientCache.getDistributedSystem().getProperties(); + dsProps = clientCache.getDistributedSystem().getProperties(); assertThat(dsProps.getProperty(LOCATORS)).isEqualTo(""); assertThat(dsProps.getProperty(MCAST_PORT)).isEqualTo("0"); @@ -420,7 +420,7 @@ public class ClientCacheFactoryJUnitTest { File cacheXmlFile = temporaryFolder.newFile(testName.getMethodName() + ".xml"); try (PrintWriter printWriter = new PrintWriter(new FileWriter(cacheXmlFile), true)) { - CacheXmlGenerator.generate(clientCacheCreation, printWriter, true, false, false); + CacheXmlGenerator.generate(clientCacheCreation, printWriter, false, false); clientCache = new ClientCacheFactory() .set(LOG_LEVEL, "warn") .set(LOG_FILE, logFile.getAbsolutePath()) @@ -441,7 +441,7 @@ public class ClientCacheFactoryJUnitTest { File logFile = temporaryFolder.newFile(testName.getMethodName() + ".log"); File cacheXmlFile = temporaryFolder.newFile(testName.getMethodName() + ".xml"); try (PrintWriter printWriter = new PrintWriter(new FileWriter(cacheXmlFile), true)) { - CacheXmlGenerator.generate(clientCacheCreation, printWriter, true, false, false); + CacheXmlGenerator.generate(clientCacheCreation, printWriter, false, false); clientCache = new ClientCacheFactory() .set(LOG_LEVEL, "warn") .set(LOG_FILE, logFile.getAbsolutePath()) diff --git a/geode-core/src/main/java/org/apache/geode/distributed/internal/membership/gms/mgr/GMSMembershipManager.java b/geode-core/src/main/java/org/apache/geode/distributed/internal/membership/gms/mgr/GMSMembershipManager.java index 592c749..f9352ea 100644 --- a/geode-core/src/main/java/org/apache/geode/distributed/internal/membership/gms/mgr/GMSMembershipManager.java +++ b/geode-core/src/main/java/org/apache/geode/distributed/internal/membership/gms/mgr/GMSMembershipManager.java @@ -12,6 +12,7 @@ * or implied. See the License for the specific language governing permissions and limitations under * the License. */ + package org.apache.geode.distributed.internal.membership.gms.mgr; import java.io.NotSerializableException; @@ -1583,7 +1584,7 @@ public class GMSMembershipManager implements MembershipManager, Manager { try { logger.info("generating XML to rebuild the cache after reconnect completes"); StringPrintWriter pw = new StringPrintWriter(); - CacheXmlGenerator.generate(cache, pw, true, false); + CacheXmlGenerator.generate(cache, pw, false); String cacheXML = pw.toString(); cache.getCacheConfig().setCacheXMLDescription(cacheXML); logger.info("XML generation completed: {}", cacheXML); diff --git a/geode-core/src/main/java/org/apache/geode/internal/cache/xmlcache/CacheXmlGenerator.java b/geode-core/src/main/java/org/apache/geode/internal/cache/xmlcache/CacheXmlGenerator.java index 2ff5b9c..660a11b 100644 --- a/geode-core/src/main/java/org/apache/geode/internal/cache/xmlcache/CacheXmlGenerator.java +++ b/geode-core/src/main/java/org/apache/geode/internal/cache/xmlcache/CacheXmlGenerator.java @@ -12,6 +12,7 @@ * or implied. See the License for the specific language governing permissions and limitations under * the License. */ + package org.apache.geode.internal.cache.xmlcache; import static javax.xml.XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI; @@ -51,8 +52,6 @@ import org.xml.sax.EntityResolver; import org.xml.sax.ErrorHandler; import org.xml.sax.InputSource; import org.xml.sax.SAXException; -import org.xml.sax.SAXNotRecognizedException; -import org.xml.sax.SAXNotSupportedException; import org.xml.sax.XMLReader; import org.xml.sax.helpers.AttributesImpl; @@ -152,7 +151,7 @@ public class CacheXmlGenerator extends CacheXml implements XMLReader { /** * Will the generated XML file reference an XML schema instead of the DTD? */ - private boolean useSchema = true; + private boolean useSchema; private boolean includeKeysValues = true; private final boolean generateDefaults; @@ -171,44 +170,39 @@ public class CacheXmlGenerator extends CacheXml implements XMLReader { * @since GemFire 4.0 */ public static void generate(Cache cache, PrintWriter pw, boolean useSchema, String version) { - (new CacheXmlGenerator(cache, useSchema, version, true)).generate(pw); + new CacheXmlGenerator(cache, useSchema, version, true).generate(pw); } /** * Examines the given <code>Cache</code> and from it generates XML data that is written to the * given <code>PrintWriter</code>. The schema/dtd for the current version of GemFire is used. * - * @param useSchema Should the generated XML reference a schema (as opposed to a DTD)? As of 8.1 - * this value is ignored and always true. + * @param includeKeysValues true if the xml should include keys and values false otherwise */ - public static void generate(Cache cache, PrintWriter pw, boolean useSchema) { - (new CacheXmlGenerator(cache, true /* latest version always true */, VERSION_LATEST, true)) - .generate(pw); + public static void generate(Cache cache, PrintWriter pw, boolean includeKeysValues) { + new CacheXmlGenerator(cache, true, VERSION_LATEST, includeKeysValues).generate(pw); } /** - * Examines the given <code>Cache</code> and from it generates XML data that is written to the - * given <code>PrintWriter</code>. The schema/dtd for the current version of GemFire is used. - * * @param useSchema Should the generated XML reference a schema (as opposed to a DTD)? As of 8.1 * this value is ignored and always true. - * @param includeKeysValues true if the xml should include keys and values false otherwise + * @param includeDefaults set to false to cause generated xml to not have defaults values. + * @deprecated Only used for rolling upgrades */ + @Deprecated public static void generate(Cache cache, PrintWriter pw, boolean useSchema, - boolean includeKeysValues) { - (new CacheXmlGenerator(cache, true /* latest version always true */, VERSION_LATEST, - includeKeysValues)).generate(pw); + boolean includeKeysValues, boolean includeDefaults) { + new CacheXmlGenerator(cache, true, VERSION_LATEST, includeKeysValues, includeDefaults) + .generate(pw); } /** - * @param useSchema Should the generated XML reference a schema (as opposed to a DTD)? As of 8.1 - * this value is ignored and always true. * @param includeDefaults set to false to cause generated xml to not have defaults values. */ - public static void generate(Cache cache, PrintWriter pw, boolean useSchema, - boolean includeKeysValues, boolean includeDefaults) { - (new CacheXmlGenerator(cache, true /* latest version always true */, VERSION_LATEST, - includeKeysValues, includeDefaults)).generate(pw); + public static void generate(Cache cache, PrintWriter pw, boolean includeKeysValues, + boolean includeDefaults) { + new CacheXmlGenerator(cache, true, VERSION_LATEST, includeKeysValues, includeDefaults) + .generate(pw); } /** @@ -216,7 +210,7 @@ public class CacheXmlGenerator extends CacheXml implements XMLReader { * given <code>PrintWriter</code>. */ public static void generate(Cache cache, PrintWriter pw) { - generate(cache, pw, true /* useSchema */); + new CacheXmlGenerator(cache, true, VERSION_LATEST, true).generate(pw); } /** @@ -232,33 +226,17 @@ public class CacheXmlGenerator extends CacheXml implements XMLReader { */ public static void generate(ClientCache cache, PrintWriter pw, boolean useSchema, String version) { - (new CacheXmlGenerator(cache, useSchema, version, true)).generate(pw); - } - - /** - * Examines the given <code>ClientCache</code> and from it generates XML data that is written to - * the given <code>PrintWriter</code>. The schema/dtd for the current version of GemFire is used. - * - * @param useSchema Should the generated XML reference a schema (as opposed to a DTD)? As of 8.1 - * this value is ignored and always true. - */ - public static void generate(ClientCache cache, PrintWriter pw, boolean useSchema) { - (new CacheXmlGenerator(cache, true /* latest version always true */, VERSION_LATEST, true)) - .generate(pw); + new CacheXmlGenerator(cache, useSchema, version, true).generate(pw); } /** * Examines the given <code>ClientCache</code> and from it generates XML data that is written to * the given <code>PrintWriter</code>. The schema/dtd for the current version of GemFire is used. * - * @param useSchema Should the generated XML reference a schema (as opposed to a DTD)? As of 8.1 - * this value is ignored and always true. * @param includeKeysValues true if the xml should include keys and values false otherwise */ - public static void generate(ClientCache cache, PrintWriter pw, boolean useSchema, - boolean includeKeysValues) { - (new CacheXmlGenerator(cache, true /* latest version always true */, VERSION_LATEST, - includeKeysValues)).generate(pw); + public static void generate(ClientCache cache, PrintWriter pw, boolean includeKeysValues) { + new CacheXmlGenerator(cache, true, VERSION_LATEST, includeKeysValues).generate(pw); } /** @@ -266,7 +244,7 @@ public class CacheXmlGenerator extends CacheXml implements XMLReader { * given <code>PrintWriter</code>. */ public static void generate(ClientCache cache, PrintWriter pw) { - generate(cache, pw, true /* useSchema */); + new CacheXmlGenerator(cache, true, VERSION_LATEST, true).generate(pw); } /** @@ -293,55 +271,55 @@ public class CacheXmlGenerator extends CacheXml implements XMLReader { this.generateDefaults = generateDefaults; if (cache instanceof CacheCreation) { - this.creation = (CacheCreation) cache; - this.creation.startingGenerate(); + creation = (CacheCreation) cache; + creation.startingGenerate(); } else if (cache instanceof GemFireCacheImpl) { if (((InternalCache) cache).isClient()) { - this.creation = new ClientCacheCreation(); + creation = new ClientCacheCreation(); if (generateDefaults() || cache.getCopyOnRead()) { - this.creation.setCopyOnRead(cache.getCopyOnRead()); + creation.setCopyOnRead(cache.getCopyOnRead()); } } else { // if we are not generating defaults then create the CacheCreation for parsing // so that we can fetch the actual PoolManager and not a fake. - this.creation = new CacheCreation(!generateDefaults); + creation = new CacheCreation(!generateDefaults); if (generateDefaults() || cache.getLockLease() != GemFireCacheImpl.DEFAULT_LOCK_LEASE) { - this.creation.setLockLease(cache.getLockLease()); + creation.setLockLease(cache.getLockLease()); } if (generateDefaults() || cache.getLockTimeout() != GemFireCacheImpl.DEFAULT_LOCK_TIMEOUT) { - this.creation.setLockTimeout(cache.getLockTimeout()); + creation.setLockTimeout(cache.getLockTimeout()); } if (generateDefaults() || cache.getSearchTimeout() != GemFireCacheImpl.DEFAULT_SEARCH_TIMEOUT) { - this.creation.setSearchTimeout(cache.getSearchTimeout()); + creation.setSearchTimeout(cache.getSearchTimeout()); } if (generateDefaults() || cache.isServer()) { - this.creation.setIsServer(cache.isServer()); + creation.setIsServer(cache.isServer()); } if (generateDefaults() || cache.getCopyOnRead()) { - this.creation.setCopyOnRead(cache.getCopyOnRead()); + creation.setCopyOnRead(cache.getCopyOnRead()); } } } else { // if we are not generating defaults then create the CacheCreation for parsing // so that we can fetch the actual PoolManager and not a fake. - this.creation = new CacheCreation(!generateDefaults); + creation = new CacheCreation(!generateDefaults); if (generateDefaults() || cache.getLockLease() != GemFireCacheImpl.DEFAULT_LOCK_LEASE) { - this.creation.setLockLease(cache.getLockLease()); + creation.setLockLease(cache.getLockLease()); } if (generateDefaults() || cache.getLockTimeout() != GemFireCacheImpl.DEFAULT_LOCK_TIMEOUT) { - this.creation.setLockTimeout(cache.getLockTimeout()); + creation.setLockTimeout(cache.getLockTimeout()); } if (generateDefaults() || cache.getSearchTimeout() != GemFireCacheImpl.DEFAULT_SEARCH_TIMEOUT) { - this.creation.setSearchTimeout(cache.getSearchTimeout()); + creation.setSearchTimeout(cache.getSearchTimeout()); } if (generateDefaults() || cache.isServer()) { - this.creation.setIsServer(cache.isServer()); + creation.setIsServer(cache.isServer()); } if (generateDefaults() || cache.getCopyOnRead()) { - this.creation.setCopyOnRead(cache.getCopyOnRead()); + creation.setCopyOnRead(cache.getCopyOnRead()); } } } @@ -356,16 +334,16 @@ public class CacheXmlGenerator extends CacheXml implements XMLReader { this.useSchema = useSchema; this.version = CacheXmlVersion.valueForVersion(version); this.includeKeysValues = includeKeysValues; - this.generateDefaults = true; - if (cache instanceof ClientCacheCreation) { - this.creation = (ClientCacheCreation) cache; - this.creation.startingGenerate(); + generateDefaults = true; + if (cache instanceof ClientCacheCreation) { + creation = (ClientCacheCreation) cache; + creation.startingGenerate(); } else { - this.creation = new ClientCacheCreation(); - if (generateDefaults() || cache.getCopyOnRead()) { - this.creation.setCopyOnRead(cache.getCopyOnRead()); + creation = new ClientCacheCreation(); + if (cache.getCopyOnRead()) { + creation.setCopyOnRead(cache.getCopyOnRead()); } } } @@ -374,19 +352,19 @@ public class CacheXmlGenerator extends CacheXml implements XMLReader { * return true if default values should be generated. */ private boolean generateDefaults() { - return this.generateDefaults; + return generateDefaults; } /** * Creates a generator for a default cache. */ private CacheXmlGenerator() { - this.cache = null; - this.useSchema = true; - this.version = CacheXmlVersion.valueForVersion(VERSION_LATEST); - this.generateDefaults = true; + cache = null; + useSchema = true; + version = CacheXmlVersion.valueForVersion(VERSION_LATEST); + generateDefaults = true; - this.creation = new CacheCreation(); + creation = new CacheCreation(); creation.setLockLease(GemFireCacheImpl.DEFAULT_LOCK_LEASE); creation.setLockTimeout(GemFireCacheImpl.DEFAULT_LOCK_TIMEOUT); creation.setSearchTimeout(GemFireCacheImpl.DEFAULT_SEARCH_TIMEOUT); @@ -419,10 +397,7 @@ public class CacheXmlGenerator extends CacheXml implements XMLReader { pw.flush(); } catch (Exception ex) { - RuntimeException ex2 = new RuntimeException( - "An Exception was thrown while generating XML."); - ex2.initCause(ex); - throw ex2; + throw new RuntimeException("An Exception was thrown while generating XML.", ex); } } @@ -432,16 +407,15 @@ public class CacheXmlGenerator extends CacheXml implements XMLReader { */ @Override public void parse(InputSource input) throws SAXException { - Assert.assertTrue(this.handler != null); + Assert.assertTrue(handler != null); - boolean isClientCache = this.creation instanceof ClientCacheCreation; + boolean isClientCache = creation instanceof ClientCacheCreation; handler.startDocument(); AttributesImpl atts = new AttributesImpl(); - if (this.useSchema) { + if (useSchema) { if (null == version.getSchemaLocation()) { - // TODO jbarrett - localize throw new IllegalStateException("No schema for version " + version.getVersion()); } // add schema location for cache schema. @@ -452,7 +426,7 @@ public class CacheXmlGenerator extends CacheXml implements XMLReader { // add cache schema to default prefix. handler.startPrefixMapping(XmlConstants.DEFAULT_PREFIX, version.getNamespace()); - addAttribute(atts, VERSION, this.version.getVersion()); + addAttribute(atts, VERSION, version.getVersion()); } // Don't generate XML for attributes that are not set. @@ -466,34 +440,13 @@ public class CacheXmlGenerator extends CacheXml implements XMLReader { if (creation.hasSearchTimeout()) { atts.addAttribute("", "", SEARCH_TIMEOUT, "", String.valueOf(creation.getSearchTimeout())); } - if (this.version.compareTo(CacheXmlVersion.GEMFIRE_5_5) >= 0) { - // TODO - } - if (this.version.compareTo(CacheXmlVersion.GEMFIRE_5_7) >= 0) { - // TODO - } - if (this.version.compareTo(CacheXmlVersion.GEMFIRE_5_8) >= 0) { - // TODO - } - if (this.version.compareTo(CacheXmlVersion.GEMFIRE_6_0) >= 0) { - // TODO - } - if (this.version.compareTo(CacheXmlVersion.GEMFIRE_6_5) >= 0) { - // TODO - } - if (this.version.compareTo(CacheXmlVersion.GEMFIRE_7_0) >= 0) { - // TODO - } - if (this.version.compareTo(CacheXmlVersion.GEMFIRE_7_0) >= 0) { - // TODO - } - if (this.version.compareTo(CacheXmlVersion.GEMFIRE_5_1) >= 0) { + if (version.compareTo(CacheXmlVersion.GEMFIRE_5_1) >= 0) { if (creation.hasMessageSyncInterval()) { atts.addAttribute("", "", MESSAGE_SYNC_INTERVAL, "", String.valueOf(creation.getMessageSyncInterval())); } } - if (this.version.compareTo(CacheXmlVersion.GEMFIRE_4_0) >= 0) { + if (version.compareTo(CacheXmlVersion.GEMFIRE_4_0) >= 0) { if (creation.hasServer()) { atts.addAttribute("", "", IS_SERVER, "", String.valueOf(creation.isServer())); } @@ -506,45 +459,44 @@ public class CacheXmlGenerator extends CacheXml implements XMLReader { } else { handler.startElement("", CACHE, CACHE, atts); } - if (this.cache != null) { + if (cache != null) { if (!isClientCache) { - generate(this.cache.getCacheTransactionManager()); - } else if (this.version.compareTo(CacheXmlVersion.GEMFIRE_6_6) >= 0) { - generate(this.cache.getCacheTransactionManager()); + generate(cache.getCacheTransactionManager()); + } else if (version.compareTo(CacheXmlVersion.GEMFIRE_6_6) >= 0) { + generate(cache.getCacheTransactionManager()); } - generateDynamicRegionFactory(this.cache); + generateDynamicRegionFactory(cache); if (!isClientCache) { - if (this.version.compareTo(CacheXmlVersion.GEMFIRE_7_0) >= 0) { + if (version.compareTo(CacheXmlVersion.GEMFIRE_7_0) >= 0) { Set<GatewaySender> senderSet = cache.getGatewaySenders(); for (GatewaySender sender : senderSet) { generateGatewaySender(sender); } - generateGatewayReceiver(this.cache); - generateAsyncEventQueue(this.cache); + generateGatewayReceiver(cache); + generateAsyncEventQueue(cache); } } - if (!isClientCache && this.version.compareTo(CacheXmlVersion.GEMFIRE_7_0) >= 0) { - if (this.cache.getGatewayConflictResolver() != null) { - generate(GATEWAY_CONFLICT_RESOLVER, this.cache.getGatewayConflictResolver()); + if (!isClientCache && version.compareTo(CacheXmlVersion.GEMFIRE_7_0) >= 0) { + if (cache.getGatewayConflictResolver() != null) { + generate(GATEWAY_CONFLICT_RESOLVER, cache.getGatewayConflictResolver()); } } if (!isClientCache) { - for (Iterator iter = this.cache.getCacheServers().iterator(); iter.hasNext();) { - CacheServer bridge = (CacheServer) iter.next(); + for (CacheServer bridge : cache.getCacheServers()) { generate(bridge); } } - if (this.version.compareTo(CacheXmlVersion.GEMFIRE_5_7) >= 0) { + if (version.compareTo(CacheXmlVersion.GEMFIRE_5_7) >= 0) { Iterator pools; - if (this.cache instanceof GemFireCacheImpl) { + if (cache instanceof GemFireCacheImpl) { pools = PoolManager.getAll().values().iterator(); } else { - pools = this.creation.getPools().values().iterator(); + pools = creation.getPools().values().iterator(); } while (pools.hasNext()) { Pool cp = (Pool) pools.next(); @@ -552,26 +504,26 @@ public class CacheXmlGenerator extends CacheXml implements XMLReader { } } - if (this.version.compareTo(CacheXmlVersion.GEMFIRE_6_5) >= 0) { - if (this.cache instanceof GemFireCacheImpl) { - InternalCache gfc = (InternalCache) this.cache; + if (version.compareTo(CacheXmlVersion.GEMFIRE_6_5) >= 0) { + if (cache instanceof GemFireCacheImpl) { + InternalCache gfc = (InternalCache) cache; for (DiskStore ds : gfc.listDiskStores()) { generate(ds); } } else { - for (DiskStore ds : this.creation.listDiskStores()) { + for (DiskStore ds : creation.listDiskStores()) { generate(ds); } } } - if (this.version.compareTo(CacheXmlVersion.GEMFIRE_6_6) >= 0) { + if (version.compareTo(CacheXmlVersion.GEMFIRE_6_6) >= 0) { generatePdx(); } - if (this.version.compareTo(CacheXmlVersion.GEMFIRE_4_1) >= 0) { - Map namedAttributes = this.cache.listRegionAttributes(); - for (Iterator iter = namedAttributes.entrySet().iterator(); iter.hasNext();) { - Map.Entry entry = (Map.Entry) iter.next(); + if (version.compareTo(CacheXmlVersion.GEMFIRE_4_1) >= 0) { + Map namedAttributes = cache.listRegionAttributes(); + for (Object o : namedAttributes.entrySet()) { + Map.Entry entry = (Map.Entry) o; String id = (String) entry.getKey(); RegionAttributes attrs = (RegionAttributes) entry.getValue(); // Since CacheCreation predefines these even in later versions @@ -579,7 +531,7 @@ public class CacheXmlGenerator extends CacheXml implements XMLReader { // It would be better if CacheCreation could only predefine them // for versions 6.5 and later but that is not easy to do { - if (this.creation instanceof ClientCacheCreation) { + if (creation instanceof ClientCacheCreation) { try { ClientRegionShortcut.valueOf(id); // skip this client region since id mapped to one of the enum types @@ -604,37 +556,35 @@ public class CacheXmlGenerator extends CacheXml implements XMLReader { if (cache instanceof GemFireCacheImpl) { generateRegions(); } else { - TreeSet rSet = new TreeSet(new RegionComparator()); - rSet.addAll(this.cache.rootRegions()); - Iterator it = rSet.iterator(); - while (it.hasNext()) { - Region root = (Region) it.next(); - generateRegion(root); + TreeSet<Region<?, ?>> rSet = new TreeSet<>(new RegionComparator()); + rSet.addAll(cache.rootRegions()); + for (Region<?, ?> region : rSet) { + generateRegion(region); } } - if (this.version.compareTo(CacheXmlVersion.GEMFIRE_5_8) >= 0) { + if (version.compareTo(CacheXmlVersion.GEMFIRE_5_8) >= 0) { generateFunctionService(); } - if (this.version.compareTo(CacheXmlVersion.GEMFIRE_6_0) >= 0) { + if (version.compareTo(CacheXmlVersion.GEMFIRE_6_0) >= 0) { generateResourceManager(); generateSerializerRegistration(); } if (!isClientCache) { - if (this.version.compareTo(CacheXmlVersion.GEMFIRE_6_5) >= 0) { - if (this.cache instanceof GemFireCacheImpl) { - InternalCache internalCache = (InternalCache) this.cache; + if (version.compareTo(CacheXmlVersion.GEMFIRE_6_5) >= 0) { + if (cache instanceof GemFireCacheImpl) { + InternalCache internalCache = (InternalCache) cache; for (File file : internalCache.getBackupFiles()) { generateBackupFile(file); } } else { - for (File file : this.creation.getBackupFiles()) { + for (File file : creation.getBackupFiles()) { generateBackupFile(file); } } } } - if (this.version.compareTo(CacheXmlVersion.GEMFIRE_6_6) >= 0) { + if (version.compareTo(CacheXmlVersion.GEMFIRE_6_6) >= 0) { generateInitializer(); } } @@ -657,43 +607,43 @@ public class CacheXmlGenerator extends CacheXml implements XMLReader { AttributesImpl atts = new AttributesImpl(); CacheConfig config = ((InternalCache) cache).getCacheConfig(); if (config.pdxReadSerializedUserSet) { - if (generateDefaults() || this.cache.getPdxReadSerialized()) + if (generateDefaults() || cache.getPdxReadSerialized()) atts.addAttribute("", "", READ_SERIALIZED, "", - Boolean.toString(this.cache.getPdxReadSerialized())); + Boolean.toString(cache.getPdxReadSerialized())); } if (config.pdxIgnoreUnreadFieldsUserSet) { - if (generateDefaults() || this.cache.getPdxIgnoreUnreadFields()) + if (generateDefaults() || cache.getPdxIgnoreUnreadFields()) atts.addAttribute("", "", IGNORE_UNREAD_FIELDS, "", - Boolean.toString(this.cache.getPdxIgnoreUnreadFields())); + Boolean.toString(cache.getPdxIgnoreUnreadFields())); } if (config.pdxPersistentUserSet) { - if (generateDefaults() || this.cache.getPdxPersistent()) - atts.addAttribute("", "", PERSISTENT, "", Boolean.toString(this.cache.getPdxPersistent())); + if (generateDefaults() || cache.getPdxPersistent()) + atts.addAttribute("", "", PERSISTENT, "", Boolean.toString(cache.getPdxPersistent())); } if (config.pdxDiskStoreUserSet) { if (generateDefaults() - || this.cache.getPdxDiskStore() != null && !this.cache.getPdxDiskStore().equals("")) - atts.addAttribute("", "", DISK_STORE_NAME, "", this.cache.getPdxDiskStore()); + || cache.getPdxDiskStore() != null && !cache.getPdxDiskStore().equals("")) + atts.addAttribute("", "", DISK_STORE_NAME, "", cache.getPdxDiskStore()); } - if (!generateDefaults() && this.cache.getPdxSerializer() == null && atts.getLength() == 0) { + if (!generateDefaults() && cache.getPdxSerializer() == null && atts.getLength() == 0) { return; } handler.startElement("", PDX, PDX, atts); - if (this.cache.getPdxSerializer() != null) { - generate(PDX_SERIALIZER, this.cache.getPdxSerializer()); + if (cache.getPdxSerializer() != null) { + generate(PDX_SERIALIZER, cache.getPdxSerializer()); } handler.endElement("", PDX, PDX); } private void generateInitializer() throws SAXException { - if (this.cache.getInitializer() != null) { - generate(INITIALIZER, this.cache.getInitializer(), this.cache.getInitializerProps()); + if (cache.getInitializer() != null) { + generate(cache.getInitializer(), cache.getInitializerProps()); } } private void generateRegion(Region root) throws SAXException { - if (this.version.compareTo(CacheXmlVersion.GEMFIRE_5_0) >= 0) { + if (version.compareTo(CacheXmlVersion.GEMFIRE_5_0) >= 0) { generate(root, REGION); } else { generate(root, VM_ROOT_REGION); @@ -701,15 +651,13 @@ public class CacheXmlGenerator extends CacheXml implements XMLReader { } private void generateRegions() throws SAXException { - Set<Region> colocatedChildRegions = new HashSet<Region>(); - Set<Region> generatedRegions = new HashSet<Region>(); + Set<Region<?, ?>> colocatedChildRegions = new HashSet<>(); + Set<Region> generatedRegions = new HashSet<>(); // Merge from persist_Nov10 - iterate the regions in order for persistent recovery. - TreeSet rSet = new TreeSet(new RegionComparator()); - rSet.addAll(this.cache.rootRegions()); - Iterator it = rSet.iterator(); - while (it.hasNext()) { - Region root = (Region) it.next(); + TreeSet<Region<?, ?>> rSet = new TreeSet<>(new RegionComparator()); + rSet.addAll(cache.rootRegions()); + for (Region<?, ?> root : rSet) { Assert.assertTrue(root instanceof LocalRegion); if (root instanceof PartitionedRegion) { PartitionedRegion pr = (PartitionedRegion) root; @@ -722,8 +670,7 @@ public class CacheXmlGenerator extends CacheXml implements XMLReader { } else { // normal non pr regions, but they can have PR as subregions boolean found = false; - for (Object object : root.subregions(false)) { - Region subregion = (Region) object; + for (Region<?, ?> subregion : root.subregions(false)) { Assert.assertTrue(subregion instanceof LocalRegion); if (subregion instanceof PartitionedRegion) { PartitionedRegion pr = (PartitionedRegion) subregion; @@ -740,11 +687,9 @@ public class CacheXmlGenerator extends CacheXml implements XMLReader { } } } - TreeSet rColSet = new TreeSet(new RegionComparator()); + TreeSet<Region<?, ?>> rColSet = new TreeSet<>(new RegionComparator()); rColSet.addAll(colocatedChildRegions); - Iterator colIter = rColSet.iterator(); - while (colIter.hasNext()) { - Region root = (Region) colIter.next(); + for (Region<?, ?> root : rColSet) { Assert.assertTrue(root instanceof LocalRegion); if (root instanceof PartitionedRegion) { PartitionedRegion pr = (PartitionedRegion) root; @@ -769,33 +714,33 @@ public class CacheXmlGenerator extends CacheXml implements XMLReader { */ private void generateResourceManager() throws SAXException { AttributesImpl atts = new AttributesImpl(); - if (this.cache instanceof CacheCreation && this.creation.hasResourceManager()) { + if (cache instanceof CacheCreation && creation.hasResourceManager()) { boolean generateIt = false; - if (this.creation.getResourceManager().hasCriticalHeap()) { - float chp = this.creation.getResourceManager().getCriticalHeapPercentage(); + if (creation.getResourceManager().hasCriticalHeap()) { + float chp = creation.getResourceManager().getCriticalHeapPercentage(); if (generateDefaults() || chp != MemoryThresholds.DEFAULT_CRITICAL_PERCENTAGE) { atts.addAttribute("", "", CRITICAL_HEAP_PERCENTAGE, "", String.valueOf(chp)); generateIt = true; } } - if (this.creation.getResourceManager().hasEvictionHeap()) { - float ehp = this.creation.getResourceManager().getEvictionHeapPercentage(); + if (creation.getResourceManager().hasEvictionHeap()) { + float ehp = creation.getResourceManager().getEvictionHeapPercentage(); if (generateDefaults() || ehp != MemoryThresholds.DEFAULT_EVICTION_PERCENTAGE) { atts.addAttribute("", "", EVICTION_HEAP_PERCENTAGE, "", String.valueOf(ehp)); generateIt = true; } } - if (this.version.compareTo(CacheXmlVersion.GEODE_1_0) >= 0) { - if (this.creation.getResourceManager().hasCriticalOffHeap()) { - float chp = this.creation.getResourceManager().getCriticalOffHeapPercentage(); + if (version.compareTo(CacheXmlVersion.GEODE_1_0) >= 0) { + if (creation.getResourceManager().hasCriticalOffHeap()) { + float chp = creation.getResourceManager().getCriticalOffHeapPercentage(); if (generateDefaults() || chp != MemoryThresholds.DEFAULT_CRITICAL_PERCENTAGE) { atts.addAttribute("", "", CRITICAL_OFF_HEAP_PERCENTAGE, "", String.valueOf(chp)); generateIt = true; } } - if (this.creation.getResourceManager().hasEvictionOffHeap()) { - float ehp = this.creation.getResourceManager().getEvictionOffHeapPercentage(); + if (creation.getResourceManager().hasEvictionOffHeap()) { + float ehp = creation.getResourceManager().getEvictionOffHeapPercentage(); if (generateDefaults() || ehp != MemoryThresholds.DEFAULT_EVICTION_PERCENTAGE) { atts.addAttribute("", "", EVICTION_OFF_HEAP_PERCENTAGE, "", String.valueOf(ehp)); generateIt = true; @@ -805,28 +750,28 @@ public class CacheXmlGenerator extends CacheXml implements XMLReader { if (generateIt) { generateResourceManagerElement(atts); } - } else if (this.cache instanceof GemFireCacheImpl) { + } else if (cache instanceof GemFireCacheImpl) { { - int chp = (int) this.cache.getResourceManager().getCriticalHeapPercentage(); + int chp = (int) cache.getResourceManager().getCriticalHeapPercentage(); if (generateDefaults() || chp != MemoryThresholds.DEFAULT_CRITICAL_PERCENTAGE) atts.addAttribute("", "", CRITICAL_HEAP_PERCENTAGE, "", String.valueOf(chp)); } { - int ehp = (int) this.cache.getResourceManager().getEvictionHeapPercentage(); + int ehp = (int) cache.getResourceManager().getEvictionHeapPercentage(); if (generateDefaults() || ehp != MemoryThresholds.DEFAULT_EVICTION_PERCENTAGE) atts.addAttribute("", "", EVICTION_HEAP_PERCENTAGE, "", String.valueOf(ehp)); } - if (this.version.compareTo(CacheXmlVersion.GEODE_1_0) >= 0) { + if (version.compareTo(CacheXmlVersion.GEODE_1_0) >= 0) { { - int chp = (int) this.cache.getResourceManager().getCriticalOffHeapPercentage(); + int chp = (int) cache.getResourceManager().getCriticalOffHeapPercentage(); if (generateDefaults() || chp != MemoryThresholds.DEFAULT_CRITICAL_PERCENTAGE) atts.addAttribute("", "", CRITICAL_OFF_HEAP_PERCENTAGE, "", String.valueOf(chp)); } { - int ehp = (int) this.cache.getResourceManager().getEvictionOffHeapPercentage(); + int ehp = (int) cache.getResourceManager().getEvictionOffHeapPercentage(); if (generateDefaults() || ehp != MemoryThresholds.DEFAULT_EVICTION_PERCENTAGE) atts.addAttribute("", "", EVICTION_OFF_HEAP_PERCENTAGE, "", String.valueOf(ehp)); } @@ -852,7 +797,7 @@ public class CacheXmlGenerator extends CacheXml implements XMLReader { * */ private void generateSerializerRegistration() throws SAXException { - final SerializerCreation sc = this.creation.getSerializerCreation(); + final SerializerCreation sc = creation.getSerializerCreation(); if (sc == null) { return; } @@ -884,9 +829,9 @@ public class CacheXmlGenerator extends CacheXml implements XMLReader { private void generateFunctionService() throws SAXException { Collection<Function> functions = Collections.emptyList(); - if (this.cache instanceof CacheCreation) { - if (this.creation.hasFunctionService()) { - functions = this.creation.getFunctionServiceCreation().getFunctionList(); + if (cache instanceof CacheCreation) { + if (creation.hasFunctionService()) { + functions = creation.getFunctionServiceCreation().getFunctionList(); } } else { functions = FunctionService.getRegisteredFunctions().values(); @@ -912,7 +857,7 @@ public class CacheXmlGenerator extends CacheXml implements XMLReader { * * @since GemFire 5.7 */ - private void generateClientHaQueue(CacheServer bridge) throws SAXException { + private void generateClientHaQueue(CacheServer bridge) { AttributesImpl atts = new AttributesImpl(); ClientSubscriptionConfigImpl csc = (ClientSubscriptionConfigImpl) bridge.getClientSubscriptionConfig(); @@ -920,7 +865,7 @@ public class CacheXmlGenerator extends CacheXml implements XMLReader { atts.addAttribute("", "", CLIENT_SUBSCRIPTION_EVICTION_POLICY, "", csc.getEvictionPolicy()); atts.addAttribute("", "", CLIENT_SUBSCRIPTION_CAPACITY, "", String.valueOf(csc.getCapacity())); - if (this.version.compareTo(CacheXmlVersion.GEMFIRE_6_5) >= 0) { + if (version.compareTo(CacheXmlVersion.GEMFIRE_6_5) >= 0) { String dsVal = csc.getDiskStoreName(); if (dsVal != null) { atts.addAttribute("", "", DISK_STORE_NAME, "", dsVal); @@ -943,7 +888,7 @@ public class CacheXmlGenerator extends CacheXml implements XMLReader { * @since GemFire 4.0 */ private void generate(CacheServer bridge) throws SAXException { - if (this.version.compareTo(CacheXmlVersion.GEMFIRE_4_0) < 0) { + if (version.compareTo(CacheXmlVersion.GEMFIRE_4_0) < 0) { return; } AttributesImpl atts = new AttributesImpl(); @@ -951,7 +896,7 @@ public class CacheXmlGenerator extends CacheXml implements XMLReader { if (generateDefaults() || bridge.getPort() != CacheServer.DEFAULT_PORT) atts.addAttribute("", "", PORT, "", String.valueOf(bridge.getPort())); - if (this.version.compareTo(CacheXmlVersion.GEMFIRE_4_1) < 0) { + if (version.compareTo(CacheXmlVersion.GEMFIRE_4_1) < 0) { return; } if (generateDefaults() @@ -969,14 +914,14 @@ public class CacheXmlGenerator extends CacheXml implements XMLReader { atts.addAttribute("", "", SOCKET_BUFFER_SIZE, "", String.valueOf(bridge.getSocketBufferSize())); - if (this.version.compareTo(CacheXmlVersion.GEMFIRE_5_0) < 0) { + if (version.compareTo(CacheXmlVersion.GEMFIRE_5_0) < 0) { return; } if (generateDefaults() || bridge.getMaxConnections() != CacheServer.DEFAULT_MAX_CONNECTIONS) atts.addAttribute("", "", MAX_CONNECTIONS, "", String.valueOf(bridge.getMaxConnections())); - if (this.version.compareTo(CacheXmlVersion.GEMFIRE_5_1) < 0) { + if (version.compareTo(CacheXmlVersion.GEMFIRE_5_1) < 0) { return; } @@ -993,7 +938,7 @@ public class CacheXmlGenerator extends CacheXml implements XMLReader { String.valueOf(bridge.getMessageTimeToLive())); } - if (this.version.compareTo(CacheXmlVersion.GEMFIRE_5_7) < 0) { + if (version.compareTo(CacheXmlVersion.GEMFIRE_5_7) < 0) { return; } @@ -1010,7 +955,7 @@ public class CacheXmlGenerator extends CacheXml implements XMLReader { atts.addAttribute("", "", LOAD_POLL_INTERVAL, "", String.valueOf(bridge.getLoadPollInterval())); - if (this.version.compareTo(CacheXmlVersion.GEMFIRE_8_0) < 0) { + if (version.compareTo(CacheXmlVersion.GEMFIRE_8_0) < 0) { return; } @@ -1019,17 +964,16 @@ public class CacheXmlGenerator extends CacheXml implements XMLReader { } } finally { - if (this.version.compareTo(CacheXmlVersion.GEMFIRE_5_7) >= 0) { + if (version.compareTo(CacheXmlVersion.GEMFIRE_5_7) >= 0) { handler.startElement("", CACHE_SERVER, CACHE_SERVER, atts); } else { handler.startElement("", BRIDGE_SERVER, BRIDGE_SERVER, atts); } - if (this.version.compareTo(CacheXmlVersion.GEMFIRE_5_7) >= 0) { + if (version.compareTo(CacheXmlVersion.GEMFIRE_5_7) >= 0) { String[] groups = bridge.getGroups(); if (groups.length > 0) { - for (int i = 0; i < groups.length; i++) { - String group = groups[i]; + for (String group : groups) { handler.startElement("", GROUP, GROUP, EMPTY); handler.characters(group.toCharArray(), 0, group.length()); handler.endElement("", GROUP, GROUP); @@ -1045,7 +989,7 @@ public class CacheXmlGenerator extends CacheXml implements XMLReader { generate(LOAD_PROBE, probe); } } - if (this.version.compareTo(CacheXmlVersion.GEMFIRE_5_7) >= 0) { + if (version.compareTo(CacheXmlVersion.GEMFIRE_5_7) >= 0) { handler.endElement("", "", CACHE_SERVER); } else { handler.endElement("", "", BRIDGE_SERVER); @@ -1059,7 +1003,7 @@ public class CacheXmlGenerator extends CacheXml implements XMLReader { * @since GemFire prPersistSprint2 */ private void generate(DiskStore ds) throws SAXException { - if (this.version.compareTo(CacheXmlVersion.GEMFIRE_6_5) < 0) { + if (version.compareTo(CacheXmlVersion.GEMFIRE_6_5) < 0) { return; } AttributesImpl atts = new AttributesImpl(); @@ -1113,7 +1057,7 @@ public class CacheXmlGenerator extends CacheXml implements XMLReader { atts.addAttribute("", "", QUEUE_SIZE, "", String.valueOf(ds.getQueueSize())); } - if (this.version.compareTo(CacheXmlVersion.GEMFIRE_8_0) >= 0) { + if (version.compareTo(CacheXmlVersion.GEMFIRE_8_0) >= 0) { if ((!(ds instanceof DiskStoreAttributesCreation) || ((DiskStoreAttributesCreation) ds).hasDiskUsageWarningPercentage())) { if (generateDefaults() || ds @@ -1164,20 +1108,10 @@ public class CacheXmlGenerator extends CacheXml implements XMLReader { /** * Compare regions by name */ - class RegionComparator implements Comparator { - @Override - public int compare(Object o1, Object o2) { - return (((Region) o1).getFullPath().compareTo(((Region) o2).getFullPath())); - } - + static class RegionComparator implements Comparator<Region> { @Override - public boolean equals(Object anObj) { - return ((Region) this).getFullPath().equals(((Region) anObj).getFullPath()); - } - - @Override - public int hashCode() { - return ((Region) this).getFullPath().hashCode(); + public int compare(Region o1, Region o2) { + return o1.getFullPath().compareTo(o2.getFullPath()); } } @@ -1187,7 +1121,7 @@ public class CacheXmlGenerator extends CacheXml implements XMLReader { * @since GemFire 5.7 */ private void generate(Pool cp) throws SAXException { - if (this.version.compareTo(CacheXmlVersion.GEMFIRE_5_7) < 0) { + if (version.compareTo(CacheXmlVersion.GEMFIRE_5_7) < 0) { return; } if (((PoolImpl) cp).isUsedByGateway()) { @@ -1197,7 +1131,7 @@ public class CacheXmlGenerator extends CacheXml implements XMLReader { AttributesImpl atts = new AttributesImpl(); try { atts.addAttribute("", "", NAME, "", cp.getName()); - if (this.version.compareTo(CacheXmlVersion.GEODE_1_0) >= 0) { + if (version.compareTo(CacheXmlVersion.GEODE_1_0) >= 0) { if (generateDefaults() || cp .getSubscriptionTimeoutMultiplier() != PoolFactory.DEFAULT_SUBSCRIPTION_TIMEOUT_MULTIPLIER) { atts.addAttribute("", "", SUBSCRIPTION_TIMEOUT_MULTIPLIER, "", @@ -1258,14 +1192,14 @@ public class CacheXmlGenerator extends CacheXml implements XMLReader { atts.addAttribute("", "", THREAD_LOCAL_CONNECTIONS, "", String.valueOf(cp.getThreadLocalConnections())); - if (this.version.compareTo(CacheXmlVersion.GEMFIRE_6_1) > 0) { + if (version.compareTo(CacheXmlVersion.GEMFIRE_6_1) > 0) { if (generateDefaults() || cp.getPRSingleHopEnabled() != PoolFactory.DEFAULT_PR_SINGLE_HOP_ENABLED) atts.addAttribute("", "", PR_SINGLE_HOP_ENABLED, "", String.valueOf(cp.getPRSingleHopEnabled())); } - if (this.version.compareTo(CacheXmlVersion.GEMFIRE_6_1) > 0) { + if (version.compareTo(CacheXmlVersion.GEMFIRE_6_1) > 0) { if (generateDefaults() || cp.getMultiuserAuthentication() != PoolFactory.DEFAULT_MULTIUSER_AUTHENTICATION) atts.addAttribute("", "", MULTIUSER_SECURE_MODE_ENABLED, "", @@ -1274,9 +1208,7 @@ public class CacheXmlGenerator extends CacheXml implements XMLReader { } finally { handler.startElement("", CONNECTION_POOL, CONNECTION_POOL, atts); { - Iterator/* <InetSocketAddress> */ locators = cp.getLocators().iterator(); - while (locators.hasNext()) { - InetSocketAddress addr = (InetSocketAddress) locators.next(); + for (InetSocketAddress addr : cp.getLocators()) { AttributesImpl sAtts = new AttributesImpl(); sAtts.addAttribute("", "", HOST, "", addr.getHostName()); sAtts.addAttribute("", "", PORT, "", String.valueOf(addr.getPort())); @@ -1285,9 +1217,7 @@ public class CacheXmlGenerator extends CacheXml implements XMLReader { } } { - Iterator/* <InetSocketAddress> */ servers = cp.getServers().iterator(); - while (servers.hasNext()) { - InetSocketAddress addr = (InetSocketAddress) servers.next(); + for (InetSocketAddress addr : cp.getServers()) { AttributesImpl sAtts = new AttributesImpl(); sAtts.addAttribute("", "", HOST, "", addr.getHostName()); sAtts.addAttribute("", "", PORT, "", String.valueOf(addr.getPort())); @@ -1305,7 +1235,7 @@ public class CacheXmlGenerator extends CacheXml implements XMLReader { * @since GemFire 4.0 */ private void generate(CacheTransactionManager txMgr) throws SAXException { - if (this.version.compareTo(CacheXmlVersion.GEMFIRE_4_0) < 0) { + if (version.compareTo(CacheXmlVersion.GEMFIRE_4_0) < 0) { return; } @@ -1319,8 +1249,8 @@ public class CacheXmlGenerator extends CacheXml implements XMLReader { handler.startElement("", TRANSACTION_MANAGER, TRANSACTION_MANAGER, EMPTY); { TransactionListener[] listeners = txMgr.getListeners(); - for (int i = 0; i < listeners.length; i++) { - generate(TRANSACTION_LISTENER, listeners[i]); + for (TransactionListener listener : listeners) { + generate(TRANSACTION_LISTENER, listener); } if (txMgr.getWriter() != null) { generate(TRANSACTION_WRITER, txMgr.getWriter()); @@ -1335,7 +1265,7 @@ public class CacheXmlGenerator extends CacheXml implements XMLReader { * @since GemFire 4.3 */ private void generateDynamicRegionFactory(Cache c) throws SAXException { - if (this.version.compareTo(CacheXmlVersion.GEMFIRE_4_1) < 0) { + if (version.compareTo(CacheXmlVersion.GEMFIRE_4_1) < 0) { return; } DynamicRegionFactory.Config cfg; @@ -1446,7 +1376,7 @@ public class CacheXmlGenerator extends CacheXml implements XMLReader { generateGatewayEventFilter(gef); } - if (this.version.compareTo(CacheXmlVersion.GEMFIRE_8_0) >= 0) { + if (version.compareTo(CacheXmlVersion.GEMFIRE_8_0) >= 0) { if (sender.getGatewayEventSubstitutionFilter() != null) { generateGatewayEventSubstitutionFilter(sender.getGatewayEventSubstitutionFilter()); } @@ -1510,7 +1440,7 @@ public class CacheXmlGenerator extends CacheXml implements XMLReader { String.valueOf(asyncEventQueue.getOrderPolicy())); } // eviction and expiration events - if (this.version.compareTo(CacheXmlVersion.GEODE_1_0) >= 0) { + if (version.compareTo(CacheXmlVersion.GEODE_1_0) >= 0) { if (generateDefaults() || asyncEventQueue .isForwardExpirationDestroy() != (GatewaySender.DEFAULT_FORWARD_EXPIRATION_DESTROY)) atts.addAttribute("", "", FORWARD_EXPIRATION_DESTROY, "", @@ -1532,7 +1462,7 @@ public class CacheXmlGenerator extends CacheXml implements XMLReader { } } - if (this.version.compareTo(CacheXmlVersion.GEMFIRE_8_0) >= 0) { + if (version.compareTo(CacheXmlVersion.GEMFIRE_8_0) >= 0) { if (asyncEventQueue.getGatewayEventSubstitutionFilter() != null) { generateGatewayEventSubstitutionFilter( asyncEventQueue.getGatewayEventSubstitutionFilter()); @@ -1578,7 +1508,7 @@ public class CacheXmlGenerator extends CacheXml implements XMLReader { atts.addAttribute("", "", SOCKET_BUFFER_SIZE, "", String.valueOf(receiver.getSocketBufferSize())); - if (this.version.compareTo(CacheXmlVersion.GEMFIRE_8_0) < 0) { + if (version.compareTo(CacheXmlVersion.GEMFIRE_8_0) < 0) { return; } // manual-start @@ -1602,7 +1532,7 @@ public class CacheXmlGenerator extends CacheXml implements XMLReader { handler.startElement("", CLASS_NAME, CLASS_NAME, EMPTY); handler.characters(className.toCharArray(), 0, className.length()); handler.endElement("", CLASS_NAME, CLASS_NAME); - Properties props = null; + Properties props; if (gef instanceof Declarable2) { props = ((Declarable2) gef).getConfig(); generate(props, null); @@ -1617,7 +1547,7 @@ public class CacheXmlGenerator extends CacheXml implements XMLReader { handler.startElement("", CLASS_NAME, CLASS_NAME, EMPTY); handler.characters(className.toCharArray(), 0, className.length()); handler.endElement("", CLASS_NAME, CLASS_NAME); - Properties props = null; + Properties props; if (gef instanceof Declarable2) { props = ((Declarable2) gef).getConfig(); generate(props, null); @@ -1635,7 +1565,7 @@ public class CacheXmlGenerator extends CacheXml implements XMLReader { handler.startElement("", CLASS_NAME, CLASS_NAME, EMPTY); handler.characters(className.toCharArray(), 0, className.length()); handler.endElement("", CLASS_NAME, CLASS_NAME); - Properties props = null; + Properties props; if (filter instanceof Declarable2) { props = ((Declarable2) filter).getConfig(); generate(props, null); @@ -1646,7 +1576,7 @@ public class CacheXmlGenerator extends CacheXml implements XMLReader { /** * Generates XML for a given region */ - private void generate(Region region, String elementName) throws SAXException { + private void generate(Region<?, ?> region, String elementName) throws SAXException { if (region == null) { return; } @@ -1672,7 +1602,7 @@ public class CacheXmlGenerator extends CacheXml implements XMLReader { } // generate index data here - Collection<Index> indexesForRegion = this.cache.getQueryService().getIndexes(region); + Collection<Index> indexesForRegion = cache.getQueryService().getIndexes(region); for (Index index : indexesForRegion) { generate(index); } @@ -1680,25 +1610,24 @@ public class CacheXmlGenerator extends CacheXml implements XMLReader { if (region instanceof PartitionedRegion) { if (includeKeysValues) { if (!region.isEmpty()) { - for (Iterator iter = region.entrySet(false).iterator(); iter.hasNext();) { - Region.Entry entry = (Region.Entry) iter.next(); + for (Object o : region.entrySet(false)) { + Region.Entry entry = (Region.Entry) o; generate(entry); } } } } else { if (includeKeysValues) { - for (Iterator iter = region.entrySet(false).iterator(); iter.hasNext();) { - Region.Entry entry = (Region.Entry) iter.next(); + for (Object o : region.entrySet(false)) { + Region.Entry entry = (Region.Entry) o; generate(entry); } } } - TreeSet rSet = new TreeSet(new RegionComparator()); + TreeSet<Region<?, ?>> rSet = new TreeSet<>(new RegionComparator()); rSet.addAll(region.subregions(false)); - for (Iterator iter = rSet.iterator(); iter.hasNext();) { - Region subregion = (Region) iter.next(); + for (Region<?, ?> subregion : rSet) { generate(subregion, REGION); } @@ -1784,7 +1713,7 @@ public class CacheXmlGenerator extends CacheXml implements XMLReader { * * @param id The id of the named region attributes (may be <code>null</code>) */ - private void generate(String id, RegionAttributes attrs) throws SAXException { + private void generate(String id, RegionAttributes<?, ?> attrs) throws SAXException { AttributesImpl atts = new AttributesImpl(); if (id != null) { @@ -1865,11 +1794,11 @@ public class CacheXmlGenerator extends CacheXml implements XMLReader { String.valueOf(attrs.getEnableAsyncConflation())); } - if (this.version.compareTo(CacheXmlVersion.GEMFIRE_5_0) >= 0) { + if (version.compareTo(CacheXmlVersion.GEMFIRE_5_0) >= 0) { if ((!(attrs instanceof RegionAttributesCreation) || ((RegionAttributesCreation) attrs).hasEnableSubscriptionConflation())) { - if (this.version.compareTo(CacheXmlVersion.GEMFIRE_5_7) >= 0) { + if (version.compareTo(CacheXmlVersion.GEMFIRE_5_7) >= 0) { // starting with 5.7 it is enable-subscription-conflation if (generateDefaults() || attrs.getEnableSubscriptionConflation()) atts.addAttribute("", "", ENABLE_SUBSCRIPTION_CONFLATION, "", @@ -1899,7 +1828,7 @@ public class CacheXmlGenerator extends CacheXml implements XMLReader { } else if (dp == DataPolicy.PERSISTENT_PARTITION) { dpString = PERSISTENT_PARTITION_DP; } else if (dp.isPartition()) { - if (this.version.compareTo(CacheXmlVersion.GEMFIRE_5_1) >= 0) { + if (version.compareTo(CacheXmlVersion.GEMFIRE_5_1) >= 0) { dpString = PARTITION_DP; } else { // prior to 5.1 the data policy for partitioned regions was EMPTY @@ -1963,10 +1892,10 @@ public class CacheXmlGenerator extends CacheXml implements XMLReader { String.valueOf(attrs.getConcurrencyLevel())); } - if (this.version.compareTo(CacheXmlVersion.GEMFIRE_7_0) >= 0) { + if (version.compareTo(CacheXmlVersion.GEMFIRE_7_0) >= 0) { if ((!(attrs instanceof RegionAttributesCreation) || ((RegionAttributesCreation) attrs).hasConcurrencyChecksEnabled())) { - if (generateDefaults() || attrs.getConcurrencyChecksEnabled() != true/* fixes bug 46654 */) + if (generateDefaults() || !attrs.getConcurrencyChecksEnabled()) atts.addAttribute("", "", CONCURRENCY_CHECKS_ENABLED, "", String.valueOf(attrs.getConcurrencyChecksEnabled())); } @@ -1985,14 +1914,14 @@ public class CacheXmlGenerator extends CacheXml implements XMLReader { atts.addAttribute("", "", IGNORE_JTA, "", String.valueOf(attrs.getIgnoreJTA())); } - if (this.version.compareTo(CacheXmlVersion.GEMFIRE_4_0) >= 0) { + if (version.compareTo(CacheXmlVersion.GEMFIRE_4_0) >= 0) { if ((!(attrs instanceof RegionAttributesCreation) || ((RegionAttributesCreation) attrs).hasIsLockGrantor())) { if (generateDefaults() || attrs.isLockGrantor()) atts.addAttribute("", "", IS_LOCK_GRANTOR, "", String.valueOf(attrs.isLockGrantor())); } } - if (this.version.compareTo(CacheXmlVersion.GEMFIRE_5_7) >= 0) { + if (version.compareTo(CacheXmlVersion.GEMFIRE_5_7) >= 0) { if ((!(attrs instanceof RegionAttributesCreation) || ((RegionAttributesCreation) attrs).hasPoolName())) { String cpVal = attrs.getPoolName(); @@ -2003,7 +1932,7 @@ public class CacheXmlGenerator extends CacheXml implements XMLReader { atts.addAttribute("", "", POOL_NAME, "", cpVal); } } - if (this.version.compareTo(CacheXmlVersion.GEMFIRE_6_5) >= 0) { + if (version.compareTo(CacheXmlVersion.GEMFIRE_6_5) >= 0) { if ((!(attrs instanceof RegionAttributesCreation) || ((RegionAttributesCreation) attrs).hasDiskStoreName())) { String dsVal = attrs.getDiskStoreName(); @@ -2019,17 +1948,17 @@ public class CacheXmlGenerator extends CacheXml implements XMLReader { String.valueOf(attrs.isDiskSynchronous())); } } - if (this.version.compareTo(CacheXmlVersion.GEMFIRE_6_1) >= 0) + if (version.compareTo(CacheXmlVersion.GEMFIRE_6_1) >= 0) if ((!(attrs instanceof RegionAttributesCreation) || ((RegionAttributesCreation) attrs).hasCloningEnabled())) { if (generateDefaults() || attrs.getCloningEnabled()) atts.addAttribute("", "", CLONING_ENABLED, "", String.valueOf(attrs.getCloningEnabled())); } - if (this.version.compareTo(CacheXmlVersion.GEMFIRE_7_0) >= 0) { + if (version.compareTo(CacheXmlVersion.GEMFIRE_7_0) >= 0) { if ((!(attrs instanceof RegionAttributesCreation) || ((RegionAttributesCreation) attrs).hasGatewaySenderId())) { - Set<String> senderIds = new HashSet<String>(attrs.getGatewaySenderIds()); + Set<String> senderIds = new HashSet<>(attrs.getGatewaySenderIds()); StringBuilder senderStringBuff = new StringBuilder(); if (senderIds.size() != 0) { for (String senderId : senderIds) { @@ -2044,10 +1973,10 @@ public class CacheXmlGenerator extends CacheXml implements XMLReader { } } - if (this.version.compareTo(CacheXmlVersion.GEMFIRE_7_0) >= 0) { + if (version.compareTo(CacheXmlVersion.GEMFIRE_7_0) >= 0) { if ((!(attrs instanceof RegionAttributesCreation) || ((RegionAttributesCreation) attrs).hasAsyncEventListeners())) { - Set<String> asyncEventQueueIds = new HashSet<String>(attrs.getAsyncEventQueueIds()); + Set<String> asyncEventQueueIds = new HashSet<>(attrs.getAsyncEventQueueIds()); StringBuilder asyncEventQueueStringBuff = new StringBuilder(); if (asyncEventQueueIds.size() != 0) { for (String asyncEventQueueId : asyncEventQueueIds) { @@ -2063,7 +1992,7 @@ public class CacheXmlGenerator extends CacheXml implements XMLReader { } } - if (this.version.compareTo(CacheXmlVersion.GEODE_1_0) >= 0) { + if (version.compareTo(CacheXmlVersion.GEODE_1_0) >= 0) { if ((!(attrs instanceof RegionAttributesCreation) || ((RegionAttributesCreation) attrs).hasOffHeap())) { if (generateDefaults() || attrs.getOffHeap()) { @@ -2113,7 +2042,7 @@ public class CacheXmlGenerator extends CacheXml implements XMLReader { } if (attrs.getDiskStoreName() == null - && (generateDefaults() || this.version.compareTo(CacheXmlVersion.GEMFIRE_6_5) < 0)) { + && (generateDefaults() || version.compareTo(CacheXmlVersion.GEMFIRE_6_5) < 0)) { if ((!(attrs instanceof RegionAttributesCreation) || ((RegionAttributesCreation) attrs).hasDiskWriteAttributes())) { generate(attrs.getDiskWriteAttributes()); @@ -2141,7 +2070,7 @@ public class CacheXmlGenerator extends CacheXml implements XMLReader { } } // pre 6.5 - if (this.version.compareTo(CacheXmlVersion.GEMFIRE_5_0) >= 0) { + if (version.compareTo(CacheXmlVersion.GEMFIRE_5_0) >= 0) { if ((!(attrs instanceof RegionAttributesCreation) || ((RegionAttributesCreation) attrs).hasPartitionAttributes())) { PartitionAttributes p = attrs.getPartitionAttributes(); @@ -2151,14 +2080,14 @@ public class CacheXmlGenerator extends CacheXml implements XMLReader { } } - if (this.version.compareTo(CacheXmlVersion.GEMFIRE_5_0) >= 0) { + if (version.compareTo(CacheXmlVersion.GEMFIRE_5_0) >= 0) { MembershipAttributes p = attrs.getMembershipAttributes(); if (p != null && p.hasRequiredRoles()) { generate(p); } } - if (this.version.compareTo(CacheXmlVersion.GEMFIRE_5_0) >= 0) { + if (version.compareTo(CacheXmlVersion.GEMFIRE_5_0) >= 0) { if ((!(attrs instanceof RegionAttributesCreation) || ((RegionAttributesCreation) attrs).hasSubscriptionAttributes())) { SubscriptionAttributes sa = attrs.getSubscriptionAttributes(); @@ -2180,12 +2109,12 @@ public class CacheXmlGenerator extends CacheXml implements XMLReader { if ((!(attrs instanceof RegionAttributesCreation) || ((RegionAttributesCreation) attrs).hasCacheListeners())) { CacheListener[] listeners = attrs.getCacheListeners(); - for (int i = 0; i < listeners.length; i++) { - generate(CACHE_LISTENER, listeners[i]); + for (CacheListener listener : listeners) { + generate(CACHE_LISTENER, listener); } } - if (this.version.compareTo(CacheXmlVersion.GEMFIRE_8_0) >= 0) { + if (version.compareTo(CacheXmlVersion.GEMFIRE_8_0) >= 0) { if ((!(attrs instanceof RegionAttributesCreation) || ((RegionAttributesCreation) attrs).hasCompressor())) { generate(COMPRESSOR, attrs.getCompressor()); @@ -2228,12 +2157,12 @@ public class CacheXmlGenerator extends CacheXml implements XMLReader { handler.endElement("", kind, kind); } - private void generate(String kind, Declarable d, Properties p) throws SAXException { + private void generate(Declarable d, Properties p) throws SAXException { if (d == null) { return; } - handler.startElement("", kind, kind, EMPTY); + handler.startElement("", CacheXml.INITIALIZER, CacheXml.INITIALIZER, EMPTY); String className = d.getClass().getName(); handler.startElement("", CLASS_NAME, CLASS_NAME, EMPTY); @@ -2242,7 +2171,7 @@ public class CacheXmlGenerator extends CacheXml implements XMLReader { generate(p, null); - handler.endElement("", kind, kind); + handler.endElement("", CacheXml.INITIALIZER, CacheXml.INITIALIZER); } private void generate(EvictionAttributes ea) throws SAXException { @@ -2269,7 +2198,7 @@ public class CacheXmlGenerator extends CacheXml implements XMLReader { handler.endElement("", LRU_MEMORY_SIZE, LRU_MEMORY_SIZE); } else if (ea.getAlgorithm() == EvictionAlgorithm.LRU_HEAP) { handler.startElement("", LRU_HEAP_PERCENTAGE, LRU_HEAP_PERCENTAGE, atts); - if (this.version.compareTo(CacheXmlVersion.GEMFIRE_6_0) >= 0) { + if (version.compareTo(CacheXmlVersion.GEMFIRE_6_0) >= 0) { ObjectSizer os = ea.getObjectSizer(); if (!(os instanceof SizeClassOnceObjectSizer)) { if (os != null) { @@ -2278,8 +2207,6 @@ public class CacheXmlGenerator extends CacheXml implements XMLReader { } } handler.endElement("", LRU_HEAP_PERCENTAGE, LRU_HEAP_PERCENTAGE); - } else { - // all other algos are ignored } handler.endElement("", EVICTION_ATTRIBUTES, EVICTION_ATTRIBUTES); } @@ -2325,7 +2252,7 @@ public class CacheXmlGenerator extends CacheXml implements XMLReader { if (custom != null) { AttributesImpl endAtts = new AttributesImpl(); handler.startElement("", CUSTOM_EXPIRY, CUSTOM_EXPIRY, endAtts); - generate((Declarable) custom, false); + generate(custom, false); handler.endElement("", CUSTOM_EXPIRY, CUSTOM_EXPIRY); } handler.endElement("", EXPIRATION_ATTRIBUTES, EXPIRATION_ATTRIBUTES); @@ -2341,7 +2268,7 @@ public class CacheXmlGenerator extends CacheXml implements XMLReader { return; } - String interestString = null; + String interestString; InterestPolicy ip = attrs.getInterestPolicy(); AttributesImpl atts = new AttributesImpl(); @@ -2363,14 +2290,14 @@ public class CacheXmlGenerator extends CacheXml implements XMLReader { /** * Generates XML for a <code>PartitionAttributes</code> */ - private void generate(PartitionAttributes pa) throws SAXException { + private void generate(PartitionAttributes<?, ?> pa) throws SAXException { AttributesImpl atts = new AttributesImpl(); if (generateDefaults() || pa.getRedundantCopies() != 0) atts.addAttribute("", "", PARTITION_REDUNDANT_COPIES, "", String.valueOf(pa.getRedundantCopies())); - if (this.version.compareTo(CacheXmlVersion.GEMFIRE_5_1) >= 0) { + if (version.compareTo(CacheXmlVersion.GEMFIRE_5_1) >= 0) { if (generateDefaults() || pa.getLocalMaxMemory() != ((PartitionAttributesImpl) pa).getLocalMaxMemoryDefault()) atts.addAttribute("", "", LOCAL_MAX_MEMORY, "", String.valueOf(pa.getLocalMaxMemory())); @@ -2382,12 +2309,12 @@ public class CacheXmlGenerator extends CacheXml implements XMLReader { atts.addAttribute("", "", TOTAL_NUM_BUCKETS, "", String.valueOf(pa.getTotalNumBuckets())); } // GEMFIRE_5_1 - if (this.version.compareTo(CacheXmlVersion.GEMFIRE_5_8) >= 0) { + if (version.compareTo(CacheXmlVersion.GEMFIRE_5_8) >= 0) { if (pa.getColocatedWith() != null) atts.addAttribute("", "", PARTITION_COLOCATED_WITH, "", pa.getColocatedWith()); } - if (this.version.compareTo(CacheXmlVersion.GEMFIRE_6_0) >= 0) { + if (version.compareTo(CacheXmlVersion.GEMFIRE_6_0) >= 0) { if (generateDefaults() || pa.getRecoveryDelay() != PartitionAttributesFactory.RECOVERY_DELAY_DEFAULT) atts.addAttribute("", "", RECOVERY_DELAY, "", String.valueOf(pa.getRecoveryDelay())); @@ -2405,31 +2332,30 @@ public class CacheXmlGenerator extends CacheXml implements XMLReader { handler.startElement("", PARTITION_ATTRIBUTES, PARTITION_ATTRIBUTES, atts); - if (this.version.compareTo(CacheXmlVersion.GEMFIRE_5_8) >= 0) { + if (version.compareTo(CacheXmlVersion.GEMFIRE_5_8) >= 0) { PartitionResolver rr = pa.getPartitionResolver(); if (rr != null) { - generate(PARTITION_RESOLVER, rr); + generate(rr); } } - if (this.version.compareTo(CacheXmlVersion.GEMFIRE_6_1) >= 0) { + if (version.compareTo(CacheXmlVersion.GEMFIRE_6_1) >= 0) { PartitionListener[] listeners = pa.getPartitionListeners(); - for (int i = 0; i < listeners.length; i++) { - PartitionListener listener = listeners[i]; + for (PartitionListener listener : listeners) { if (listener != null) { - generate(PARTITION_LISTENER, listener); + generate(listener); } } } - if (this.version.compareTo(CacheXmlVersion.GEMFIRE_6_6) >= 0) { + if (version.compareTo(CacheXmlVersion.GEMFIRE_6_6) >= 0) { List<FixedPartitionAttributes> staticAttrs = pa.getFixedPartitionAttributes(); if (staticAttrs != null) { - generateFixedPartitionAttributes(FIXED_PARTITION_ATTRIBUTES, staticAttrs); + generateFixedPartitionAttributes(staticAttrs); } } - if (this.version.compareTo(CacheXmlVersion.GEMFIRE_5_1) < 0) { + if (version.compareTo(CacheXmlVersion.GEMFIRE_5_1) < 0) { Properties p = pa.getLocalProperties(); generate(p, LOCAL_PROPERTIES); @@ -2443,59 +2369,61 @@ public class CacheXmlGenerator extends CacheXml implements XMLReader { /** * Generate XML for partition-resolver element in PartitionedRegion Attributes */ - private void generate(String kind, PartitionResolver rr) throws SAXException { + private void generate(PartitionResolver rr) throws SAXException { if (rr == null) return; - handler.startElement("", kind, kind, EMPTY); + handler.startElement("", CacheXml.PARTITION_RESOLVER, CacheXml.PARTITION_RESOLVER, EMPTY); String className = rr.getClass().getName(); handler.startElement("", CLASS_NAME, CLASS_NAME, EMPTY); handler.characters(className.toCharArray(), 0, className.length()); handler.endElement("", CLASS_NAME, CLASS_NAME); - Properties props = null; + Properties props; if (rr instanceof Declarable2) { props = ((Declarable2) rr).getConfig(); generate(props, null); } - handler.endElement("", kind, kind); + handler.endElement("", CacheXml.PARTITION_RESOLVER, CacheXml.PARTITION_RESOLVER); } /** * Generate XML for partition-listener element in PartitionedRegion Attributes */ - private void generate(String kind, PartitionListener pl) throws SAXException { + private void generate(PartitionListener pl) throws SAXException { if (pl == null) return; - handler.startElement("", kind, kind, EMPTY); + handler.startElement("", CacheXml.PARTITION_LISTENER, CacheXml.PARTITION_LISTENER, EMPTY); String className = pl.getClass().getName(); handler.startElement("", CLASS_NAME, CLASS_NAME, EMPTY); handler.characters(className.toCharArray(), 0, className.length()); handler.endElement("", CLASS_NAME, CLASS_NAME); - Properties props = null; + Properties props; if (pl instanceof Declarable2) { props = ((Declarable2) pl).getConfig(); generate(props, null); } - handler.endElement("", kind, kind); + handler.endElement("", CacheXml.PARTITION_LISTENER, CacheXml.PARTITION_LISTENER); } /** * Generate XML for FixedPartitionAttribute element in PartitionedRegion Attributes */ - private void generateFixedPartitionAttributes(String kind, - List<FixedPartitionAttributes> allStaticAttrs) throws SAXException { + private void generateFixedPartitionAttributes(List<FixedPartitionAttributes> allStaticAttrs) + throws SAXException { for (FixedPartitionAttributes attr : allStaticAttrs) { AttributesImpl sAtts = new AttributesImpl(); sAtts.addAttribute("", "", PARTITION_NAME, "", attr.getPartitionName()); sAtts.addAttribute("", "", IS_PRIMARY, "", String.valueOf(attr.isPrimary())); sAtts.addAttribute("", "", NUM_BUCKETS, "", String.valueOf(attr.getNumBuckets())); - handler.startElement("", kind, kind, sAtts); - handler.endElement("", kind, kind); + handler.startElement("", CacheXml.FIXED_PARTITION_ATTRIBUTES, + CacheXml.FIXED_PARTITION_ATTRIBUTES, sAtts); + handler.endElement("", CacheXml.FIXED_PARTITION_ATTRIBUTES, + CacheXml.FIXED_PARTITION_ATTRIBUTES); } } @@ -2558,8 +2486,8 @@ public class CacheXmlGenerator extends CacheXml implements XMLReader { handler.startElement("", MEMBERSHIP_ATTRIBUTES, MEMBERSHIP_ATTRIBUTES, raAtts); - for (Iterator iter = roles.iterator(); iter.hasNext();) { - Role role = (Role) iter.next(); + for (Object o : roles) { + Role role = (Role) o; AttributesImpl roleAtts = new AttributesImpl(); roleAtts.addAttribute("", "", NAME, "", role.getName()); handler.startElement("", REQUIRED_ROLE, REQUIRED_ROLE, roleAtts); @@ -2657,8 +2585,7 @@ public class CacheXmlGenerator extends CacheXml implements XMLReader { if (elementName != null) { handler.startElement("", elementName, elementName, EMPTY); } - for (Iterator iter = props.entrySet().iterator(); iter.hasNext();) { - Map.Entry entry = (Map.Entry) iter.next(); + for (Map.Entry<Object, Object> entry : props.entrySet()) { String name = (String) entry.getKey(); Object value = entry.getValue(); @@ -2672,9 +2599,6 @@ public class CacheXmlGenerator extends CacheXml implements XMLReader { } else if (value instanceof Declarable) { generate((Declarable) value); - - } else { - // Ignore it } handler.endElement("", PARAMETER, PARAMETER); @@ -2701,7 +2625,7 @@ public class CacheXmlGenerator extends CacheXml implements XMLReader { @Override public ContentHandler getContentHandler() { - return this.handler; + return handler; } @Override @@ -2710,27 +2634,23 @@ public class CacheXmlGenerator extends CacheXml implements XMLReader { } @Override - public boolean getFeature(String name) - throws SAXNotRecognizedException, SAXNotSupportedException { + public boolean getFeature(String name) { return false; } @Override - public void setFeature(String name, boolean value) - throws SAXNotRecognizedException, SAXNotSupportedException { + public void setFeature(String name, boolean value) { // nothing } @Override - public Object getProperty(String name) - throws SAXNotRecognizedException, SAXNotSupportedException { + public Object getProperty(String name) { return null; } @Override - public void setProperty(String name, Object value) - throws SAXNotRecognizedException, SAXNotSupportedException { + public void setProperty(String name, Object value) { // nothing } @@ -2760,7 +2680,7 @@ public class CacheXmlGenerator extends CacheXml implements XMLReader { } @Override - public void parse(String systemId) throws IOException, SAXException { + public void parse(String systemId) { // nothing } @@ -2768,7 +2688,7 @@ public class CacheXmlGenerator extends CacheXml implements XMLReader { * Used by gemfire build.xml to generate a default gemfire.properties for use by applications. See * bug 30995 for the feature request. */ - public static void main(String args[]) throws IOException { + public static void main(String[] args) throws IOException { FileWriter fw = new FileWriter(new File("cache.xml")); PrintWriter pw = new PrintWriter(fw); diff --git a/geode-core/src/main/java/org/apache/geode/internal/cache/xmlcache/XmlGenerator.java b/geode-core/src/main/java/org/apache/geode/internal/cache/xmlcache/XmlGenerator.java index ea9be93..e4c5d09 100644 --- a/geode-core/src/main/java/org/apache/geode/internal/cache/xmlcache/XmlGenerator.java +++ b/geode-core/src/main/java/org/apache/geode/internal/cache/xmlcache/XmlGenerator.java @@ -34,17 +34,6 @@ public interface XmlGenerator<T> { */ String getNamespaceUri(); - // TODO jbarrett - investigate new logging. - // /** - // * Sets the XML config {@link LogWriter} on this parser. - // * - // * @param logWriter - // * current XML config {@link LogWriter}. - // * @since GemFire 8.1 - // */ - // void setLogWriter(LogWriterI18n logWriter); - // - /** * Generate XML configuration to the given {@link CacheXmlGenerator}. * diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/ExportConfigFunction.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/ExportConfigFunction.java index 17a9b1f..eef45ad 100644 --- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/ExportConfigFunction.java +++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/functions/ExportConfigFunction.java @@ -12,6 +12,7 @@ * or implied. See the License for the specific language governing permissions and limitations under * the License. */ + package org.apache.geode.management.internal.cli.functions; import java.io.PrintWriter; @@ -32,7 +33,7 @@ import org.apache.geode.internal.cache.execute.InternalFunction; import org.apache.geode.internal.cache.xmlcache.CacheXmlGenerator; import org.apache.geode.internal.logging.LogService; -public class ExportConfigFunction implements InternalFunction { +public class ExportConfigFunction implements InternalFunction<Object> { private static final Logger logger = LogService.getLogger(); public static final String ID = ExportConfigFunction.class.getName(); @@ -40,7 +41,7 @@ public class ExportConfigFunction implements InternalFunction { private static final long serialVersionUID = 1L; @Override - public void execute(FunctionContext context) { + public void execute(FunctionContext<Object> context) { // Declared here so that it's available when returning a Throwable String memberId = ""; @@ -57,14 +58,14 @@ public class ExportConfigFunction implements InternalFunction { // Generate the cache XML StringWriter xmlWriter = new StringWriter(); PrintWriter printWriter = new PrintWriter(xmlWriter); - CacheXmlGenerator.generate(cache, printWriter, true, false, false); + CacheXmlGenerator.generate(cache, printWriter, false, false); printWriter.close(); // Generate the properties file DistributionConfigImpl config = (DistributionConfigImpl) ((InternalDistributedSystem) cache.getDistributedSystem()) .getConfig(); - StringBuffer propStringBuf = new StringBuffer(); + StringBuilder propStringBuf = new StringBuilder(); String lineSeparator = System.getProperty("line.separator"); for (Map.Entry entry : config.getConfigPropsFromSource(ConfigSource.runtime()).entrySet()) { if (entry.getValue() != null && !entry.getValue().equals("")) { diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/configuration/domain/XmlEntity.java b/geode-core/src/main/java/org/apache/geode/management/internal/configuration/domain/XmlEntity.java index 01da678..5e64d1c 100644 --- a/geode-core/src/main/java/org/apache/geode/management/internal/configuration/domain/XmlEntity.java +++ b/geode-core/src/main/java/org/apache/geode/management/internal/configuration/domain/XmlEntity.java @@ -12,6 +12,7 @@ * or implied. See the License for the specific language governing permissions and limitations under * the License. */ + package org.apache.geode.management.internal.configuration.domain; import java.io.DataInput; @@ -101,7 +102,7 @@ public class XmlEntity implements VersionedDataSerializable { */ @Deprecated public XmlEntity() { - this.cacheProvider = createDefaultCacheProvider(); + cacheProvider = createDefaultCacheProvider(); } /** @@ -114,9 +115,9 @@ public class XmlEntity implements VersionedDataSerializable { * @param value Value of the attribute to match. */ public XmlEntity(final String type, final String key, final String value) { - this.cacheProvider = createDefaultCacheProvider(); + cacheProvider = createDefaultCacheProvider(); this.type = type; - this.attributes.put(key, value); + attributes.put(key, value); init(); } @@ -137,10 +138,10 @@ public class XmlEntity implements VersionedDataSerializable { */ public XmlEntity(final String parentType, final String parentKey, final String parentValue, final String childType, final String childKey, final String childValue) { - this.cacheProvider = createDefaultCacheProvider(); + cacheProvider = createDefaultCacheProvider(); this.parentType = parentType; - this.type = childType; - initializeSearchString(parentKey, parentValue, this.prefix, childKey, childValue); + type = childType; + initializeSearchString(parentKey, parentValue, prefix, childKey, childValue); } /** @@ -164,9 +165,9 @@ public class XmlEntity implements VersionedDataSerializable { final String childPrefix, final String childNamespace, final String childType, final String childKey, final String childValue) { // Note: Do not invoke init - this.cacheProvider = createDefaultCacheProvider(); + cacheProvider = createDefaultCacheProvider(); this.parentType = parentType; - this.type = childType; + type = childType; this.childPrefix = childPrefix; this.childNamespace = childNamespace; initializeSearchString(parentKey, parentValue, childPrefix, childKey, childValue); @@ -177,18 +178,15 @@ public class XmlEntity implements VersionedDataSerializable { final String key, final String value) { this.cacheProvider = cacheProvider; this.parentType = parentType; - this.type = childType; - this.prefix = childPrefix; - this.namespace = childNamespace; + type = childType; + prefix = childPrefix; + namespace = childNamespace; this.childPrefix = childPrefix; this.childNamespace = childNamespace; - this.attributes.put(key, value); + attributes.put(key, value); - StringBuilder sb = new StringBuilder(); - sb.append("//").append(this.parentType); - sb.append('/').append(childPrefix).append(':').append(this.type); - this.searchString = sb.toString(); - this.xmlDefinition = parseXmlForDefinition(); + searchString = "//" + this.parentType + '/' + childPrefix + ':' + type; + xmlDefinition = parseXmlForDefinition(); } private String parseXmlForDefinition() { @@ -196,7 +194,7 @@ public class XmlEntity implements VersionedDataSerializable { final StringWriter stringWriter = new StringWriter(); final PrintWriter printWriter = new PrintWriter(stringWriter); - CacheXmlGenerator.generate(cache, printWriter, true, false, false); + CacheXmlGenerator.generate(cache, printWriter, false, false); printWriter.close(); InputSource inputSource = new InputSource(new StringReader(stringWriter.toString())); @@ -219,18 +217,18 @@ public class XmlEntity implements VersionedDataSerializable { private void initializeSearchString(final String parentKey, final String parentValue, final String childPrefix, final String childKey, final String childValue) { StringBuilder sb = new StringBuilder(); - sb.append("//").append(this.prefix).append(':').append(this.parentType); + sb.append("//").append(prefix).append(':').append(parentType); if (StringUtils.isNotBlank(parentKey) && StringUtils.isNotBlank(parentValue)) { sb.append("[@").append(parentKey).append("='").append(parentValue).append("']"); } - sb.append('/').append(childPrefix).append(':').append(this.type); + sb.append('/').append(childPrefix).append(':').append(type); if (StringUtils.isNotBlank(childKey) && StringUtils.isNotBlank(childValue)) { sb.append("[@").append(childKey).append("='").append(childValue).append("']"); } - this.searchString = sb.toString(); + searchString = sb.toString(); } /** @@ -260,7 +258,7 @@ public class XmlEntity implements VersionedDataSerializable { final StringWriter stringWriter = new StringWriter(); final PrintWriter printWriter = new PrintWriter(stringWriter); - CacheXmlGenerator.generate(cache, printWriter, true, false, false); + CacheXmlGenerator.generate(cache, printWriter, false, false); printWriter.close(); return loadXmlDefinition(stringWriter.toString()); @@ -290,10 +288,10 @@ public class XmlEntity implements VersionedDataSerializable { * @return XML for XmlEntity if found, otherwise {@code null}. * @since GemFire 8.1 */ - public String loadXmlDefinition(final Document document) + private String loadXmlDefinition(final Document document) throws XPathExpressionException, TransformerFactoryConfigurationError, TransformerException { - this.searchString = createQueryString(prefix, type, attributes); - logger.info("XmlEntity:searchString: {}", this.searchString); + searchString = createQueryString(prefix, type, attributes); + logger.info("XmlEntity:searchString: {}", searchString); if (document != null) { XPathContext xpathContext = new XPathContext(); @@ -303,7 +301,7 @@ public class XmlEntity implements VersionedDataSerializable { xpathContext.addNamespace(childPrefix, childNamespace); // Create an XPathContext here - Node element = XmlUtils.querySingleElement(document, this.searchString, xpathContext); + Node element = XmlUtils.querySingleElement(document, searchString, xpathContext); // Must copy to preserve namespaces. if (null != element) { @@ -349,15 +347,15 @@ public class XmlEntity implements VersionedDataSerializable { } public String getSearchString() { - return this.searchString; + return searchString; } public String getType() { - return this.type; + return type; } public Map<String, String> getAttributes() { - return this.attributes; + return attributes; } /** @@ -368,7 +366,7 @@ public class XmlEntity implements VersionedDataSerializable { * @return The value of the attribute. */ public String getAttribute(String key) { - return this.attributes.get(key); + return attributes.get(key); } /** @@ -378,15 +376,15 @@ public class XmlEntity implements VersionedDataSerializable { * @return The name or id attribute or null if neither is found. */ public String getNameOrId() { - if (this.attributes.containsKey("name")) { - return this.attributes.get("name"); + if (attributes.containsKey("name")) { + return attributes.get("name"); } - return this.attributes.get("id"); + return attributes.get("id"); } public String getXmlDefinition() { - return this.xmlDefinition; + return xmlDefinition; } /** @@ -415,7 +413,7 @@ public class XmlEntity implements VersionedDataSerializable { * @return XML element prefix for the child element */ public String getChildPrefix() { - return this.childPrefix; + return childPrefix; } /** @@ -424,7 +422,7 @@ public class XmlEntity implements VersionedDataSerializable { * @return XML element namespace for the child element */ public String getChildNamespace() { - return this.childNamespace; + return childNamespace; } @Override @@ -434,16 +432,16 @@ public class XmlEntity implements VersionedDataSerializable { @Override public String toString() { - return "XmlEntity [namespace=" + namespace + ", type=" + this.type + ", attributes=" - + this.attributes + ", xmlDefinition=" + this.xmlDefinition + ']'; + return "XmlEntity [namespace=" + namespace + ", type=" + type + ", attributes=" + + attributes + ", xmlDefinition=" + xmlDefinition + ']'; } @Override public int hashCode() { final int prime = 31; int result = 1; - result = prime * result + ((this.attributes == null) ? 0 : this.attributes.hashCode()); - result = prime * result + ((this.type == null) ? 0 : this.type.hashCode()); + result = prime * result + ((attributes == null) ? 0 : attributes.hashCode()); + result = prime * result + ((type == null) ? 0 : type.hashCode()); return result; } @@ -456,55 +454,53 @@ public class XmlEntity implements VersionedDataSerializable { if (getClass() != obj.getClass()) return false; XmlEntity other = (XmlEntity) obj; - if (this.attributes == null) { + if (attributes == null) { if (other.attributes != null) return false; - } else if (!this.attributes.equals(other.attributes)) + } else if (!attributes.equals(other.attributes)) return false; - if (this.namespace == null) { + if (namespace == null) { if (other.namespace != null) return false; - } else if (!this.namespace.equals(other.namespace)) + } else if (!namespace.equals(other.namespace)) return false; - if (this.type == null) { - if (other.type != null) - return false; - } else if (!this.type.equals(other.type)) - return false; - return true; + if (type == null) { + return other.type == null; + } else + return type.equals(other.type); } @Override public void toData(DataOutput out) throws IOException { toDataPre_GEODE_1_1_1_0(out); - DataSerializer.writeString(this.childPrefix, out); - DataSerializer.writeString(this.childNamespace, out); + DataSerializer.writeString(childPrefix, out); + DataSerializer.writeString(childNamespace, out); } public void toDataPre_GEODE_1_1_1_0(DataOutput out) throws IOException { - DataSerializer.writeString(this.type, out); - DataSerializer.writeObject(this.attributes, out); - DataSerializer.writeString(this.xmlDefinition, out); - DataSerializer.writeString(this.searchString, out); - DataSerializer.writeString(this.prefix, out); - DataSerializer.writeString(this.namespace, out); + DataSerializer.writeString(type, out); + DataSerializer.writeObject(attributes, out); + DataSerializer.writeString(xmlDefinition, out); + DataSerializer.writeString(searchString, out); + DataSerializer.writeString(prefix, out); + DataSerializer.writeString(namespace, out); } @Override public void fromData(DataInput in) throws IOException, ClassNotFoundException { fromDataPre_GEODE_1_1_1_0(in); - this.childPrefix = DataSerializer.readString(in); - this.childNamespace = DataSerializer.readString(in); + childPrefix = DataSerializer.readString(in); + childNamespace = DataSerializer.readString(in); } public void fromDataPre_GEODE_1_1_1_0(DataInput in) throws IOException, ClassNotFoundException { - this.type = DataSerializer.readString(in); - this.attributes = DataSerializer.readObject(in); - this.xmlDefinition = DataSerializer.readString(in); - this.searchString = DataSerializer.readString(in); - this.prefix = DataSerializer.readString(in); - this.namespace = DataSerializer.readString(in); - this.cacheProvider = createDefaultCacheProvider(); + type = DataSerializer.readString(in); + attributes = DataSerializer.readObject(in); + xmlDefinition = DataSerializer.readString(in); + searchString = DataSerializer.readString(in); + prefix = DataSerializer.readString(in); + namespace = DataSerializer.readString(in); + cacheProvider = createDefaultCacheProvider(); } /** @@ -528,6 +524,7 @@ public class XmlEntity implements VersionedDataSerializable { * * @since GemFire 8.1 */ + @SuppressWarnings("deprecation") XmlEntityBuilder() { xmlEntity = new XmlEntity(); } @@ -540,6 +537,7 @@ public class XmlEntity implements VersionedDataSerializable { * * @since GemFire 8.1 */ + @SuppressWarnings("deprecation") public XmlEntity build() { xmlEntity.init(); @@ -614,23 +612,6 @@ public class XmlEntity implements VersionedDataSerializable { * * <b>Should only be used for testing.</b> * - * @param xmlDocument Config XML document. - * @return this XmlEntityBuilder - * @since GemFire 8.1 - */ - public XmlEntityBuilder withConfig(final String xmlDocument) { - xmlEntity.xmlDefinition = xmlEntity.loadXmlDefinition(xmlDocument); - - return this; - } - - /** - * Sets a config xml document source to get the entity XML Definition from as returned by - * {@link XmlEntity#getXmlDefinition()}. Defaults to current active configuration for - * {@link Cache}. - * - * <b>Should only be used for testing.</b> - * * @param document Config XML {@link Document}. * @return this XmlEntityBuilder * @since GemFire 8.1 diff --git a/geode-lucene/src/integrationTest/java/org/apache/geode/cache/lucene/internal/xml/LuceneIndexXmlGeneratorIntegrationJUnitTest.java b/geode-lucene/src/integrationTest/java/org/apache/geode/cache/lucene/internal/xml/LuceneIndexXmlGeneratorIntegrationJUnitTest.java index 27b7f17..b20f65e 100644 --- a/geode-lucene/src/integrationTest/java/org/apache/geode/cache/lucene/internal/xml/LuceneIndexXmlGeneratorIntegrationJUnitTest.java +++ b/geode-lucene/src/integrationTest/java/org/apache/geode/cache/lucene/internal/xml/LuceneIndexXmlGeneratorIntegrationJUnitTest.java @@ -20,12 +20,11 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; +import static org.junit.Assert.assertNotSame; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.PrintWriter; -import java.nio.charset.Charset; import java.util.Properties; import org.junit.After; @@ -139,20 +138,17 @@ public class LuceneIndexXmlGeneratorIntegrationJUnitTest { private LuceneIndex generateAndParseXml(LuceneService service) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); PrintWriter pw = new PrintWriter(baos); - CacheXmlGenerator.generate(cache, pw, true, false, false); + CacheXmlGenerator.generate(cache, pw, false, false); pw.flush(); cache.close(); cache = new CacheFactory().set(MCAST_PORT, "0").create(); byte[] bytes = baos.toByteArray(); - ByteArrayInputStream in = new ByteArrayInputStream(bytes); - System.out.println("---FILE---"); - System.out.println(new String(bytes, Charset.defaultCharset())); cache.loadCacheXml(new ByteArrayInputStream(bytes)); LuceneService service2 = LuceneServiceProvider.get(cache); - assertTrue(service != service2); + assertNotSame(service, service2); LuceneIndex index = service2.getIndex("index", "region"); assertNotNull(index); diff --git a/geode-wan/src/upgradeTest/java/org/apache/geode/cache/wan/WANRollingUpgradeMultipleReceiversDefinedInClusterConfiguration.java b/geode-wan/src/upgradeTest/java/org/apache/geode/cache/wan/WANRollingUpgradeMultipleReceiversDefinedInClusterConfiguration.java index 24ca251..d95a4cd 100644 --- a/geode-wan/src/upgradeTest/java/org/apache/geode/cache/wan/WANRollingUpgradeMultipleReceiversDefinedInClusterConfiguration.java +++ b/geode-wan/src/upgradeTest/java/org/apache/geode/cache/wan/WANRollingUpgradeMultipleReceiversDefinedInClusterConfiguration.java @@ -12,6 +12,7 @@ * or implied. See the License for the specific language governing permissions and limitations under * the License. */ + package org.apache.geode.cache.wan; import static org.apache.geode.test.awaitility.GeodeAwaitility.await; @@ -85,8 +86,7 @@ public class WANRollingUpgradeMultipleReceiversDefinedInClusterConfiguration }); System.out.println("running against these versions and attributes: " - + result.stream().map(entry -> Arrays.toString(entry)).collect( - Collectors.joining(", "))); + + result.stream().map(Arrays::toString).collect(Collectors.joining(", "))); return result; } @@ -139,7 +139,7 @@ public class WANRollingUpgradeMultipleReceiversDefinedInClusterConfiguration } @Test - public void testMultipleReceiversRemovedDuringRoll() throws Exception { + public void testMultipleReceiversRemovedDuringRoll() { // Get old locator properties VM locator = Host.getHost(0).getVM(oldVersion, 0); String hostName = NetworkUtils.getServerHostName(); @@ -158,22 +158,21 @@ public class WANRollingUpgradeMultipleReceiversDefinedInClusterConfiguration InternalLocator.getLocator().isSharedConfigurationRunning()).isTrue())); // Add cluster configuration elements containing multiple receivers - locator.invoke( - () -> addMultipleGatewayReceiverElementsToClusterConfiguration()); + locator.invoke(this::addMultipleGatewayReceiverElementsToClusterConfiguration); // Roll old locator to current rollLocatorToCurrent(locator, locatorPort, 0, locators, null, true); // Verify cluster configuration contains expected number of receivers - locator.invoke(() -> verifyGatewayReceiverClusterConfigurationElements()); + locator.invoke(this::verifyGatewayReceiverClusterConfigurationElements); // Start member in current version with cluster configuration enabled VM server = Host.getHost(0).getVM(VersionManager.CURRENT_VERSION, 1); server.invoke(() -> createCache(locators, true, true)); // Verify member has expected number of receivers - server.invoke(() -> verifyGatewayReceivers()); + server.invoke(this::verifyGatewayReceivers); } private void addMultipleGatewayReceiverElementsToClusterConfiguration() @@ -243,11 +242,7 @@ public class WANRollingUpgradeMultipleReceiversDefinedInClusterConfiguration } public String toString() { - return new StringBuilder() - .append(this.name) - .append("=") - .append(this.value) - .toString(); + return name + "=" + value; } } }