Removed deprecated constructor in AbstractDispatcher 65/2665/1
authorMaros Marsalek <mmarsale@cisco.com>
Tue, 12 Nov 2013 13:19:22 +0000 (14:19 +0100)
committerMaros Marsalek <mmarsale@cisco.com>
Tue, 12 Nov 2013 13:20:18 +0000 (14:20 +0100)
Change-Id: I8fde5e2c8f473b3c8f804b6d5cdea19f6d92ea41
Signed-off-by: Maros Marsalek <mmarsale@cisco.com>
bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/BGPDispatcherImpl.java
framework/src/main/java/org/opendaylight/protocol/framework/AbstractDispatcher.java
framework/src/test/java/org/opendaylight/protocol/framework/ServerTest.java
framework/src/test/java/org/opendaylight/protocol/framework/SimpleDispatcher.java
pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/PCEPDispatcherImpl.java

index 54d75e0bcbd1b7983d87722b815efb0e2f433bae..f53c85ea5df5f6ef3d72845fa278aff4e952abec 100644 (file)
@@ -26,7 +26,7 @@ import java.net.InetSocketAddress;
 /**
  * Implementation of BGPDispatcher.
  */
-public final class BGPDispatcherImpl extends AbstractDispatcher<BGPSessionImpl, BGPSessionListener> implements BGPDispatcher {
+public final class BGPDispatcherImpl extends AbstractDispatcher<BGPSessionImpl, BGPSessionListener> implements BGPDispatcher, AutoCloseable {
        private final Timer timer = new HashedWheelTimer();
 
        private final BGPHandlerFactory hf;
@@ -55,4 +55,8 @@ public final class BGPDispatcherImpl extends AbstractDispatcher<BGPSessionImpl,
                        }
                });
        }
+
+       @Override
+               public void close() throws Exception {
+       }
 }
index c040170e1b3dbbcc50c7341139c37ecdf63389d6..c4e7d31f7476cd6c5f7470ffa866e8e337c64045 100644 (file)
@@ -31,7 +31,7 @@ import java.net.InetSocketAddress;
  * Dispatcher class for creating servers and clients. The idea is to first create servers and clients and the run the
  * start method that will handle sockets in different thread.
  */
-public abstract class AbstractDispatcher<S extends ProtocolSession<?>, L extends SessionListener<?, ?, ?>> implements Closeable {
+public abstract class AbstractDispatcher<S extends ProtocolSession<?>, L extends SessionListener<?, ?, ?>> {
 
        protected interface PipelineInitializer<S extends ProtocolSession<?>> {
                /**
@@ -51,17 +51,6 @@ public abstract class AbstractDispatcher<S extends ProtocolSession<?>, L extends
 
        private final EventLoopGroup workerGroup;
 
-
-       /**
-        * Internally creates new instances of NioEventLoopGroup, might deplete system resources and result in Too many open files exception.
-        *
-        * @deprecated use {@link AbstractDispatcher#AbstractDispatcher(io.netty.channel.EventLoopGroup, io.netty.channel.EventLoopGroup)} instead.
-        */
-       @Deprecated
-       protected AbstractDispatcher() {
-               this(new NioEventLoopGroup(),new NioEventLoopGroup());
-       }
-
        protected AbstractDispatcher(EventLoopGroup bossGroup, EventLoopGroup workerGroup) {
                this.bossGroup = bossGroup;
                this.workerGroup = workerGroup;
@@ -141,12 +130,4 @@ public abstract class AbstractDispatcher<S extends ProtocolSession<?>, L extends
 
        }
 
-       @Override
-       public void close() {
-               try {
-                       this.workerGroup.shutdownGracefully();
-               } finally {
-                       this.bossGroup.shutdownGracefully();
-               }
-       }
 }
index de214877f68be5ef26be712a61d1379534a5e25e..e86b40ee6be5f8f1b403cfff062a91d01ef791f5 100644 (file)
@@ -7,14 +7,16 @@
  */
 package org.opendaylight.protocol.framework;
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
 import io.netty.channel.Channel;
 import io.netty.channel.ChannelFuture;
+import io.netty.channel.nio.NioEventLoopGroup;
 import io.netty.util.concurrent.DefaultPromise;
 import io.netty.util.concurrent.Future;
 import io.netty.util.concurrent.GlobalEventExecutor;
 import io.netty.util.concurrent.Promise;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
 
 import java.io.IOException;
 import java.net.InetSocketAddress;
@@ -22,9 +24,8 @@ import java.util.concurrent.ExecutionException;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.TimeoutException;
 
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
 
 public class ServerTest {
        SimpleDispatcher clientDispatcher, dispatcher;
@@ -36,11 +37,14 @@ public class ServerTest {
        ChannelFuture server = null;
 
        InetSocketAddress serverAddress;
+       private NioEventLoopGroup eventLoopGroup;
+
 
        @Before
        public void setUp() {
                final int port = 10000 + (int)(10000 * Math.random());
                serverAddress = new InetSocketAddress("127.0.0.5", port);
+               eventLoopGroup = new NioEventLoopGroup();
        }
 
        @Test
@@ -55,7 +59,7 @@ public class ServerTest {
                                p.setSuccess(true);
                                return new SimpleSessionNegotiator(promise, channel);
                        }
-               }, new ProtocolHandlerFactory<>(new MessageFactory()), new DefaultPromise<SimpleSession>(GlobalEventExecutor.INSTANCE));
+               }, new ProtocolHandlerFactory<>(new MessageFactory()), new DefaultPromise<SimpleSession>(GlobalEventExecutor.INSTANCE), eventLoopGroup);
 
                this.server = this.dispatcher.createServer(this.serverAddress, new SessionListenerFactory<SimpleSessionListener>() {
                        @Override
@@ -72,7 +76,7 @@ public class ServerTest {
                                        final Channel channel, final Promise<SimpleSession> promise) {
                                return new SimpleSessionNegotiator(promise, channel);
                        }
-               }, new ProtocolHandlerFactory<>(new MessageFactory()), new DefaultPromise<SimpleSession>(GlobalEventExecutor.INSTANCE));
+               }, new ProtocolHandlerFactory<>(new MessageFactory()), new DefaultPromise<SimpleSession>(GlobalEventExecutor.INSTANCE), eventLoopGroup);
 
                this.session = (SimpleSession) this.clientDispatcher.createClient(this.serverAddress,
                                new NeverReconnectStrategy(GlobalEventExecutor.INSTANCE, 5000), new SessionListenerFactory<SimpleSessionListener>() {
@@ -97,7 +101,7 @@ public class ServerTest {
                                p.setSuccess(true);
                                return new SimpleSessionNegotiator(promise, channel);
                        }
-               }, new ProtocolHandlerFactory<>(new MessageFactory()), new DefaultPromise<SimpleSession>(GlobalEventExecutor.INSTANCE));
+               }, new ProtocolHandlerFactory<>(new MessageFactory()), new DefaultPromise<SimpleSession>(GlobalEventExecutor.INSTANCE), eventLoopGroup);
 
                this.server = this.dispatcher.createServer(this.serverAddress, new SessionListenerFactory<SimpleSessionListener>() {
                        @Override
@@ -114,7 +118,7 @@ public class ServerTest {
                                        final Channel channel, final Promise<SimpleSession> promise) {
                                return new SimpleSessionNegotiator(promise, channel);
                        }
-               }, new ProtocolHandlerFactory<>(new MessageFactory()), new DefaultPromise<SimpleSession>(GlobalEventExecutor.INSTANCE));
+               }, new ProtocolHandlerFactory<>(new MessageFactory()), new DefaultPromise<SimpleSession>(GlobalEventExecutor.INSTANCE), eventLoopGroup);
 
                this.session = (SimpleSession) this.clientDispatcher.createClient(this.serverAddress,
                                new NeverReconnectStrategy(GlobalEventExecutor.INSTANCE, 5000), new SessionListenerFactory<SimpleSessionListener>() {
@@ -135,12 +139,11 @@ public class ServerTest {
        }
 
        @After
-       public void tearDown() throws IOException {
+       public void tearDown() throws IOException, InterruptedException {
                this.server.channel().close();
-               this.dispatcher.close();
-               this.clientDispatcher.close();
+               this.eventLoopGroup.shutdownGracefully();
                try {
-                       Thread.sleep(100);
+                       Thread.sleep(500);
                } catch (final InterruptedException e) {
                        throw new RuntimeException(e);
                }
index 68bf1ceb844b64f954c8abf166814cd1dc11c0e7..8542c784948aa441ad95ee6f797b0de7f0d0628e 100644 (file)
@@ -2,7 +2,7 @@ package org.opendaylight.protocol.framework;
 
 import com.google.common.base.Preconditions;
 import io.netty.channel.ChannelFuture;
-import io.netty.channel.nio.NioEventLoopGroup;
+import io.netty.channel.EventLoopGroup;
 import io.netty.channel.socket.SocketChannel;
 import io.netty.util.concurrent.Future;
 import io.netty.util.concurrent.Promise;
@@ -18,6 +18,7 @@ public class SimpleDispatcher extends AbstractDispatcher<SimpleSession, SimpleSe
        private final SessionNegotiatorFactory<SimpleMessage, SimpleSession, SimpleSessionListener> negotiatorFactory;
        private final ProtocolHandlerFactory<?> factory;
 
+
        private final class SimplePipelineInitializer implements PipelineInitializer<SimpleSession> {
                final SessionListenerFactory<SimpleSessionListener> listenerFactory;
 
@@ -36,8 +37,8 @@ public class SimpleDispatcher extends AbstractDispatcher<SimpleSession, SimpleSe
        }
 
        public SimpleDispatcher(final SessionNegotiatorFactory<SimpleMessage, SimpleSession, SimpleSessionListener> negotiatorFactory, final ProtocolHandlerFactory<?> factory,
-                       final Promise<SimpleSession> promise) {
-               super(new NioEventLoopGroup(), new NioEventLoopGroup());
+                       final Promise<SimpleSession> promise, EventLoopGroup eventLoopGroup) {
+               super(eventLoopGroup, eventLoopGroup);
                this.negotiatorFactory = Preconditions.checkNotNull(negotiatorFactory);
                this.factory = Preconditions.checkNotNull(factory);
        }
@@ -49,4 +50,5 @@ public class SimpleDispatcher extends AbstractDispatcher<SimpleSession, SimpleSe
        public ChannelFuture createServer(final InetSocketAddress address, final SessionListenerFactory<SimpleSessionListener> listenerFactory) {
                return super.createServer(address, new SimplePipelineInitializer(listenerFactory));
        }
+
 }
index 05e09aa7add5294651de2a42f8bd591be688f639..f89990ed726ebb145b352e131bd77380747323b8 100644 (file)
@@ -26,7 +26,7 @@ import java.net.InetSocketAddress;
 /**
  * Implementation of PCEPDispatcher.
  */
-public class PCEPDispatcherImpl extends AbstractDispatcher<PCEPSessionImpl, PCEPSessionListener> implements PCEPDispatcher {
+public class PCEPDispatcherImpl extends AbstractDispatcher<PCEPSessionImpl, PCEPSessionListener> implements PCEPDispatcher, AutoCloseable {
 
        private final SessionNegotiatorFactory<Message, PCEPSessionImpl, PCEPSessionListener> snf;
        private final PCEPHandlerFactory hf;
@@ -55,4 +55,8 @@ public class PCEPDispatcherImpl extends AbstractDispatcher<PCEPSessionImpl, PCEP
                        }
                });
        }
+
+       @Override
+               public void close() throws Exception {
+       }
 }