Rename getChildGroup() to childEventLoopGroup() / Minor cleanup

This commit is contained in:
Trustin Lee 2013-10-08 17:03:20 +09:00
parent e743a27e75
commit 1c15ba0c95
12 changed files with 31 additions and 44 deletions

View File

@ -17,7 +17,6 @@ package io.netty.channel.sctp.nio;
import com.sun.nio.sctp.SctpChannel; import com.sun.nio.sctp.SctpChannel;
import com.sun.nio.sctp.SctpServerChannel; import com.sun.nio.sctp.SctpServerChannel;
import io.netty.channel.ChannelException; import io.netty.channel.ChannelException;
import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelMetadata; import io.netty.channel.ChannelMetadata;
@ -25,7 +24,6 @@ import io.netty.channel.ChannelOutboundBuffer;
import io.netty.channel.ChannelPromise; import io.netty.channel.ChannelPromise;
import io.netty.channel.EventLoop; import io.netty.channel.EventLoop;
import io.netty.channel.EventLoopGroup; import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.AbstractNioMessageChannel;
import io.netty.channel.nio.AbstractNioMessageServerChannel; import io.netty.channel.nio.AbstractNioMessageServerChannel;
import io.netty.channel.sctp.DefaultSctpServerChannelConfig; import io.netty.channel.sctp.DefaultSctpServerChannelConfig;
import io.netty.channel.sctp.SctpServerChannelConfig; import io.netty.channel.sctp.SctpServerChannelConfig;
@ -145,7 +143,7 @@ public class NioSctpServerChannel extends AbstractNioMessageServerChannel
if (ch == null) { if (ch == null) {
return 0; return 0;
} }
buf.add(new NioSctpChannel(this, getChildGroup().next(), ch)); buf.add(new NioSctpChannel(this, childEventLoopGroup().next(), ch));
return 1; return 1;
} }

View File

@ -17,7 +17,6 @@ package io.netty.channel.sctp.oio;
import com.sun.nio.sctp.SctpChannel; import com.sun.nio.sctp.SctpChannel;
import com.sun.nio.sctp.SctpServerChannel; import com.sun.nio.sctp.SctpServerChannel;
import io.netty.channel.ChannelException; import io.netty.channel.ChannelException;
import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelMetadata; import io.netty.channel.ChannelMetadata;
@ -25,7 +24,6 @@ import io.netty.channel.ChannelOutboundBuffer;
import io.netty.channel.ChannelPromise; import io.netty.channel.ChannelPromise;
import io.netty.channel.EventLoop; import io.netty.channel.EventLoop;
import io.netty.channel.EventLoopGroup; import io.netty.channel.EventLoopGroup;
import io.netty.channel.oio.AbstractOioMessageChannel;
import io.netty.channel.oio.AbstractOioMessageServerChannel; import io.netty.channel.oio.AbstractOioMessageServerChannel;
import io.netty.channel.sctp.DefaultSctpServerChannelConfig; import io.netty.channel.sctp.DefaultSctpServerChannelConfig;
import io.netty.channel.sctp.SctpServerChannelConfig; import io.netty.channel.sctp.SctpServerChannelConfig;
@ -200,7 +198,7 @@ public class OioSctpServerChannel extends AbstractOioMessageServerChannel
if (key.isAcceptable()) { if (key.isAcceptable()) {
s = sch.accept(); s = sch.accept();
if (s != null) { if (s != null) {
buf.add(new OioSctpChannel(this, getChildGroup().next(), s)); buf.add(new OioSctpChannel(this, childEventLoopGroup().next(), s));
acceptedChannels ++; acceptedChannels ++;
} }
} }

View File

@ -17,7 +17,6 @@ package io.netty.channel.udt.nio;
import com.barchart.udt.TypeUDT; import com.barchart.udt.TypeUDT;
import com.barchart.udt.nio.SocketChannelUDT; import com.barchart.udt.nio.SocketChannelUDT;
import io.netty.channel.ChannelMetadata; import io.netty.channel.ChannelMetadata;
import io.netty.channel.EventLoop; import io.netty.channel.EventLoop;
import io.netty.channel.EventLoopGroup; import io.netty.channel.EventLoopGroup;
@ -41,7 +40,7 @@ public class NioUdtByteAcceptorChannel extends NioUdtAcceptorChannel {
if (channelUDT == null) { if (channelUDT == null) {
return 0; return 0;
} else { } else {
buf.add(new NioUdtByteConnectorChannel(this, getChildGroup().next(), channelUDT)); buf.add(new NioUdtByteConnectorChannel(this, childEventLoopGroup().next(), channelUDT));
return 1; return 1;
} }
} }

View File

@ -17,7 +17,6 @@ package io.netty.channel.udt.nio;
import com.barchart.udt.TypeUDT; import com.barchart.udt.TypeUDT;
import com.barchart.udt.nio.SocketChannelUDT; import com.barchart.udt.nio.SocketChannelUDT;
import io.netty.channel.ChannelMetadata; import io.netty.channel.ChannelMetadata;
import io.netty.channel.EventLoop; import io.netty.channel.EventLoop;
import io.netty.channel.EventLoopGroup; import io.netty.channel.EventLoopGroup;
@ -41,7 +40,7 @@ public class NioUdtMessageAcceptorChannel extends NioUdtAcceptorChannel {
if (channelUDT == null) { if (channelUDT == null) {
return 0; return 0;
} else { } else {
buf.add(new NioUdtMessageConnectorChannel(this, getChildGroup().next(), channelUDT)); buf.add(new NioUdtMessageConnectorChannel(this, childEventLoopGroup().next(), channelUDT));
return 1; return 1;
} }
} }

View File

@ -23,15 +23,14 @@ import com.barchart.udt.nio.RendezvousChannelUDT;
import com.barchart.udt.nio.SelectorProviderUDT; import com.barchart.udt.nio.SelectorProviderUDT;
import com.barchart.udt.nio.ServerSocketChannelUDT; import com.barchart.udt.nio.ServerSocketChannelUDT;
import com.barchart.udt.nio.SocketChannelUDT; import com.barchart.udt.nio.SocketChannelUDT;
import io.netty.bootstrap.ChannelFactory; import io.netty.bootstrap.ChannelFactory;
import io.netty.bootstrap.ServerChannelFactory; import io.netty.bootstrap.ServerChannelFactory;
import io.netty.channel.Channel; import io.netty.channel.Channel;
import io.netty.channel.ChannelException; import io.netty.channel.ChannelException;
import io.netty.channel.EventLoop; import io.netty.channel.EventLoop;
import io.netty.channel.EventLoopGroup; import io.netty.channel.EventLoopGroup;
import io.netty.channel.udt.UdtServerChannel;
import io.netty.channel.udt.UdtChannel; import io.netty.channel.udt.UdtChannel;
import io.netty.channel.udt.UdtServerChannel;
import java.io.IOException; import java.io.IOException;
import java.nio.channels.spi.SelectorProvider; import java.nio.channels.spi.SelectorProvider;
@ -43,7 +42,7 @@ import java.nio.channels.spi.SelectorProvider;
* <p> * <p>
* Provides {@link SelectorProvider} for UDT channels. * Provides {@link SelectorProvider} for UDT channels.
*/ */
public abstract class NioUdtProvider<T extends UdtChannel> { public abstract class NioUdtProvider {
/** /**
* {@link ChannelFactory} for UDT Byte Acceptor. See {@link TypeUDT#STREAM} * {@link ChannelFactory} for UDT Byte Acceptor. See {@link TypeUDT#STREAM}
@ -132,8 +131,7 @@ public abstract class NioUdtProvider<T extends UdtChannel> {
/** /**
* Convenience factory for {@link KindUDT#ACCEPTOR} channels. * Convenience factory for {@link KindUDT#ACCEPTOR} channels.
*/ */
protected static ServerSocketChannelUDT newAcceptorChannelUDT( protected static ServerSocketChannelUDT newAcceptorChannelUDT(final TypeUDT type) {
final TypeUDT type) {
try { try {
return SelectorProviderUDT.from(type).openServerSocketChannel(); return SelectorProviderUDT.from(type).openServerSocketChannel();
} catch (final IOException e) { } catch (final IOException e) {
@ -155,8 +153,7 @@ public abstract class NioUdtProvider<T extends UdtChannel> {
/** /**
* Convenience factory for {@link KindUDT#RENDEZVOUS} channels. * Convenience factory for {@link KindUDT#RENDEZVOUS} channels.
*/ */
protected static RendezvousChannelUDT newRendezvousChannelUDT( protected static RendezvousChannelUDT newRendezvousChannelUDT(final TypeUDT type) {
final TypeUDT type) {
try { try {
return SelectorProviderUDT.from(type).openRendezvousChannel(); return SelectorProviderUDT.from(type).openRendezvousChannel();
} catch (final IOException e) { } catch (final IOException e) {
@ -197,8 +194,11 @@ public abstract class NioUdtProvider<T extends UdtChannel> {
return kind; return kind;
} }
private static final class NioUdtChannelFactory<T extends UdtChannel> extends NioUdtProvider<T> /**
implements ChannelFactory<T> { * Produce new {@link UdtChannel} based on factory {@link #kind()} and {@link #type()}
*/
private static final class NioUdtChannelFactory<T extends UdtChannel>
extends NioUdtProvider implements ChannelFactory<T> {
private NioUdtChannelFactory(final TypeUDT type, final KindUDT kind) { private NioUdtChannelFactory(final TypeUDT type, final KindUDT kind) {
super(type, kind); super(type, kind);
@ -209,7 +209,7 @@ public abstract class NioUdtProvider<T extends UdtChannel> {
public T newChannel(EventLoop eventLoop) { public T newChannel(EventLoop eventLoop) {
switch (kind()) { switch (kind()) {
case ACCEPTOR: case ACCEPTOR:
throw new IllegalStateException("wrong kind=" + kind()); throw new IllegalStateException("wrong kind: " + kind());
case CONNECTOR: case CONNECTOR:
switch (type()) { switch (type()) {
case DATAGRAM: case DATAGRAM:
@ -217,7 +217,7 @@ public abstract class NioUdtProvider<T extends UdtChannel> {
case STREAM: case STREAM:
return (T) new NioUdtByteConnectorChannel(eventLoop); return (T) new NioUdtByteConnectorChannel(eventLoop);
default: default:
throw new IllegalStateException("wrong type=" + type()); throw new IllegalStateException("wrong type: " + type());
} }
case RENDEZVOUS: case RENDEZVOUS:
switch (type()) { switch (type()) {
@ -226,15 +226,15 @@ public abstract class NioUdtProvider<T extends UdtChannel> {
case STREAM: case STREAM:
return (T) new NioUdtByteRendezvousChannel(eventLoop); return (T) new NioUdtByteRendezvousChannel(eventLoop);
default: default:
throw new IllegalStateException("wrong type=" + type()); throw new IllegalStateException("wrong type: " + type());
} }
default: default:
throw new IllegalStateException("wrong kind=" + kind()); throw new IllegalStateException("wrong kind: " + kind());
} }
} }
} }
private static final class NioUdtServerChannelFactory<T extends UdtServerChannel> extends NioUdtProvider<T> private static final class NioUdtServerChannelFactory<T extends UdtServerChannel> extends NioUdtProvider
implements ServerChannelFactory<T> { implements ServerChannelFactory<T> {
private NioUdtServerChannelFactory(final TypeUDT type, final KindUDT kind) { private NioUdtServerChannelFactory(final TypeUDT type, final KindUDT kind) {
@ -252,27 +252,20 @@ public abstract class NioUdtProvider<T extends UdtChannel> {
case STREAM: case STREAM:
return (T) new NioUdtByteAcceptorChannel(eventLoop, childGroup); return (T) new NioUdtByteAcceptorChannel(eventLoop, childGroup);
default: default:
throw new IllegalStateException("wrong type=" + type()); throw new IllegalStateException("wrong type: " + type());
} }
case CONNECTOR: case CONNECTOR:
case RENDEZVOUS: case RENDEZVOUS:
default: default:
throw new IllegalStateException("wrong kind=" + kind()); throw new IllegalStateException("wrong kind: " + kind());
} }
} }
} }
/**
* Produce new {@link UdtChannel} based on factory {@link #kind()} and {@link #type()}
*/
/*
*/
/** /**
* UDT Socket Type. See {@link TypeUDT} * UDT Socket Type. See {@link TypeUDT}
*/ */
public TypeUDT type() { public TypeUDT type() {
return type; return type;
} }
} }

View File

@ -74,7 +74,8 @@ public abstract class AbstractServerChannel extends AbstractChannel implements S
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }
public EventLoopGroup getChildGroup() { @Override
public EventLoopGroup childEventLoopGroup() {
return childGroup; return childGroup;
} }

View File

@ -23,5 +23,5 @@ import io.netty.channel.socket.ServerSocketChannel;
*/ */
public interface ServerChannel extends Channel { public interface ServerChannel extends Channel {
EventLoopGroup getChildGroup(); EventLoopGroup childEventLoopGroup();
} }

View File

@ -136,7 +136,7 @@ public class LocalServerChannel extends AbstractServerChannel {
} }
LocalChannel serve(final LocalChannel peer) { LocalChannel serve(final LocalChannel peer) {
final LocalChannel child = new LocalChannel(this, getChildGroup().next(), peer); final LocalChannel child = new LocalChannel(this, childEventLoopGroup().next(), peer);
if (eventLoop().inEventLoop()) { if (eventLoop().inEventLoop()) {
serve0(child); serve0(child);
} else { } else {

View File

@ -15,13 +15,13 @@
*/ */
package io.netty.channel.nio; package io.netty.channel.nio;
import java.nio.channels.SelectableChannel;
import io.netty.channel.Channel; import io.netty.channel.Channel;
import io.netty.channel.EventLoop; import io.netty.channel.EventLoop;
import io.netty.channel.EventLoopGroup; import io.netty.channel.EventLoopGroup;
import io.netty.channel.ServerChannel; import io.netty.channel.ServerChannel;
import java.nio.channels.SelectableChannel;
public abstract class AbstractNioMessageServerChannel extends AbstractNioMessageChannel implements ServerChannel { public abstract class AbstractNioMessageServerChannel extends AbstractNioMessageChannel implements ServerChannel {
private final EventLoopGroup childGroup; private final EventLoopGroup childGroup;
@ -33,8 +33,8 @@ public abstract class AbstractNioMessageServerChannel extends AbstractNioMessage
} }
@Override @Override
public EventLoopGroup getChildGroup() { public EventLoopGroup childEventLoopGroup() {
return this.childGroup; return childGroup;
} }
} }

View File

@ -30,7 +30,7 @@ public abstract class AbstractOioMessageServerChannel extends AbstractOioMessage
} }
@Override @Override
public EventLoopGroup getChildGroup() { public EventLoopGroup childEventLoopGroup() {
return childGroup; return childGroup;
} }

View File

@ -20,7 +20,6 @@ import io.netty.channel.ChannelMetadata;
import io.netty.channel.ChannelOutboundBuffer; import io.netty.channel.ChannelOutboundBuffer;
import io.netty.channel.EventLoop; import io.netty.channel.EventLoop;
import io.netty.channel.EventLoopGroup; import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.AbstractNioMessageChannel;
import io.netty.channel.nio.AbstractNioMessageServerChannel; import io.netty.channel.nio.AbstractNioMessageServerChannel;
import io.netty.channel.socket.DefaultServerSocketChannelConfig; import io.netty.channel.socket.DefaultServerSocketChannelConfig;
import io.netty.channel.socket.ServerSocketChannelConfig; import io.netty.channel.socket.ServerSocketChannelConfig;
@ -116,7 +115,7 @@ public class NioServerSocketChannel extends AbstractNioMessageServerChannel
try { try {
if (ch != null) { if (ch != null) {
buf.add(new NioSocketChannel(this, getChildGroup().next(), ch)); buf.add(new NioSocketChannel(this, childEventLoopGroup().next(), ch));
return 1; return 1;
} }
} catch (Throwable t) { } catch (Throwable t) {

View File

@ -155,7 +155,7 @@ public class OioServerSocketChannel extends AbstractOioMessageServerChannel impl
Socket s = socket.accept(); Socket s = socket.accept();
try { try {
if (s != null) { if (s != null) {
buf.add(new OioSocketChannel(this, getChildGroup().next(), s)); buf.add(new OioSocketChannel(this, childEventLoopGroup().next(), s));
return 1; return 1;
} }
} catch (Throwable t) { } catch (Throwable t) {