From fd0b0a4e2be5ccaeff5ea0a6c1c995c114f09a10 Mon Sep 17 00:00:00 2001 From: Trustin Lee Date: Fri, 30 Mar 2012 12:48:28 +0900 Subject: [PATCH] Code cleanup --- buffer/pom.xml | 1 - codec-http/pom.xml | 1 - .../codec/spdy/SpdyProtocolException.java | 2 ++ codec/pom.xml | 1 - common/pom.xml | 1 - example/pom.xml | 1 - .../example/objectecho/ObjectEchoClient.java | 11 +++++--- .../example/objectecho/ObjectEchoServer.java | 11 +++++--- handler/pom.xml | 1 - testsuite/pom.xml | 1 - .../AbstractSocketObjectStreamEchoTest.java | 25 +++++++++++-------- transport-http/pom.xml | 1 - transport-rxtx/pom.xml | 1 - transport-sctp/pom.xml | 1 - .../UnsupportedOperatingSystemException.java | 3 +++ .../channel/sctp/SctpNotificationHandler.java | 10 ++++---- .../io/netty/channel/sctp/SctpWorker.java | 24 ++++++------------ .../AbstractSocketObjectStreamEchoTest.java | 25 +++++++++++++------ .../sctp/SctpMultiHomingEchoTest.java | 25 +++++++++++++------ transport/pom.xml | 1 - 20 files changed, 79 insertions(+), 68 deletions(-) diff --git a/buffer/pom.xml b/buffer/pom.xml index eb1d841c09..f8a14ece94 100644 --- a/buffer/pom.xml +++ b/buffer/pom.xml @@ -23,7 +23,6 @@ 4.0.0.Alpha1-SNAPSHOT - io.netty netty-buffer jar diff --git a/codec-http/pom.xml b/codec-http/pom.xml index 3227f5e442..82417dac2a 100644 --- a/codec-http/pom.xml +++ b/codec-http/pom.xml @@ -23,7 +23,6 @@ 4.0.0.Alpha1-SNAPSHOT - io.netty netty-codec-http jar diff --git a/codec-http/src/main/java/io/netty/handler/codec/spdy/SpdyProtocolException.java b/codec-http/src/main/java/io/netty/handler/codec/spdy/SpdyProtocolException.java index f373bed840..4148e4d16c 100644 --- a/codec-http/src/main/java/io/netty/handler/codec/spdy/SpdyProtocolException.java +++ b/codec-http/src/main/java/io/netty/handler/codec/spdy/SpdyProtocolException.java @@ -22,6 +22,8 @@ package io.netty.handler.codec.spdy; */ public class SpdyProtocolException extends Exception { + private static final long serialVersionUID = -1097979786367505658L; + /** * Creates a new instance. */ diff --git a/codec/pom.xml b/codec/pom.xml index a8691be22c..7dde784f51 100644 --- a/codec/pom.xml +++ b/codec/pom.xml @@ -23,7 +23,6 @@ 4.0.0.Alpha1-SNAPSHOT - io.netty netty-codec jar diff --git a/common/pom.xml b/common/pom.xml index 24edd61632..d3df86ba98 100644 --- a/common/pom.xml +++ b/common/pom.xml @@ -23,7 +23,6 @@ 4.0.0.Alpha1-SNAPSHOT - io.netty netty-common jar diff --git a/example/pom.xml b/example/pom.xml index b21e2ea2e3..c06ddcb577 100644 --- a/example/pom.xml +++ b/example/pom.xml @@ -23,7 +23,6 @@ 4.0.0.Alpha1-SNAPSHOT - io.netty netty-example jar diff --git a/example/src/main/java/io/netty/example/objectecho/ObjectEchoClient.java b/example/src/main/java/io/netty/example/objectecho/ObjectEchoClient.java index 9b2dec06b6..38c84f7887 100644 --- a/example/src/main/java/io/netty/example/objectecho/ObjectEchoClient.java +++ b/example/src/main/java/io/netty/example/objectecho/ObjectEchoClient.java @@ -15,18 +15,19 @@ */ package io.netty.example.objectecho; -import java.net.InetSocketAddress; -import java.util.concurrent.Executors; - import io.netty.bootstrap.ClientBootstrap; import io.netty.channel.ChannelPipeline; import io.netty.channel.ChannelPipelineFactory; import io.netty.channel.Channels; import io.netty.channel.socket.nio.NioClientSocketChannelFactory; import io.netty.example.echo.EchoClient; +import io.netty.handler.codec.serialization.ClassResolvers; import io.netty.handler.codec.serialization.ObjectDecoder; import io.netty.handler.codec.serialization.ObjectEncoder; +import java.net.InetSocketAddress; +import java.util.concurrent.Executors; + /** * Modification of {@link EchoClient} which utilizes Java object serialization. */ @@ -50,10 +51,12 @@ public class ObjectEchoClient { // Set up the pipeline factory. bootstrap.setPipelineFactory(new ChannelPipelineFactory() { + @Override public ChannelPipeline getPipeline() throws Exception { return Channels.pipeline( new ObjectEncoder(), - new ObjectDecoder(), + new ObjectDecoder( + ClassResolvers.cacheDisabled(getClass().getClassLoader())), new ObjectEchoClientHandler(firstMessageSize)); } }); diff --git a/example/src/main/java/io/netty/example/objectecho/ObjectEchoServer.java b/example/src/main/java/io/netty/example/objectecho/ObjectEchoServer.java index abc6ec535d..8ccccdc1d6 100644 --- a/example/src/main/java/io/netty/example/objectecho/ObjectEchoServer.java +++ b/example/src/main/java/io/netty/example/objectecho/ObjectEchoServer.java @@ -15,18 +15,19 @@ */ package io.netty.example.objectecho; -import java.net.InetSocketAddress; -import java.util.concurrent.Executors; - import io.netty.bootstrap.ServerBootstrap; import io.netty.channel.ChannelPipeline; import io.netty.channel.ChannelPipelineFactory; import io.netty.channel.Channels; import io.netty.channel.socket.nio.NioServerSocketChannelFactory; import io.netty.example.echo.EchoServer; +import io.netty.handler.codec.serialization.ClassResolvers; import io.netty.handler.codec.serialization.ObjectDecoder; import io.netty.handler.codec.serialization.ObjectEncoder; +import java.net.InetSocketAddress; +import java.util.concurrent.Executors; + /** * Modification of {@link EchoServer} which utilizes Java object serialization. */ @@ -46,10 +47,12 @@ public class ObjectEchoServer { // Set up the pipeline factory. bootstrap.setPipelineFactory(new ChannelPipelineFactory() { + @Override public ChannelPipeline getPipeline() throws Exception { return Channels.pipeline( new ObjectEncoder(), - new ObjectDecoder(), + new ObjectDecoder( + ClassResolvers.cacheDisabled(getClass().getClassLoader())), new ObjectEchoServerHandler()); } }); diff --git a/handler/pom.xml b/handler/pom.xml index 9c9c64263e..284046706b 100644 --- a/handler/pom.xml +++ b/handler/pom.xml @@ -23,7 +23,6 @@ 4.0.0.Alpha1-SNAPSHOT - io.netty netty-handler jar diff --git a/testsuite/pom.xml b/testsuite/pom.xml index 3bc918d5c6..83a0a10452 100644 --- a/testsuite/pom.xml +++ b/testsuite/pom.xml @@ -23,7 +23,6 @@ 4.0.0.Alpha1-SNAPSHOT - io.netty netty-testsuite jar diff --git a/testsuite/src/test/java/io/netty/testsuite/transport/socket/AbstractSocketObjectStreamEchoTest.java b/testsuite/src/test/java/io/netty/testsuite/transport/socket/AbstractSocketObjectStreamEchoTest.java index 4e324c6c16..dccebb3a4e 100644 --- a/testsuite/src/test/java/io/netty/testsuite/transport/socket/AbstractSocketObjectStreamEchoTest.java +++ b/testsuite/src/test/java/io/netty/testsuite/transport/socket/AbstractSocketObjectStreamEchoTest.java @@ -16,15 +16,6 @@ package io.netty.testsuite.transport.socket; import static org.junit.Assert.*; - -import java.io.IOException; -import java.net.InetSocketAddress; -import java.util.Random; -import java.util.concurrent.Executor; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.atomic.AtomicReference; - import io.netty.bootstrap.ClientBootstrap; import io.netty.bootstrap.ServerBootstrap; import io.netty.channel.Channel; @@ -35,10 +26,20 @@ import io.netty.channel.ChannelStateEvent; import io.netty.channel.ExceptionEvent; import io.netty.channel.MessageEvent; import io.netty.channel.SimpleChannelUpstreamHandler; +import io.netty.handler.codec.serialization.ClassResolvers; import io.netty.handler.codec.serialization.ObjectDecoder; import io.netty.handler.codec.serialization.ObjectEncoder; import io.netty.util.SocketAddresses; import io.netty.util.internal.ExecutorUtil; + +import java.io.IOException; +import java.net.InetSocketAddress; +import java.util.Random; +import java.util.concurrent.Executor; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.atomic.AtomicReference; + import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; @@ -83,11 +84,13 @@ public abstract class AbstractSocketObjectStreamEchoTest { EchoHandler sh = new EchoHandler(); EchoHandler ch = new EchoHandler(); - sb.getPipeline().addLast("decoder", new ObjectDecoder()); + sb.getPipeline().addLast("decoder", new ObjectDecoder( + ClassResolvers.cacheDisabled(getClass().getClassLoader()))); sb.getPipeline().addLast("encoder", new ObjectEncoder()); sb.getPipeline().addLast("handler", sh); - cb.getPipeline().addLast("decoder", new ObjectDecoder()); + cb.getPipeline().addLast("decoder", new ObjectDecoder( + ClassResolvers.cacheDisabled(getClass().getClassLoader()))); cb.getPipeline().addLast("encoder", new ObjectEncoder()); cb.getPipeline().addLast("handler", ch); diff --git a/transport-http/pom.xml b/transport-http/pom.xml index eb28818dd9..65e21d10f4 100644 --- a/transport-http/pom.xml +++ b/transport-http/pom.xml @@ -23,7 +23,6 @@ 4.0.0.Alpha1-SNAPSHOT - io.netty netty-transport-http jar diff --git a/transport-rxtx/pom.xml b/transport-rxtx/pom.xml index ca39dd2e2c..dafb386e1c 100644 --- a/transport-rxtx/pom.xml +++ b/transport-rxtx/pom.xml @@ -23,7 +23,6 @@ 4.0.0.Alpha1-SNAPSHOT - io.netty netty-transport-rxtx jar diff --git a/transport-sctp/pom.xml b/transport-sctp/pom.xml index 2d6a2d8b6e..6ae84222b5 100644 --- a/transport-sctp/pom.xml +++ b/transport-sctp/pom.xml @@ -23,7 +23,6 @@ 4.0.0.Alpha1-SNAPSHOT - io.netty netty-transport-sctp jar diff --git a/transport-sctp/src/main/java/com/sun/nio/sctp/UnsupportedOperatingSystemException.java b/transport-sctp/src/main/java/com/sun/nio/sctp/UnsupportedOperatingSystemException.java index ad990c757f..8cd99f1783 100644 --- a/transport-sctp/src/main/java/com/sun/nio/sctp/UnsupportedOperatingSystemException.java +++ b/transport-sctp/src/main/java/com/sun/nio/sctp/UnsupportedOperatingSystemException.java @@ -16,6 +16,9 @@ package com.sun.nio.sctp; public class UnsupportedOperatingSystemException extends RuntimeException { + + private static final long serialVersionUID = -221782446524784377L; + public static void raise() { throw new UnsupportedOperatingSystemException(); } diff --git a/transport-sctp/src/main/java/io/netty/channel/sctp/SctpNotificationHandler.java b/transport-sctp/src/main/java/io/netty/channel/sctp/SctpNotificationHandler.java index 345041149e..65f2502040 100644 --- a/transport-sctp/src/main/java/io/netty/channel/sctp/SctpNotificationHandler.java +++ b/transport-sctp/src/main/java/io/netty/channel/sctp/SctpNotificationHandler.java @@ -15,6 +15,9 @@ */ package io.netty.channel.sctp; +import io.netty.channel.ChannelPipeline; +import io.netty.channel.Channels; + import com.sun.nio.sctp.AbstractNotificationHandler; import com.sun.nio.sctp.AssociationChangeNotification; import com.sun.nio.sctp.HandlerResult; @@ -23,20 +26,17 @@ import com.sun.nio.sctp.PeerAddressChangeNotification; import com.sun.nio.sctp.SendFailedNotification; import com.sun.nio.sctp.ShutdownNotification; -import io.netty.channel.ChannelPipeline; -import io.netty.channel.Channels; - /** */ -class SctpNotificationHandler extends AbstractNotificationHandler { +class SctpNotificationHandler extends AbstractNotificationHandler { private final SctpChannelImpl sctpChannel; private final ChannelPipeline pipeline; SctpNotificationHandler(SctpChannelImpl sctpChannel) { this.sctpChannel = sctpChannel; - this.pipeline = sctpChannel.getPipeline(); + pipeline = sctpChannel.getPipeline(); } @Override diff --git a/transport-sctp/src/main/java/io/netty/channel/sctp/SctpWorker.java b/transport-sctp/src/main/java/io/netty/channel/sctp/SctpWorker.java index f99d076ecc..534bab2e8b 100644 --- a/transport-sctp/src/main/java/io/netty/channel/sctp/SctpWorker.java +++ b/transport-sctp/src/main/java/io/netty/channel/sctp/SctpWorker.java @@ -15,16 +15,7 @@ */ package io.netty.channel.sctp; -import static io.netty.channel.Channels.fireChannelBound; -import static io.netty.channel.Channels.fireChannelClosed; -import static io.netty.channel.Channels.fireChannelConnected; -import static io.netty.channel.Channels.fireChannelDisconnected; -import static io.netty.channel.Channels.fireChannelInterestChanged; -import static io.netty.channel.Channels.fireChannelUnbound; -import static io.netty.channel.Channels.fireExceptionCaught; -import static io.netty.channel.Channels.fireMessageReceived; -import static io.netty.channel.Channels.fireWriteComplete; -import static io.netty.channel.Channels.succeededFuture; +import static io.netty.channel.Channels.*; import io.netty.buffer.ChannelBuffer; import io.netty.buffer.ChannelBufferFactory; import io.netty.channel.Channel; @@ -61,7 +52,6 @@ import com.sun.nio.sctp.MessageInfo; /** */ -@SuppressWarnings("unchecked") class SctpWorker implements Worker { private static final InternalLogger logger = @@ -249,7 +239,7 @@ class SctpWorker implements Worker { } } } - + @Override public void executeInIoThread(Runnable task) { if (Thread.currentThread() == thread) { @@ -261,15 +251,15 @@ class SctpWorker implements Worker { // wake up the selector to speed things selector.wakeup(); } - + } } - + static boolean isIoThread(SctpChannelImpl channel) { return Thread.currentThread() == channel.worker.thread; } - + private void processRegisterTaskQueue() throws IOException { for (; ;) { final Runnable task = registerTaskQueue.poll(); @@ -293,7 +283,7 @@ class SctpWorker implements Worker { cleanUpCancelledKeys(); } } - + private void processEventQueue() throws IOException { for (;;) { final Runnable task = eventQueue.poll(); @@ -304,7 +294,7 @@ class SctpWorker implements Worker { cleanUpCancelledKeys(); } } - + private void processSelectedKeys(final Set selectedKeys) throws IOException { for (Iterator i = selectedKeys.iterator(); i.hasNext();) { SelectionKey k = i.next(); diff --git a/transport-sctp/src/test/java/io/netty/testsuite/transport/AbstractSocketObjectStreamEchoTest.java b/transport-sctp/src/test/java/io/netty/testsuite/transport/AbstractSocketObjectStreamEchoTest.java index 59102e3ce8..26b97f1efb 100644 --- a/transport-sctp/src/test/java/io/netty/testsuite/transport/AbstractSocketObjectStreamEchoTest.java +++ b/transport-sctp/src/test/java/io/netty/testsuite/transport/AbstractSocketObjectStreamEchoTest.java @@ -15,18 +15,24 @@ */ package io.netty.testsuite.transport; +import static org.junit.Assert.*; import io.netty.bootstrap.ClientBootstrap; import io.netty.bootstrap.ServerBootstrap; -import io.netty.channel.*; +import io.netty.channel.Channel; +import io.netty.channel.ChannelFactory; +import io.netty.channel.ChannelFuture; +import io.netty.channel.ChannelHandlerContext; +import io.netty.channel.ChannelStateEvent; +import io.netty.channel.ExceptionEvent; +import io.netty.channel.MessageEvent; +import io.netty.channel.SimpleChannelUpstreamHandler; import io.netty.channel.sctp.codec.SctpFrameDecoder; import io.netty.channel.sctp.codec.SctpFrameEncoder; +import io.netty.handler.codec.serialization.ClassResolvers; import io.netty.handler.codec.serialization.ObjectDecoder; import io.netty.handler.codec.serialization.ObjectEncoder; import io.netty.testsuite.util.SctpSocketAddresses; import io.netty.util.internal.ExecutorUtil; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; import java.io.IOException; import java.net.InetSocketAddress; @@ -36,8 +42,9 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.atomic.AtomicReference; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; public abstract class AbstractSocketObjectStreamEchoTest { @@ -81,13 +88,15 @@ public abstract class AbstractSocketObjectStreamEchoTest { sb.getPipeline().addLast("sctp-decoder", new SctpFrameDecoder()); sb.getPipeline().addLast("sctp-encoder", new SctpFrameEncoder()); - sb.getPipeline().addLast("decoder", new ObjectDecoder()); + sb.getPipeline().addLast("decoder", new ObjectDecoder( + ClassResolvers.cacheDisabled(getClass().getClassLoader()))); sb.getPipeline().addLast("encoder", new ObjectEncoder()); sb.getPipeline().addLast("handler", sh); cb.getPipeline().addLast("sctp-decoder", new SctpFrameDecoder()); cb.getPipeline().addLast("sctp-encoder", new SctpFrameEncoder()); - cb.getPipeline().addLast("decoder", new ObjectDecoder()); + cb.getPipeline().addLast("decoder", new ObjectDecoder( + ClassResolvers.cacheDisabled(getClass().getClassLoader()))); cb.getPipeline().addLast("encoder", new ObjectEncoder()); cb.getPipeline().addLast("handler", ch); diff --git a/transport-sctp/src/test/java/io/netty/testsuite/transport/sctp/SctpMultiHomingEchoTest.java b/transport-sctp/src/test/java/io/netty/testsuite/transport/sctp/SctpMultiHomingEchoTest.java index ace6899480..f2057168d9 100644 --- a/transport-sctp/src/test/java/io/netty/testsuite/transport/sctp/SctpMultiHomingEchoTest.java +++ b/transport-sctp/src/test/java/io/netty/testsuite/transport/sctp/SctpMultiHomingEchoTest.java @@ -15,20 +15,28 @@ */ package io.netty.testsuite.transport.sctp; +import static org.junit.Assert.*; import io.netty.bootstrap.ClientBootstrap; import io.netty.bootstrap.ServerBootstrap; import io.netty.buffer.ChannelBuffer; import io.netty.buffer.ChannelBuffers; -import io.netty.channel.*; -import io.netty.channel.sctp.*; +import io.netty.channel.Channel; +import io.netty.channel.ChannelFactory; +import io.netty.channel.ChannelFuture; +import io.netty.channel.ChannelHandlerContext; +import io.netty.channel.ChannelStateEvent; +import io.netty.channel.ExceptionEvent; +import io.netty.channel.MessageEvent; +import io.netty.channel.sctp.SctpChannel; +import io.netty.channel.sctp.SctpClientSocketChannelFactory; +import io.netty.channel.sctp.SctpNotificationEvent; +import io.netty.channel.sctp.SctpServerChannel; +import io.netty.channel.sctp.SctpServerSocketChannelFactory; import io.netty.channel.sctp.codec.SctpFrameDecoder; import io.netty.channel.sctp.codec.SctpFrameEncoder; import io.netty.channel.sctp.handler.SimpleSctpChannelHandler; import io.netty.testsuite.util.SctpSocketAddresses; import io.netty.util.internal.ExecutorUtil; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; import java.io.IOException; import java.net.InetAddress; @@ -39,8 +47,9 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.atomic.AtomicReference; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; public class SctpMultiHomingEchoTest { private static final Random random = new Random(); @@ -152,7 +161,7 @@ public class SctpMultiHomingEchoTest { assertTrue(multiHomingUnbindFuture.awaitUninterruptibly().isSuccess()); ChannelFuture multiHomingServerUnbindFuture = serverChannel.unbindAddress(InetAddress.getByName(SctpSocketAddresses.LOOP_BACK2)); - assertTrue(multiHomingUnbindFuture.awaitUninterruptibly().isSuccess()); + assertTrue(multiHomingServerUnbindFuture.awaitUninterruptibly().isSuccess()); sh.channel.close().awaitUninterruptibly(); diff --git a/transport/pom.xml b/transport/pom.xml index 01f293a234..89f4adee74 100644 --- a/transport/pom.xml +++ b/transport/pom.xml @@ -23,7 +23,6 @@ 4.0.0.Alpha1-SNAPSHOT - io.netty netty-transport jar