AbstractNioWorker -> SelectorEventLoop
This commit is contained in:
parent
0d8afa7a4c
commit
a8647d6dc8
@ -39,9 +39,9 @@ import java.util.concurrent.atomic.AtomicInteger;
|
|||||||
public abstract class AbstractNioChannel extends AbstractChannel implements NioChannel {
|
public abstract class AbstractNioChannel extends AbstractChannel implements NioChannel {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The {@link AbstractNioWorker}.
|
* The {@link SelectorEventLoop}.
|
||||||
*/
|
*/
|
||||||
private final AbstractNioWorker worker;
|
private final SelectorEventLoop worker;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Monitor object to synchronize access to InterestedOps.
|
* Monitor object to synchronize access to InterestedOps.
|
||||||
@ -97,7 +97,7 @@ public abstract class AbstractNioChannel extends AbstractChannel implements NioC
|
|||||||
|
|
||||||
private final JdkChannel channel;
|
private final JdkChannel channel;
|
||||||
|
|
||||||
protected AbstractNioChannel(Integer id, Channel parent, ChannelFactory factory, ChannelPipeline pipeline, ChannelSink sink, AbstractNioWorker worker, JdkChannel ch) {
|
protected AbstractNioChannel(Integer id, Channel parent, ChannelFactory factory, ChannelPipeline pipeline, ChannelSink sink, SelectorEventLoop worker, JdkChannel ch) {
|
||||||
super(id, parent, factory, pipeline, sink);
|
super(id, parent, factory, pipeline, sink);
|
||||||
this.worker = worker;
|
this.worker = worker;
|
||||||
this.channel = ch;
|
this.channel = ch;
|
||||||
@ -105,7 +105,7 @@ public abstract class AbstractNioChannel extends AbstractChannel implements NioC
|
|||||||
|
|
||||||
protected AbstractNioChannel(
|
protected AbstractNioChannel(
|
||||||
Channel parent, ChannelFactory factory,
|
Channel parent, ChannelFactory factory,
|
||||||
ChannelPipeline pipeline, ChannelSink sink, AbstractNioWorker worker, JdkChannel ch) {
|
ChannelPipeline pipeline, ChannelSink sink, SelectorEventLoop worker, JdkChannel ch) {
|
||||||
super(parent, factory, pipeline, sink);
|
super(parent, factory, pipeline, sink);
|
||||||
this.worker = worker;
|
this.worker = worker;
|
||||||
this.channel = ch;
|
this.channel = ch;
|
||||||
@ -116,11 +116,11 @@ public abstract class AbstractNioChannel extends AbstractChannel implements NioC
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the {@link AbstractNioWorker} that handle the IO of the {@link AbstractNioChannel}
|
* Return the {@link SelectorEventLoop} that handle the IO of the {@link AbstractNioChannel}
|
||||||
*
|
*
|
||||||
* @return worker
|
* @return worker
|
||||||
*/
|
*/
|
||||||
public AbstractNioWorker getWorker() {
|
public SelectorEventLoop getWorker() {
|
||||||
return worker;
|
return worker;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,9 +29,9 @@ import java.util.concurrent.atomic.AtomicInteger;
|
|||||||
* {@link #nextWorker()}
|
* {@link #nextWorker()}
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public abstract class AbstractNioWorkerPool<E extends AbstractNioWorker> implements WorkerPool<E> , ExternalResourceReleasable {
|
public abstract class AbstractNioWorkerPool<E extends SelectorEventLoop> implements WorkerPool<E> , ExternalResourceReleasable {
|
||||||
|
|
||||||
private final AbstractNioWorker[] workers;
|
private final SelectorEventLoop[] workers;
|
||||||
private final AtomicInteger workerIndex = new AtomicInteger();
|
private final AtomicInteger workerIndex = new AtomicInteger();
|
||||||
private final Executor workerExecutor;
|
private final Executor workerExecutor;
|
||||||
|
|
||||||
@ -51,7 +51,7 @@ public abstract class AbstractNioWorkerPool<E extends AbstractNioWorker> impleme
|
|||||||
"workerCount (" + workerCount + ") " +
|
"workerCount (" + workerCount + ") " +
|
||||||
"must be a positive integer.");
|
"must be a positive integer.");
|
||||||
}
|
}
|
||||||
workers = new AbstractNioWorker[workerCount];
|
workers = new SelectorEventLoop[workerCount];
|
||||||
|
|
||||||
for (int i = 0; i < workers.length; i++) {
|
for (int i = 0; i < workers.length; i++) {
|
||||||
workers[i] = createWorker(workerExecutor, allowShutDownOnIdle);
|
workers[i] = createWorker(workerExecutor, allowShutDownOnIdle);
|
||||||
|
@ -43,7 +43,7 @@ import java.util.concurrent.Executor;
|
|||||||
* A class responsible for registering channels with {@link Selector}.
|
* A class responsible for registering channels with {@link Selector}.
|
||||||
* It also implements the {@link Selector} loop.
|
* It also implements the {@link Selector} loop.
|
||||||
*/
|
*/
|
||||||
public class NioDatagramWorker extends AbstractNioWorker {
|
public class NioDatagramWorker extends SelectorEventLoop {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sole constructor.
|
* Sole constructor.
|
||||||
|
@ -34,7 +34,7 @@ import java.nio.channels.SelectionKey;
|
|||||||
import java.nio.channels.SocketChannel;
|
import java.nio.channels.SocketChannel;
|
||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
|
|
||||||
public class NioWorker extends AbstractNioWorker {
|
public class NioWorker extends SelectorEventLoop {
|
||||||
|
|
||||||
protected final ReceiveBufferPool recvBufferPool = new ReceiveBufferPool();
|
protected final ReceiveBufferPool recvBufferPool = new ReceiveBufferPool();
|
||||||
|
|
||||||
|
@ -47,12 +47,12 @@ import java.util.concurrent.locks.ReentrantReadWriteLock;
|
|||||||
|
|
||||||
import static io.netty.channel.Channels.*;
|
import static io.netty.channel.Channels.*;
|
||||||
|
|
||||||
abstract class AbstractNioWorker extends SingleThreadEventLoop {
|
abstract class SelectorEventLoop extends SingleThreadEventLoop {
|
||||||
/**
|
/**
|
||||||
* Internal Netty logger.
|
* Internal Netty logger.
|
||||||
*/
|
*/
|
||||||
protected static final InternalLogger logger = InternalLoggerFactory
|
protected static final InternalLogger logger = InternalLoggerFactory
|
||||||
.getInstance(AbstractNioWorker.class);
|
.getInstance(SelectorEventLoop.class);
|
||||||
|
|
||||||
private static final int CONSTRAINT_LEVEL = NioProviderMetadata.CONSTRAINT_LEVEL;
|
private static final int CONSTRAINT_LEVEL = NioProviderMetadata.CONSTRAINT_LEVEL;
|
||||||
|
|
||||||
@ -86,11 +86,11 @@ abstract class AbstractNioWorker extends SingleThreadEventLoop {
|
|||||||
|
|
||||||
protected final SendBufferPool sendBufferPool = new SendBufferPool();
|
protected final SendBufferPool sendBufferPool = new SendBufferPool();
|
||||||
|
|
||||||
protected AbstractNioWorker() {
|
protected SelectorEventLoop() {
|
||||||
selector = openSelector();
|
selector = openSelector();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected AbstractNioWorker(ThreadFactory threadFactory) {
|
protected SelectorEventLoop(ThreadFactory threadFactory) {
|
||||||
super(threadFactory);
|
super(threadFactory);
|
||||||
selector = openSelector();
|
selector = openSelector();
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user