GEODE-2449: Moved Redis out of core with minimal Extension work added
Project: http://git-wip-us.apache.org/repos/asf/geode/repo Commit: http://git-wip-us.apache.org/repos/asf/geode/commit/c6dbc6d4 Tree: http://git-wip-us.apache.org/repos/asf/geode/tree/c6dbc6d4 Diff: http://git-wip-us.apache.org/repos/asf/geode/diff/c6dbc6d4 Branch: refs/heads/feature/GEODE-2449 Commit: c6dbc6d4e4ea82d65074e30c4c15085a5e3d8688 Parents: 6f35a02 Author: Udo Kohlmeyer <[email protected]> Authored: Fri Feb 10 13:33:31 2017 -0800 Committer: Udo Kohlmeyer <[email protected]> Committed: Fri Feb 10 13:33:32 2017 -0800 ---------------------------------------------------------------------- geode-core/build.gradle | 4 - .../distributed/ConfigurationProperties.java | 2 - .../internal/DistributionConfigImpl.java | 1 - .../geode/internal/cache/GemFireCacheImpl.java | 335 +- .../org/apache/geode/internal/hll/Bits.java | 45 - .../internal/hll/CardinalityMergeException.java | 24 - .../apache/geode/internal/hll/HyperLogLog.java | 336 -- .../geode/internal/hll/HyperLogLogPlus.java | 1866 ----------- .../org/apache/geode/internal/hll/IBuilder.java | 22 - .../apache/geode/internal/hll/ICardinality.java | 74 - .../apache/geode/internal/hll/MurmurHash.java | 214 -- .../apache/geode/internal/hll/RegisterSet.java | 108 - .../domain/FixedPartitionAttributesInfo.java | 1 - .../apache/geode/redis/GeodeRedisServer.java | 729 ----- .../apache/geode/redis/GeodeRedisService.java | 27 + .../geode/redis/internal/ByteArrayWrapper.java | 174 -- .../redis/internal/ByteToCommandDecoder.java | 188 -- .../apache/geode/redis/internal/Command.java | 145 - .../geode/redis/internal/DoubleWrapper.java | 76 - .../redis/internal/ExecutionHandlerContext.java | 392 --- .../apache/geode/redis/internal/Executor.java | 34 - .../apache/geode/redis/internal/Extendable.java | 31 - .../internal/RedisCommandParserException.java | 42 - .../geode/redis/internal/RedisCommandType.java | 2896 ------------------ .../geode/redis/internal/RedisConstants.java | 308 -- .../geode/redis/internal/RedisDataType.java | 116 - .../RedisDataTypeMismatchException.java | 35 - .../redis/internal/RegionCreationException.java | 37 - .../geode/redis/internal/RegionProvider.java | 567 ---- .../internal/executor/AbstractExecutor.java | 138 - .../internal/executor/AbstractScanExecutor.java | 47 - .../redis/internal/executor/AuthExecutor.java | 54 - .../redis/internal/executor/DBSizeExecutor.java | 29 - .../redis/internal/executor/DelExecutor.java | 53 - .../redis/internal/executor/EchoExecutor.java | 38 - .../redis/internal/executor/ExistsExecutor.java | 47 - .../internal/executor/ExpirationExecutor.java | 39 - .../internal/executor/ExpireAtExecutor.java | 92 - .../redis/internal/executor/ExpireExecutor.java | 92 - .../internal/executor/FlushAllExecutor.java | 47 - .../redis/internal/executor/KeysExecutor.java | 69 - .../redis/internal/executor/ListQuery.java | 64 - .../internal/executor/PExpireAtExecutor.java | 30 - .../internal/executor/PExpireExecutor.java | 30 - .../redis/internal/executor/PTTLExecutor.java | 31 - .../internal/executor/PersistExecutor.java | 51 - .../redis/internal/executor/PingExecutor.java | 30 - .../redis/internal/executor/QuitExecutor.java | 30 - .../redis/internal/executor/ScanExecutor.java | 145 - .../internal/executor/ShutDownExecutor.java | 25 - .../redis/internal/executor/SortedSetQuery.java | 283 -- .../redis/internal/executor/TTLExecutor.java | 75 - .../redis/internal/executor/TimeExecutor.java | 49 - .../redis/internal/executor/TypeExecutor.java | 47 - .../redis/internal/executor/UnkownExecutor.java | 30 - .../internal/executor/hash/HDelExecutor.java | 65 - .../internal/executor/hash/HExistsExecutor.java | 64 - .../internal/executor/hash/HGetAllExecutor.java | 62 - .../internal/executor/hash/HGetExecutor.java | 61 - .../internal/executor/hash/HIncrByExecutor.java | 111 - .../executor/hash/HIncrByFloatExecutor.java | 104 - .../internal/executor/hash/HKeysExecutor.java | 61 - .../internal/executor/hash/HLenExecutor.java | 55 - .../internal/executor/hash/HMGetExecutor.java | 71 - .../internal/executor/hash/HMSetExecutor.java | 61 - .../internal/executor/hash/HScanExecutor.java | 166 - .../internal/executor/hash/HSetExecutor.java | 77 - .../internal/executor/hash/HSetNXExecutor.java | 31 - .../internal/executor/hash/HValsExecutor.java | 60 - .../internal/executor/hash/HashExecutor.java | 40 - .../internal/executor/hll/HllExecutor.java | 37 - .../internal/executor/hll/PFAddExecutor.java | 65 - .../internal/executor/hll/PFCountExecutor.java | 69 - .../internal/executor/hll/PFMergeExecutor.java | 73 - .../redis/internal/executor/hll/Varint.java | 238 -- .../internal/executor/list/LIndexExecutor.java | 118 - .../internal/executor/list/LInsertExecutor.java | 28 - .../internal/executor/list/LLenExecutor.java | 56 - .../internal/executor/list/LPopExecutor.java | 32 - .../internal/executor/list/LPushExecutor.java | 32 - .../internal/executor/list/LPushXExecutor.java | 32 - .../internal/executor/list/LRangeExecutor.java | 113 - .../internal/executor/list/LRemExecutor.java | 115 - .../internal/executor/list/LSetExecutor.java | 108 - .../internal/executor/list/LTrimExecutor.java | 123 - .../internal/executor/list/ListExecutor.java | 141 - .../internal/executor/list/PopExecutor.java | 134 - .../internal/executor/list/PushExecutor.java | 54 - .../internal/executor/list/PushXExecutor.java | 57 - .../internal/executor/list/RPopExecutor.java | 32 - .../internal/executor/list/RPushExecutor.java | 32 - .../internal/executor/list/RPushXExecutor.java | 32 - .../internal/executor/set/SAddExecutor.java | 60 - .../internal/executor/set/SCardExecutor.java | 54 - .../internal/executor/set/SDiffExecutor.java | 45 - .../executor/set/SDiffStoreExecutor.java | 31 - .../internal/executor/set/SInterExecutor.java | 48 - .../executor/set/SInterStoreExecutor.java | 32 - .../executor/set/SIsMemberExecutor.java | 62 - .../internal/executor/set/SMembersExecutor.java | 55 - .../internal/executor/set/SMoveExecutor.java | 74 - .../internal/executor/set/SPopExecutor.java | 60 - .../executor/set/SRandMemberExecutor.java | 101 - .../internal/executor/set/SRemExecutor.java | 62 - .../internal/executor/set/SScanExecutor.java | 157 - .../internal/executor/set/SUnionExecutor.java | 50 - .../executor/set/SUnionStoreExecutor.java | 32 - .../internal/executor/set/SetExecutor.java | 21 - .../internal/executor/set/SetOpExecutor.java | 114 - .../executor/sortedset/SortedSetExecutor.java | 43 - .../executor/sortedset/ZAddExecutor.java | 90 - .../executor/sortedset/ZCardExecutor.java | 53 - .../executor/sortedset/ZCountExecutor.java | 146 - .../executor/sortedset/ZIncrByExecutor.java | 76 - .../executor/sortedset/ZLexCountExecutor.java | 148 - .../executor/sortedset/ZRangeByLexExecutor.java | 221 -- .../sortedset/ZRangeByScoreExecutor.java | 214 -- .../executor/sortedset/ZRangeExecutor.java | 124 - .../executor/sortedset/ZRankExecutor.java | 97 - .../executor/sortedset/ZRemExecutor.java | 62 - .../sortedset/ZRemRangeByLexExecutor.java | 161 - .../sortedset/ZRemRangeByRankExecutor.java | 121 - .../sortedset/ZRemRangeByScoreExecutor.java | 145 - .../sortedset/ZRevRangeByScoreExecutor.java | 31 - .../executor/sortedset/ZRevRangeExecutor.java | 32 - .../executor/sortedset/ZRevRankExecutor.java | 30 - .../executor/sortedset/ZScanExecutor.java | 164 - .../executor/sortedset/ZScoreExecutor.java | 58 - .../executor/string/AppendExecutor.java | 68 - .../executor/string/BitCountExecutor.java | 97 - .../internal/executor/string/BitOpExecutor.java | 154 - .../executor/string/BitPosExecutor.java | 140 - .../executor/string/DecrByExecutor.java | 113 - .../internal/executor/string/DecrExecutor.java | 95 - .../executor/string/GetBitExecutor.java | 80 - .../internal/executor/string/GetExecutor.java | 51 - .../executor/string/GetRangeExecutor.java | 96 - .../executor/string/GetSetExecutor.java | 58 - .../executor/string/IncrByExecutor.java | 108 - .../executor/string/IncrByFloatExecutor.java | 128 - .../internal/executor/string/IncrExecutor.java | 91 - .../internal/executor/string/MGetExecutor.java | 67 - .../internal/executor/string/MSetExecutor.java | 62 - .../executor/string/MSetNXExecutor.java | 86 - .../executor/string/PSetEXExecutor.java | 32 - .../executor/string/SetBitExecutor.java | 108 - .../internal/executor/string/SetEXExecutor.java | 90 - .../internal/executor/string/SetExecutor.java | 155 - .../internal/executor/string/SetNXExecutor.java | 58 - .../executor/string/SetRangeExecutor.java | 96 - .../executor/string/StringExecutor.java | 45 - .../executor/string/StrlenExecutor.java | 56 - .../executor/transactions/DiscardExecutor.java | 40 - .../executor/transactions/ExecExecutor.java | 87 - .../executor/transactions/MultiExecutor.java | 45 - .../transactions/TransactionExecutor.java | 21 - .../executor/transactions/UnwatchExecutor.java | 30 - .../executor/transactions/WatchExecutor.java | 30 - .../org/apache/hadoop/fs/GlobPattern.java | 165 - .../org/apache/geode/redis/AuthJUnitTest.java | 160 - .../apache/geode/redis/ConcurrentStartTest.java | 100 - .../org/apache/geode/redis/HashesJUnitTest.java | 185 -- .../org/apache/geode/redis/ListsJUnitTest.java | 251 -- .../apache/geode/redis/RedisDistDUnitTest.java | 265 -- .../org/apache/geode/redis/RedisServerTest.java | 84 - .../org/apache/geode/redis/SetsJUnitTest.java | 257 -- .../apache/geode/redis/SortedSetsJUnitTest.java | 420 --- .../apache/geode/redis/StringsJunitTest.java | 304 -- geode-redis/build.gradle | 29 + .../geode/redis/GeodeRedisServiceImpl.java | 597 ++++ .../geode/redis/internal/ByteArrayWrapper.java | 174 ++ .../redis/internal/ByteToCommandDecoder.java | 188 ++ .../apache/geode/redis/internal/Command.java | 145 + .../geode/redis/internal/DoubleWrapper.java | 76 + .../redis/internal/ExecutionHandlerContext.java | 392 +++ .../apache/geode/redis/internal/Executor.java | 34 + .../apache/geode/redis/internal/Extendable.java | 31 + .../internal/RedisCommandParserException.java | 42 + .../geode/redis/internal/RedisCommandType.java | 2896 ++++++++++++++++++ .../geode/redis/internal/RedisConstants.java | 308 ++ .../geode/redis/internal/RedisDataType.java | 116 + .../RedisDataTypeMismatchException.java | 35 + .../redis/internal/RegionCreationException.java | 37 + .../geode/redis/internal/RegionProvider.java | 567 ++++ .../internal/executor/AbstractExecutor.java | 139 + .../internal/executor/AbstractScanExecutor.java | 47 + .../redis/internal/executor/AuthExecutor.java | 54 + .../redis/internal/executor/DBSizeExecutor.java | 29 + .../redis/internal/executor/DelExecutor.java | 53 + .../redis/internal/executor/EchoExecutor.java | 38 + .../redis/internal/executor/ExistsExecutor.java | 47 + .../internal/executor/ExpirationExecutor.java | 39 + .../internal/executor/ExpireAtExecutor.java | 92 + .../redis/internal/executor/ExpireExecutor.java | 92 + .../internal/executor/FlushAllExecutor.java | 47 + .../redis/internal/executor/KeysExecutor.java | 69 + .../redis/internal/executor/ListQuery.java | 64 + .../internal/executor/PExpireAtExecutor.java | 30 + .../internal/executor/PExpireExecutor.java | 30 + .../redis/internal/executor/PTTLExecutor.java | 31 + .../internal/executor/PersistExecutor.java | 51 + .../redis/internal/executor/PingExecutor.java | 30 + .../redis/internal/executor/QuitExecutor.java | 30 + .../redis/internal/executor/ScanExecutor.java | 146 + .../internal/executor/ShutDownExecutor.java | 25 + .../redis/internal/executor/SortedSetQuery.java | 283 ++ .../redis/internal/executor/TTLExecutor.java | 75 + .../redis/internal/executor/TimeExecutor.java | 48 + .../redis/internal/executor/TypeExecutor.java | 47 + .../redis/internal/executor/UnkownExecutor.java | 30 + .../internal/executor/hash/HDelExecutor.java | 65 + .../internal/executor/hash/HExistsExecutor.java | 64 + .../internal/executor/hash/HGetAllExecutor.java | 62 + .../internal/executor/hash/HGetExecutor.java | 61 + .../internal/executor/hash/HIncrByExecutor.java | 111 + .../executor/hash/HIncrByFloatExecutor.java | 104 + .../internal/executor/hash/HKeysExecutor.java | 61 + .../internal/executor/hash/HLenExecutor.java | 55 + .../internal/executor/hash/HMGetExecutor.java | 71 + .../internal/executor/hash/HMSetExecutor.java | 61 + .../internal/executor/hash/HScanExecutor.java | 166 + .../internal/executor/hash/HSetExecutor.java | 77 + .../internal/executor/hash/HSetNXExecutor.java | 31 + .../internal/executor/hash/HValsExecutor.java | 60 + .../internal/executor/hash/HashExecutor.java | 40 + .../internal/executor/hll/HllExecutor.java | 37 + .../internal/executor/hll/PFAddExecutor.java | 65 + .../internal/executor/hll/PFCountExecutor.java | 69 + .../internal/executor/hll/PFMergeExecutor.java | 73 + .../redis/internal/executor/hll/Varint.java | 238 ++ .../internal/executor/list/LIndexExecutor.java | 118 + .../internal/executor/list/LInsertExecutor.java | 28 + .../internal/executor/list/LLenExecutor.java | 56 + .../internal/executor/list/LPopExecutor.java | 32 + .../internal/executor/list/LPushExecutor.java | 32 + .../internal/executor/list/LPushXExecutor.java | 32 + .../internal/executor/list/LRangeExecutor.java | 113 + .../internal/executor/list/LRemExecutor.java | 115 + .../internal/executor/list/LSetExecutor.java | 108 + .../internal/executor/list/LTrimExecutor.java | 123 + .../internal/executor/list/ListExecutor.java | 141 + .../internal/executor/list/PopExecutor.java | 133 + .../internal/executor/list/PushExecutor.java | 54 + .../internal/executor/list/PushXExecutor.java | 57 + .../internal/executor/list/RPopExecutor.java | 32 + .../internal/executor/list/RPushExecutor.java | 32 + .../internal/executor/list/RPushXExecutor.java | 32 + .../internal/executor/set/SAddExecutor.java | 60 + .../internal/executor/set/SCardExecutor.java | 54 + .../internal/executor/set/SDiffExecutor.java | 45 + .../executor/set/SDiffStoreExecutor.java | 31 + .../internal/executor/set/SInterExecutor.java | 48 + .../executor/set/SInterStoreExecutor.java | 32 + .../executor/set/SIsMemberExecutor.java | 62 + .../internal/executor/set/SMembersExecutor.java | 55 + .../internal/executor/set/SMoveExecutor.java | 74 + .../internal/executor/set/SPopExecutor.java | 60 + .../executor/set/SRandMemberExecutor.java | 101 + .../internal/executor/set/SRemExecutor.java | 62 + .../internal/executor/set/SScanExecutor.java | 157 + .../internal/executor/set/SUnionExecutor.java | 50 + .../executor/set/SUnionStoreExecutor.java | 32 + .../internal/executor/set/SetExecutor.java | 21 + .../internal/executor/set/SetOpExecutor.java | 114 + .../executor/sortedset/SortedSetExecutor.java | 43 + .../executor/sortedset/ZAddExecutor.java | 90 + .../executor/sortedset/ZCardExecutor.java | 53 + .../executor/sortedset/ZCountExecutor.java | 146 + .../executor/sortedset/ZIncrByExecutor.java | 76 + .../executor/sortedset/ZLexCountExecutor.java | 148 + .../executor/sortedset/ZRangeByLexExecutor.java | 220 ++ .../sortedset/ZRangeByScoreExecutor.java | 214 ++ .../executor/sortedset/ZRangeExecutor.java | 124 + .../executor/sortedset/ZRankExecutor.java | 97 + .../executor/sortedset/ZRemExecutor.java | 62 + .../sortedset/ZRemRangeByLexExecutor.java | 161 + .../sortedset/ZRemRangeByRankExecutor.java | 121 + .../sortedset/ZRemRangeByScoreExecutor.java | 145 + .../sortedset/ZRevRangeByScoreExecutor.java | 31 + .../executor/sortedset/ZRevRangeExecutor.java | 32 + .../executor/sortedset/ZRevRankExecutor.java | 30 + .../executor/sortedset/ZScanExecutor.java | 164 + .../executor/sortedset/ZScoreExecutor.java | 58 + .../executor/string/AppendExecutor.java | 68 + .../executor/string/BitCountExecutor.java | 97 + .../internal/executor/string/BitOpExecutor.java | 154 + .../executor/string/BitPosExecutor.java | 140 + .../executor/string/DecrByExecutor.java | 113 + .../internal/executor/string/DecrExecutor.java | 95 + .../executor/string/GetBitExecutor.java | 80 + .../internal/executor/string/GetExecutor.java | 51 + .../executor/string/GetRangeExecutor.java | 96 + .../executor/string/GetSetExecutor.java | 58 + .../executor/string/IncrByExecutor.java | 108 + .../executor/string/IncrByFloatExecutor.java | 128 + .../internal/executor/string/IncrExecutor.java | 91 + .../internal/executor/string/MGetExecutor.java | 67 + .../internal/executor/string/MSetExecutor.java | 62 + .../executor/string/MSetNXExecutor.java | 86 + .../executor/string/PSetEXExecutor.java | 32 + .../executor/string/SetBitExecutor.java | 108 + .../internal/executor/string/SetEXExecutor.java | 90 + .../internal/executor/string/SetExecutor.java | 155 + .../internal/executor/string/SetNXExecutor.java | 58 + .../executor/string/SetRangeExecutor.java | 96 + .../executor/string/StringExecutor.java | 45 + .../executor/string/StrlenExecutor.java | 56 + .../executor/transactions/DiscardExecutor.java | 40 + .../executor/transactions/ExecExecutor.java | 86 + .../executor/transactions/MultiExecutor.java | 45 + .../transactions/TransactionExecutor.java | 21 + .../executor/transactions/UnwatchExecutor.java | 30 + .../executor/transactions/WatchExecutor.java | 30 + .../apache/geode/redis/internal/hll/Bits.java | 45 + .../internal/hll/CardinalityMergeException.java | 22 + .../geode/redis/internal/hll/HyperLogLog.java | 336 ++ .../redis/internal/hll/HyperLogLogPlus.java | 1866 +++++++++++ .../geode/redis/internal/hll/IBuilder.java | 22 + .../geode/redis/internal/hll/ICardinality.java | 74 + .../geode/redis/internal/hll/MurmurHash.java | 214 ++ .../geode/redis/internal/hll/RegisterSet.java | 108 + .../org/apache/hadoop/fs/GlobPattern.java | 165 + ...org.apache.geode.internal.cache.CacheService | 1 + .../org/apache/geode/redis/AuthJUnitTest.java | 120 + .../apache/geode/redis/ConcurrentStartTest.java | 85 + .../org/apache/geode/redis/HashesJUnitTest.java | 147 + .../org/apache/geode/redis/ListsJUnitTest.java | 212 ++ .../apache/geode/redis/RedisDistDUnitTest.java | 266 ++ .../org/apache/geode/redis/RedisServerTest.java | 54 + .../org/apache/geode/redis/RedisTestBase.java | 103 + .../org/apache/geode/redis/SetsJUnitTest.java | 194 ++ .../apache/geode/redis/SortedSetsJUnitTest.java | 417 +++ .../apache/geode/redis/StringsJunitTest.java | 287 ++ gradle/dependency-versions.properties | 4 +- settings.gradle | 2 + 335 files changed, 20528 insertions(+), 20773 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/geode/blob/c6dbc6d4/geode-core/build.gradle ---------------------------------------------------------------------- diff --git a/geode-core/build.gradle b/geode-core/build.gradle index 8eba6d4..fd7cdeb 100755 --- a/geode-core/build.gradle +++ b/geode-core/build.gradle @@ -47,9 +47,6 @@ dependencies { exclude module: 'xml-apis' ext.optional = true } - compile ('io.netty:netty-all:' + project.'netty-all.version') { - ext.optional = true - } compile 'it.unimi.dsi:fastutil:' + project.'fastutil.version' compile ('javax.mail:javax.mail-api:' + project.'javax.mail-api.version') { ext.optional = true; @@ -126,7 +123,6 @@ dependencies { testRuntime 'commons-configuration:commons-configuration:' + project.'commons-configuration.version' testRuntime 'commons-io:commons-io:' + project.'commons-io.version' testCompile 'net.spy:spymemcached:' + project.'spymemcached.version' - testCompile 'redis.clients:jedis:' + project.'jedis.version' testCompile 'org.powermock:powermock-core:' + project.'powermock.version' testCompile 'org.powermock:powermock-module-junit4:' + project.'powermock.version' http://git-wip-us.apache.org/repos/asf/geode/blob/c6dbc6d4/geode-core/src/main/java/org/apache/geode/distributed/ConfigurationProperties.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/distributed/ConfigurationProperties.java b/geode-core/src/main/java/org/apache/geode/distributed/ConfigurationProperties.java index 63f6505..e11ace2 100644 --- a/geode-core/src/main/java/org/apache/geode/distributed/ConfigurationProperties.java +++ b/geode-core/src/main/java/org/apache/geode/distributed/ConfigurationProperties.java @@ -15,8 +15,6 @@ package org.apache.geode.distributed; -import org.apache.geode.redis.GeodeRedisServer; - /** * This interface defines all the configuration properties that can be used. <U>Since</U>: Geode 1.0 */ http://git-wip-us.apache.org/repos/asf/geode/blob/c6dbc6d4/geode-core/src/main/java/org/apache/geode/distributed/internal/DistributionConfigImpl.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/distributed/internal/DistributionConfigImpl.java b/geode-core/src/main/java/org/apache/geode/distributed/internal/DistributionConfigImpl.java index fa6d13f..9b97c7e 100644 --- a/geode-core/src/main/java/org/apache/geode/distributed/internal/DistributionConfigImpl.java +++ b/geode-core/src/main/java/org/apache/geode/distributed/internal/DistributionConfigImpl.java @@ -35,7 +35,6 @@ import java.util.Set; import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.builder.EqualsBuilder; import org.apache.commons.lang.builder.HashCodeBuilder; -import org.apache.geode.redis.GeodeRedisServer; import org.apache.geode.GemFireConfigException; import org.apache.geode.GemFireIOException; http://git-wip-us.apache.org/repos/asf/geode/blob/c6dbc6d4/geode-core/src/main/java/org/apache/geode/internal/cache/GemFireCacheImpl.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/internal/cache/GemFireCacheImpl.java b/geode-core/src/main/java/org/apache/geode/internal/cache/GemFireCacheImpl.java index 6e374ec..fd48be1 100755 --- a/geode-core/src/main/java/org/apache/geode/internal/cache/GemFireCacheImpl.java +++ b/geode-core/src/main/java/org/apache/geode/internal/cache/GemFireCacheImpl.java @@ -88,6 +88,7 @@ import org.apache.geode.distributed.DistributedSystem; import org.apache.geode.distributed.DistributedSystemDisconnectedException; import org.apache.geode.distributed.Locator; import org.apache.geode.distributed.internal.CacheTime; +import org.apache.geode.distributed.internal.ClusterConfigurationService; import org.apache.geode.distributed.internal.DM; import org.apache.geode.distributed.internal.DistributionAdvisee; import org.apache.geode.distributed.internal.DistributionAdvisor; @@ -102,7 +103,6 @@ import org.apache.geode.distributed.internal.ReplyProcessor21; import org.apache.geode.distributed.internal.ResourceEvent; import org.apache.geode.distributed.internal.ResourceEventsListener; import org.apache.geode.distributed.internal.ServerLocation; -import org.apache.geode.distributed.internal.ClusterConfigurationService; import org.apache.geode.distributed.internal.locks.DLockService; import org.apache.geode.distributed.internal.membership.InternalDistributedMember; import org.apache.geode.i18n.LogWriterI18n; @@ -172,7 +172,7 @@ import org.apache.geode.pdx.internal.AutoSerializableManager; import org.apache.geode.pdx.internal.PdxInstanceFactoryImpl; import org.apache.geode.pdx.internal.PdxInstanceImpl; import org.apache.geode.pdx.internal.TypeRegistry; -import org.apache.geode.redis.GeodeRedisServer; +import org.apache.geode.redis.GeodeRedisService; import org.apache.logging.log4j.Logger; import java.io.BufferedReader; @@ -230,9 +230,9 @@ import java.util.concurrent.atomic.AtomicReference; import javax.naming.Context; // @todo somebody Come up with more reasonable values for {@link #DEFAULT_LOCK_TIMEOUT}, etc. + /** * GemFire's implementation of a distributed {@link org.apache.geode.cache.Cache}. - * */ @SuppressWarnings("deprecation") public class GemFireCacheImpl @@ -241,7 +241,9 @@ public class GemFireCacheImpl // moved *SERIAL_NUMBER stuff to DistributionAdvisor - /** The default number of seconds to wait for a distributed lock */ + /** + * The default number of seconds to wait for a distributed lock + */ public static final int DEFAULT_LOCK_TIMEOUT = Integer .getInteger(DistributionConfig.GEMFIRE_PREFIX + "Cache.defaultLockTimeout", 60).intValue(); @@ -251,10 +253,14 @@ public class GemFireCacheImpl public static final int DEFAULT_LOCK_LEASE = Integer .getInteger(DistributionConfig.GEMFIRE_PREFIX + "Cache.defaultLockLease", 120).intValue(); - /** The default "copy on read" attribute value */ + /** + * The default "copy on read" attribute value + */ public static final boolean DEFAULT_COPY_ON_READ = false; - /** the last instance of GemFireCache created */ + /** + * the last instance of GemFireCache created + */ private static volatile GemFireCacheImpl instance = null; /** * Just like instance but is valid for a bit longer so that pdx can still find the cache during a @@ -284,7 +290,6 @@ public class GemFireCacheImpl * If true then when a delta is applied the size of the entry value will be recalculated. If false * (the default) then the size of the entry value is unchanged by a delta application. Not a final * so that tests can change this value. - * * @since GemFire hitachi 6.1.2.9 */ public static boolean DELTAS_RECALCULATE_SIZE = @@ -329,7 +334,9 @@ public class GemFireCacheImpl // time in ms private static final int FIVE_HOURS = 5 * 60 * 60 * 1000; - /** To test MAX_QUERY_EXECUTION_TIME option. */ + /** + * To test MAX_QUERY_EXECUTION_TIME option. + */ public int TEST_MAX_QUERY_EXECUTION_TIME = -1; public boolean TEST_MAX_QUERY_EXECUTION_TIME_OVERRIDE_EXCEPTION = false; @@ -360,21 +367,31 @@ public class GemFireCacheImpl protected volatile boolean closingGatewaySendersByShutdownAll = false; protected volatile boolean closingGatewayReceiversByShutdownAll = false; - /** Amount of time (in seconds) to wait for a distributed lock */ + /** + * Amount of time (in seconds) to wait for a distributed lock + */ private int lockTimeout = DEFAULT_LOCK_TIMEOUT; - /** Amount of time a lease of a distributed lock lasts */ + /** + * Amount of time a lease of a distributed lock lasts + */ private int lockLease = DEFAULT_LOCK_LEASE; - /** Amount of time to wait for a <code>netSearch</code> to complete */ + /** + * Amount of time to wait for a <code>netSearch</code> to complete + */ private int searchTimeout = DEFAULT_SEARCH_TIMEOUT; private final CachePerfStats cachePerfStats; - /** Date on which this instances was created */ + /** + * Date on which this instances was created + */ private final Date creationDate; - /** thread pool for event dispatching */ + /** + * thread pool for event dispatching + */ private final ThreadPoolExecutor eventThreadPool; /** @@ -386,7 +403,6 @@ public class GemFireCacheImpl /** * Controls updates to the list of all gateway senders - * * @see #allGatewaySenders */ public final Object allGatewaySendersLock = new Object(); @@ -413,7 +429,6 @@ public class GemFireCacheImpl /** * Controls updates to the list of all gateway receivers - * * @see #allGatewayReceivers */ public final Object allGatewayReceiversLock = new Object(); @@ -424,7 +439,9 @@ public class GemFireCacheImpl */ private volatile Set<GatewayReceiver> allGatewayReceivers = Collections.emptySet(); - /** PartitionedRegion instances (for required-events notification */ + /** + * PartitionedRegion instances (for required-events notification + */ // This is a HashSet because I know that clear() on it does not // allocate any objects. private final HashSet<PartitionedRegion> partitionedRegions = new HashSet<PartitionedRegion>(); @@ -443,25 +460,32 @@ public class GemFireCacheImpl /** * conflict resolver for WAN, if any - * * @guarded.By {@link #allGatewayHubsLock} */ private GatewayConflictResolver gatewayConflictResolver; - /** Is this is "server" cache? */ + /** + * Is this is "server" cache? + */ private boolean isServer = false; - /** transaction manager for this cache */ + /** + * transaction manager for this cache + */ private final TXManagerImpl txMgr; private RestAgent restAgent; private boolean isRESTServiceRunning = false; - /** Copy on Read feature for all read operations e.g. get */ + /** + * Copy on Read feature for all read operations e.g. get + */ private volatile boolean copyOnRead = DEFAULT_COPY_ON_READ; - /** The named region attributes registered with this cache. */ + /** + * The named region attributes registered with this cache. + */ private final Map namedRegionAttributes = Collections.synchronizedMap(new HashMap()); /** @@ -476,7 +500,9 @@ public class GemFireCacheImpl */ protected volatile Throwable disconnectCause = null; - /** context where this cache was created -- for debugging, really... */ + /** + * context where this cache was created -- for debugging, really... + */ public Exception creationStack = null; /** @@ -490,7 +516,6 @@ public class GemFireCacheImpl * DistributedLockService for PartitionedRegions. Remains null until the first PartitionedRegion * is created. Destroyed by GemFireCache when closing the cache. Protected by synchronization on * this GemFireCache. - * * @guarded.By prLockServiceLock */ private DistributedLockService prLockService; @@ -503,7 +528,6 @@ public class GemFireCacheImpl /** * DistributedLockService for GatewaySenders. Remains null until the first GatewaySender is * created. Destroyed by GemFireCache when closing the cache. - * * @guarded.By gatewayLockServiceLock */ private volatile DistributedLockService gatewayLockService; @@ -529,7 +553,6 @@ public class GemFireCacheImpl /** * Enabled when CacheExistsException issues arise in debugging - * * @see #creationStack */ private static final boolean DEBUG_CREATION_STACK = false; @@ -562,7 +585,9 @@ public class GemFireCacheImpl private final Map<Declarable, Properties> declarablePropertiesMap = new ConcurrentHashMap<Declarable, Properties>(); - /** {@link PropertyResolver} to resolve ${} type property strings */ + /** + * {@link PropertyResolver} to resolve ${} type property strings + */ protected static PropertyResolver resolver; protected static boolean xmlParameterizationEnabled = @@ -578,14 +603,13 @@ public class GemFireCacheImpl */ private GemFireMemcachedServer memcachedServer; - /** - * Redis server is started when {@link DistributionConfig#getRedisPort()} is set - */ - private GeodeRedisServer redisServer; + // /** + // * Redis server is started when {@link DistributionConfig#getRedisPort()} is set + // */ + // private CacheService redisServer; /** * {@link ExtensionPoint} support. - * * @since GemFire 8.1 */ private SimpleExtensionPoint<Cache> extensionPoint = new SimpleExtensionPoint<Cache>(this, this); @@ -621,16 +645,13 @@ public class GemFireCacheImpl * kernel data, shared memory, and memory-mapped files. All mapped pages are guaranteed to be * resident in RAM when the call returns successfully; the pages are guaranteed to stay in RAM * until later unlocked. - * * @param flags MCL_CURRENT 1 - Lock all pages which are currently mapped into the address space - * of the process. - * - * MCL_FUTURE 2 - Lock all pages which will become mapped into the address space of the - * process in the future. These could be for instance new pages required by a growing heap - * and stack as well as new memory mapped files or shared memory regions. - * + * of the process. + * + * MCL_FUTURE 2 - Lock all pages which will become mapped into the address space of the process in + * the future. These could be for instance new pages required by a growing heap and stack as well + * as new memory mapped files or shared memory regions. * @return 0 if success, non-zero if error and errno set - * */ private static native int mlockall(int flags); @@ -693,10 +714,14 @@ public class GemFireCacheImpl // ////////////////////// Constructors ///////////////////////// - /** Map of Futures used to track Regions that are being reinitialized */ + /** + * Map of Futures used to track Regions that are being reinitialized + */ private final ConcurrentMap reinitializingRegions = new ConcurrentHashMap(); - /** Returns the last created instance of GemFireCache */ + /** + * Returns the last created instance of GemFireCache + */ public static GemFireCacheImpl getInstance() { return instance; } @@ -712,7 +737,6 @@ public class GemFireCacheImpl /** * Returns an existing instance. If a cache does not exist throws a cache closed exception. - * * @return the existing cache * @throws CacheClosedException if an existing cache can not be found. */ @@ -731,7 +755,6 @@ public class GemFireCacheImpl /** * Returns an existing instance. If a cache does not exist throws an exception. - * * @param reason the reason an existing cache is being requested. * @return the existing cache * @throws CacheClosedException if an existing cache can not be found. @@ -765,7 +788,7 @@ public class GemFireCacheImpl // } public static GemFireCacheImpl createClient(DistributedSystem system, PoolFactory pf, - CacheConfig cacheConfig) { + CacheConfig cacheConfig) { return basicCreate(system, true, cacheConfig, pf, true, ASYNC_EVENT_LISTENERS, null); } @@ -774,20 +797,22 @@ public class GemFireCacheImpl } public static GemFireCacheImpl createWithAsyncEventListeners(DistributedSystem system, - CacheConfig cacheConfig, TypeRegistry typeRegistry) { + CacheConfig cacheConfig, + TypeRegistry typeRegistry) { return basicCreate(system, true, cacheConfig, null, false, true, typeRegistry); } public static Cache create(DistributedSystem system, boolean existingOk, - CacheConfig cacheConfig) { + CacheConfig cacheConfig) { return basicCreate(system, existingOk, cacheConfig, null, false, ASYNC_EVENT_LISTENERS, null); } - private static GemFireCacheImpl basicCreate(DistributedSystem system, boolean existingOk, - CacheConfig cacheConfig, PoolFactory pf, boolean isClient, boolean asyncEventListeners, - TypeRegistry typeRegistry) throws CacheExistsException, TimeoutException, + CacheConfig cacheConfig, PoolFactory pf, + boolean isClient, boolean asyncEventListeners, + TypeRegistry typeRegistry) + throws CacheExistsException, TimeoutException, CacheWriterException, GatewayException, RegionExistsException { try { synchronized (GemFireCacheImpl.class) { @@ -830,11 +855,11 @@ public class GemFireCacheImpl /** * Creates a new instance of GemFireCache and populates it according to the * <code>cache.xml</code>, if appropriate. - * * @param typeRegistry: currently only unit tests set this parameter to a non-null value */ private GemFireCacheImpl(boolean isClient, PoolFactory pf, DistributedSystem system, - CacheConfig cacheConfig, boolean asyncEventListeners, TypeRegistry typeRegistry) { + CacheConfig cacheConfig, boolean asyncEventListeners, + TypeRegistry typeRegistry) { this.isClient = isClient; this.clientpf = pf; this.cacheConfig = cacheConfig; // do early for bug 43213 @@ -982,7 +1007,6 @@ public class GemFireCacheImpl /** * Used by Hydra tests to get handle of Rest Agent - * * @return RestAgent */ public RestAgent getRestAgent() { @@ -996,13 +1020,15 @@ public class GemFireCacheImpl public ConfigurationResponse requestSharedConfiguration() { final DistributionConfig config = this.system.getConfig(); - if (!(dm instanceof DistributionManager)) + if (!(dm instanceof DistributionManager)) { return null; + } // do nothing if this vm is/has locator or this is a client if (((DistributionManager) dm).getDMType() == DistributionManager.LOCATOR_DM_TYPE || isClient - || Locator.getLocator() != null) + || Locator.getLocator() != null) { return null; + } // can't simply return null if server is not using shared configuration, since we need to find // out @@ -1021,7 +1047,6 @@ public class GemFireCacheImpl return null; } - ConfigurationResponse response = null; List<String> locatorConnectionStrings = getSharedConfigLocatorConnectionStringList(); @@ -1056,7 +1081,7 @@ public class GemFireCacheImpl if (isMisConfigured(clusterSecProperties, serverSecProperties, ConfigurationProperties.SECURITY_MANAGER) || isMisConfigured(clusterSecProperties, serverSecProperties, - ConfigurationProperties.SECURITY_POST_PROCESSOR)) { + ConfigurationProperties.SECURITY_POST_PROCESSOR)) { throw new GemFireConfigException( LocalizedStrings.GEMFIRE_CACHE_SECURITY_MISCONFIGURATION.toLocalizedString()); } @@ -1089,17 +1114,19 @@ public class GemFireCacheImpl // When called, clusterProps and serverProps and key could not be null public static boolean isMisConfigured(Properties clusterProps, Properties serverProps, - String key) { + String key) { String clusterPropValue = clusterProps.getProperty(key); String serverPropValue = serverProps.getProperty(key); // if this server prop is not specified, this is always OK. - if (StringUtils.isBlank(serverPropValue)) + if (StringUtils.isBlank(serverPropValue)) { return false; + } // server props is not blank, but cluster props is blank, NOT OK. - if (StringUtils.isBlank(clusterPropValue)) + if (StringUtils.isBlank(clusterPropValue)) { return true; + } // at this point check for eqality return !clusterPropValue.equals(serverPropValue); @@ -1130,7 +1157,6 @@ public class GemFireCacheImpl } - /** * Used by unit tests to force cache creation to use a test generated cache.xml */ @@ -1147,7 +1173,6 @@ public class GemFireCacheImpl /** * Method to check for GemFire client. In addition to checking for ClientCacheFactory, this method * checks for any defined pools. - * * @return true if the cache has pools declared */ public boolean hasPool() { @@ -1156,7 +1181,7 @@ public class GemFireCacheImpl private Collection<Pool> getAllPools() { Collection<Pool> pools = PoolManagerImpl.getPMI().getMap().values(); - for (Iterator<Pool> itr = pools.iterator(); itr.hasNext();) { + for (Iterator<Pool> itr = pools.iterator(); itr.hasNext(); ) { PoolImpl pool = (PoolImpl) itr.next(); if (pool.isUsedByGateway()) { itr.remove(); @@ -1189,7 +1214,7 @@ public class GemFireCacheImpl GemFireCacheImpl.pdxInstance = this; for (Iterator<CacheLifecycleListener> iter = cacheLifecycleListeners.iterator(); iter - .hasNext();) { + .hasNext(); ) { CacheLifecycleListener listener = (CacheLifecycleListener) iter.next(); listener.cacheCreated(this); } @@ -1215,7 +1240,6 @@ public class GemFireCacheImpl securityService.setPostProcessor(cacheConfig.getPostProcessor()); } - SystemMemberCacheEventProcessor.send(this, Operation.CACHE_CREATE); this.resourceAdvisor.initializationGate(); @@ -1317,11 +1341,11 @@ public class GemFireCacheImpl if (bindAddress.equals(DistributionConfig.DEFAULT_MEMCACHED_BIND_ADDRESS)) { logger.info(LocalizedMessage.create( LocalizedStrings.GemFireCacheImpl_STARTING_GEMFIRE_MEMCACHED_SERVER_ON_PORT_0_FOR_1_PROTOCOL, - new Object[] {port, protocol})); + new Object[]{port, protocol})); } else { logger.info(LocalizedMessage.create( LocalizedStrings.GemFireCacheImpl_STARTING_GEMFIRE_MEMCACHED_SERVER_ON_BIND_ADDRESS_0_PORT_1_FOR_2_PROTOCOL, - new Object[] {bindAddress, port, protocol})); + new Object[]{bindAddress, port, protocol})); } this.memcachedServer = new GemFireMemcachedServer(bindAddress, port, Protocol.valueOf(protocol.toUpperCase())); @@ -1330,21 +1354,11 @@ public class GemFireCacheImpl } private void startRedisServer() { + //TODO this needs to be fixed up. Maybe we don't want to leave the starting of redis to the setting of the port. int port = system.getConfig().getRedisPort(); if (port != 0) { - String bindAddress = system.getConfig().getRedisBindAddress(); - assert bindAddress != null; - if (bindAddress.equals(DistributionConfig.DEFAULT_REDIS_BIND_ADDRESS)) { - getLoggerI18n().info( - LocalizedStrings.GemFireCacheImpl_STARTING_GEMFIRE_REDIS_SERVER_ON_PORT_0, - new Object[] {port}); - } else { - getLoggerI18n().info( - LocalizedStrings.GemFireCacheImpl_STARTING_GEMFIRE_REDIS_SERVER_ON_BIND_ADDRESS_0_PORT_1, - new Object[] {bindAddress, port}); - } - this.redisServer = new GeodeRedisServer(bindAddress, port); - this.redisServer.start(); + GeodeRedisService geodeRedisService = getService(GeodeRedisService.class); + geodeRedisService.start(); } } @@ -1403,18 +1417,16 @@ public class GemFireCacheImpl * file specified by the given <code>DistributedSystem</code>. Note that this operation cannot be * performed in the constructor because creating regions in the cache, etc. uses the cache itself * (which isn't initialized until the constructor returns). - * * @throws CacheXmlException If something goes wrong while parsing the declarative caching XML - * file. + * file. * @throws TimeoutException If a {@link org.apache.geode.cache.Region#put(Object, Object)}times - * out while initializing the cache. + * out while initializing the cache. * @throws CacheWriterException If a <code>CacheWriterException</code> is thrown while - * initializing the cache. + * initializing the cache. * @throws RegionExistsException If the declarative caching XML file desribes a region that - * already exists (including the root region). + * already exists (including the root region). * @throws GatewayException If a <code>GatewayException</code> is thrown while initializing the - * cache. - * + * cache. * @see #loadCacheXml */ private void initializeDeclarativeCache() @@ -1452,12 +1464,12 @@ public class GemFireCacheImpl } catch (IOException ex) { throw new CacheXmlException( LocalizedStrings.GemFireCache_WHILE_OPENING_CACHE_XML_0_THE_FOLLOWING_ERROR_OCCURRED_1 - .toLocalizedString(new Object[] {url.toString(), ex})); + .toLocalizedString(new Object[]{url.toString(), ex})); } catch (CacheXmlException ex) { CacheXmlException newEx = new CacheXmlException(LocalizedStrings.GemFireCache_WHILE_READING_CACHE_XML_0_1 - .toLocalizedString(new Object[] {url, ex.getMessage()})); + .toLocalizedString(new Object[]{url, ex.getMessage()})); newEx.setStackTrace(ex.getStackTrace()); newEx.initCause(ex.getCause()); throw newEx; @@ -1482,11 +1494,11 @@ public class GemFireCacheImpl } logger.info( LocalizedMessage.create(LocalizedStrings.GemFireCache_INITIALIZING_CACHE_USING__0__1, - new Object[] {url.toString(), sb.toString()})); + new Object[]{url.toString(), sb.toString()})); } else { logger.info( LocalizedMessage.create(LocalizedStrings.GemFireCache_INITIALIZING_CACHE_USING__0__1, - new Object[] {"generated description from old cache", cacheXmlDescription})); + new Object[]{"generated description from old cache", cacheXmlDescription})); } } @@ -1518,7 +1530,6 @@ public class GemFireCacheImpl /** * create diskstore factory with default attributes - * * @since GemFire prPersistSprint2 */ public DiskStoreFactory createDiskStoreFactory() { @@ -1527,7 +1538,6 @@ public class GemFireCacheImpl /** * create diskstore factory with predefined attributes - * * @since GemFire prPersistSprint2 */ public DiskStoreFactory createDiskStoreFactory(DiskStoreAttributes attrs) { @@ -1605,12 +1615,16 @@ public class GemFireCacheImpl return stopper; } - /** return true if the cache was closed due to being shunned by other members */ + /** + * return true if the cache was closed due to being shunned by other members + */ public boolean forcedDisconnect() { return this.forcedDisconnect || this.system.forcedDisconnect(); } - /** return a CacheClosedException with the given reason */ + /** + * return a CacheClosedException with the given reason + */ public CacheClosedException getCacheClosedException(String reason, Throwable cause) { CacheClosedException result; if (cause != null) { @@ -1623,21 +1637,21 @@ public class GemFireCacheImpl return result; } - /** if the cache was forcibly closed this exception will reflect the cause */ + /** + * if the cache was forcibly closed this exception will reflect the cause + */ public Throwable getDisconnectCause() { return this.disconnectCause; } /** * Set to true during a cache close if user requested durable subscriptions to be kept. - * * @since GemFire 5.7 */ private boolean keepAlive; /** * Returns true if durable subscriptions (registrations and queries) should be preserved. - * * @since GemFire 5.7 */ public boolean keepDurableSubscriptionsAlive() { @@ -1651,12 +1665,12 @@ public class GemFireCacheImpl /** * Ensure that all the necessary classes for closing the cache are loaded - * * @see SystemFailure#loadEmergencyClasses() */ static public void loadEmergencyClasses() { - if (emergencyClassesLoaded) + if (emergencyClassesLoaded) { return; + } emergencyClassesLoaded = true; InternalDistributedSystem.loadEmergencyClasses(); AcceptorImpl.loadEmergencyClasses(); @@ -1666,7 +1680,6 @@ public class GemFireCacheImpl /** * Close the distributed system, cache servers, and gateways. Clears the rootRegions and * partitionedRegions map. Marks the cache as closed. - * * @see SystemFailure#emergencyClose() */ static public void emergencyClose() { @@ -1762,7 +1775,7 @@ public class GemFireCacheImpl } } if (!this.isShutDownAll.compareAndSet(false, true)) { - // it's already doing shutdown by another thread + // it's already doing stop by another thread try { this.shutDownAllFinished.await(); } catch (InterruptedException e) { @@ -1803,8 +1816,7 @@ public class GemFireCacheImpl try { es.awaitTermination(Integer.MAX_VALUE, TimeUnit.SECONDS); } catch (InterruptedException e) { - logger - .debug("Shutdown all interrupted while waiting for PRs to be shutdown gracefully."); + logger.debug("Shutdown all interrupted while waiting for PRs to be stop gracefully."); } } else { @@ -1999,7 +2011,6 @@ public class GemFireCacheImpl /** * Gets or lazily creates the PartitionedRegion distributed lock service. This call will * synchronize on this GemFireCache. - * * @return the PartitionedRegion distributed lock service */ protected DistributedLockService getPartitionedRegionLockService() { @@ -2025,7 +2036,6 @@ public class GemFireCacheImpl /** * Gets or lazily creates the GatewaySender distributed lock service. - * * @return the GatewaySender distributed lock service */ public DistributedLockService getGatewaySenderLockService() { @@ -2115,7 +2125,6 @@ public class GemFireCacheImpl /** * close the cache - * * @param reason the reason the cache is being closed * @param systemFailureCause whether this member was ejected from the distributed system * @param keepalive whoever added this should javadoc it @@ -2125,7 +2134,7 @@ public class GemFireCacheImpl } public void close(String reason, Throwable systemFailureCause, boolean keepalive, - boolean keepDS) { + boolean keepDS) { securityService.close(); if (isClosed()) { @@ -2267,7 +2276,7 @@ public class GemFireCacheImpl LocalRegion prRoot = null; - for (Iterator itr = rootRegionValues.iterator(); itr.hasNext();) { + for (Iterator itr = rootRegionValues.iterator(); itr.hasNext(); ) { LocalRegion lr = (LocalRegion) itr.next(); if (isDebugEnabled) { logger.debug("{}: processing region {}", this, lr.getFullPath()); @@ -2287,7 +2296,7 @@ public class GemFireCacheImpl if (isDebugEnabled || !forcedDisconnect) { logger.warn(LocalizedMessage.create( LocalizedStrings.GemFireCache_0_ERROR_CLOSING_REGION_1, - new Object[] {this, lr.getFullPath()}), e); + new Object[]{this, lr.getFullPath()}), e); } } } @@ -2467,7 +2476,7 @@ public class GemFireCacheImpl // do this late to prevent 43412 TypeRegistry.setPdxSerializer(null); - for (Iterator iter = cacheLifecycleListeners.iterator(); iter.hasNext();) { + for (Iterator iter = cacheLifecycleListeners.iterator(); iter.hasNext(); ) { CacheLifecycleListener listener = (CacheLifecycleListener) iter.next(); listener.cacheClosed(this); } @@ -2519,21 +2528,20 @@ public class GemFireCacheImpl if (this.memcachedServer != null) { logger.info(LocalizedMessage.create( LocalizedStrings.GemFireCacheImpl_MEMCACHED_SERVER_ON_PORT_0_IS_SHUTTING_DOWN, - new Object[] {this.system.getConfig().getMemcachedPort()})); + new Object[]{this.system.getConfig().getMemcachedPort()})); this.memcachedServer.shutdown(); } } private void stopRedisServer() { - if (redisServer != null) - this.redisServer.shutdown(); + getService(GeodeRedisService.class).stop(); } private void stopRestAgentServer() { if (this.restAgent != null) { logger.info(LocalizedMessage.create( LocalizedStrings.GemFireCacheImpl_REST_SERVER_ON_PORT_0_IS_SHUTTING_DOWN, - new Object[] {this.system.getConfig().getHttpServicePort()})); + new Object[]{this.system.getConfig().getHttpServicePort()})); this.restAgent.stop(); } } @@ -2554,7 +2562,7 @@ public class GemFireCacheImpl } /** - * Used to guard access to compactorPool and set to true when cache is shutdown. + * Used to guard access to compactorPool and set to true when cache is stop. */ private final AtomicBoolean diskStoreTaskSync = new AtomicBoolean(false); /** @@ -2594,8 +2602,9 @@ public class GemFireCacheImpl this.diskStores.remove(dsi.getName()); this.regionOwnedDiskStores.remove(dsi.getName()); /** Added for M&M **/ - if (!dsi.getOwnedByRegion()) + if (!dsi.getOwnedByRegion()) { system.handleResourceEvent(ResourceEvent.DISKSTORE_REMOVE, dsi); + } } public void addRegionOwnedDiskStore(DiskStoreImpl dsi) { @@ -2659,7 +2668,6 @@ public class GemFireCacheImpl /** * Returns the DiskStore by name - * * @since GemFire prPersistSprint2 */ public DiskStore findDiskStore(String name) { @@ -2671,7 +2679,6 @@ public class GemFireCacheImpl /** * Returns the DiskStore list - * * @since GemFire prPersistSprint2 */ public Collection<DiskStoreImpl> listDiskStores() { @@ -2700,7 +2707,7 @@ public class GemFireCacheImpl return true; } catch (RejectedExecutionException ex) { if (logger.isDebugEnabled()) { - logger.debug("Ignored compact schedule during shutdown", ex); + logger.debug("Ignored compact schedule during stop", ex); } } } @@ -2870,7 +2877,6 @@ public class GemFireCacheImpl /** * Returns the member id of my distributed system - * * @since GemFire 5.0 */ public InternalDistributedMember getMyId() { @@ -2963,7 +2969,6 @@ public class GemFireCacheImpl /** * get the threadid/sequenceid sweeper task for this cache - * * @return the sweeper task */ protected EventTracker.ExpiryTask getEventTrackerTask() { @@ -2980,7 +2985,6 @@ public class GemFireCacheImpl /** * Get the list of all instances of properties for Declarables with the given class name. - * * @param className Class name of the declarable * @return List of all instances of properties found for the given declarable */ @@ -2998,7 +3002,6 @@ public class GemFireCacheImpl /** * Get the properties for the given declarable. - * * @param declarable The declarable * @return Properties found for the given declarable */ @@ -3008,7 +3011,6 @@ public class GemFireCacheImpl /** * Returns the date and time that this cache was created. - * * @since GemFire 3.5 */ public Date getCreationDate() { @@ -3017,7 +3019,6 @@ public class GemFireCacheImpl /** * Returns the number of seconds that have elapsed since the Cache was created. - * * @since GemFire 3.5 */ public int getUpTime() { @@ -3028,7 +3029,6 @@ public class GemFireCacheImpl * All entry and region operations should be using this time rather than * System.currentTimeMillis(). Specially all version stamps/tags must be populated with this * timestamp. - * * @return distributed cache time. */ @Override @@ -3127,7 +3127,6 @@ public class GemFireCacheImpl /** * Used to see if a existing cache's pool is compatible with us. - * * @return the default pool that is right for us */ public Pool determineDefaultPool(PoolFactory pf) { @@ -3211,7 +3210,7 @@ public class GemFireCacheImpl } public <K, V> Region<K, V> createVMRegion(String name, RegionAttributes<K, V> p_attrs, - InternalRegionArguments internalRegionArgs) + InternalRegionArguments internalRegionArgs) throws RegionExistsException, TimeoutException, IOException, ClassNotFoundException { if (getMyId().getVmKind() == DistributionManager.LOCATOR_DM_TYPE) { if (!internalRegionArgs.isUsedForMetaRegion() @@ -3240,7 +3239,7 @@ public class GemFireCacheImpl final String regionPath = LocalRegion.calcFullPath(name, null); try { - for (;;) { + for (; ; ) { getCancelCriterion().checkCancelInProgress(null); Future future = null; @@ -3297,8 +3296,9 @@ public class GemFireCacheImpl } catch (CancellationException e) { // future was cancelled } finally { - if (interrupted) + if (interrupted) { Thread.currentThread().interrupt(); + } } } // for @@ -3349,8 +3349,6 @@ public class GemFireCacheImpl } // success } - - rgn.postCreateRegion(); } catch (RegionExistsException ex) { // outside of sync make sure region is initialized to fix bug 37563 @@ -3371,7 +3369,8 @@ public class GemFireCacheImpl } public RegionAttributes invokeRegionBefore(LocalRegion parent, String name, - RegionAttributes attrs, InternalRegionArguments internalRegionArgs) { + RegionAttributes attrs, + InternalRegionArguments internalRegionArgs) { for (RegionListener listener : regionListeners) { attrs = listener.beforeCreate(parent, name, attrs, internalRegionArgs); } @@ -3390,7 +3389,6 @@ public class GemFireCacheImpl /** * returns a set of all current regions in the cache, including buckets - * * @since GemFire 6.0 */ public Set<LocalRegion> getAllRegions() { @@ -3483,8 +3481,9 @@ public class GemFireCacheImpl LocalRegion root; synchronized (this.rootRegions) { root = (LocalRegion) this.rootRegions.get(pathParts[0]); - if (root == null) + if (root == null) { return null; + } } if (logger.isDebugEnabled()) { logger.debug("GemFireCache.getRegion, calling getSubregion on root({}): {}", pathParts[0], @@ -3587,7 +3586,9 @@ public class GemFireCacheImpl } } - /** Return true if this region is initializing */ + /** + * Return true if this region is initializing + */ boolean isGlobalRegionInitializing(String fullPath) { stopper.checkCancelInProgress(null); int oldLevel = LocalRegion.setThreadInitLevelRequirement(LocalRegion.ANY_INIT); // go through @@ -3600,7 +3601,9 @@ public class GemFireCacheImpl } } - /** Return true if this region is initializing */ + /** + * Return true if this region is initializing + */ boolean isGlobalRegionInitializing(LocalRegion region) { boolean result = region != null && region.scope.isGlobal() && !region.isInitialized(); if (result) { @@ -3623,19 +3626,19 @@ public class GemFireCacheImpl stopper.checkCancelInProgress(null); Set regions = new HashSet(); synchronized (this.rootRegions) { - for (Iterator itr = this.rootRegions.values().iterator(); itr.hasNext();) { + for (Iterator itr = this.rootRegions.values().iterator(); itr.hasNext(); ) { LocalRegion r = (LocalRegion) itr.next(); // If this is an internal meta-region, don't return it to end user if (r.isSecret() || r.isUsedForMetaRegion() || r instanceof HARegion || !includePRAdminRegions - && (r.isUsedForPartitionedRegionAdmin() || r.isUsedForPartitionedRegionBucket())) { + && (r.isUsedForPartitionedRegionAdmin() || r.isUsedForPartitionedRegionBucket())) { continue; // Skip administrative PartitionedRegions } regions.add(r); } } if (waitForInit) { - for (Iterator r = regions.iterator(); r.hasNext();) { + for (Iterator r = regions.iterator(); r.hasNext(); ) { LocalRegion lr = (LocalRegion) r.next(); // lr.waitOnInitialization(); if (!lr.checkForInitialization()) { @@ -3648,13 +3651,13 @@ public class GemFireCacheImpl /** * Called by ccn when a client goes away - * * @since GemFire 5.7 */ public void cleanupForClient(CacheClientNotifier ccn, ClientProxyMembershipID client) { try { - if (isClosed()) + if (isClosed()) { return; + } Iterator it = rootRegions(false, false).iterator(); while (it.hasNext()) { LocalRegion lr = (LocalRegion) it.next(); @@ -3757,7 +3760,6 @@ public class GemFireCacheImpl /** * Register the specified region name as reinitializing, creating and adding a Future for it to * the map. - * * @throws IllegalStateException if there is already a region by that name registered. */ void regionReinitializing(String fullPath) { @@ -3771,7 +3773,6 @@ public class GemFireCacheImpl /** * Set the reinitialized region and unregister it as reinitializing. - * * @throws IllegalStateException if there is no region by that name registered as reinitializing. */ void regionReinitialized(Region region) { @@ -3788,11 +3789,11 @@ public class GemFireCacheImpl /** * Clear a reinitializing region, e.g. reinitialization failed. - * * @throws IllegalStateException if cannot find reinitializing region registered by that name. */ void unregisterReinitializingRegion(String fullPath) { - /* Object previous = */this.reinitializingRegions.remove(fullPath); + /* Object previous = */ + this.reinitializingRegions.remove(fullPath); // if (previous == null) { // throw new IllegalStateException("Could not find a reinitializing region // named " + @@ -3804,7 +3805,6 @@ public class GemFireCacheImpl /** * Returns true if get should give a copy; false if a reference. - * * @since GemFire 4.0 */ final boolean isCopyOnRead() { @@ -3813,7 +3813,6 @@ public class GemFireCacheImpl /** * Implementation of {@link org.apache.geode.cache.Cache#setCopyOnRead} - * * @since GemFire 4.0 */ public void setCopyOnRead(boolean copyOnRead) { @@ -3822,7 +3821,6 @@ public class GemFireCacheImpl /** * Implementation of {@link org.apache.geode.cache.Cache#getCopyOnRead} - * * @since GemFire 4.0 */ final public boolean getCopyOnRead() { @@ -3831,7 +3829,6 @@ public class GemFireCacheImpl /** * Remove the specified root region - * * @param rootRgn the region to be removed * @return true if root region was removed, false if not found */ @@ -3843,14 +3840,15 @@ public class GemFireCacheImpl LocalRegion previous = (LocalRegion) this.rootRegions.remove(rgnName); Assert.assertTrue(previous == rootRgn); return true; - } else + } else { return false; + } } } /** * @return array of two Strings, the root name and the relative path from root If there is no - * relative path from root, then String[1] will be an empty string + * relative path from root, then String[1] will be an empty string */ static String[] parsePath(String p_path) { String path = p_path; @@ -3882,7 +3880,6 @@ public class GemFireCacheImpl /** * Removes a <code>CacheLifecycleListener</code> - * * @return Whether or not the listener was removed */ public static boolean removeCacheLifecycleListener(CacheLifecycleListener l) { @@ -3907,9 +3904,7 @@ public class GemFireCacheImpl /** * Creates the single instance of the Transation Manager for this cache. Returns the existing one * upon request. - * * @return the CacheTransactionManager instance. - * * @since GemFire 4.0 */ public CacheTransactionManager getCacheTransactionManager() { @@ -3917,8 +3912,8 @@ public class GemFireCacheImpl } /** - * @see CacheClientProxy * @guarded.By {@link #ccpTimerMutex} + * @see CacheClientProxy */ private SystemTimer ccpTimer; @@ -3929,7 +3924,6 @@ public class GemFireCacheImpl /** * Get cache-wide CacheClientProxy SystemTimer - * * @return the timer, lazily created */ public SystemTimer getCCPTimer() { @@ -3952,7 +3946,6 @@ public class GemFireCacheImpl /** * Get cache-wide ExpirationScheduler - * * @return the scheduler, lazily created */ public ExpirationScheduler getExpirationScheduler() { @@ -3966,7 +3959,6 @@ public class GemFireCacheImpl /** * Returns the <code>Executor</code> (thread pool) that is used to execute cache event listeners. * Returns <code>null</code> if no pool exists. - * * @since GemFire 3.5 */ Executor getEventThreadPool() { @@ -4083,7 +4075,6 @@ public class GemFireCacheImpl /** * Returns List of GatewaySender (excluding the senders for internal use) - * * @return List List of GatewaySender objects */ public Set<GatewaySender> getGatewaySenders() { @@ -4098,7 +4089,6 @@ public class GemFireCacheImpl /** * Returns List of all GatewaySenders (including the senders for internal use) - * * @return List List of GatewaySender objects */ public Set<GatewaySender> getAllGatewaySenders() { @@ -4190,7 +4180,7 @@ public class GemFireCacheImpl */ public void requiresPREvents() { synchronized (this.partitionedRegions) { - for (Iterator it = this.partitionedRegions.iterator(); it.hasNext();) { + for (Iterator it = this.partitionedRegions.iterator(); it.hasNext(); ) { ((PartitionedRegion) it.next()).cacheRequiresNotification(); } } @@ -4291,7 +4281,7 @@ public class GemFireCacheImpl } private void addColocatedChildRecursively(LinkedHashMap<String, PartitionedRegion> prMap, - PartitionedRegion pr) { + PartitionedRegion pr) { for (PartitionedRegion colocatedRegion : ColocationHelper.getColocatedChildRegions(pr)) { addColocatedChildRecursively(prMap, colocatedRegion); } @@ -4302,7 +4292,6 @@ public class GemFireCacheImpl * check to see if any cache components require notification from a partitioned region. * Notification adds to the messaging a PR must do on each put/destroy/invalidate operation and * should be kept to a minimum - * * @param r the partitioned region * @return true if the region should deliver all of its events to this cache */ @@ -4338,7 +4327,6 @@ public class GemFireCacheImpl /** * remove a partitioned region from the set of tracked instances. - * * @see #addPartitionedRegion(PartitionedRegion) */ public void removePartitionedRegion(PartitionedRegion r) { @@ -4506,7 +4494,6 @@ public class GemFireCacheImpl /** * Returns this cache's ReliableMessageQueueFactory. - * * @since GemFire 5.0 */ public ReliableMessageQueueFactory getReliableMessageQueueFactory() { @@ -4558,7 +4545,7 @@ public class GemFireCacheImpl private final ArrayList<SimpleWaiter> riWaiters = new ArrayList<SimpleWaiter>(); private TypeRegistry pdxRegistry; // never changes but is currently only - // initialized in constructor by unit tests + // initialized in constructor by unit tests /** * update stats for completion of a registerInterest operation @@ -4635,13 +4622,11 @@ public class GemFireCacheImpl /** * Wait for given sender queue to flush for given timeout. - * * @param id ID of GatewaySender or AsyncEventQueue * @param isAsyncListener true if this is for an AsyncEventQueue and false if for a GatewaySender * @param maxWaitTime maximum time to wait in seconds; zero or -ve means infinite wait - * * @return zero if maxWaitTime was not breached, -1 if queue could not be found or is closed, and - * elapsed time if timeout was breached + * elapsed time if timeout was breached */ public int waitForSenderQueueFlush(String id, boolean isAsyncListener, int maxWaitTime) { getCancelCriterion().checkCancelInProgress(null); @@ -4696,7 +4681,6 @@ public class GemFireCacheImpl /** * Returns the QueryMonitor instance based on system property MAX_QUERY_EXECUTION_TIME. - * * @since GemFire 6.0 */ public QueryMonitor getQueryMonitor() { @@ -4729,7 +4713,6 @@ public class GemFireCacheImpl maxTime = FIVE_HOURS; } - this.queryMonitor = new QueryMonitor(maxTime); final LoggingThreadGroup group = LoggingThreadGroup.createThreadGroup("QueryMonitor Thread Group", logger); @@ -4748,13 +4731,13 @@ public class GemFireCacheImpl /** * Simple class to allow waiters for register interest. Has at most one thread that ever calls * wait. - * * @since GemFire 5.7 */ private class SimpleWaiter { private boolean notified = false; - SimpleWaiter() {} + SimpleWaiter() { + } public void doWait() { synchronized (this) { @@ -5230,7 +5213,6 @@ public class GemFireCacheImpl /** * Returns true if any of the GemFire services prefers PdxInstance. And application has not * requested getObject() on the PdxInstance. - * */ public boolean getPdxReadSerializedByAnyGemFireServices() { if ((getPdxReadSerialized() || DefaultQuery.getPdxReadSerialized()) @@ -5327,7 +5309,6 @@ public class GemFireCacheImpl /** * Add to the map of declarable properties. Any properties that exactly match existing properties * for a class in the list will be discarded (no duplicate Properties allowed). - * * @param mapOfNewDeclarableProps Map of the declarable properties to add */ public void addDeclarableProperties(final Map<Declarable, Properties> mapOfNewDeclarableProps) { @@ -5341,7 +5322,7 @@ public class GemFireCacheImpl if (clazz.getName().equals(oldEntry.getKey().getClass().getName()) && (newEntry.getValue() .equals(oldEntry.getValue()) || ((newEntry.getKey() instanceof Identifiable) && (((Identifiable) oldEntry.getKey()) - .getId().equals(((Identifiable) newEntry.getKey()).getId()))))) { + .getId().equals(((Identifiable) newEntry.getKey()).getId()))))) { matchingDeclarable = oldEntry.getKey(); break; } http://git-wip-us.apache.org/repos/asf/geode/blob/c6dbc6d4/geode-core/src/main/java/org/apache/geode/internal/hll/Bits.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/internal/hll/Bits.java b/geode-core/src/main/java/org/apache/geode/internal/hll/Bits.java deleted file mode 100755 index 595fb57..0000000 --- a/geode-core/src/main/java/org/apache/geode/internal/hll/Bits.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright (C) 2011 Clearspring Technologies, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License - * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express - * or implied. See the License for the specific language governing permissions and limitations under - * the License. - */ -package org.apache.geode.internal.hll; - -import java.io.ByteArrayInputStream; -import java.io.DataInput; -import java.io.DataInputStream; -import java.io.IOException; - -public class Bits { - - public static int[] getBits(byte[] mBytes) throws IOException { - int bitSize = mBytes.length / 4; - int[] bits = new int[bitSize]; - DataInputStream dis = new DataInputStream(new ByteArrayInputStream(mBytes)); - for (int i = 0; i < bitSize; i++) { - bits[i] = dis.readInt(); - } - return bits; - } - - /** - * This method might be better described as "byte array to int array" or "data input to int array" - */ - public static int[] getBits(DataInput dataIn, int byteLength) throws IOException { - int bitSize = byteLength / 4; - int[] bits = new int[bitSize]; - for (int i = 0; i < bitSize; i++) { - bits[i] = dataIn.readInt(); - } - return bits; - } - -} http://git-wip-us.apache.org/repos/asf/geode/blob/c6dbc6d4/geode-core/src/main/java/org/apache/geode/internal/hll/CardinalityMergeException.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/internal/hll/CardinalityMergeException.java b/geode-core/src/main/java/org/apache/geode/internal/hll/CardinalityMergeException.java deleted file mode 100755 index 59ab095..0000000 --- a/geode-core/src/main/java/org/apache/geode/internal/hll/CardinalityMergeException.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright (C) 2011 Clearspring Technologies, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License - * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express - * or implied. See the License for the specific language governing permissions and limitations under - * the License. - */ -package org.apache.geode.internal.hll; - - - -@SuppressWarnings("serial") -public abstract class CardinalityMergeException extends Exception { - - public CardinalityMergeException(String message) { - super(message); - } -} http://git-wip-us.apache.org/repos/asf/geode/blob/c6dbc6d4/geode-core/src/main/java/org/apache/geode/internal/hll/HyperLogLog.java ---------------------------------------------------------------------- diff --git a/geode-core/src/main/java/org/apache/geode/internal/hll/HyperLogLog.java b/geode-core/src/main/java/org/apache/geode/internal/hll/HyperLogLog.java deleted file mode 100755 index 4bdf81c..0000000 --- a/geode-core/src/main/java/org/apache/geode/internal/hll/HyperLogLog.java +++ /dev/null @@ -1,336 +0,0 @@ -/* - * Copyright (C) 2012 Clearspring Technologies, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License - * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express - * or implied. See the License for the specific language governing permissions and limitations under - * the License. - */ -package org.apache.geode.internal.hll; - -import org.apache.geode.redis.internal.executor.hll.HllExecutor; - -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.DataInput; -import java.io.DataInputStream; -import java.io.DataOutput; -import java.io.DataOutputStream; -import java.io.Externalizable; -import java.io.IOException; -import java.io.ObjectInput; -import java.io.ObjectOutput; -import java.io.Serializable; - -/** - * Java implementation of HyperLogLog (HLL) algorithm from this paper: - * <p/> - * http://algo.inria.fr/flajolet/Publications/FlFuGaMe07.pdf - * <p/> - * HLL is an improved version of LogLog that is capable of estimating the cardinality of a set with - * accuracy = 1.04/sqrt(m) where m = 2^b. So we can control accuracy vs space usage by increasing or - * decreasing b. - * <p/> - * The main benefit of using HLL over LL is that it only requires 64% of the space that LL does to - * get the same accuracy. - * <p/> - * This implementation implements a single counter. If a large (millions) number of counters are - * required you may want to refer to: - * <p/> - * http://dsiutils.dsi.unimi.it/ - * <p/> - * It has a more complex implementation of HLL that supports multiple counters in a single object, - * drastically reducing the java overhead from creating a large number of objects. - * <p/> - * This implementation leveraged a javascript implementation that Yammer has been working on: - * <p/> - * https://github.com/yammer/probablyjs - * <p> - * Note that this implementation does not include the long range correction function defined in the - * original paper. Empirical evidence shows that the correction function causes more harm than good. - * </p> - * <p/> - * <p> - * Users have different motivations to use different types of hashing functions. Rather than try to - * keep up with all available hash functions and to remove the concern of causing future binary - * incompatibilities this class allows clients to offer the value in hashed int or long form. This - * way clients are free to change their hash function on their own time line. We recommend using - * Google's Guava Murmur3_128 implementation as it provides good performance and speed when high - * precision is required. In our tests the 32bit MurmurHash function included in this project is - * faster and produces better results than the 32 bit murmur3 implementation google provides. - * </p> - */ -public class HyperLogLog implements ICardinality, Serializable { - - private static final long serialVersionUID = -4661220245111112301L; - private final RegisterSet registerSet; - private final int log2m; - private final double alphaMM; - - - /** - * Create a new HyperLogLog instance using the specified standard deviation. - * - * @param rsd - the relative standard deviation for the counter. smaller values create counters - * that require more space. - */ - public HyperLogLog(double rsd) { - this(log2m(rsd)); - } - - private static int log2m(double rsd) { - return (int) (Math.log((1.106 / rsd) * (1.106 / rsd)) / Math.log(2)); - } - - /** - * Create a new HyperLogLog instance. The log2m parameter defines the accuracy of the counter. The - * larger the log2m the better the accuracy. - * <p/> - * accuracy = 1.04/sqrt(2^log2m) - * - * @param log2m - the number of bits to use as the basis for the HLL instance - */ - public HyperLogLog(int log2m) { - this(log2m, new RegisterSet(1 << log2m)); - } - - /** - * Creates a new HyperLogLog instance using the given registers. Used for unmarshalling a - * serialized instance and for merging multiple counters together. - * - * @param registerSet - the initial values for the register set - */ - @Deprecated - public HyperLogLog(int log2m, RegisterSet registerSet) { - if (log2m < 0 || log2m > 30) { - throw new IllegalArgumentException( - "log2m argument is " + log2m + " and is outside the range [0, 30]"); - } - this.registerSet = registerSet; - this.log2m = log2m; - int m = 1 << this.log2m; - - alphaMM = getAlphaMM(log2m, m); - } - - @Override - public boolean offerHashed(long hashedValue) { - // j becomes the binary address determined by the first b log2m of x - // j will be between 0 and 2^log2m - final int j = (int) (hashedValue >>> (Long.SIZE - log2m)); - final int r = - Long.numberOfLeadingZeros((hashedValue << this.log2m) | (1 << (this.log2m - 1)) + 1) + 1; - return registerSet.updateIfGreater(j, r); - } - - @Override - public boolean offerHashed(int hashedValue) { - // j becomes the binary address determined by the first b log2m of x - // j will be between 0 and 2^log2m - final int j = hashedValue >>> (Integer.SIZE - log2m); - final int r = - Integer.numberOfLeadingZeros((hashedValue << this.log2m) | (1 << (this.log2m - 1)) + 1) + 1; - return registerSet.updateIfGreater(j, r); - } - - @Override - public boolean offer(Object o) { - final int x = MurmurHash.hash(o); - return offerHashed(x); - } - - - @Override - public long cardinality() { - double registerSum = 0; - int count = registerSet.count; - double zeros = 0.0; - for (int j = 0; j < registerSet.count; j++) { - int val = registerSet.get(j); - registerSum += 1.0 / (1 << val); - if (val == 0) { - zeros++; - } - } - - double estimate = alphaMM * (1 / registerSum); - - if (estimate <= (5.0 / 2.0) * count) { - // Small Range Estimate - return Math.round(linearCounting(count, zeros)); - } else { - return Math.round(estimate); - } - } - - @Override - public int sizeof() { - return registerSet.size * 4; - } - - @Override - public byte[] getBytes() throws IOException { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - DataOutput dos = new DataOutputStream(baos); - writeBytes(dos); - - return baos.toByteArray(); - } - - private void writeBytes(DataOutput serializedByteStream) throws IOException { - serializedByteStream.writeInt(log2m); - serializedByteStream.writeInt(registerSet.size * 4); - for (int x : registerSet.readOnlyBits()) { - serializedByteStream.writeInt(x); - } - } - - /** - * Add all the elements of the other set to this set. - * <p/> - * This operation does not imply a loss of precision. - * - * @param other A compatible Hyperloglog instance (same log2m) - * @throws CardinalityMergeException if other is not compatible - */ - public void addAll(HyperLogLog other) throws CardinalityMergeException { - if (this.sizeof() != other.sizeof()) { - throw new HyperLogLogMergeException("Cannot merge estimators of different sizes"); - } - - registerSet.merge(other.registerSet); - } - - @Override - public ICardinality merge(ICardinality... estimators) throws CardinalityMergeException { - HyperLogLog merged = new HyperLogLog(HllExecutor.DEFAULT_HLL_STD_DEV);// new HyperLogLog(log2m, - // new - // RegisterSet(this.registerSet.count)); - merged.addAll(this); - - if (estimators == null) { - return merged; - } - - for (ICardinality estimator : estimators) { - if (!(estimator instanceof HyperLogLog)) { - throw new HyperLogLogMergeException("Cannot merge estimators of different class"); - } - HyperLogLog hll = (HyperLogLog) estimator; - merged.addAll(hll); - } - - return merged; - } - - private Object writeReplace() { - return new SerializationHolder(this); - } - - /** - * This class exists to support Externalizable semantics for HyperLogLog objects without having to - * expose a public constructor, public write/read methods, or pretend final fields aren't final. - * - * In short, Externalizable allows you to skip some of the more verbose meta-data default - * Serializable gets you, but still includes the class name. In that sense, there is some cost to - * this holder object because it has a longer class name. I imagine people who care about - * optimizing for that have their own work-around for long class names in general, or just use a - * custom serialization framework. Therefore we make no attempt to optimize that here (eg. by - * raising this from an inner class and giving it an unhelpful name). - */ - private static class SerializationHolder implements Externalizable { - - HyperLogLog hyperLogLogHolder; - - public SerializationHolder(HyperLogLog hyperLogLogHolder) { - this.hyperLogLogHolder = hyperLogLogHolder; - } - - /** - * required for Externalizable - */ - @SuppressWarnings("unused") - public SerializationHolder() { - - } - - @Override - public void writeExternal(ObjectOutput out) throws IOException { - hyperLogLogHolder.writeBytes(out); - } - - @Override - public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { - hyperLogLogHolder = Builder.build(in); - } - - private Object readResolve() { - return hyperLogLogHolder; - } - } - - public static class Builder implements IBuilder<ICardinality>, Serializable { - - private static final long serialVersionUID = -979314356097156719L; - private double rsd; - - public Builder(double rsd) { - this.rsd = rsd; - } - - @Override - public HyperLogLog build() { - return new HyperLogLog(rsd); - } - - @Override - public int sizeof() { - int log2m = log2m(rsd); - int k = 1 << log2m; - return RegisterSet.getBits(k) * 4; - } - - public static HyperLogLog build(byte[] bytes) throws IOException { - ByteArrayInputStream bais = new ByteArrayInputStream(bytes); - return build(new DataInputStream(bais)); - } - - public static HyperLogLog build(DataInput serializedByteStream) throws IOException { - int log2m = serializedByteStream.readInt(); - int byteArraySize = serializedByteStream.readInt(); - return new HyperLogLog(log2m, - new RegisterSet(1 << log2m, Bits.getBits(serializedByteStream, byteArraySize))); - } - } - - @SuppressWarnings("serial") - protected static class HyperLogLogMergeException extends CardinalityMergeException { - - public HyperLogLogMergeException(String message) { - super(message); - } - } - - protected static double getAlphaMM(final int p, final int m) { - // See the paper. - switch (p) { - case 4: - return 0.673 * m * m; - case 5: - return 0.697 * m * m; - case 6: - return 0.709 * m * m; - default: - return (0.7213 / (1 + 1.079 / m)) * m * m; - } - } - - protected static double linearCounting(int m, double V) { - return m * Math.log(m / V); - } -}
