diff --git a/redisson/src/main/java/org/redisson/api/LocalCachedMapOptions.java b/redisson/src/main/java/org/redisson/api/LocalCachedMapOptions.java index 6227b04e6..34a6a2f1e 100644 --- a/redisson/src/main/java/org/redisson/api/LocalCachedMapOptions.java +++ b/redisson/src/main/java/org/redisson/api/LocalCachedMapOptions.java @@ -76,22 +76,6 @@ public class LocalCachedMapOptions extends MapOptions { } - /** - * Use {@link #syncStrategy(SyncStrategy)} and/or {@link #reconnectionStrategy(ReconnectionStrategy)} instead - * - */ - @Deprecated - public enum InvalidationPolicy { - - NONE, - - ON_CHANGE, - - ON_CHANGE_WITH_CLEAR_ON_RECONNECT, - - ON_CHANGE_WITH_LOAD_ON_RECONNECT - } - public enum EvictionPolicy { /** @@ -219,41 +203,6 @@ public class LocalCachedMapOptions extends MapOptions { return this; } - /* - * Use {@link #syncStrategy(SyncStrategy)} and/or {@link #reconnectionStrategy(ReconnectionStrategy)} instead - * - */ - @Deprecated - public LocalCachedMapOptions invalidationPolicy(InvalidationPolicy invalidationPolicy) { - if (invalidationPolicy == InvalidationPolicy.NONE) { - this.syncStrategy = SyncStrategy.NONE; - } - if (invalidationPolicy == InvalidationPolicy.ON_CHANGE) { - this.syncStrategy = SyncStrategy.INVALIDATE; - } - if (invalidationPolicy == InvalidationPolicy.ON_CHANGE_WITH_CLEAR_ON_RECONNECT) { - this.syncStrategy = SyncStrategy.INVALIDATE; - this.reconnectionStrategy = ReconnectionStrategy.CLEAR; - } - if (invalidationPolicy == InvalidationPolicy.ON_CHANGE_WITH_LOAD_ON_RECONNECT) { - this.syncStrategy = SyncStrategy.INVALIDATE; - this.reconnectionStrategy = ReconnectionStrategy.LOAD; - } - return this; - } - - /* - * Use {@link #syncStrategy(SyncStrategy)} and/or {@link #reconnectionStrategy(ReconnectionStrategy)} instead - * - */ - @Deprecated - public LocalCachedMapOptions invalidateEntryOnChange(boolean value) { - if (value) { - return invalidationPolicy(InvalidationPolicy.ON_CHANGE); - } - return invalidationPolicy(InvalidationPolicy.NONE); - } - /** * Sets eviction policy. * diff --git a/redisson/src/main/java/org/redisson/config/Config.java b/redisson/src/main/java/org/redisson/config/Config.java index cdf70bd70..698805ea8 100644 --- a/redisson/src/main/java/org/redisson/config/Config.java +++ b/redisson/src/main/java/org/redisson/config/Config.java @@ -25,12 +25,10 @@ import java.util.concurrent.ExecutorService; import org.redisson.client.codec.Codec; import org.redisson.codec.DefaultReferenceCodecProvider; import org.redisson.codec.FstCodec; -import org.redisson.codec.JsonJacksonCodec; import org.redisson.codec.ReferenceCodecProvider; +import org.redisson.connection.AddressResolverGroupFactory; import org.redisson.connection.ConnectionManager; -import org.redisson.connection.DnsAddressResolverGroupFactory; import org.redisson.connection.MultiDnsAddressResolverGroupFactory; -import org.redisson.connection.AddressResolverGroupFactory; import org.redisson.connection.ReplicatedConnectionManager; import org.redisson.misc.URIBuilder; @@ -52,8 +50,6 @@ public class Config { private ClusterServersConfig clusterServersConfig; - private ElasticacheServersConfig elasticacheServersConfig; - private ReplicatedServersConfig replicatedServersConfig; private ConnectionManager connectionManager; @@ -138,9 +134,6 @@ public class Config { if (oldConf.getClusterServersConfig() != null) { setClusterServersConfig(new ClusterServersConfig(oldConf.getClusterServersConfig())); } - if (oldConf.getElasticacheServersConfig() != null) { - setElasticacheServersConfig(new ElasticacheServersConfig(oldConf.getElasticacheServersConfig())); - } if (oldConf.getReplicatedServersConfig() != null) { setReplicatedServersConfig(new ReplicatedServersConfig(oldConf.getReplicatedServersConfig())); } @@ -224,7 +217,6 @@ public class Config { checkMasterSlaveServersConfig(); checkSentinelServersConfig(); checkSingleServerConfig(); - checkElasticacheServersConfig(); checkReplicatedServersConfig(); if (clusterServersConfig == null) { @@ -241,37 +233,6 @@ public class Config { this.clusterServersConfig = clusterServersConfig; } - /** - * - * Use {@link #useReplicatedServers()} - * - * @return config object - */ - @Deprecated - public ElasticacheServersConfig useElasticacheServers() { - return useElasticacheServers(new ElasticacheServersConfig()); - } - - ElasticacheServersConfig useElasticacheServers(ElasticacheServersConfig config) { - checkClusterServersConfig(); - checkMasterSlaveServersConfig(); - checkSentinelServersConfig(); - checkSingleServerConfig(); - - if (elasticacheServersConfig == null) { - elasticacheServersConfig = new ElasticacheServersConfig(); - } - return elasticacheServersConfig; - } - - ElasticacheServersConfig getElasticacheServersConfig() { - return elasticacheServersConfig; - } - - void setElasticacheServersConfig(ElasticacheServersConfig elasticacheServersConfig) { - this.elasticacheServersConfig = elasticacheServersConfig; - } - /** * Init Replicated servers configuration. * Most used with Azure Redis Cache or AWS Elasticache @@ -287,7 +248,6 @@ public class Config { checkMasterSlaveServersConfig(); checkSentinelServersConfig(); checkSingleServerConfig(); - checkElasticacheServersConfig(); if (replicatedServersConfig == null) { replicatedServersConfig = new ReplicatedServersConfig(); @@ -338,7 +298,6 @@ public class Config { checkClusterServersConfig(); checkMasterSlaveServersConfig(); checkSentinelServersConfig(); - checkElasticacheServersConfig(); checkReplicatedServersConfig(); if (singleServerConfig == null) { @@ -368,7 +327,6 @@ public class Config { checkClusterServersConfig(); checkSingleServerConfig(); checkMasterSlaveServersConfig(); - checkElasticacheServersConfig(); checkReplicatedServersConfig(); if (this.sentinelServersConfig == null) { @@ -398,7 +356,6 @@ public class Config { checkClusterServersConfig(); checkSingleServerConfig(); checkSentinelServersConfig(); - checkElasticacheServersConfig(); checkReplicatedServersConfig(); if (masterSlaveServersConfig == null) { @@ -468,12 +425,6 @@ public class Config { } } - private void checkElasticacheServersConfig() { - if (elasticacheServersConfig != null) { - throw new IllegalStateException("elasticache replication group servers config already used!"); - } - } - private void checkReplicatedServersConfig() { if (replicatedServersConfig != null) { throw new IllegalStateException("Replication servers config already used!"); diff --git a/redisson/src/main/java/org/redisson/config/ConfigSupport.java b/redisson/src/main/java/org/redisson/config/ConfigSupport.java index c6eb09310..64ce5eca0 100644 --- a/redisson/src/main/java/org/redisson/config/ConfigSupport.java +++ b/redisson/src/main/java/org/redisson/config/ConfigSupport.java @@ -16,13 +16,19 @@ package org.redisson.config; import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileReader; import java.io.IOException; import java.io.InputStream; +import java.io.InputStreamReader; import java.io.Reader; import java.net.URI; import java.net.URL; import java.util.List; +import java.util.Scanner; import java.util.UUID; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import org.redisson.api.RedissonNodeInitializer; import org.redisson.client.codec.Codec; @@ -30,7 +36,6 @@ import org.redisson.cluster.ClusterConnectionManager; import org.redisson.codec.ReferenceCodecProvider; import org.redisson.connection.AddressResolverGroupFactory; import org.redisson.connection.ConnectionManager; -import org.redisson.connection.ElasticacheConnectionManager; import org.redisson.connection.MasterSlaveConnectionManager; import org.redisson.connection.ReplicatedConnectionManager; import org.redisson.connection.SentinelConnectionManager; @@ -111,9 +116,6 @@ public class ConfigSupport { @JsonProperty ClusterServersConfig clusterServersConfig; - @JsonProperty - ElasticacheServersConfig elasticacheServersConfig; - @JsonProperty ReplicatedServersConfig replicatedServersConfig; @@ -122,7 +124,33 @@ public class ConfigSupport { private ObjectMapper jsonMapper = createMapper(null, null); private ObjectMapper yamlMapper = createMapper(new YAMLFactory(), null); + private String resolveEnvParams(Readable in) { + Scanner s = new Scanner(in).useDelimiter("\\A"); + try { + if (s.hasNext()) { + return resolveEnvParams(s.next()); + } + return ""; + } finally { + s.close(); + } + } + + private String resolveEnvParams(String content) { + Pattern pattern = Pattern.compile("\\$\\{(\\w+)\\}"); + Matcher m = pattern.matcher(content); + while (m.find()) { + String s = m.group(1); + String v = System.getenv(s); + if (v != null) { + content = content.replace(m.group(), v); + } + } + return content; + } + public T fromJSON(String content, Class configType) throws IOException { + content = resolveEnvParams(content); return jsonMapper.readValue(content, configType); } @@ -132,19 +160,23 @@ public class ConfigSupport { public T fromJSON(File file, Class configType, ClassLoader classLoader) throws IOException { jsonMapper = createMapper(null, classLoader); - return jsonMapper.readValue(file, configType); + String content = resolveEnvParams(new FileReader(file)); + return jsonMapper.readValue(content, configType); } public T fromJSON(URL url, Class configType) throws IOException { - return jsonMapper.readValue(url, configType); + String content = resolveEnvParams(new InputStreamReader(url.openStream())); + return jsonMapper.readValue(content, configType); } public T fromJSON(Reader reader, Class configType) throws IOException { - return jsonMapper.readValue(reader, configType); + String content = resolveEnvParams(reader); + return jsonMapper.readValue(content, configType); } public T fromJSON(InputStream inputStream, Class configType) throws IOException { - return jsonMapper.readValue(inputStream, configType); + String content = resolveEnvParams(new InputStreamReader(inputStream)); + return jsonMapper.readValue(content, configType); } public String toJSON(Config config) throws IOException { @@ -152,29 +184,33 @@ public class ConfigSupport { } public T fromYAML(String content, Class configType) throws IOException { + content = resolveEnvParams(content); return yamlMapper.readValue(content, configType); } public T fromYAML(File file, Class configType) throws IOException { - return yamlMapper.readValue(file, configType); + return fromYAML(file, configType, null); } public T fromYAML(File file, Class configType, ClassLoader classLoader) throws IOException { yamlMapper = createMapper(new YAMLFactory(), classLoader); - return yamlMapper.readValue(file, configType); + String content = resolveEnvParams(new FileReader(file)); + return yamlMapper.readValue(content, configType); } - public T fromYAML(URL url, Class configType) throws IOException { - return yamlMapper.readValue(url, configType); + String content = resolveEnvParams(new InputStreamReader(url.openStream())); + return yamlMapper.readValue(content, configType); } public T fromYAML(Reader reader, Class configType) throws IOException { - return yamlMapper.readValue(reader, configType); + String content = resolveEnvParams(reader); + return yamlMapper.readValue(content, configType); } public T fromYAML(InputStream inputStream, Class configType) throws IOException { - return yamlMapper.readValue(inputStream, configType); + String content = resolveEnvParams(new InputStreamReader(inputStream)); + return yamlMapper.readValue(content, configType); } public String toYAML(Config config) throws IOException { @@ -196,9 +232,6 @@ public class ConfigSupport { } else if (configCopy.getClusterServersConfig() != null) { validate(configCopy.getClusterServersConfig()); return new ClusterConnectionManager(configCopy.getClusterServersConfig(), configCopy, id); - } else if (configCopy.getElasticacheServersConfig() != null) { - validate(configCopy.getElasticacheServersConfig()); - return new ElasticacheConnectionManager(configCopy.getElasticacheServersConfig(), configCopy, id); } else if (configCopy.getReplicatedServersConfig() != null) { validate(configCopy.getReplicatedServersConfig()); return new ReplicatedConnectionManager(configCopy.getReplicatedServersConfig(), configCopy, id); diff --git a/redisson/src/main/java/org/redisson/config/ElasticacheServersConfig.java b/redisson/src/main/java/org/redisson/config/ElasticacheServersConfig.java deleted file mode 100644 index 18e9f6789..000000000 --- a/redisson/src/main/java/org/redisson/config/ElasticacheServersConfig.java +++ /dev/null @@ -1,31 +0,0 @@ -/** - * Copyright 2018 Nikita Koksharov - * - * 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.redisson.config; - -/** - * Use {@link org.redisson.config.ReplicatedServersConfig} - */ -@Deprecated -public class ElasticacheServersConfig extends ReplicatedServersConfig { - - public ElasticacheServersConfig() { - } - - public ElasticacheServersConfig(ReplicatedServersConfig config) { - super(config); - } - -} diff --git a/redisson/src/main/java/org/redisson/connection/ElasticacheConnectionManager.java b/redisson/src/main/java/org/redisson/connection/ElasticacheConnectionManager.java deleted file mode 100644 index 4857988d3..000000000 --- a/redisson/src/main/java/org/redisson/connection/ElasticacheConnectionManager.java +++ /dev/null @@ -1,31 +0,0 @@ -/** - * Copyright 2018 Nikita Koksharov - * - * 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.redisson.connection; - -import java.util.UUID; - -import org.redisson.config.Config; -import org.redisson.config.ElasticacheServersConfig; - -@Deprecated -public class ElasticacheConnectionManager extends ReplicatedConnectionManager { - - public ElasticacheConnectionManager(ElasticacheServersConfig cfg, Config config, UUID id) { - super(cfg, config, id); - } - -} - diff --git a/redisson/src/test/java/org/redisson/RedissonLocalCachedMapTest.java b/redisson/src/test/java/org/redisson/RedissonLocalCachedMapTest.java index 56a6d2148..118387879 100644 --- a/redisson/src/test/java/org/redisson/RedissonLocalCachedMapTest.java +++ b/redisson/src/test/java/org/redisson/RedissonLocalCachedMapTest.java @@ -94,28 +94,6 @@ public class RedissonLocalCachedMapTest extends BaseMapTest { } -// @Test - public void testPerf() { - LocalCachedMapOptions options = LocalCachedMapOptions.defaults().evictionPolicy(EvictionPolicy.NONE).cacheSize(100000).invalidateEntryOnChange(true); - Map map = redisson.getLocalCachedMap("test", options); - -// Map map = redisson.getMap("test"); - - - for (int i = 0; i < 10000; i++) { - map.put("" + i, i); - } - - long s = System.currentTimeMillis(); - for (int i = 0; i < 10; i++) { - for (int j = 0; j < 10000; j++) { - map.get("" + j); - } - } - System.out.println(System.currentTimeMillis() - s); - - } - @Override protected RMap getMap(String name) { return redisson.getLocalCachedMap(name, LocalCachedMapOptions.defaults()); diff --git a/redisson/src/test/java/org/redisson/RedissonTest.java b/redisson/src/test/java/org/redisson/RedissonTest.java index baba687f6..c947d73ab 100644 --- a/redisson/src/test/java/org/redisson/RedissonTest.java +++ b/redisson/src/test/java/org/redisson/RedissonTest.java @@ -953,15 +953,6 @@ public class RedissonTest { Thread.sleep(1500); } - @Test(expected = RedisConnectionException.class) - public void testElasticacheConnectionFail() throws InterruptedException { - Config config = new Config(); - config.useElasticacheServers().addNodeAddress("redis://127.99.0.1:1111"); - Redisson.create(config); - - Thread.sleep(1500); - } - @Test(expected = RedisConnectionException.class) public void testReplicatedConnectionFail() throws InterruptedException { Config config = new Config();