云服务 v8.0.9版本的 MD5 值为:547a053af090cf9044d8e9e53f35e8e3
以下内容为反编译后的 BioReadWriteProcessor.java 源代码,内容仅作参考
package com.open.net.client.impl.tcp.bio.processor;
import com.open.net.client.impl.tcp.bio.BioConnectListener;
import com.open.net.client.structures.BaseClient;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintStream;
import java.net.InetSocketAddress;
import java.net.Socket;
public class BioReadWriteProcessor {
private static int G_SOCKET_ID;
private long connect_timeout;
private BaseClient mClient;
private ConnectRunnable mConnectProcessor;
private BioConnectListener mConnectStatusListener;
private String mIp;
private int mPort;
private ReadRunnable mReadProcessor;
private int mSocketId;
private WriteRunnable mWriteProcessor;
private String TAG = "BioReadWriteProcessor";
private Socket mSocket = null;
private OutputStream mOutputStream = null;
private InputStream mInputStream = null;
private Thread mConnectThread = null;
private Thread mWriteThread = null;
private Thread mReadThread = null;
private int r_w_count = 2;
public BioReadWriteProcessor(String str, int i, long j, BaseClient baseClient, BioConnectListener bioConnectListener) {
this.mIp = "192.168.1.1";
this.mPort = 9999;
this.connect_timeout = 10000L;
int i2 = G_SOCKET_ID + 1;
G_SOCKET_ID = i2;
this.mSocketId = i2;
this.mIp = str;
this.mPort = i;
this.connect_timeout = j;
this.mClient = baseClient;
this.mConnectStatusListener = bioConnectListener;
}
public void start() {
this.mConnectProcessor = new ConnectRunnable();
Thread thread = new Thread(this.mConnectProcessor);
this.mConnectThread = thread;
thread.start();
}
public synchronized void close() {
wakeUp();
try {
try {
OutputStream outputStream = this.mOutputStream;
if (outputStream != null) {
outputStream.close();
}
} catch (Exception e) {
e.printStackTrace();
}
try {
try {
InputStream inputStream = this.mInputStream;
if (inputStream != null) {
inputStream.close();
}
} finally {
this.mInputStream = null;
}
} catch (Exception e2) {
e2.printStackTrace();
}
try {
try {
Socket socket = this.mSocket;
if (socket != null) {
socket.close();
}
} finally {
this.mSocket = null;
}
} catch (Exception e3) {
e3.printStackTrace();
}
try {
try {
Thread thread = this.mWriteThread;
if (thread != null && thread.isAlive()) {
this.mWriteThread.interrupt();
}
} catch (Exception e4) {
e4.printStackTrace();
}
try {
try {
Thread thread2 = this.mReadThread;
if (thread2 != null && thread2.isAlive()) {
this.mReadThread.interrupt();
}
} catch (Exception e5) {
e5.printStackTrace();
}
} finally {
this.mReadThread = null;
}
} finally {
this.mWriteThread = null;
}
} finally {
this.mOutputStream = null;
}
}
public void wakeUp() {
WriteRunnable writeRunnable = this.mWriteProcessor;
if (writeRunnable != null) {
writeRunnable.wakeup();
}
}
public synchronized void onSocketExit(int i) {
BioConnectListener bioConnectListener;
int i2 = this.r_w_count - 1;
this.r_w_count = i2;
boolean z = i2 <= 0;
PrintStream printStream = System.out;
StringBuilder sb = new StringBuilder();
sb.append(this.TAG);
sb.append("onSocketExit mSocketId ");
sb.append(this.mSocketId);
sb.append(" exit_code ");
sb.append(i);
sb.append(i == 1 ? " onWrite" : " onRead");
sb.append(" isWriterReaderExit ");
sb.append(z);
printStream.println(sb.toString());
close();
if (z && (bioConnectListener = this.mConnectStatusListener) != null) {
bioConnectListener.onConnectFailed(this);
}
}
private class ConnectRunnable implements Runnable {
private ConnectRunnable() {
}
@Override
public void run() {
boolean z;
try {
BioReadWriteProcessor.this.mSocket = new Socket();
BioReadWriteProcessor.this.mSocket.connect(new InetSocketAddress(BioReadWriteProcessor.this.mIp, BioReadWriteProcessor.this.mPort), (int) BioReadWriteProcessor.this.connect_timeout);
BioReadWriteProcessor bioReadWriteProcessor = BioReadWriteProcessor.this;
bioReadWriteProcessor.mOutputStream = bioReadWriteProcessor.mSocket.getOutputStream();
BioReadWriteProcessor bioReadWriteProcessor2 = BioReadWriteProcessor.this;
bioReadWriteProcessor2.mInputStream = bioReadWriteProcessor2.mSocket.getInputStream();
BioReadWriteProcessor bioReadWriteProcessor3 = BioReadWriteProcessor.this;
bioReadWriteProcessor3.mWriteProcessor = new WriteRunnable();
BioReadWriteProcessor bioReadWriteProcessor4 = BioReadWriteProcessor.this;
bioReadWriteProcessor4.mReadProcessor = new ReadRunnable();
BioReadWriteProcessor.this.mWriteThread = new Thread(BioReadWriteProcessor.this.mWriteProcessor);
BioReadWriteProcessor.this.mReadThread = new Thread(BioReadWriteProcessor.this.mReadProcessor);
BioReadWriteProcessor.this.mWriteThread.start();
BioReadWriteProcessor.this.mReadThread.start();
if (BioReadWriteProcessor.this.mConnectStatusListener != null) {
BioConnectListener bioConnectListener = BioReadWriteProcessor.this.mConnectStatusListener;
BioReadWriteProcessor bioReadWriteProcessor5 = BioReadWriteProcessor.this;
bioConnectListener.onConnectSuccess(bioReadWriteProcessor5, bioReadWriteProcessor5.mOutputStream, BioReadWriteProcessor.this.mInputStream);
}
z = true;
} catch (Exception e) {
e.printStackTrace();
z = false;
}
if (z || BioReadWriteProcessor.this.mConnectStatusListener == null) {
return;
}
BioReadWriteProcessor.this.mConnectStatusListener.onConnectFailed(BioReadWriteProcessor.this);
}
}
public class WriteRunnable implements Runnable {
private final Object lock;
private WriteRunnable() {
this.lock = new Object();
}
public void wakeup() {
synchronized (this.lock) {
this.lock.notifyAll();
}
}
@Override
public void run() {
while (BioReadWriteProcessor.this.mClient.onWrite()) {
try {
synchronized (this.lock) {
this.lock.wait();
}
} catch (Exception e) {
e.printStackTrace();
}
}
BioReadWriteProcessor.this.onSocketExit(1);
}
}
private class ReadRunnable implements Runnable {
private ReadRunnable() {
}
@Override
public void run() {
BioReadWriteProcessor.this.mClient.onRead();
BioReadWriteProcessor.this.onSocketExit(2);
}
}
}