-
Notifications
You must be signed in to change notification settings - Fork 987
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reduced test load, fix for sync connect, changed shutdown order
- Loading branch information
Showing
2 changed files
with
41 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,11 @@ | ||
package com.lambdaworks.redis; | ||
|
||
import java.io.Closeable; | ||
import java.net.SocketAddress; | ||
import java.util.Set; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
import com.google.common.base.Supplier; | ||
import com.google.common.collect.ImmutableList; | ||
import com.lambdaworks.redis.internal.ChannelGroupListener; | ||
import com.lambdaworks.redis.protocol.CommandHandler; | ||
import com.lambdaworks.redis.protocol.ConnectionWatchdog; | ||
import com.lambdaworks.redis.pubsub.PubSubCommandHandler; | ||
|
||
import io.netty.bootstrap.Bootstrap; | ||
import io.netty.channel.Channel; | ||
import io.netty.channel.ChannelInitializer; | ||
|
@@ -24,18 +18,25 @@ | |
import io.netty.channel.nio.NioEventLoopGroup; | ||
import io.netty.channel.socket.nio.NioSocketChannel; | ||
import io.netty.util.HashedWheelTimer; | ||
import io.netty.util.concurrent.Future; | ||
import io.netty.util.concurrent.GlobalEventExecutor; | ||
import io.netty.util.internal.ConcurrentSet; | ||
import io.netty.util.internal.logging.InternalLogger; | ||
import io.netty.util.internal.logging.InternalLoggerFactory; | ||
|
||
import java.io.Closeable; | ||
import java.net.SocketAddress; | ||
import java.util.Set; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
/** | ||
* @author <a href="mailto:[email protected]">Mark Paluch</a> | ||
* @since 26.05.14 17:28 | ||
*/ | ||
public abstract class AbstractRedisClient { | ||
protected static final InternalLogger logger = InternalLoggerFactory.getInstance(RedisClient.class); | ||
protected EventLoopGroup group; | ||
|
||
protected HashedWheelTimer timer; | ||
protected ChannelGroup channels; | ||
protected long timeout; | ||
|
@@ -89,7 +90,7 @@ protected void initChannel(Channel ch) throws Exception { | |
} | ||
}); | ||
|
||
redisBootstrap.connect(redisAddress).sync(); | ||
redisBootstrap.connect(redisAddress).get(); | ||
|
||
connection.addListener(new CloseEvents.CloseListener() { | ||
@Override | ||
|
@@ -100,7 +101,7 @@ public void resourceClosed(Object resource) { | |
closeableResources.add(connection); | ||
|
||
return connection; | ||
} catch (Throwable e) { | ||
} catch (Exception e) { | ||
throw new RedisException("Unable to connect", e); | ||
} | ||
} | ||
|
@@ -133,9 +134,14 @@ public void shutdown() { | |
psCommandHandler.close(); | ||
} | ||
} | ||
ChannelGroupFuture future = channels.close(); | ||
future.awaitUninterruptibly(); | ||
group.shutdownGracefully().syncUninterruptibly(); | ||
ChannelGroupFuture closeFuture = channels.close(); | ||
Future<?> groupCloseFuture = group.shutdownGracefully(); | ||
try { | ||
closeFuture.get(); | ||
groupCloseFuture.get(); | ||
} catch (Exception e) { | ||
throw new RedisException(e); | ||
} | ||
timer.stop(); | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters