Merge branch 'master' into 3.0.0

pull/1833/head
Nikita Koksharov 6 years ago
commit cf5548279b

@ -76,22 +76,6 @@ public class LocalCachedMapOptions<K, V> extends MapOptions<K, V> {
}
/**
* 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<K, V> extends MapOptions<K, V> {
return this;
}
/*
* Use {@link #syncStrategy(SyncStrategy)} and/or {@link #reconnectionStrategy(ReconnectionStrategy)} instead
*
*/
@Deprecated
public LocalCachedMapOptions<K, V> 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<K, V> invalidateEntryOnChange(boolean value) {
if (value) {
return invalidationPolicy(InvalidationPolicy.ON_CHANGE);
}
return invalidationPolicy(InvalidationPolicy.NONE);
}
/**
* Sets eviction policy.
*

@ -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!");

@ -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> T fromJSON(String content, Class<T> configType) throws IOException {
content = resolveEnvParams(content);
return jsonMapper.readValue(content, configType);
}
@ -132,19 +160,23 @@ public class ConfigSupport {
public <T> T fromJSON(File file, Class<T> 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> T fromJSON(URL url, Class<T> configType) throws IOException {
return jsonMapper.readValue(url, configType);
String content = resolveEnvParams(new InputStreamReader(url.openStream()));
return jsonMapper.readValue(content, configType);
}
public <T> T fromJSON(Reader reader, Class<T> configType) throws IOException {
return jsonMapper.readValue(reader, configType);
String content = resolveEnvParams(reader);
return jsonMapper.readValue(content, configType);
}
public <T> T fromJSON(InputStream inputStream, Class<T> 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> T fromYAML(String content, Class<T> configType) throws IOException {
content = resolveEnvParams(content);
return yamlMapper.readValue(content, configType);
}
public <T> T fromYAML(File file, Class<T> configType) throws IOException {
return yamlMapper.readValue(file, configType);
return fromYAML(file, configType, null);
}
public <T> T fromYAML(File file, Class<T> 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> T fromYAML(URL url, Class<T> configType) throws IOException {
return yamlMapper.readValue(url, configType);
String content = resolveEnvParams(new InputStreamReader(url.openStream()));
return yamlMapper.readValue(content, configType);
}
public <T> T fromYAML(Reader reader, Class<T> configType) throws IOException {
return yamlMapper.readValue(reader, configType);
String content = resolveEnvParams(reader);
return yamlMapper.readValue(content, configType);
}
public <T> T fromYAML(InputStream inputStream, Class<T> 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);

@ -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);
}
}

@ -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);
}
}

@ -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<String, Integer> map = redisson.getLocalCachedMap("test", options);
// Map<String, Integer> 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 <K, V> RMap<K, V> getMap(String name) {
return redisson.getLocalCachedMap(name, LocalCachedMapOptions.<K, V>defaults());

@ -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();

Loading…
Cancel
Save