Deprecate protocol-framework tests
[netconf.git] / protocol-framework / src / test / java / org / opendaylight / protocol / framework / SimpleDispatcher.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.protocol.framework;
9
10 import com.google.common.base.Preconditions;
11 import io.netty.channel.ChannelFuture;
12 import io.netty.channel.ChannelOutboundHandler;
13 import io.netty.channel.EventLoopGroup;
14 import io.netty.channel.socket.SocketChannel;
15 import io.netty.util.concurrent.Future;
16 import io.netty.util.concurrent.Promise;
17 import java.net.InetSocketAddress;
18 import org.slf4j.Logger;
19 import org.slf4j.LoggerFactory;
20
21 @Deprecated
22 public class SimpleDispatcher extends AbstractDispatcher<SimpleSession, SimpleSessionListener> {
23     private static final Logger LOG = LoggerFactory.getLogger(SimpleDispatcher.class);
24
25     private final SessionNegotiatorFactory<SimpleMessage, SimpleSession, SimpleSessionListener> negotiatorFactory;
26     private final ChannelOutboundHandler encoder = new SimpleMessageToByteEncoder();
27
28     private final class SimplePipelineInitializer implements PipelineInitializer<SimpleSession> {
29         final SessionListenerFactory<SimpleSessionListener> listenerFactory;
30
31         SimplePipelineInitializer(final SessionListenerFactory<SimpleSessionListener> listenerFactory) {
32             this.listenerFactory = Preconditions.checkNotNull(listenerFactory);
33         }
34
35         @Override
36         public void initializeChannel(final SocketChannel channel, final Promise<SimpleSession> promise) {
37             channel.pipeline().addLast(new SimpleByteToMessageDecoder());
38             channel.pipeline().addLast("negotiator", negotiatorFactory.getSessionNegotiator(listenerFactory, channel, promise));
39             channel.pipeline().addLast(encoder);
40             LOG.debug("initialization completed for channel {}", channel);
41         }
42
43     }
44
45     public SimpleDispatcher(final SessionNegotiatorFactory<SimpleMessage, SimpleSession, SimpleSessionListener> negotiatorFactory,
46             final Promise<SimpleSession> promise, final EventLoopGroup eventLoopGroup) {
47         super(eventLoopGroup, eventLoopGroup);
48         this.negotiatorFactory = Preconditions.checkNotNull(negotiatorFactory);
49     }
50
51     public Future<SimpleSession> createClient(final InetSocketAddress address, final ReconnectStrategy strategy, final SessionListenerFactory<SimpleSessionListener> listenerFactory) {
52         return super.createClient(address, strategy, new SimplePipelineInitializer(listenerFactory));
53     }
54
55     public Future<Void> createReconnectingClient(final InetSocketAddress address, final ReconnectStrategyFactory strategy, final SessionListenerFactory<SimpleSessionListener> listenerFactory) {
56         return super.createReconnectingClient(address, strategy, new SimplePipelineInitializer(listenerFactory));
57     }
58
59     public ChannelFuture createServer(final InetSocketAddress address, final SessionListenerFactory<SimpleSessionListener> listenerFactory) {
60         return super.createServer(address, new SimplePipelineInitializer(listenerFactory));
61     }
62
63     @Override
64     public void close() {
65     }
66 }