Skip to content

Commit

Permalink
Revert "ConnectionListener renamed to ServerListener"
Browse files Browse the repository at this point in the history
This reverts commit ba7d963.
  • Loading branch information
Nikita committed Dec 15, 2015
1 parent ba7d963 commit 67a3a84
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 41 deletions.
18 changes: 9 additions & 9 deletions src/main/java/org/redisson/Config.java
Expand Up @@ -17,7 +17,7 @@


import org.redisson.client.codec.Codec; import org.redisson.client.codec.Codec;
import org.redisson.codec.JsonJacksonCodec; import org.redisson.codec.JsonJacksonCodec;
import org.redisson.connection.ServerListener; import org.redisson.connection.ConnectionListener;


/** /**
* Redisson configuration * Redisson configuration
Expand Down Expand Up @@ -49,7 +49,7 @@ public class Config {


private boolean useLinuxNativeEpoll; private boolean useLinuxNativeEpoll;


private ServerListener serverListener; private ConnectionListener connectionListener;


public Config() { public Config() {
} }
Expand All @@ -62,7 +62,7 @@ public Config(Config oldConf) {
oldConf.setCodec(new JsonJacksonCodec()); oldConf.setCodec(new JsonJacksonCodec());
} }


setServerListener(oldConf.getServerListener()); setConnectionListener(oldConf.getConnectionListener());
setThreads(oldConf.getThreads()); setThreads(oldConf.getThreads());
setCodec(oldConf.getCodec()); setCodec(oldConf.getCodec());
if (oldConf.getSingleServerConfig() != null) { if (oldConf.getSingleServerConfig() != null) {
Expand Down Expand Up @@ -337,18 +337,18 @@ public boolean isUseLinuxNativeEpoll() {
return useLinuxNativeEpoll; return useLinuxNativeEpoll;
} }


public ServerListener getServerListener() { public ConnectionListener getConnectionListener() {
return serverListener; return connectionListener;
} }


/** /**
* Setup server listener which methods will be triggered * Setup connect listener which will be triggered
* on some Redisson events. * when Redisson has just been connected to or disconnected from redis server
* *
* @param connectionListener * @param connectionListener
*/ */
public Config setServerListener(ServerListener serverListener) { public Config setConnectionListener(ConnectionListener connectionListener) {
this.serverListener = serverListener; this.connectionListener = connectionListener;
return this; return this;
} }


Expand Down
Expand Up @@ -20,36 +20,36 @@


import io.netty.util.internal.PlatformDependent; import io.netty.util.internal.PlatformDependent;


public class ServerEventsHub { public class ConnectionEventsHub {


public enum Status {CONNECTED, DISCONNECTED}; public enum Status {CONNECTED, DISCONNECTED};


private final ConcurrentMap<InetSocketAddress, Status> statusMap = PlatformDependent.newConcurrentHashMap(); private final ConcurrentMap<InetSocketAddress, Status> maps = PlatformDependent.newConcurrentHashMap();


private final ServerListener serverListener; private final ConnectionListener connectionListener;


public ServerEventsHub(ServerListener connectionListener) { public ConnectionEventsHub(ConnectionListener connectionListener) {
this.serverListener = connectionListener; this.connectionListener = connectionListener;
} }


public void fireConnect(InetSocketAddress addr) { public void fireConnect(InetSocketAddress addr) {
if (serverListener == null || statusMap.get(addr) == Status.CONNECTED) { if (connectionListener == null || maps.get(addr) == Status.CONNECTED) {
return; return;
} }


if (statusMap.putIfAbsent(addr, Status.CONNECTED) == null if (maps.putIfAbsent(addr, Status.CONNECTED) == null
|| statusMap.replace(addr, Status.DISCONNECTED, Status.CONNECTED)) { || maps.replace(addr, Status.DISCONNECTED, Status.CONNECTED)) {
serverListener.onConnect(addr); connectionListener.onConnect(addr);
} }
} }


public void fireDisconnect(InetSocketAddress addr) { public void fireDisconnect(InetSocketAddress addr) {
if (serverListener == null || statusMap.get(addr) == Status.DISCONNECTED) { if (connectionListener == null || maps.get(addr) == Status.DISCONNECTED) {
return; return;
} }


if (statusMap.replace(addr, Status.CONNECTED, Status.DISCONNECTED)) { if (maps.replace(addr, Status.CONNECTED, Status.DISCONNECTED)) {
serverListener.onDisconnect(addr); connectionListener.onDisconnect(addr);
} }
} }


Expand Down
Expand Up @@ -17,23 +17,10 @@


import java.net.InetSocketAddress; import java.net.InetSocketAddress;


public interface ServerListener { public interface ConnectionListener {


/**
* This method will be triggered when Redisson
* connects to Redis server.
*
* @param addr - Redis server network address
*/
void onConnect(InetSocketAddress addr); void onConnect(InetSocketAddress addr);


/**
* This method will be triggered when Redisson
* discovers that Redis server connected before
* now in disconnected state.
*
* @param addr - Redis server network address
*/
void onDisconnect(InetSocketAddress addr); void onDisconnect(InetSocketAddress addr);


} }
Expand Up @@ -45,7 +45,7 @@
*/ */
public interface ConnectionManager { public interface ConnectionManager {


ServerEventsHub getConnectionEventsHub(); ConnectionEventsHub getConnectionEventsHub();


boolean isShutdown(); boolean isShutdown();


Expand Down
Expand Up @@ -122,7 +122,7 @@ public boolean cancel() {


private IdleConnectionWatcher connectionWatcher; private IdleConnectionWatcher connectionWatcher;


private ServerEventsHub connectionEventsHub; private ConnectionEventsHub connectionEventsHub;


public MasterSlaveConnectionManager(MasterSlaveServersConfig cfg, Config config) { public MasterSlaveConnectionManager(MasterSlaveServersConfig cfg, Config config) {
init(config); init(config);
Expand Down Expand Up @@ -198,7 +198,7 @@ protected void init(Config cfg) {
} }
this.codec = cfg.getCodec(); this.codec = cfg.getCodec();


connectionEventsHub = new ServerEventsHub(cfg.getServerListener()); connectionEventsHub = new ConnectionEventsHub(cfg.getConnectionListener());
} }


@Override @Override
Expand Down Expand Up @@ -703,7 +703,7 @@ public InfinitySemaphoreLatch getShutdownLatch() {
} }


@Override @Override
public ServerEventsHub getConnectionEventsHub() { public ConnectionEventsHub getConnectionEventsHub() {
return connectionEventsHub; return connectionEventsHub;
} }


Expand Down
4 changes: 2 additions & 2 deletions src/test/java/org/redisson/RedissonTest.java
Expand Up @@ -14,7 +14,7 @@
import org.junit.Test; import org.junit.Test;
import org.redisson.client.WriteRedisConnectionException; import org.redisson.client.WriteRedisConnectionException;
import org.redisson.codec.SerializationCodec; import org.redisson.codec.SerializationCodec;
import org.redisson.connection.ServerListener; import org.redisson.connection.ConnectionListener;
import org.redisson.core.ClusterNode; import org.redisson.core.ClusterNode;
import org.redisson.core.Node; import org.redisson.core.Node;
import org.redisson.core.NodesGroup; import org.redisson.core.NodesGroup;
Expand Down Expand Up @@ -50,7 +50,7 @@ public void testConnectionListener() throws IOException, InterruptedException, T


Config config = new Config(); Config config = new Config();
config.useSingleServer().setAddress("127.0.0.1:6319").setFailedAttempts(1).setRetryAttempts(1); config.useSingleServer().setAddress("127.0.0.1:6319").setFailedAttempts(1).setRetryAttempts(1);
config.setServerListener(new ServerListener() { config.setConnectionListener(new ConnectionListener() {


@Override @Override
public void onDisconnect(InetSocketAddress addr) { public void onDisconnect(InetSocketAddress addr) {
Expand Down

0 comments on commit 67a3a84

Please sign in to comment.