You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-commits@jackrabbit.apache.org by fr...@apache.org on 2017/12/07 14:36:14 UTC
svn commit: r1817374 - in
/jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/standby/client:
StandbyClient.java StandbyClientSync.java
Author: frm
Date: Thu Dec 7 14:36:13 2017
New Revision: 1817374
URL: http://svn.apache.org/viewvc?rev=1817374&view=rev
Log:
OAK-7027 - Merge connect() into the StandbyClient constructor
Modified:
jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/standby/client/StandbyClient.java
jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/standby/client/StandbyClientSync.java
Modified: jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/standby/client/StandbyClient.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/standby/client/StandbyClient.java?rev=1817374&r1=1817373&r2=1817374&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/standby/client/StandbyClient.java (original)
+++ jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/standby/client/StandbyClient.java Thu Dec 7 14:36:13 2017
@@ -24,6 +24,7 @@ import java.util.concurrent.LinkedBlocki
import java.util.concurrent.TimeUnit;
import javax.annotation.Nullable;
+import javax.net.ssl.SSLException;
import io.netty.bootstrap.Bootstrap;
import io.netty.channel.Channel;
@@ -69,85 +70,65 @@ class StandbyClient implements AutoClose
private final BlockingQueue<GetReferencesResponse> referencesQueue = new LinkedBlockingDeque<>();
- private final boolean secure;
-
private final int readTimeoutMs;
private final String clientId;
- private final NioEventLoopGroup group;
-
- private final File spoolFolder;
-
private Channel channel;
- StandbyClient(NioEventLoopGroup group, String clientId, boolean secure, int readTimeoutMs, File spoolFolder) {
- this.group = group;
+ StandbyClient(String host, int port, NioEventLoopGroup group, String clientId, boolean secure, int readTimeoutMs, File spoolFolder) throws InterruptedException {
this.clientId = clientId;
- this.secure = secure;
this.readTimeoutMs = readTimeoutMs;
- this.spoolFolder = spoolFolder;
- }
-
- void connect(String host, int port) throws Exception {
-
- final SslContext sslContext;
-
- if (secure) {
- sslContext = SslContextBuilder.forClient().trustManager(InsecureTrustManagerFactory.INSTANCE).build();
- } else {
- sslContext = null;
- }
Bootstrap b = new Bootstrap()
- .group(group)
- .channel(NioSocketChannel.class)
- .option(ChannelOption.CONNECT_TIMEOUT_MILLIS, readTimeoutMs)
- .option(ChannelOption.TCP_NODELAY, true)
- .option(ChannelOption.SO_REUSEADDR, true)
- .option(ChannelOption.SO_KEEPALIVE, true)
- .handler(new ChannelInitializer<SocketChannel>() {
-
- @Override
- public void initChannel(SocketChannel ch) throws Exception {
- ChannelPipeline p = ch.pipeline();
+ .group(group)
+ .channel(NioSocketChannel.class)
+ .option(ChannelOption.CONNECT_TIMEOUT_MILLIS, readTimeoutMs)
+ .option(ChannelOption.TCP_NODELAY, true)
+ .option(ChannelOption.SO_REUSEADDR, true)
+ .option(ChannelOption.SO_KEEPALIVE, true)
+ .handler(new ChannelInitializer<SocketChannel>() {
+
+ @Override
+ public void initChannel(SocketChannel ch) throws Exception {
+ ChannelPipeline p = ch.pipeline();
- if (sslContext != null) {
- p.addLast(sslContext.newHandler(ch.alloc()));
- }
+ if (secure) {
+ p.addLast(SslContextBuilder.forClient().trustManager(InsecureTrustManagerFactory.INSTANCE).build().newHandler(ch.alloc()));
+ }
- p.addLast(new ReadTimeoutHandler(readTimeoutMs, TimeUnit.MILLISECONDS));
+ p.addLast(new ReadTimeoutHandler(readTimeoutMs, TimeUnit.MILLISECONDS));
- // Decoders
+ // Decoders
- p.addLast(new SnappyFrameDecoder(true));
+ p.addLast(new SnappyFrameDecoder(true));
- // The frame length limits the chunk size to max. 2.2GB
+ // The frame length limits the chunk size to max. 2.2GB
- p.addLast(new LengthFieldBasedFrameDecoder(Integer.MAX_VALUE, 0, 4));
- p.addLast(new ResponseDecoder(spoolFolder));
+ p.addLast(new LengthFieldBasedFrameDecoder(Integer.MAX_VALUE, 0, 4));
+ p.addLast(new ResponseDecoder(spoolFolder));
- // Encoders
+ // Encoders
- p.addLast(new StringEncoder(CharsetUtil.UTF_8));
- p.addLast(new GetHeadRequestEncoder());
- p.addLast(new GetSegmentRequestEncoder());
- p.addLast(new GetBlobRequestEncoder());
- p.addLast(new GetReferencesRequestEncoder());
+ p.addLast(new StringEncoder(CharsetUtil.UTF_8));
+ p.addLast(new GetHeadRequestEncoder());
+ p.addLast(new GetSegmentRequestEncoder());
+ p.addLast(new GetBlobRequestEncoder());
+ p.addLast(new GetReferencesRequestEncoder());
- // Handlers
+ // Handlers
- p.addLast(new GetHeadResponseHandler(headQueue));
- p.addLast(new GetSegmentResponseHandler(segmentQueue));
- p.addLast(new GetBlobResponseHandler(blobQueue));
- p.addLast(new GetReferencesResponseHandler(referencesQueue));
+ p.addLast(new GetHeadResponseHandler(headQueue));
+ p.addLast(new GetSegmentResponseHandler(segmentQueue));
+ p.addLast(new GetBlobResponseHandler(blobQueue));
+ p.addLast(new GetReferencesResponseHandler(referencesQueue));
- // Exception handler
+ // Exception handler
- p.addLast(new ExceptionHandler(clientId));
- }
+ p.addLast(new ExceptionHandler(clientId));
+ }
- });
+ });
channel = b.connect(host, port).sync().channel();
}
Modified: jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/standby/client/StandbyClientSync.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/standby/client/StandbyClientSync.java?rev=1817374&r1=1817373&r2=1817374&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/standby/client/StandbyClientSync.java (original)
+++ jackrabbit/oak/trunk/oak-segment-tar/src/main/java/org/apache/jackrabbit/oak/segment/standby/client/StandbyClientSync.java Thu Dec 7 14:36:13 2017
@@ -166,8 +166,7 @@ public final class StandbyClientSync imp
GCGeneration genBefore = headGeneration(fileStore);
- try (StandbyClient client = new StandbyClient(group, observer.getID(), secure, readTimeoutMs, spoolFolder)) {
- client.connect(host, port);
+ try (StandbyClient client = new StandbyClient(host, port, group, observer.getID(), secure, readTimeoutMs, spoolFolder)) {
execution.execute(client);
}