import org.opendaylight.protocol.bgp.parser.BGPSessionListener;
import org.opendaylight.protocol.bgp.rib.impl.spi.BGPDispatcher;
import org.opendaylight.protocol.bgp.rib.impl.spi.BGPSessionPreferences;
-import org.opendaylight.protocol.framework.Dispatcher;
+import org.opendaylight.protocol.framework.AbstractDispatcher;
import org.opendaylight.protocol.framework.ProtocolMessageFactory;
import org.opendaylight.protocol.framework.ReconnectStrategy;
/**
* Implementation of BGPDispatcher.
*/
-public final class BGPDispatcherImpl implements BGPDispatcher {
+public final class BGPDispatcherImpl extends AbstractDispatcher implements BGPDispatcher {
private final Timer timer = new HashedWheelTimer();
private final ProtocolMessageFactory<BGPMessage> parser;
- private final Dispatcher dispatcher;
- public BGPDispatcherImpl(final Dispatcher dispatcher, final ProtocolMessageFactory<BGPMessage> parser) {
- this.dispatcher = Preconditions.checkNotNull(dispatcher);
+ public BGPDispatcherImpl(final ProtocolMessageFactory<BGPMessage> parser) {
+ super();
this.parser = Preconditions.checkNotNull(parser);
}
@Override
public Future<? extends BGPSession> createClient(final InetSocketAddress address, final BGPSessionPreferences preferences,
final BGPSessionListener listener, final ReconnectStrategy strategy) {
- return this.dispatcher.createClient(address, listener, new BGPSessionNegotiatorFactory(timer, preferences), parser, strategy);
- }
-
- public Dispatcher getDispatcher() {
- return this.dispatcher;
+ return createClient(address, listener, new BGPSessionNegotiatorFactory(timer, preferences), parser, strategy);
}
}
import org.opendaylight.protocol.bgp.rib.impl.spi.BGPSessionPreferences;
import org.opendaylight.protocol.concepts.ASNumber;
import org.opendaylight.protocol.concepts.IPv4Address;
-import org.opendaylight.protocol.framework.DispatcherImpl;
import org.opendaylight.protocol.framework.NeverReconnectStrategy;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
BGPDispatcherImpl dispatcher;
public Main() throws IOException {
- this.dispatcher = new BGPDispatcherImpl(new DispatcherImpl(), new BGPMessageFactory());
+ this.dispatcher = new BGPDispatcherImpl(new BGPMessageFactory());
}
public static void main(final String[] args) throws NumberFormatException, IOException {
final Main m = new Main();
- final BGPSessionListener sessionListener = new TestingListener((DispatcherImpl) m.dispatcher.getDispatcher());
+ final BGPSessionListener sessionListener = new TestingListener();
final BGPSessionProposalImpl prop = new BGPSessionProposalImpl(holdTimerValue, as, new IPv4Address(InetAddress.getByName("25.25.25.2")));
import org.opendaylight.protocol.bgp.parser.BGPSession;
import org.opendaylight.protocol.bgp.parser.BGPSessionListener;
import org.opendaylight.protocol.bgp.parser.BGPTerminationReason;
-import org.opendaylight.protocol.framework.DispatcherImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class TestingListener implements BGPSessionListener {
private static final Logger logger = LoggerFactory.getLogger(TestingListener.class);
- DispatcherImpl d;
-
- TestingListener(final DispatcherImpl d) {
- this.d = d;
- }
-
@Override
public void onMessage(final BGPSession session, final BGPMessage message) {
logger.info("Client Listener: message received: {}", message.toString());
public void onSessionDown(final BGPSession session, final Exception e) {
logger.info("Client Listener: Connection lost.");
session.close();
- // this.d.stop();
}
@Override
public void onSessionTerminated(final BGPSession session, final BGPTerminationReason cause) {
logger.info("Client Listener: Connection lost: {}.", cause);
- // this.d.stop();
}
}
import org.opendaylight.protocol.bgp.rib.impl.spi.BGPSessionPreferences;
import org.opendaylight.protocol.concepts.ASNumber;
import org.opendaylight.protocol.concepts.IPv4;
-import org.opendaylight.protocol.framework.DispatcherImpl;
+import org.opendaylight.protocol.framework.AbstractDispatcher;
import org.opendaylight.protocol.framework.SessionListenerFactory;
-public class BGPSpeakerMock {
-
- DispatcherImpl dispatcher = new DispatcherImpl();
+public class BGPSpeakerMock extends AbstractDispatcher {
public static void main(final String[] args) throws IOException {
final SessionListenerFactory<BGPSessionListener> f = new SessionListenerFactory<BGPSessionListener>() {
@Override
public BGPSessionListener getSessionListener() {
- return new SpeakerSessionListener(m.dispatcher);
+ return new SpeakerSessionListener(m);
}
};
- m.dispatcher.createServer(new InetSocketAddress("127.0.0.2", 12345), f,
+ m.createServer(new InetSocketAddress("127.0.0.2", 12345), f,
new BGPSessionNegotiatorFactory(new HashedWheelTimer(), prefs), new BGPMessageFactory());
}
}
import org.opendaylight.protocol.bgp.parser.BGPSession;
import org.opendaylight.protocol.bgp.parser.BGPSessionListener;
import org.opendaylight.protocol.bgp.parser.BGPTerminationReason;
-import org.opendaylight.protocol.framework.DispatcherImpl;
+import org.opendaylight.protocol.framework.AbstractDispatcher;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class SpeakerSessionListener implements BGPSessionListener {
private static final Logger logger = LoggerFactory.getLogger(SpeakerSessionListener.class);
- DispatcherImpl d;
+ AbstractDispatcher d;
- SpeakerSessionListener(final DispatcherImpl d) {
+ SpeakerSessionListener(final AbstractDispatcher d) {
this.d = d;
}
* 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 final class DispatcherImpl implements Closeable, Dispatcher {
+public abstract class AbstractDispatcher implements Closeable {
- private static final Logger logger = LoggerFactory.getLogger(DispatcherImpl.class);
+ private static final Logger logger = LoggerFactory.getLogger(AbstractDispatcher.class);
private final EventLoopGroup bossGroup;
private final EventLoopGroup workerGroup;
- public DispatcherImpl() {
+ protected AbstractDispatcher() {
// FIXME: we should get these as arguments
this.bossGroup = new NioEventLoopGroup();
this.workerGroup = new NioEventLoopGroup();
}
- @Override
- public <M extends ProtocolMessage, S extends ProtocolSession<M>, L extends SessionListener<M, ?, ?>> ChannelFuture createServer(
+ /**
+ * Creates server. Each server needs factories to pass their instances to client sessions.
+ *
+ * @param address address to which the server should be bound
+ * @param listenerFactory factory for creating protocol listeners, passed to the negotiator
+ * @param negotiatorFactory protocol session negotiator factory
+ * @param messageFactory message parser
+ *
+ * @return ChannelFuture representing the binding process
+ */
+ protected <M extends ProtocolMessage, S extends ProtocolSession<M>, L extends SessionListener<M, ?, ?>> ChannelFuture createServer(
final InetSocketAddress address, final SessionListenerFactory<L> listenerFactory,
final SessionNegotiatorFactory<M, S, L> negotiatorFactory, final ProtocolMessageFactory<M> messageFactory) {
final ServerBootstrap b = new ServerBootstrap();
}
- @Override
- public <M extends ProtocolMessage, S extends ProtocolSession<M>, L extends SessionListener<M, ?, ?>> Future<S> createClient(
+ /**
+ * Creates a client.
+ *
+ * @param address remote address
+ * @param listener session listener
+ * @param negotiatorFactory session negotiator factory
+ * @param messageFactory message parser
+ * @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.
+ */
+ protected <M extends ProtocolMessage, S extends ProtocolSession<M>, L extends SessionListener<M, ?, ?>> Future<S> createClient(
final InetSocketAddress address, final L listener, final SessionNegotiatorFactory<M, S, L> negotiatorFactory,
final ProtocolMessageFactory<M> messageFactory, final ReconnectStrategy strategy) {
final ProtocolSessionPromise<M, S, L> p = new ProtocolSessionPromise<M, S, L>(workerGroup, address, negotiatorFactory,
return p;
}
- @Override
- public <M extends ProtocolMessage, S extends ProtocolSession<M>, L extends SessionListener<M, ?, ?>> Future<Void> createReconnectingClient(
+ /**
+ * Creates a client.
+ *
+ * @param address remote address
+ * @param listener session listener
+ * @param negotiatorFactory session negotiator factory
+ * @param messageFactory message parser
+ * @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
+ */
+ protected <M extends ProtocolMessage, S extends ProtocolSession<M>, L extends SessionListener<M, ?, ?>> Future<Void> createReconnectingClient(
final InetSocketAddress address, final L listener, final SessionNegotiatorFactory<M, S, L> negotiatorFactory,
final ProtocolMessageFactory<M> messageFactory, final ReconnectStrategyFactory connectStrategyFactory,
final ReconnectStrategy reestablishStrategy) {
+++ /dev/null
-/*
- * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.protocol.framework;
-
-import io.netty.channel.ChannelFuture;
-import io.netty.util.concurrent.Future;
-
-import java.net.InetSocketAddress;
-
-/**
- * Dispatcher class for creating protocol servers and clients.
- */
-public interface Dispatcher {
- /**
- * Creates server. Each server needs factories to pass their instances to client sessions.
- *
- * @param address address to which the server should be bound
- * @param listenerFactory factory for creating protocol listeners, passed to the negotiator
- * @param negotiatorFactory protocol session negotiator factory
- * @param messageFactory message parser
- *
- * @return ChannelFuture representing the binding process
- */
- public <M extends ProtocolMessage, S extends ProtocolSession<M>, L extends SessionListener<M, ?, ?>> ChannelFuture createServer(
- InetSocketAddress address, final SessionListenerFactory<L> listenerFactory,
- SessionNegotiatorFactory<M, S, L> negotiatorFactory, ProtocolMessageFactory<M> messageFactory);
-
- /**
- * Creates a client.
- *
- * @param address remote address
- * @param listener session listener
- * @param negotiatorFactory session negotiator factory
- * @param messageFactory message parser
- * @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.
- */
- public <M extends ProtocolMessage, S extends ProtocolSession<M>, L extends SessionListener<M, ?, ?>> Future<S> createClient(
- InetSocketAddress address, final L listener, SessionNegotiatorFactory<M, S, L> negotiatorFactory,
- ProtocolMessageFactory<M> messageFactory, ReconnectStrategy connectStrategy);
-
- /**
- * Creates a client.
- *
- * @param address remote address
- * @param listener session listener
- * @param negotiatorFactory session negotiator factory
- * @param messageFactory message parser
- * @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
- */
- public <M extends ProtocolMessage, S extends ProtocolSession<M>, L extends SessionListener<M, ?, ?>> Future<Void> createReconnectingClient(
- final InetSocketAddress address, final L listener, final SessionNegotiatorFactory<M, S, L> negotiatorFactory,
- final ProtocolMessageFactory<M> messageFactory,
- final ReconnectStrategyFactory connectStrategyFactory, final ReconnectStrategy reestablishStrategy);
-}
import com.google.common.base.Preconditions;
final class ReconnectPromise<M extends ProtocolMessage, S extends ProtocolSession<M>, L extends SessionListener<M, ?, ?>> extends DefaultPromise<Void> {
- private final Dispatcher dispatcher;
+ private final AbstractDispatcher dispatcher;
private final InetSocketAddress address;
private final L listener;
private final SessionNegotiatorFactory<M, S, L> negotiatorFactory;
private final ReconnectStrategy strategy;
private Future<?> pending;
- public ReconnectPromise(final Dispatcher dispatcher,
+ public ReconnectPromise(final AbstractDispatcher dispatcher,
final InetSocketAddress address, final L listener,
final SessionNegotiatorFactory<M, S, L> negotiatorFactory,
final ProtocolMessageFactory<M> messageFactory,
public class ServerTest {
public static final int PORT = 18080;
- DispatcherImpl clientDispatcher, dispatcher;
+ AbstractDispatcher clientDispatcher, dispatcher;
final SimpleSessionListener pce = new SimpleSessionListener();
@Test
public void testConnectionEstablished() throws Exception {
- this.dispatcher = new DispatcherImpl();
+ this.dispatcher = new AbstractDispatcher() { };
final Promise<Boolean> p = new DefaultPromise<>(GlobalEventExecutor.INSTANCE);
this.server.get();
- this.clientDispatcher = new DispatcherImpl();
+ this.clientDispatcher = new AbstractDispatcher() { };
this.session = this.clientDispatcher.createClient(this.serverAddress, new SimpleSessionListener(),
new SessionNegotiatorFactory<SimpleMessage, SimpleSession, SimpleSessionListener>() {
}
public void testConnectionFailed() throws IOException, InterruptedException {
- this.dispatcher = new DispatcherImpl();
- this.clientDispatcher = new DispatcherImpl();
+ this.dispatcher = new AbstractDispatcher() { };
+ this.clientDispatcher = new AbstractDispatcher() { };
final SimpleSessionListener listener = new SimpleSessionListener();
try {
import java.net.InetSocketAddress;
import java.util.concurrent.ExecutionException;
-import org.opendaylight.protocol.framework.Dispatcher;
+import org.opendaylight.protocol.framework.AbstractDispatcher;
import org.opendaylight.protocol.framework.ReconnectStrategy;
import org.opendaylight.protocol.framework.SessionListenerFactory;
import org.opendaylight.protocol.framework.SessionNegotiatorFactory;
/**
* Implementation of PCEPDispatcher.
*/
-public class PCEPDispatcherImpl implements PCEPDispatcher {
+public class PCEPDispatcherImpl extends AbstractDispatcher implements PCEPDispatcher {
private static final PCEPMessageFactory msgFactory = new PCEPMessageFactory();
private final SessionNegotiatorFactory<PCEPMessage, PCEPSessionImpl, PCEPSessionListener> snf;
- private final Dispatcher dispatcher;
/**
* Creates an instance of PCEPDispatcherImpl, gets the default selector and opens it.
*
* @throws IOException if some error occurred during opening the selector
*/
- public PCEPDispatcherImpl(final Dispatcher dispatcher, final SessionNegotiatorFactory<PCEPMessage, PCEPSessionImpl, PCEPSessionListener> snf) {
- this.dispatcher = dispatcher;
+ public PCEPDispatcherImpl(final SessionNegotiatorFactory<PCEPMessage, PCEPSessionImpl, PCEPSessionListener> snf) {
+ super();
this.snf = snf;
}
@Override
public ChannelFuture createServer(final InetSocketAddress address, final SessionListenerFactory<PCEPSessionListener> listenerFactory) {
- return this.dispatcher.createServer(address, listenerFactory, snf, msgFactory);
+ return this.createServer(address, listenerFactory, snf, msgFactory);
}
/**
*/
@Override
public Future<? extends PCEPSession> createClient(final InetSocketAddress address, final PCEPSessionListener listener, final ReconnectStrategy strategy) {
- return this.dispatcher.createClient(address, listener, snf, msgFactory, strategy);
+ return this.createClient(address, listener, snf, msgFactory, strategy);
}
}
import java.net.InetAddress;
import java.net.InetSocketAddress;
-import org.opendaylight.protocol.framework.DispatcherImpl;
import org.opendaylight.protocol.pcep.PCEPSessionProposalFactory;
import org.opendaylight.protocol.pcep.impl.DefaultPCEPSessionNegotiatorFactory;
import org.opendaylight.protocol.pcep.impl.PCEPDispatcherImpl;
final PCEPOpenObject prefs = spf.getSessionProposal(address, 0);
- final DispatcherImpl d = new DispatcherImpl();
- final PCEPDispatcherImpl dispatcher = new PCEPDispatcherImpl(d, new DefaultPCEPSessionNegotiatorFactory(new HashedWheelTimer(), prefs, 5));
+ final PCEPDispatcherImpl dispatcher = new PCEPDispatcherImpl(new DefaultPCEPSessionNegotiatorFactory(new HashedWheelTimer(), prefs, 5));
dispatcher.createServer(address, new TestingSessionListenerFactory()).get();
}
import java.net.InetSocketAddress;
import java.util.List;
-import org.opendaylight.protocol.framework.DispatcherImpl;
import org.opendaylight.protocol.framework.NeverReconnectStrategy;
import org.opendaylight.protocol.pcep.PCEPTlv;
import org.opendaylight.protocol.pcep.impl.DefaultPCEPSessionNegotiatorFactory;
final List<PCEPTlv> tlvs = Lists.newArrayList();
tlvs.add(new NodeIdentifierTlv(new byte[] { (byte) 127, (byte) 2, (byte) 3, (byte) 7 }));
- final DispatcherImpl di = new DispatcherImpl();
- final PCEPDispatcherImpl d = new PCEPDispatcherImpl(di, new DefaultPCEPSessionNegotiatorFactory(new HashedWheelTimer(), new PCEPOpenObject(30, 120, 0, tlvs), 0));
+ final PCEPDispatcherImpl d = new PCEPDispatcherImpl(new DefaultPCEPSessionNegotiatorFactory(new HashedWheelTimer(), new PCEPOpenObject(30, 120, 0, tlvs), 0));
try {
d.createClient(new InetSocketAddress("127.0.0.3", 12345), new SimpleSessionListener(),