Skip to content

Commit

Permalink
Rename getChildGroup() to childEventLoopGroup() / Minor cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
trustin committed Oct 8, 2013
1 parent e743a27 commit 1c15ba0
Show file tree
Hide file tree
Showing 12 changed files with 31 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,13 @@

import com.sun.nio.sctp.SctpChannel;
import com.sun.nio.sctp.SctpServerChannel;

import io.netty.channel.ChannelException;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelMetadata;
import io.netty.channel.ChannelOutboundBuffer;
import io.netty.channel.ChannelPromise;
import io.netty.channel.EventLoop;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.AbstractNioMessageChannel;
import io.netty.channel.nio.AbstractNioMessageServerChannel;
import io.netty.channel.sctp.DefaultSctpServerChannelConfig;
import io.netty.channel.sctp.SctpServerChannelConfig;
Expand Down Expand Up @@ -145,7 +143,7 @@ protected int doReadMessages(List<Object> buf) throws Exception {
if (ch == null) {
return 0;
}
buf.add(new NioSctpChannel(this, getChildGroup().next(), ch));
buf.add(new NioSctpChannel(this, childEventLoopGroup().next(), ch));
return 1;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,13 @@

import com.sun.nio.sctp.SctpChannel;
import com.sun.nio.sctp.SctpServerChannel;

import io.netty.channel.ChannelException;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelMetadata;
import io.netty.channel.ChannelOutboundBuffer;
import io.netty.channel.ChannelPromise;
import io.netty.channel.EventLoop;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.oio.AbstractOioMessageChannel;
import io.netty.channel.oio.AbstractOioMessageServerChannel;
import io.netty.channel.sctp.DefaultSctpServerChannelConfig;
import io.netty.channel.sctp.SctpServerChannelConfig;
Expand Down Expand Up @@ -200,7 +198,7 @@ protected int doReadMessages(List<Object> buf) throws Exception {
if (key.isAcceptable()) {
s = sch.accept();
if (s != null) {
buf.add(new OioSctpChannel(this, getChildGroup().next(), s));
buf.add(new OioSctpChannel(this, childEventLoopGroup().next(), s));
acceptedChannels ++;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

import com.barchart.udt.TypeUDT;
import com.barchart.udt.nio.SocketChannelUDT;

import io.netty.channel.ChannelMetadata;
import io.netty.channel.EventLoop;
import io.netty.channel.EventLoopGroup;
Expand All @@ -41,7 +40,7 @@ protected int doReadMessages(List<Object> buf) throws Exception {
if (channelUDT == null) {
return 0;
} else {
buf.add(new NioUdtByteConnectorChannel(this, getChildGroup().next(), channelUDT));
buf.add(new NioUdtByteConnectorChannel(this, childEventLoopGroup().next(), channelUDT));
return 1;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

import com.barchart.udt.TypeUDT;
import com.barchart.udt.nio.SocketChannelUDT;

import io.netty.channel.ChannelMetadata;
import io.netty.channel.EventLoop;
import io.netty.channel.EventLoopGroup;
Expand All @@ -41,7 +40,7 @@ protected int doReadMessages(List<Object> buf) throws Exception {
if (channelUDT == null) {
return 0;
} else {
buf.add(new NioUdtMessageConnectorChannel(this, getChildGroup().next(), channelUDT));
buf.add(new NioUdtMessageConnectorChannel(this, childEventLoopGroup().next(), channelUDT));
return 1;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,14 @@
import com.barchart.udt.nio.SelectorProviderUDT;
import com.barchart.udt.nio.ServerSocketChannelUDT;
import com.barchart.udt.nio.SocketChannelUDT;

import io.netty.bootstrap.ChannelFactory;
import io.netty.bootstrap.ServerChannelFactory;
import io.netty.channel.Channel;
import io.netty.channel.ChannelException;
import io.netty.channel.EventLoop;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.udt.UdtServerChannel;
import io.netty.channel.udt.UdtChannel;
import io.netty.channel.udt.UdtServerChannel;

import java.io.IOException;
import java.nio.channels.spi.SelectorProvider;
Expand All @@ -43,7 +42,7 @@
* <p>
* 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}
Expand Down Expand Up @@ -132,8 +131,7 @@ public static ChannelUDT channelUDT(final Channel channel) {
/**
* Convenience factory for {@link KindUDT#ACCEPTOR} channels.
*/
protected static ServerSocketChannelUDT newAcceptorChannelUDT(
final TypeUDT type) {
protected static ServerSocketChannelUDT newAcceptorChannelUDT(final TypeUDT type) {
try {
return SelectorProviderUDT.from(type).openServerSocketChannel();
} catch (final IOException e) {
Expand All @@ -155,8 +153,7 @@ protected static SocketChannelUDT newConnectorChannelUDT(final TypeUDT type) {
/**
* Convenience factory for {@link KindUDT#RENDEZVOUS} channels.
*/
protected static RendezvousChannelUDT newRendezvousChannelUDT(
final TypeUDT type) {
protected static RendezvousChannelUDT newRendezvousChannelUDT(final TypeUDT type) {
try {
return SelectorProviderUDT.from(type).openRendezvousChannel();
} catch (final IOException e) {
Expand Down Expand Up @@ -197,8 +194,11 @@ public KindUDT 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) {
super(type, kind);
Expand All @@ -209,15 +209,15 @@ private NioUdtChannelFactory(final TypeUDT type, final KindUDT kind) {
public T newChannel(EventLoop eventLoop) {
switch (kind()) {
case ACCEPTOR:
throw new IllegalStateException("wrong kind=" + kind());
throw new IllegalStateException("wrong kind: " + kind());
case CONNECTOR:
switch (type()) {
case DATAGRAM:
return (T) new NioUdtMessageConnectorChannel(eventLoop);
case STREAM:
return (T) new NioUdtByteConnectorChannel(eventLoop);
default:
throw new IllegalStateException("wrong type=" + type());
throw new IllegalStateException("wrong type: " + type());
}
case RENDEZVOUS:
switch (type()) {
Expand All @@ -226,15 +226,15 @@ public T newChannel(EventLoop eventLoop) {
case STREAM:
return (T) new NioUdtByteRendezvousChannel(eventLoop);
default:
throw new IllegalStateException("wrong type=" + type());
throw new IllegalStateException("wrong type: " + type());
}
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> {

private NioUdtServerChannelFactory(final TypeUDT type, final KindUDT kind) {
Expand All @@ -252,27 +252,20 @@ public T newChannel(EventLoop eventLoop, EventLoopGroup childGroup) {
case STREAM:
return (T) new NioUdtByteAcceptorChannel(eventLoop, childGroup);
default:
throw new IllegalStateException("wrong type=" + type());
throw new IllegalStateException("wrong type: " + type());
}
case CONNECTOR:
case RENDEZVOUS:
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}
*/
public TypeUDT type() {
return type;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ protected void doWrite(ChannelOutboundBuffer in) throws Exception {
throw new UnsupportedOperationException();
}

public EventLoopGroup getChildGroup() {
@Override
public EventLoopGroup childEventLoopGroup() {
return childGroup;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@
*/
public interface ServerChannel extends Channel {

EventLoopGroup getChildGroup();
EventLoopGroup childEventLoopGroup();
}
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ protected void doBeginRead() throws Exception {
}

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()) {
serve0(child);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
*/
package io.netty.channel.nio;

import java.nio.channels.SelectableChannel;

import io.netty.channel.Channel;
import io.netty.channel.EventLoop;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.ServerChannel;

import java.nio.channels.SelectableChannel;

public abstract class AbstractNioMessageServerChannel extends AbstractNioMessageChannel implements ServerChannel {

private final EventLoopGroup childGroup;
Expand All @@ -33,8 +33,8 @@ protected AbstractNioMessageServerChannel(Channel parent, EventLoop eventLoop, E
}

@Override
public EventLoopGroup getChildGroup() {
return this.childGroup;
public EventLoopGroup childEventLoopGroup() {
return childGroup;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ protected AbstractOioMessageServerChannel(Channel parent, EventLoop eventLoop, E
}

@Override
public EventLoopGroup getChildGroup() {
public EventLoopGroup childEventLoopGroup() {
return childGroup;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import io.netty.channel.ChannelOutboundBuffer;
import io.netty.channel.EventLoop;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.AbstractNioMessageChannel;
import io.netty.channel.nio.AbstractNioMessageServerChannel;
import io.netty.channel.socket.DefaultServerSocketChannelConfig;
import io.netty.channel.socket.ServerSocketChannelConfig;
Expand Down Expand Up @@ -116,7 +115,7 @@ protected int doReadMessages(List<Object> buf) throws Exception {

try {
if (ch != null) {
buf.add(new NioSocketChannel(this, getChildGroup().next(), ch));
buf.add(new NioSocketChannel(this, childEventLoopGroup().next(), ch));
return 1;
}
} catch (Throwable t) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ protected int doReadMessages(List<Object> buf) throws Exception {
Socket s = socket.accept();
try {
if (s != null) {
buf.add(new OioSocketChannel(this, getChildGroup().next(), s));
buf.add(new OioSocketChannel(this, childEventLoopGroup().next(), s));
return 1;
}
} catch (Throwable t) {
Expand Down

0 comments on commit 1c15ba0

Please sign in to comment.