mirror of
https://github.com/alibaba/canal.git
synced 2026-11-04 00:30:15 +08:00
fixed issue #726 , 多线程解析binlog DML事件,提升性能
This commit is contained in:
@@ -93,6 +93,37 @@ public class BioSocketChannel implements SocketChannel {
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(byte[] data, int off, int len, int timeout) throws IOException {
|
||||
InputStream input = this.input;
|
||||
int accTimeout = 0;
|
||||
if (input == null) {
|
||||
throw new SocketException("Socket already closed.");
|
||||
}
|
||||
|
||||
int n = 0;
|
||||
while (n < len && accTimeout < timeout) {
|
||||
try {
|
||||
int read = input.read(data, off + n, len - n);
|
||||
if (read > -1) {
|
||||
n += read;
|
||||
} else {
|
||||
throw new IOException("EOF encountered.");
|
||||
}
|
||||
} catch (SocketTimeoutException te) {
|
||||
if (Thread.interrupted()) {
|
||||
throw new ClosedByInterruptException();
|
||||
}
|
||||
accTimeout += SO_TIMEOUT;
|
||||
}
|
||||
}
|
||||
|
||||
if (n < len && accTimeout >= timeout) {
|
||||
throw new SocketTimeoutException("Timeout occurred, failed to read " + len + " bytes in " + timeout
|
||||
+ " milliseconds.");
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isConnected() {
|
||||
Socket socket = this.socket;
|
||||
if (socket != null) {
|
||||
@@ -133,4 +164,5 @@ public class BioSocketChannel implements SocketChannel {
|
||||
this.socket = null;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ import io.netty.util.internal.SystemPropertyUtil;
|
||||
import java.io.IOException;
|
||||
import java.net.SocketAddress;
|
||||
|
||||
import org.apache.commons.lang.NotImplementedException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@@ -202,6 +203,11 @@ public class NettySocketChannel implements SocketChannel {
|
||||
} while (true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(byte[] data, int off, int len, int timeout) throws IOException {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public boolean isConnected() {
|
||||
return channel != null ? true : false;
|
||||
}
|
||||
@@ -224,4 +230,5 @@ public class NettySocketChannel implements SocketChannel {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -15,6 +15,8 @@ public interface SocketChannel {
|
||||
|
||||
public byte[] read(int readSize, int timeout) throws IOException;
|
||||
|
||||
public void read(byte[] data, int off, int len, int timeout) throws IOException;
|
||||
|
||||
public boolean isConnected();
|
||||
|
||||
public SocketAddress getRemoteSocketAddress();
|
||||
|
||||
Reference in New Issue
Block a user