ResolverProvider removed. #1187

pull/1204/head
Nikita 7 years ago
parent e7bc7904ed
commit ecd78802b2

@ -76,7 +76,6 @@ import org.redisson.config.Config;
import org.redisson.config.ConfigSupport;
import org.redisson.connection.ConnectionManager;
import org.redisson.eviction.EvictionScheduler;
import org.redisson.liveobject.provider.ResolverProvider;
import org.redisson.misc.RedissonObjectFactory;
import org.redisson.pubsub.SemaphorePubSub;
import org.redisson.remote.ResponseEntry;
@ -103,7 +102,6 @@ public class Redisson implements RedissonClient {
protected final ConcurrentMap<Class<?>, Class<?>> liveObjectClassCache = PlatformDependent.newConcurrentHashMap();
protected final ReferenceCodecProvider codecProvider;
protected final ResolverProvider resolverProvider;
protected final Config config;
protected final SemaphorePubSub semaphorePubSub = new SemaphorePubSub();
@ -117,7 +115,6 @@ public class Redisson implements RedissonClient {
connectionManager = ConfigSupport.createConnectionManager(configCopy);
evictionScheduler = new EvictionScheduler(connectionManager.getCommandExecutor());
codecProvider = configCopy.getReferenceCodecProvider();
resolverProvider = configCopy.getResolverProvider();
}
public EvictionScheduler getEvictionScheduler() {
@ -574,7 +571,7 @@ public class Redisson implements RedissonClient {
@Override
public RLiveObjectService getLiveObjectService() {
return new RedissonLiveObjectService(this, liveObjectClassCache, codecProvider, resolverProvider);
return new RedissonLiveObjectService(this, liveObjectClassCache, codecProvider);
}
@Override
@ -598,11 +595,6 @@ public class Redisson implements RedissonClient {
return codecProvider;
}
@Override
public ResolverProvider getResolverProvider() {
return resolverProvider;
}
@Override
public NodesGroup<Node> getNodesGroup() {
return new RedisNodes<Node>(connectionManager);

@ -15,6 +15,7 @@
*/
package org.redisson;
import java.lang.annotation.Annotation;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.util.ArrayList;
@ -65,9 +66,9 @@ import org.redisson.liveobject.core.RedissonObjectBuilder;
import org.redisson.liveobject.misc.AdvBeanCopy;
import org.redisson.liveobject.misc.ClassUtils;
import org.redisson.liveobject.misc.Introspectior;
import org.redisson.liveobject.provider.ResolverProvider;
import org.redisson.liveobject.resolver.Resolver;
import io.netty.util.internal.PlatformDependent;
import jodd.bean.BeanCopy;
import jodd.bean.BeanUtil;
import net.bytebuddy.ByteBuddy;
@ -81,17 +82,16 @@ import net.bytebuddy.matcher.ElementMatchers;
public class RedissonLiveObjectService implements RLiveObjectService {
private static final ConcurrentMap<Class<? extends Resolver>, Resolver<?, ?, ?>> providerCache = PlatformDependent.newConcurrentHashMap();
private final ConcurrentMap<Class<?>, Class<?>> classCache;
private final RedissonClient redisson;
private final ReferenceCodecProvider codecProvider;
private final ResolverProvider resolverProvider;
private final RedissonObjectBuilder objectBuilder;
public RedissonLiveObjectService(RedissonClient redisson, ConcurrentMap<Class<?>, Class<?>> classCache, ReferenceCodecProvider codecProvider, ResolverProvider resolverProvider) {
public RedissonLiveObjectService(RedissonClient redisson, ConcurrentMap<Class<?>, Class<?>> classCache, ReferenceCodecProvider codecProvider) {
this.redisson = redisson;
this.classCache = classCache;
this.codecProvider = codecProvider;
this.resolverProvider = resolverProvider;
this.objectBuilder = new RedissonObjectBuilder(redisson, codecProvider);
}
@ -114,11 +114,21 @@ public class RedissonLiveObjectService implements RLiveObjectService {
String idFieldName = getRIdFieldName(entityClass);
RId annotation = ClassUtils.getDeclaredField(entityClass, idFieldName)
.getAnnotation(RId.class);
Resolver resolver = resolverProvider.getResolver(entityClass,
annotation.generator(), annotation);
Resolver resolver = getResolver(entityClass, annotation.generator(), annotation);
Object id = resolver.resolve(entityClass, annotation, idFieldName, redisson);
return id;
}
private Resolver<?, ?, ?> getResolver(Class<?> cls, Class<? extends Resolver> resolverClass, Annotation anno) {
if (!providerCache.containsKey(resolverClass)) {
try {
providerCache.putIfAbsent(resolverClass, resolverClass.newInstance());
} catch (Exception ex) {
throw new RuntimeException(ex);
}
}
return providerCache.get(resolverClass);
}
@Override
public <T, K> T get(Class<T> entityClass, K id) {

@ -20,7 +20,6 @@ import java.util.concurrent.TimeUnit;
import org.redisson.client.codec.Codec;
import org.redisson.codec.ReferenceCodecProvider;
import org.redisson.config.Config;
import org.redisson.liveobject.provider.ResolverProvider;
/**
* Main Redisson interface for access
@ -904,14 +903,6 @@ public interface RedissonClient {
*/
public ReferenceCodecProvider getCodecProvider();
/**
* Returns the ResolverProvider instance
*
* @return ResolverProvider object
*/
public ResolverProvider getResolverProvider();
/**
* Get Redis nodes group for server operations
*

@ -23,13 +23,11 @@ import java.net.URL;
import java.util.concurrent.ExecutorService;
import org.redisson.client.codec.Codec;
import org.redisson.codec.ReferenceCodecProvider;
import org.redisson.codec.DefaultReferenceCodecProvider;
import org.redisson.codec.JsonJacksonCodec;
import org.redisson.codec.ReferenceCodecProvider;
import org.redisson.connection.ConnectionManager;
import org.redisson.connection.ReplicatedConnectionManager;
import org.redisson.liveobject.provider.DefaultResolverProvider;
import org.redisson.liveobject.provider.ResolverProvider;
import io.netty.channel.EventLoopGroup;
@ -72,11 +70,6 @@ public class Config {
*/
private ReferenceCodecProvider referenceCodecProvider = new DefaultReferenceCodecProvider();
/**
* For resolver registry and look up. DefaultResolverProvider used by default
*/
private ResolverProvider resolverProvider = new DefaultResolverProvider();
private ExecutorService executor;
/**
@ -111,7 +104,6 @@ public class Config {
setThreads(oldConf.getThreads());
setCodec(oldConf.getCodec());
setReferenceCodecProvider(oldConf.getReferenceCodecProvider());
setResolverProvider(oldConf.getResolverProvider());
setReferenceEnabled(oldConf.isReferenceEnabled());
setEventLoopGroup(oldConf.getEventLoopGroup());
if (oldConf.getSingleServerConfig() != null) {
@ -177,26 +169,6 @@ public class Config {
return referenceCodecProvider;
}
/**
* For resolver registry and look up. DefaultResolverProvider used by default.
*
* @param resolverProvider object
* @return this
*/
public Config setResolverProvider(ResolverProvider resolverProvider) {
this.resolverProvider = resolverProvider;
return this;
}
/**
* Returns the ResolverProvider instance
*
* @return resolverProvider
*/
public ResolverProvider getResolverProvider() {
return resolverProvider;
}
/**
* Config option indicate whether Redisson Reference feature is enabled.
* <p>

@ -37,7 +37,6 @@ import org.redisson.connection.ReplicatedConnectionManager;
import org.redisson.connection.SentinelConnectionManager;
import org.redisson.connection.SingleConnectionManager;
import org.redisson.connection.balancer.LoadBalancer;
import org.redisson.liveobject.provider.ResolverProvider;
import com.fasterxml.jackson.annotation.JsonFilter;
import com.fasterxml.jackson.annotation.JsonIgnore;
@ -272,7 +271,6 @@ public class ConfigSupport {
mapper.addMixIn(SingleServerConfig.class, SingleSeverConfigMixIn.class);
mapper.addMixIn(Config.class, ConfigMixIn.class);
mapper.addMixIn(ReferenceCodecProvider.class, ClassMixIn.class);
mapper.addMixIn(ResolverProvider.class, ClassMixIn.class);
mapper.addMixIn(Codec.class, ClassMixIn.class);
mapper.addMixIn(RedissonNodeInitializer.class, ClassMixIn.class);
mapper.addMixIn(LoadBalancer.class, ClassMixIn.class);

@ -1,48 +0,0 @@
/**
* Copyright 2016 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.liveobject.provider;
import io.netty.util.internal.PlatformDependent;
import java.lang.annotation.Annotation;
import java.util.concurrent.ConcurrentMap;
import org.redisson.liveobject.resolver.Resolver;
/**
*
* @author Rui Gu (https://github.com/jackygurui)
*/
public class DefaultResolverProvider implements ResolverProvider {
public transient final ConcurrentMap<Class<? extends Resolver>, Resolver<?, ?, ?>> providerCache = PlatformDependent.newConcurrentHashMap();
@Override
public Resolver<?, ?, ?> getResolver(Class<?> cls, Class<? extends Resolver> resolverClass, Annotation anno) {
if (!providerCache.containsKey(resolverClass)) {
try {
providerCache.putIfAbsent(resolverClass, resolverClass.newInstance());
} catch (Exception ex) {
throw new RuntimeException(ex);
}
}
return providerCache.get(resolverClass);
}
@Override
public void registerResolver(Class<?> cls, Class<? extends Resolver> resolverClass, Resolver resolver) {
providerCache.putIfAbsent(resolverClass, resolver);
}
}

@ -1,49 +0,0 @@
/**
* Copyright 2016 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.liveobject.provider;
import java.lang.annotation.Annotation;
import org.redisson.liveobject.resolver.Resolver;
/**
*
* @author Rui Gu (https://github.com/jackygurui)
*/
public interface ResolverProvider {
/**
* To retrieve a resolver based on the the class requiring values to be
* resolved, the resolver type, and annotation which may carry any required
* configurations.
*
* @param cls the class requires value to be resolved
* @param resolverClass the resolver type
* @param anno annotation with configurations
* @return a Resolver instance
*/
Resolver<?, ?, ?> getResolver(Class<?> cls, Class<? extends Resolver> resolverClass, Annotation anno);
/**
* To register a resolver based on the the class it can provide value to,
* the resolver type, the resolver instance to be cached.
*
* @param cls object
* @param resolverClass object
* @param resolver object
*/
void registerResolver(Class<?> cls, Class<? extends Resolver> resolverClass, Resolver resolver);
}

@ -1,25 +1,31 @@
package org.redisson.spring.support;
import io.netty.channel.EventLoopGroup;
import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.notNullValue;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertThat;
import java.lang.reflect.Method;
import java.util.Map;
import java.util.concurrent.Executor;
import static org.hamcrest.Matchers.*;
import org.junit.Test;
import org.redisson.ClusterRunner;
import org.redisson.RedisRunner;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import static org.junit.Assert.*;
import org.redisson.client.RedisClient;
import org.redisson.client.RedisConnection;
import org.redisson.client.codec.Codec;
import org.redisson.client.protocol.RedisCommands;
import org.redisson.codec.ReferenceCodecProvider;
import org.redisson.config.Config;
import org.redisson.config.SingleServerConfig;
import org.redisson.liveobject.provider.ResolverProvider;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import io.netty.channel.EventLoopGroup;
/**
*
@ -118,7 +124,6 @@ public class SpringNamespaceWikiTest {
assertEquals(false, config.isUseLinuxNativeEpoll());
assertEquals(false, config.isReferenceEnabled());
assertSame(context.getBean("myCodecProvider", ReferenceCodecProvider.class), config.getReferenceCodecProvider());
assertSame(context.getBean("myResolverProvider", ResolverProvider.class), config.getResolverProvider());
assertSame(context.getBean("myExecutor", Executor.class), config.getExecutor());
assertSame(context.getBean("myEventLoopGroup", EventLoopGroup.class), config.getEventLoopGroup());
Method method = Config.class.getDeclaredMethod("getSingleServerConfig", (Class<?>[]) null);

Loading…
Cancel
Save