mirror of
https://github.com/alibaba/canal.git
synced 2026-11-04 00:30:15 +08:00
fixed socket wait period 10ms
This commit is contained in:
@@ -44,7 +44,7 @@ public class MysqlConnector {
|
|||||||
private long connectionId = -1;
|
private long connectionId = -1;
|
||||||
private AtomicBoolean connected = new AtomicBoolean(false);
|
private AtomicBoolean connected = new AtomicBoolean(false);
|
||||||
|
|
||||||
public static final int timeout = 3000; // 3s
|
public static final int timeout = 5 * 1000; // 5s
|
||||||
|
|
||||||
public MysqlConnector(){
|
public MysqlConnector(){
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import java.net.SocketAddress;
|
|||||||
*/
|
*/
|
||||||
public class SocketChannel {
|
public class SocketChannel {
|
||||||
|
|
||||||
|
private static final int period = 10;
|
||||||
private Channel channel = null;
|
private Channel channel = null;
|
||||||
private Object lock = new Object();
|
private Object lock = new Object();
|
||||||
private ByteBuf cache = PooledByteBufAllocator.DEFAULT.directBuffer(1024 * 1024); // 缓存大小
|
private ByteBuf cache = PooledByteBufAllocator.DEFAULT.directBuffer(1024 * 1024); // 缓存大小
|
||||||
@@ -40,7 +41,7 @@ public class SocketChannel {
|
|||||||
cache.writeBytes(buf, Math.min(cache.writableBytes(), buf.readableBytes()));
|
cache.writeBytes(buf, Math.min(cache.writableBytes(), buf.readableBytes()));
|
||||||
} else {
|
} else {
|
||||||
// dest buffer is full.
|
// dest buffer is full.
|
||||||
lock.wait(100);
|
lock.wait(period);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -62,7 +63,7 @@ public class SocketChannel {
|
|||||||
}
|
}
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
try {
|
try {
|
||||||
wait(100);
|
wait(period);
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
throw new java.nio.channels.ClosedByInterruptException();
|
throw new java.nio.channels.ClosedByInterruptException();
|
||||||
}
|
}
|
||||||
@@ -85,14 +86,14 @@ public class SocketChannel {
|
|||||||
throw new IOException("socket has Interrupted !");
|
throw new IOException("socket has Interrupted !");
|
||||||
}
|
}
|
||||||
|
|
||||||
accumulatedWaitTime += 100;
|
accumulatedWaitTime += period;
|
||||||
if (accumulatedWaitTime > timeout) {
|
if (accumulatedWaitTime > timeout) {
|
||||||
throw new IOException("socket read timeout occured !");
|
throw new IOException("socket read timeout occured !");
|
||||||
}
|
}
|
||||||
|
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
try {
|
try {
|
||||||
wait(100);
|
wait(period);
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
throw new IOException("socket has Interrupted !");
|
throw new IOException("socket has Interrupted !");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,13 +7,12 @@ import io.netty.channel.AdaptiveRecvByteBufAllocator;
|
|||||||
import io.netty.channel.Channel;
|
import io.netty.channel.Channel;
|
||||||
import io.netty.channel.ChannelFuture;
|
import io.netty.channel.ChannelFuture;
|
||||||
import io.netty.channel.ChannelHandlerContext;
|
import io.netty.channel.ChannelHandlerContext;
|
||||||
import io.netty.channel.SimpleChannelInboundHandler;
|
|
||||||
import io.netty.channel.ChannelInitializer;
|
import io.netty.channel.ChannelInitializer;
|
||||||
import io.netty.channel.ChannelOption;
|
import io.netty.channel.ChannelOption;
|
||||||
import io.netty.channel.EventLoopGroup;
|
import io.netty.channel.EventLoopGroup;
|
||||||
|
import io.netty.channel.SimpleChannelInboundHandler;
|
||||||
import io.netty.channel.nio.NioEventLoopGroup;
|
import io.netty.channel.nio.NioEventLoopGroup;
|
||||||
import io.netty.channel.socket.nio.NioSocketChannel;
|
import io.netty.channel.socket.nio.NioSocketChannel;
|
||||||
import io.netty.util.ReferenceCountUtil;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.SocketAddress;
|
import java.net.SocketAddress;
|
||||||
|
|||||||
Reference in New Issue
Block a user