Rename IOStream example / Code cleanup

This commit is contained in:
Trustin Lee 2012-01-15 00:43:28 +09:00
parent 4cff6b56ff
commit d40bd5e7f2
12 changed files with 32 additions and 68 deletions

View File

@ -13,7 +13,7 @@
* License for the specific language governing permissions and limitations
* under the License.
*/
package io.netty.example.iostream;
package io.netty.example.stdio;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
@ -27,24 +27,24 @@ import io.netty.channel.ChannelPipelineFactory;
import io.netty.channel.DefaultChannelPipeline;
import io.netty.channel.MessageEvent;
import io.netty.channel.SimpleChannelHandler;
import io.netty.channel.iostream.IOStreamAddress;
import io.netty.channel.iostream.IOStreamChannelFactory;
import io.netty.channel.iostream.IoStreamAddress;
import io.netty.channel.iostream.IoStreamChannelFactory;
import io.netty.handler.codec.frame.DelimiterBasedFrameDecoder;
import io.netty.handler.codec.frame.Delimiters;
import io.netty.handler.codec.string.StringDecoder;
import io.netty.handler.codec.string.StringEncoder;
/**
* An example demonstrating the use of the {@link io.netty.channel.iostream.IOStreamChannel}.
* An example demonstrating the use of the {@link io.netty.channel.iostream.IoStreamChannel}.
*/
public class IOStream {
public class StdioLogger {
private static volatile boolean running = true;
public static void main(String[] args) {
final ExecutorService executorService = Executors.newCachedThreadPool();
final ClientBootstrap bootstrap = new ClientBootstrap(new IOStreamChannelFactory(executorService));
final ClientBootstrap bootstrap = new ClientBootstrap(new IoStreamChannelFactory(executorService));
// Configure the event pipeline factory.
bootstrap.setPipelineFactory(new ChannelPipelineFactory() {
@ -64,7 +64,7 @@ public class IOStream {
e.getChannel().write("Message received: " + message);
}
if ("exit".equals(message)) {
IOStream.running = false;
StdioLogger.running = false;
}
super.messageReceived(ctx, e);
}
@ -75,7 +75,7 @@ public class IOStream {
});
// Make a new connection.
ChannelFuture connectFuture = bootstrap.connect(new IOStreamAddress(System.in, System.out));
ChannelFuture connectFuture = bootstrap.connect(new IoStreamAddress(System.in, System.out));
// Wait until the connection is made successfully.
Channel channel = connectFuture.awaitUninterruptibly().getChannel();

View File

@ -88,9 +88,6 @@ public class CIDR4 extends CIDR {
return 1;
}
/* (non-Javadoc)
* @see io.netty.handler.ipfilter.CIDR#contains(java.net.InetAddress)
*/
@Override
public boolean contains(InetAddress inetAddress) {
int search = ipv4AddressToInt(inetAddress);

View File

@ -93,9 +93,6 @@ public class CIDR6 extends CIDR {
return res;
}
/* (non-Javadoc)
* @see io.netty.handler.ipfilter.CIDR#contains(java.net.InetAddress)
*/
@Override
public boolean contains(InetAddress inetAddress) {
BigInteger search = ipv6AddressToBigInteger(inetAddress);

View File

@ -235,9 +235,6 @@ public class IpFilterRuleHandler extends IpFilteringHandlerImpl {
return ipFilterRuleList.size();
}
/* (non-Javadoc)
* @see io.netty.handler.ipfilter.IpFilteringHandler#accept(io.netty.channel.ChannelHandlerContext, io.netty.channel.ChannelEvent, java.net.InetSocketAddress)
*/
@Override
protected boolean accept(ChannelHandlerContext ctx, ChannelEvent e, InetSocketAddress inetSocketAddress)
throws Exception {

View File

@ -95,9 +95,6 @@ public abstract class IpFilteringHandlerImpl implements ChannelUpstreamHandler,
}
}
/* (non-Javadoc)
* @see io.netty.channel.ChannelUpstreamHandler#handleUpstream(io.netty.channel.ChannelHandlerContext, io.netty.channel.ChannelEvent)
*/
@Override
public void handleUpstream(ChannelHandlerContext ctx, ChannelEvent e) throws Exception {
if (e instanceof ChannelStateEvent) {
@ -153,17 +150,11 @@ public abstract class IpFilteringHandlerImpl implements ChannelUpstreamHandler,
ctx.sendUpstream(e);
}
/* (non-Javadoc)
* @see io.netty.handler.ipfilter.IpFilteringHandler#setIpFilterListener(io.netty.handler.ipfilter.IpFilterListener)
*/
@Override
public void setIpFilterListener(IpFilterListener listener) {
this.listener = listener;
}
/* (non-Javadoc)
* @see io.netty.handler.ipfilter.IpFilteringHandler#removeIpFilterListener()
*/
@Override
public void removeIpFilterListener() {
this.listener = null;

View File

@ -40,9 +40,6 @@ public class OneIpFilterHandler extends IpFilteringHandlerImpl {
/** HashMap of current remote connected InetAddress */
private final ConcurrentMap<InetAddress, Boolean> connectedSet = new ConcurrentHashMap<InetAddress, Boolean>();
/* (non-Javadoc)
* @see io.netty.handler.ipfilter.IpFilteringHandler#accept(io.netty.channel.ChannelHandlerContext, io.netty.channel.ChannelEvent, java.net.InetSocketAddress)
*/
@Override
protected boolean accept(ChannelHandlerContext ctx, ChannelEvent e, InetSocketAddress inetSocketAddress)
throws Exception {
@ -54,9 +51,6 @@ public class OneIpFilterHandler extends IpFilteringHandlerImpl {
return true;
}
/* (non-Javadoc)
* @see io.netty.handler.ipfilter.IpFilteringHandler#handleUpstream(io.netty.channel.ChannelHandlerContext, io.netty.channel.ChannelEvent)
*/
@Override
public void handleUpstream(ChannelHandlerContext ctx, ChannelEvent e) throws Exception {
super.handleUpstream(ctx, e);

View File

@ -81,25 +81,16 @@ public class PatternRule implements IpFilterRule, Comparable<Object> {
return this.pattern;
}
/* (non-Javadoc)
* @see io.netty.handler.ipfilter.IpFilterRule#isAllowRule()
*/
@Override
public boolean isAllowRule() {
return isAllowRule;
}
/* (non-Javadoc)
* @see io.netty.handler.ipfilter.IpFilterRule#isDenyRule()
*/
@Override
public boolean isDenyRule() {
return !isAllowRule;
}
/* (non-Javadoc)
* @see io.netty.handler.ipfilter.IpSet#contains(java.net.InetAddress)
*/
@Override
public boolean contains(InetAddress inetAddress) {
if (localhost) {

View File

@ -369,9 +369,6 @@ public abstract class AbstractTrafficShapingHandler extends
return trafficCounter;
}
/* (non-Javadoc)
* @see io.netty.util.ExternalResourceReleasable#releaseExternalResources()
*/
@Override
public void releaseExternalResources() {
if (trafficCounter != null) {

View File

@ -22,9 +22,9 @@ import java.net.SocketAddress;
/**
* A {@link java.net.SocketAddress} implementation holding an
* {@link java.io.InputStream} and an {@link java.io.OutputStream} instance used
* as "remote" address to connect to with a {@link IOStreamChannel}.
* as "remote" address to connect to with a {@link IoStreamChannel}.
*/
public class IOStreamAddress extends SocketAddress {
public class IoStreamAddress extends SocketAddress {
private static final long serialVersionUID = -4382415449059935960L;
@ -32,7 +32,7 @@ public class IOStreamAddress extends SocketAddress {
private final OutputStream outputStream;
public IOStreamAddress(final InputStream inputStream, final OutputStream outputStream) {
public IoStreamAddress(final InputStream inputStream, final OutputStream outputStream) {
this.inputStream = inputStream;
this.outputStream = outputStream;

View File

@ -28,25 +28,25 @@ import io.netty.channel.ChannelSink;
* A channel to an {@link java.io.InputStream} and an
* {@link java.io.OutputStream}.
*/
public class IOStreamChannel extends AbstractChannel {
public class IoStreamChannel extends AbstractChannel {
IOStreamChannel(final ChannelFactory factory, final ChannelPipeline pipeline, final ChannelSink sink) {
IoStreamChannel(final ChannelFactory factory, final ChannelPipeline pipeline, final ChannelSink sink) {
super(null, factory, pipeline, sink);
}
@Override
public ChannelConfig getConfig() {
return ((IOStreamChannelSink) getPipeline().getSink()).getConfig();
return ((IoStreamChannelSink) getPipeline().getSink()).getConfig();
}
@Override
public boolean isBound() {
return ((IOStreamChannelSink) getPipeline().getSink()).isBound();
return ((IoStreamChannelSink) getPipeline().getSink()).isBound();
}
@Override
public boolean isConnected() {
return ((IOStreamChannelSink) getPipeline().getSink()).isConnected();
return ((IoStreamChannelSink) getPipeline().getSink()).isConnected();
}
@Override
@ -56,7 +56,7 @@ public class IOStreamChannel extends AbstractChannel {
@Override
public SocketAddress getRemoteAddress() {
return ((IOStreamChannelSink) getPipeline().getSink()).getRemoteAddress();
return ((IoStreamChannelSink) getPipeline().getSink()).getRemoteAddress();
}
@Override

View File

@ -27,22 +27,22 @@ import io.netty.util.internal.ExecutorUtil;
import java.util.concurrent.ExecutorService;
/**
* A {@link io.netty.channel.ChannelFactory} for creating {@link IOStreamChannel} instances.
* A {@link io.netty.channel.ChannelFactory} for creating {@link IoStreamChannel} instances.
*/
public class IOStreamChannelFactory implements ChannelFactory {
public class IoStreamChannelFactory implements ChannelFactory {
private final ChannelGroup channels = new DefaultChannelGroup("IOStreamChannelFactory-ChannelGroup");
private final ExecutorService executorService;
public IOStreamChannelFactory(ExecutorService executorService) {
public IoStreamChannelFactory(ExecutorService executorService) {
this.executorService = executorService;
}
@Override
public Channel newChannel(final ChannelPipeline pipeline) {
IOStreamChannelSink sink = new IOStreamChannelSink(executorService);
IOStreamChannel channel = new IOStreamChannel(this, pipeline, sink);
IoStreamChannelSink sink = new IoStreamChannelSink(executorService);
IoStreamChannel channel = new IoStreamChannel(this, pipeline, sink);
sink.setChannel(channel);
channels.add(channel);
return channel;

View File

@ -37,13 +37,13 @@ import io.netty.channel.MessageEvent;
* A {@link io.netty.channel.ChannelSink} implementation which reads from
* an {@link java.io.InputStream} and writes to an {@link java.io.OutputStream}.
*/
public class IOStreamChannelSink extends AbstractChannelSink {
public class IoStreamChannelSink extends AbstractChannelSink {
private static class ReadRunnable implements Runnable {
private final IOStreamChannelSink channelSink;
private final IoStreamChannelSink channelSink;
public ReadRunnable(final IOStreamChannelSink channelSink) {
public ReadRunnable(final IoStreamChannelSink channelSink) {
this.channelSink = channelSink;
}
@ -88,9 +88,9 @@ public class IOStreamChannelSink extends AbstractChannelSink {
private final ExecutorService executorService;
private IOStreamChannel channel;
private IoStreamChannel channel;
public IOStreamChannelSink(final ExecutorService executorService) {
public IoStreamChannelSink(final ExecutorService executorService) {
this.executorService = executorService;
}
@ -98,7 +98,7 @@ public class IOStreamChannelSink extends AbstractChannelSink {
return inputStream != null && outputStream != null;
}
public IOStreamAddress getRemoteAddress() {
public IoStreamAddress getRemoteAddress() {
return remoteAddress;
}
@ -110,11 +110,11 @@ public class IOStreamChannelSink extends AbstractChannelSink {
return config;
}
public void setChannel(final IOStreamChannel channel) {
public void setChannel(final IoStreamChannel channel) {
this.channel = channel;
}
private IOStreamAddress remoteAddress;
private IoStreamAddress remoteAddress;
private OutputStream outputStream;
@ -139,7 +139,7 @@ public class IOStreamChannelSink extends AbstractChannelSink {
if (Boolean.FALSE.equals(value)) {
outputStream = null;
inputStream = null;
((IOStreamChannel) e.getChannel()).doSetClosed();
((IoStreamChannel) e.getChannel()).doSetClosed();
}
break;
@ -148,7 +148,7 @@ public class IOStreamChannelSink extends AbstractChannelSink {
case CONNECTED:
if (value != null) {
remoteAddress = (IOStreamAddress) value;
remoteAddress = (IoStreamAddress) value;
outputStream = remoteAddress.getOutputStream();
inputStream = new PushbackInputStream(remoteAddress.getInputStream());
executorService.execute(new ReadRunnable(this));