云服务 v8.0.9版本的 MD5 值为:547a053af090cf9044d8e9e53f35e8e3
以下内容为反编译后的 UdpBioReadWriteProcessor.java 源代码,内容仅作参考
package com.open.net.client.impl.udp.bio.processor;
import com.open.net.client.impl.udp.bio.UdpBioClient;
import com.open.net.client.impl.udp.bio.UdpBioConnectListener;
import com.open.net.client.structures.BaseClient;
import java.io.PrintStream;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.SocketException;
import java.net.UnknownHostException;
public class UdpBioReadWriteProcessor {
private static int G_SOCKET_ID;
private BaseClient mClient;
private ConnectRunnable mConnectProcessor;
private UdpBioConnectListener mConnectStatusListener;
private String mIp;
private int mPort;
private ReadRunnable mReadProcessor;
private DatagramSocket mSocket;
private int mSocketId;
private WriteRunnable mWriteProcessor;
private String TAG = "UdpBioReadWriteProcessor";
private Thread mConnectThread = null;
private Thread mWriteThread = null;
private Thread mReadThread = null;
private int r_w_count = 2;
public UdpBioReadWriteProcessor(String str, int i, BaseClient baseClient, UdpBioConnectListener udpBioConnectListener) {
this.mIp = "192.168.1.1";
this.mPort = 9999;
int i2 = G_SOCKET_ID + 1;
G_SOCKET_ID = i2;
this.mSocketId = i2;
this.mIp = str;
this.mPort = i;
this.mClient = baseClient;
this.mConnectStatusListener = udpBioConnectListener;
}
public void start() {
this.mConnectProcessor = new ConnectRunnable();
Thread thread = new Thread(this.mConnectProcessor);
this.mConnectThread = thread;
thread.start();
}
public synchronized void close() {
wakeUp();
DatagramSocket datagramSocket = this.mSocket;
if (datagramSocket != null) {
datagramSocket.close();
}
try {
try {
Thread thread = this.mConnectThread;
if (thread != null && thread.isAlive()) {
this.mConnectThread.interrupt();
}
} catch (Exception e) {
e.printStackTrace();
}
try {
try {
Thread thread2 = this.mWriteThread;
if (thread2 != null && thread2.isAlive()) {
this.mWriteThread.interrupt();
}
} catch (Exception e2) {
e2.printStackTrace();
}
try {
try {
Thread thread3 = this.mReadThread;
if (thread3 != null && thread3.isAlive()) {
this.mReadThread.interrupt();
}
} finally {
this.mReadThread = null;
}
} catch (Exception e3) {
e3.printStackTrace();
}
} finally {
this.mWriteThread = null;
}
} finally {
this.mConnectThread = null;
}
}
public void wakeUp() {
WriteRunnable writeRunnable = this.mWriteProcessor;
if (writeRunnable != null) {
writeRunnable.wakeup();
}
}
public synchronized void onSocketExit(int i) {
UdpBioConnectListener udpBioConnectListener;
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 && (udpBioConnectListener = this.mConnectStatusListener) != null) {
udpBioConnectListener.onConnectFailed(this);
}
}
private class ConnectRunnable implements Runnable {
private ConnectRunnable() {
}
@Override
public void run() {
byte[] bArr = ((UdpBioClient) UdpBioReadWriteProcessor.this.mClient).mWriteBuff;
byte[] bArr2 = ((UdpBioClient) UdpBioReadWriteProcessor.this.mClient).mReadBuff;
boolean z = false;
try {
UdpBioReadWriteProcessor.this.mSocket = new DatagramSocket();
DatagramPacket datagramPacket = new DatagramPacket(bArr, bArr.length, InetAddress.getByName(UdpBioReadWriteProcessor.this.mIp), UdpBioReadWriteProcessor.this.mPort);
DatagramPacket datagramPacket2 = new DatagramPacket(bArr2, bArr2.length);
if (UdpBioReadWriteProcessor.this.mConnectStatusListener != null) {
UdpBioConnectListener udpBioConnectListener = UdpBioReadWriteProcessor.this.mConnectStatusListener;
UdpBioReadWriteProcessor udpBioReadWriteProcessor = UdpBioReadWriteProcessor.this;
udpBioConnectListener.onConnectSuccess(udpBioReadWriteProcessor, udpBioReadWriteProcessor.mSocket, datagramPacket, datagramPacket2);
}
UdpBioReadWriteProcessor udpBioReadWriteProcessor2 = UdpBioReadWriteProcessor.this;
udpBioReadWriteProcessor2.mWriteProcessor = new WriteRunnable();
UdpBioReadWriteProcessor udpBioReadWriteProcessor3 = UdpBioReadWriteProcessor.this;
udpBioReadWriteProcessor3.mReadProcessor = new ReadRunnable();
UdpBioReadWriteProcessor.this.mWriteThread = new Thread(UdpBioReadWriteProcessor.this.mWriteProcessor);
UdpBioReadWriteProcessor.this.mReadThread = new Thread(UdpBioReadWriteProcessor.this.mReadProcessor);
UdpBioReadWriteProcessor.this.mWriteThread.start();
UdpBioReadWriteProcessor.this.mReadThread.start();
z = true;
} catch (SocketException e) {
e.printStackTrace();
} catch (UnknownHostException e2) {
e2.printStackTrace();
}
if (z || UdpBioReadWriteProcessor.this.mConnectStatusListener == null) {
return;
}
UdpBioReadWriteProcessor.this.mConnectStatusListener.onConnectFailed(UdpBioReadWriteProcessor.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 (UdpBioReadWriteProcessor.this.mClient.onWrite()) {
try {
synchronized (this.lock) {
this.lock.wait();
}
} catch (Exception e) {
e.printStackTrace();
}
}
UdpBioReadWriteProcessor.this.onSocketExit(1);
}
}
private class ReadRunnable implements Runnable {
private ReadRunnable() {
}
@Override
public void run() {
UdpBioReadWriteProcessor.this.mClient.onRead();
UdpBioReadWriteProcessor.this.onSocketExit(2);
}
}
}