1 package org.opendaylight.openflowjava.protocol.impl.core;
3 import io.netty.bootstrap.Bootstrap;
4 import io.netty.channel.EventLoopGroup;
5 import io.netty.channel.nio.NioEventLoopGroup;
6 import io.netty.channel.socket.nio.NioSocketChannel;
8 import org.opendaylight.openflowjava.protocol.api.connection.ThreadConfiguration;
9 import org.slf4j.Logger;
10 import org.slf4j.LoggerFactory;
12 import com.google.common.base.Preconditions;
13 import com.google.common.util.concurrent.ListenableFuture;
14 import com.google.common.util.concurrent.SettableFuture;
17 * Initializes (TCP) connection to device
18 * @author martin.uhlir
21 public class TcpConnectionInitializer implements ServerFacade,
22 ConnectionInitializer {
24 private static final Logger LOGGER = LoggerFactory
25 .getLogger(TcpConnectionInitializer.class);
26 private EventLoopGroup workerGroup;
27 private ThreadConfiguration threadConfig;
29 private TcpChannelInitializer channelInitializer;
34 * @param workerGroup - shared worker group
36 public TcpConnectionInitializer(NioEventLoopGroup workerGroup) {
37 Preconditions.checkNotNull(workerGroup, "WorkerGroup can't be null");
38 this.workerGroup = workerGroup;
44 b.group(workerGroup).channel(NioSocketChannel.class)
45 .handler(channelInitializer);
49 public ListenableFuture<Boolean> shutdown() {
50 final SettableFuture<Boolean> result = SettableFuture.create();
51 workerGroup.shutdownGracefully();
56 public ListenableFuture<Boolean> getIsOnlineFuture() {
61 public void setThreadConfig(ThreadConfiguration threadConfig) {
62 this.threadConfig = threadConfig;
66 public void initiateConnection(String host, int port) {
68 b.connect(host, port).sync();
69 } catch (InterruptedException e) {
70 LOGGER.error("Unable to initiate connection", e);
75 * @param channelInitializer
77 public void setChannelInitializer(TcpChannelInitializer channelInitializer) {
78 this.channelInitializer = channelInitializer;