This commit is contained in:
@@ -137,40 +137,23 @@ public abstract class AsyncConnection implements AutoCloseable {
|
||||
this.readBuffer = null;
|
||||
return rs;
|
||||
}
|
||||
// Thread thread = Thread.currentThread();
|
||||
// if (thread instanceof IOThread) {
|
||||
// return ((IOThread) thread).getBufferPool().get();
|
||||
// }
|
||||
return bufferSupplier.get();
|
||||
}
|
||||
|
||||
public void offerBuffer(ByteBuffer buffer) {
|
||||
if (buffer == null) return;
|
||||
// Thread thread = Thread.currentThread();
|
||||
// if (thread instanceof IOThread) {
|
||||
// ((IOThread) thread).getBufferPool().accept((ByteBuffer) buffer);
|
||||
// return;
|
||||
// }
|
||||
bufferConsumer.accept(buffer);
|
||||
}
|
||||
|
||||
public void offerBuffer(ByteBuffer... buffers) {
|
||||
if (buffers == null) return;
|
||||
Consumer<ByteBuffer> consumer = this.bufferConsumer;
|
||||
// Thread thread = Thread.currentThread();
|
||||
// if (thread instanceof IOThread) {
|
||||
// consumer = ((IOThread) thread).getBufferPool();
|
||||
// }
|
||||
for (ByteBuffer buffer : buffers) {
|
||||
consumer.accept(buffer);
|
||||
}
|
||||
}
|
||||
|
||||
public ByteBuffer pollWriteBuffer() {
|
||||
// Thread thread = Thread.currentThread();
|
||||
// if (thread instanceof IOThread) {
|
||||
// return ((IOThread) thread).getBufferPool().get();
|
||||
// }
|
||||
return bufferSupplier.get();
|
||||
}
|
||||
|
||||
|
||||
@@ -6,8 +6,13 @@
|
||||
package org.redkale.net.nio;
|
||||
|
||||
/**
|
||||
*
|
||||
* <p>
|
||||
* 详情见: https://redkale.org
|
||||
*
|
||||
* @author zhangjx
|
||||
*
|
||||
* @since 2.1.0
|
||||
*/
|
||||
public abstract class AbstractLoop extends Thread {
|
||||
|
||||
|
||||
48
src/org/redkale/net/nio/CompletionHandlerRunner.java
Normal file
48
src/org/redkale/net/nio/CompletionHandlerRunner.java
Normal file
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package org.redkale.net.nio;
|
||||
|
||||
import java.nio.channels.CompletionHandler;
|
||||
import java.util.concurrent.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* <p>
|
||||
* 详情见: https://redkale.org
|
||||
*
|
||||
* @author zhangjx
|
||||
*
|
||||
* @since 2.1.0
|
||||
*/
|
||||
class CompletionHandlerRunner<A> implements CompletionHandler<Integer, A>, Runnable {
|
||||
|
||||
private final CompletionHandler<Integer, A> handler;
|
||||
|
||||
private final A attachment;
|
||||
|
||||
ScheduledFuture timeoutFuture;
|
||||
|
||||
public CompletionHandlerRunner(CompletionHandler<Integer, A> handler, A attachment) {
|
||||
this.handler = handler;
|
||||
this.attachment = attachment;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void completed(Integer result, A attach) {
|
||||
handler.completed(result, attachment);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void failed(Throwable exc, A attach) {
|
||||
handler.failed(exc, attachment);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
handler.failed(new TimeoutException(), attachment);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -10,8 +10,13 @@ import java.nio.channels.*;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* <p>
|
||||
* 详情见: https://redkale.org
|
||||
*
|
||||
* @author zhangjx
|
||||
*
|
||||
* @since 2.1.0
|
||||
*/
|
||||
public abstract class NioEventLoop extends AbstractLoop {
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package org.redkale.net;
|
||||
package org.redkale.net.nio;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
@@ -16,8 +16,10 @@ import org.redkale.util.*;
|
||||
* 详情见: https://redkale.org
|
||||
*
|
||||
* @author zhangjx
|
||||
*
|
||||
* @since 2.1.0
|
||||
*/
|
||||
public class IOThread extends Thread {
|
||||
public class NioThread extends Thread {
|
||||
|
||||
protected Thread localThread;
|
||||
|
||||
@@ -25,7 +27,7 @@ public class IOThread extends Thread {
|
||||
|
||||
protected ObjectPool<ByteBuffer> bufferPool;
|
||||
|
||||
public IOThread(ExecutorService executor, ObjectPool<ByteBuffer> bufferPool, Runnable runner) {
|
||||
public NioThread(ExecutorService executor, ObjectPool<ByteBuffer> bufferPool, Runnable runner) {
|
||||
super(runner);
|
||||
this.executor = executor;
|
||||
this.bufferPool = bufferPool;
|
||||
@@ -6,8 +6,13 @@
|
||||
package org.redkale.net.nio;
|
||||
|
||||
/**
|
||||
*
|
||||
* <p>
|
||||
* 详情见: https://redkale.org
|
||||
*
|
||||
* @author zhangjx
|
||||
*
|
||||
* @since 2.1.0
|
||||
*/
|
||||
public class NioWorkerThread extends NioEventLoop {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user