-import io.netty.util.concurrent.Promise;
-
-import java.io.Closeable;
-import java.net.InetSocketAddress;
-
-import org.opendaylight.controller.netconf.util.AbstractChannelInitializer;
-import org.opendaylight.protocol.framework.AbstractDispatcher;
-import org.opendaylight.protocol.framework.ReconnectStrategy;
-import org.opendaylight.protocol.framework.ReconnectStrategyFactory;
-import org.opendaylight.protocol.framework.SessionListenerFactory;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import com.google.common.base.Optional;
-
-public class NetconfClientDispatcher extends AbstractDispatcher<NetconfClientSession, NetconfClientSessionListener> implements Closeable {
-
- private static final Logger logger = LoggerFactory.getLogger(NetconfClientDispatcher.class);
-
- private final NetconfClientSessionNegotiatorFactory negotatorFactory;
- private final HashedWheelTimer timer;
-
- public NetconfClientDispatcher(EventLoopGroup bossGroup, EventLoopGroup workerGroup, long clientConnectionTimeoutMillis) {
- super(bossGroup, workerGroup);
- timer = new HashedWheelTimer();
- this.negotatorFactory = new NetconfClientSessionNegotiatorFactory(timer, Optional.<String>absent(), clientConnectionTimeoutMillis);
- }
-
- public NetconfClientDispatcher(EventLoopGroup bossGroup, EventLoopGroup workerGroup, String additionalHeader, long connectionTimeoutMillis) {
- super(bossGroup, workerGroup);
- timer = new HashedWheelTimer();
- this.negotatorFactory = new NetconfClientSessionNegotiatorFactory(timer, Optional.of(additionalHeader), connectionTimeoutMillis);
- }
-
- public Future<NetconfClientSession> createClient(InetSocketAddress address,
- final NetconfClientSessionListener sessionListener, ReconnectStrategy strat) {
-
- return super.createClient(address, strat, new PipelineInitializer<NetconfClientSession>() {
-
- @Override
- public void initializeChannel(final SocketChannel ch, final Promise<NetconfClientSession> promise) {
- initialize(ch, promise);
- }
-
- private void initialize(SocketChannel ch, Promise<NetconfClientSession> promise) {
- new ClientChannelInitializer( negotatorFactory, sessionListener).initialize(ch, promise);
- }
- });
- }
-
- public Future<Void> createReconnectingClient(final InetSocketAddress address,
- final NetconfClientSessionListener listener,
- final ReconnectStrategyFactory connectStrategyFactory, final ReconnectStrategy reestablishStrategy) {
- final ClientChannelInitializer init = new ClientChannelInitializer(negotatorFactory, listener);
-
- return super.createReconnectingClient(address, connectStrategyFactory, reestablishStrategy,
- new PipelineInitializer<NetconfClientSession>() {
- @Override
- public void initializeChannel(final SocketChannel ch, final Promise<NetconfClientSession> promise) {
- init.initialize(ch, promise);
- }
- });
- }
-
- private static class ClientChannelInitializer extends AbstractChannelInitializer<NetconfClientSession> {
-
- private final NetconfClientSessionNegotiatorFactory negotiatorFactory;
- private final NetconfClientSessionListener sessionListener;