优化代码,性能暴涨

This commit is contained in:
Administrator
2025-01-29 14:01:11 +08:00
parent e243203535
commit 6de65562be
130 changed files with 9138 additions and 1020 deletions
@@ -5,18 +5,19 @@ import java.io.OutputStream;
import java.net.*;
import java.nio.channels.SocketChannel;
import org.kne.cloud.network.klalb.CannotAssociateException;
import org.kne.cloud.network.klalb.KLALBVirtualSocket;
import org.kne.cloud.network.klalb.KLALBVirtualSocketChannel;
import org.kne.io.Task;
public class SocketChannelBridge extends Task{
protected SocketChannel a;
protected SocketChannel b;
protected StreamChannelBridge bridgeAB;
protected StreamChannelBridge bridgeBA;
public StreamChannelBridge getBridgeAB() {
protected ChannelBridge bridgeAB;
protected ChannelBridge bridgeBA;
public ChannelBridge getBridgeAB() {
return bridgeAB;
}
public StreamChannelBridge getBridgeBA() {
public ChannelBridge getBridgeBA() {
return bridgeBA;
}
public SocketChannelBridge(SocketChannel a, SocketChannel b) throws IOException {
@@ -26,16 +27,32 @@ public class SocketChannelBridge extends Task{
createStreamChannelBridge();
}
protected void createStreamChannelBridge() throws IOException {
bridgeAB = new StreamChannelBridge(a, b);
bridgeBA = new StreamChannelBridge(b, a);
bridgeAB = new ChannelBridge(a, b);
bridgeBA = new ChannelBridge(b, a);
}
@Override
protected void runTask() {
try {
if(a instanceof KLALBVirtualSocketChannel) {
try {
((KLALBVirtualSocketChannel) a).associateSocketChannel(b);
}catch(CannotAssociateException e) {
bridgeAB.runAtNewThread("SocketBridge A->B thread");
bridgeBA.runAtNewThread("SocketBridge B->A thread");
bridgeAB.waitfortask();
bridgeBA.waitfortask();
}
}else if(b instanceof KLALBVirtualSocketChannel){
try {
((KLALBVirtualSocketChannel) b).associateSocketChannel(a);
}catch(CannotAssociateException e) {
bridgeAB.runAtNewThread("SocketBridge A->B thread");
bridgeBA.runAtNewThread("SocketBridge B->A thread");
bridgeAB.waitfortask();
bridgeBA.waitfortask();
}
}else {
bridgeAB.runAtNewThread("SocketBridge A->B thread");
bridgeBA.runAtNewThread("SocketBridge B->A thread");
@@ -49,12 +66,14 @@ public class SocketChannelBridge extends Task{
//new Exception().printStackTrace();
try {
a.close();
//System.out.println("closeA");
} catch (IOException e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
}
try {
b.close();
//System.out.println("closeB");
} catch (IOException e) {
// TODO 自动生成的 catch 块
e.printStackTrace();