fixed issue #726 , 多线程解析binlog DML事件,提升性能

This commit is contained in:
七锋
2018-07-04 23:37:20 +08:00
parent f0bed4c762
commit da8bf59d5b
24 changed files with 880 additions and 107 deletions

View File

@@ -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;
}
}

View File

@@ -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 {
}
}
}

View File

@@ -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();