From: Maros Marsalek Date: Fri, 8 Nov 2013 10:21:17 +0000 (+0100) Subject: EventLoopGroup instances moved to constructor parameters for AbstractDispatcher. X-Git-Tag: jenkins-bgpcep-bulk-release-prepare-only-1~237^2~61 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;h=365d6585c96ae16d4e86cb035bc183c7207cc53c;p=bgpcep.git EventLoopGroup instances moved to constructor parameters for AbstractDispatcher. Change-Id: I489913f3766e9562ec8cefeae0870fdd88b757c7 Signed-off-by: Maros Marsalek --- diff --git a/bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/BGPDispatcherImpl.java b/bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/BGPDispatcherImpl.java index a590a63004..54d75e0bcb 100644 --- a/bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/BGPDispatcherImpl.java +++ b/bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/BGPDispatcherImpl.java @@ -7,14 +7,12 @@ */ package org.opendaylight.protocol.bgp.rib.impl; +import io.netty.channel.EventLoopGroup; import io.netty.channel.socket.SocketChannel; import io.netty.util.HashedWheelTimer; import io.netty.util.Timer; import io.netty.util.concurrent.Future; import io.netty.util.concurrent.Promise; - -import java.net.InetSocketAddress; - import org.opendaylight.protocol.bgp.parser.BGPMessageFactory; import org.opendaylight.protocol.bgp.parser.BGPSessionListener; import org.opendaylight.protocol.bgp.rib.impl.spi.BGPDispatcher; @@ -23,6 +21,8 @@ import org.opendaylight.protocol.framework.AbstractDispatcher; import org.opendaylight.protocol.framework.ReconnectStrategy; import org.opendaylight.protocol.framework.SessionListenerFactory; +import java.net.InetSocketAddress; + /** * Implementation of BGPDispatcher. */ @@ -31,8 +31,8 @@ public final class BGPDispatcherImpl extends AbstractDispatcher, L extends SessionListener> extends AbstractDispatcher { @@ -41,6 +40,7 @@ public class BGPSpeakerMock, L extends SessionLi public BGPSpeakerMock(final SessionNegotiatorFactory negotiatorFactory, final ProtocolHandlerFactory factory, final DefaultPromise defaultPromise) { + super(new NioEventLoopGroup(), new NioEventLoopGroup()); this.negotiatorFactory = Preconditions.checkNotNull(negotiatorFactory); this.factory = Preconditions.checkNotNull(factory); } diff --git a/framework/src/main/java/org/opendaylight/protocol/framework/AbstractDispatcher.java b/framework/src/main/java/org/opendaylight/protocol/framework/AbstractDispatcher.java index afea289c00..c040170e1b 100644 --- a/framework/src/main/java/org/opendaylight/protocol/framework/AbstractDispatcher.java +++ b/framework/src/main/java/org/opendaylight/protocol/framework/AbstractDispatcher.java @@ -21,13 +21,12 @@ 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.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.io.Closeable; import java.net.InetSocketAddress; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - /** * 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. @@ -38,7 +37,7 @@ public abstract class AbstractDispatcher, L extends /** * Initializes channel by specifying the handlers in its pipeline. Handlers are protocol specific, therefore this * method needs to be implemented in protocol specific Dispatchers. - * + * * @param channel whose pipeline should be defined, also to be passed to {@link SessionNegotiatorFactory} * @param promise to be passed to {@link SessionNegotiatorFactory} */ @@ -52,18 +51,28 @@ public abstract class AbstractDispatcher, 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() { - // FIXME: we should get these as arguments - this.bossGroup = new NioEventLoopGroup(); - this.workerGroup = new NioEventLoopGroup(); + this(new NioEventLoopGroup(),new NioEventLoopGroup()); + } + + protected AbstractDispatcher(EventLoopGroup bossGroup, EventLoopGroup workerGroup) { + this.bossGroup = bossGroup; + this.workerGroup = workerGroup; } /** * Creates server. Each server needs factories to pass their instances to client sessions. - * + * * @param address address to which the server should be bound * @param initializer instance of PipelineInitializer used to initialize the channel pipeline - * + * * @return ChannelFuture representing the binding process */ protected ChannelFuture createServer(final InetSocketAddress address, final PipelineInitializer initializer) { @@ -89,12 +98,12 @@ public abstract class AbstractDispatcher, L extends /** * Creates a client. - * + * * @param address remote address * @param connectStrategy Reconnection strategy to be used when initial connection fails - * + * * @return Future representing the connection process. Its result represents the combined success of TCP connection - * as well as session negotiation. + * as well as session negotiation. */ protected Future createClient(final InetSocketAddress address, final ReconnectStrategy strategy, final PipelineInitializer initializer) { final Bootstrap b = new Bootstrap(); @@ -114,13 +123,13 @@ public abstract class AbstractDispatcher, L extends /** * Creates a client. - * + * * @param address remote address * @param connectStrategyFactory Factory for creating reconnection strategy to be used when initial connection fails * @param reestablishStrategy Reconnection strategy to be used when the already-established session fails - * + * * @return Future representing the reconnection task. It will report completion based on reestablishStrategy, e.g. - * success if it indicates no further attempts should be made and failure if it reports an error + * success if it indicates no further attempts should be made and failure if it reports an error */ protected Future createReconnectingClient(final InetSocketAddress address, final ReconnectStrategyFactory connectStrategyFactory, final ReconnectStrategy reestablishStrategy, final PipelineInitializer initializer) { diff --git a/framework/src/test/java/org/opendaylight/protocol/framework/SimpleDispatcher.java b/framework/src/test/java/org/opendaylight/protocol/framework/SimpleDispatcher.java index bbaf5ca4ac..68bf1ceb84 100644 --- a/framework/src/test/java/org/opendaylight/protocol/framework/SimpleDispatcher.java +++ b/framework/src/test/java/org/opendaylight/protocol/framework/SimpleDispatcher.java @@ -1,16 +1,15 @@ 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.socket.SocketChannel; import io.netty.util.concurrent.Future; import io.netty.util.concurrent.Promise; - -import java.net.InetSocketAddress; - import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import com.google.common.base.Preconditions; +import java.net.InetSocketAddress; public class SimpleDispatcher extends AbstractDispatcher { @@ -38,6 +37,7 @@ public class SimpleDispatcher extends AbstractDispatcher negotiatorFactory, final ProtocolHandlerFactory factory, final Promise promise) { + super(new NioEventLoopGroup(), new NioEventLoopGroup()); this.negotiatorFactory = Preconditions.checkNotNull(negotiatorFactory); this.factory = Preconditions.checkNotNull(factory); } diff --git a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/PCEPDispatcherImpl.java b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/PCEPDispatcherImpl.java index 0e3351fd8b..05e09aa7ad 100644 --- a/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/PCEPDispatcherImpl.java +++ b/pcep/impl/src/main/java/org/opendaylight/protocol/pcep/impl/PCEPDispatcherImpl.java @@ -7,13 +7,11 @@ */ package org.opendaylight.protocol.pcep.impl; +import com.google.common.base.Preconditions; import io.netty.channel.ChannelFuture; +import io.netty.channel.EventLoopGroup; import io.netty.channel.socket.SocketChannel; import io.netty.util.concurrent.Promise; - -import java.io.IOException; -import java.net.InetSocketAddress; - import org.opendaylight.protocol.framework.AbstractDispatcher; import org.opendaylight.protocol.framework.SessionListenerFactory; import org.opendaylight.protocol.framework.SessionNegotiatorFactory; @@ -22,7 +20,8 @@ import org.opendaylight.protocol.pcep.PCEPSessionListener; import org.opendaylight.protocol.pcep.spi.MessageHandlerRegistry; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Message; -import com.google.common.base.Preconditions; +import java.io.IOException; +import java.net.InetSocketAddress; /** * Implementation of PCEPDispatcher. @@ -34,11 +33,13 @@ public class PCEPDispatcherImpl extends AbstractDispatcher negotiatorFactory) { - super(); + public PCEPDispatcherImpl(final MessageHandlerRegistry registry, + final SessionNegotiatorFactory negotiatorFactory, + EventLoopGroup bossGroup, EventLoopGroup workerGroup) { + super(bossGroup, workerGroup); this.snf = Preconditions.checkNotNull(negotiatorFactory); this.hf = new PCEPHandlerFactory(registry); } diff --git a/pcep/testtool/src/main/java/org/opendaylight/protocol/pcep/testtool/Main.java b/pcep/testtool/src/main/java/org/opendaylight/protocol/pcep/testtool/Main.java index e8dd2b4820..2855f4f288 100644 --- a/pcep/testtool/src/main/java/org/opendaylight/protocol/pcep/testtool/Main.java +++ b/pcep/testtool/src/main/java/org/opendaylight/protocol/pcep/testtool/Main.java @@ -7,11 +7,8 @@ */ package org.opendaylight.protocol.pcep.testtool; +import io.netty.channel.nio.NioEventLoopGroup; import io.netty.util.HashedWheelTimer; - -import java.net.InetAddress; -import java.net.InetSocketAddress; - import org.opendaylight.protocol.pcep.PCEPSessionProposalFactory; import org.opendaylight.protocol.pcep.impl.DefaultPCEPSessionNegotiatorFactory; import org.opendaylight.protocol.pcep.impl.PCEPDispatcherImpl; @@ -21,6 +18,9 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.typ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.net.InetAddress; +import java.net.InetSocketAddress; + public class Main { private static final Logger logger = LoggerFactory.getLogger(Main.class); @@ -126,7 +126,9 @@ public class Main { final Open prefs = spf.getSessionProposal(address, 0); - final PCEPDispatcherImpl dispatcher = new PCEPDispatcherImpl(PCEPExtensionProviderContextImpl.getSingletonInstance().getMessageHandlerRegistry(), new DefaultPCEPSessionNegotiatorFactory(new HashedWheelTimer(), prefs, 5)); + final PCEPDispatcherImpl dispatcher = new PCEPDispatcherImpl(PCEPExtensionProviderContextImpl + .getSingletonInstance().getMessageHandlerRegistry(), new DefaultPCEPSessionNegotiatorFactory( + new HashedWheelTimer(), prefs, 5), new NioEventLoopGroup(), new NioEventLoopGroup()); dispatcher.createServer(address, new TestingSessionListenerFactory()).get(); } diff --git a/pcep/testtool/src/test/java/org/opendaylight/protocol/pcep/testtool/PCCMock.java b/pcep/testtool/src/test/java/org/opendaylight/protocol/pcep/testtool/PCCMock.java index 8889967079..dc846b3751 100644 --- a/pcep/testtool/src/test/java/org/opendaylight/protocol/pcep/testtool/PCCMock.java +++ b/pcep/testtool/src/test/java/org/opendaylight/protocol/pcep/testtool/PCCMock.java @@ -7,15 +7,14 @@ */ package org.opendaylight.protocol.pcep.testtool; +import com.google.common.base.Preconditions; +import io.netty.channel.nio.NioEventLoopGroup; import io.netty.channel.socket.SocketChannel; import io.netty.util.HashedWheelTimer; 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 java.net.InetSocketAddress; - import org.opendaylight.protocol.framework.AbstractDispatcher; import org.opendaylight.protocol.framework.NeverReconnectStrategy; import org.opendaylight.protocol.framework.ProtocolHandlerFactory; @@ -34,7 +33,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.typ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.open.TlvsBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.predundancy.group.id.tlv.PredundancyGroupIdBuilder; -import com.google.common.base.Preconditions; +import java.net.InetSocketAddress; public class PCCMock, L extends SessionListener> extends AbstractDispatcher { @@ -43,6 +42,7 @@ public class PCCMock, L extends SessionListener< public PCCMock(final SessionNegotiatorFactory negotiatorFactory, final ProtocolHandlerFactory factory, final DefaultPromise defaultPromise) { + super(new NioEventLoopGroup(), new NioEventLoopGroup()); this.negotiatorFactory = Preconditions.checkNotNull(negotiatorFactory); this.factory = Preconditions.checkNotNull(factory); } diff --git a/pcep/topology-provider/src/main/java/org/opendaylight/bgpcep/pcep/topology/provider/BundleActivator.java b/pcep/topology-provider/src/main/java/org/opendaylight/bgpcep/pcep/topology/provider/BundleActivator.java index 21cb7ffa55..7a51170d8e 100644 --- a/pcep/topology-provider/src/main/java/org/opendaylight/bgpcep/pcep/topology/provider/BundleActivator.java +++ b/pcep/topology-provider/src/main/java/org/opendaylight/bgpcep/pcep/topology/provider/BundleActivator.java @@ -7,7 +7,9 @@ */ package org.opendaylight.bgpcep.pcep.topology.provider; +import com.google.common.base.Preconditions; import io.netty.channel.ChannelFuture; +import io.netty.channel.nio.NioEventLoopGroup; import io.netty.util.HashedWheelTimer; import java.net.InetSocketAddress; @@ -28,7 +30,8 @@ import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import com.google.common.base.Preconditions; +import java.net.InetSocketAddress; +import java.util.concurrent.ExecutionException; public final class BundleActivator extends AbstractBindingAwareProvider { private static final Logger LOG = LoggerFactory.getLogger(BundleActivator.class); @@ -41,7 +44,10 @@ public final class BundleActivator extends AbstractBindingAwareProvider { final InetSocketAddress address = new InetSocketAddress("0.0.0.0", 4189); final PCEPSessionProposalFactory spf = new PCEPSessionProposalFactoryImpl(30, 10, true, true, true, true, 0); final Open prefs = spf.getSessionProposal(address, 0); - final PCEPDispatcher dispatcher = new PCEPDispatcherImpl(PCEPExtensionProviderContextImpl.getSingletonInstance().getMessageHandlerRegistry(), new DefaultPCEPSessionNegotiatorFactory(new HashedWheelTimer(), prefs, 5)); + final PCEPDispatcher dispatcher = new PCEPDispatcherImpl(PCEPExtensionProviderContextImpl + .getSingletonInstance().getMessageHandlerRegistry(), new DefaultPCEPSessionNegotiatorFactory( + new HashedWheelTimer(), prefs, 5), new NioEventLoopGroup(), new NioEventLoopGroup()); + final InstanceIdentifier topology = InstanceIdentifier.builder().node(Topology.class).toInstance(); final PCEPTopologyProvider exp = new PCEPTopologyProvider(dispatcher, null, dps, topology);