Merge "add basic lib - plugin communication"
[openflowjava.git] / openflow-protocol-impl / src / test / java / org / openflow / lib / clients / SimpleClientInitializer.java
1 /* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */
2
3 package org.openflow.lib.clients;
4
5 import io.netty.channel.ChannelInitializer;
6 import io.netty.channel.ChannelPipeline;
7 import io.netty.channel.socket.SocketChannel;
8 import io.netty.handler.ssl.SslHandler;
9
10 import javax.net.ssl.SSLEngine;
11
12 import org.openflow.lib.SslContextFactory;
13
14 import com.google.common.util.concurrent.SettableFuture;
15
16 /** Initializes secured {@link SimpleClient} pipeline
17  * 
18  * @author michal.polkorab
19  */
20 public class SimpleClientInitializer extends ChannelInitializer<SocketChannel> {
21     
22     private SettableFuture<Boolean> sf;
23
24     /**
25      * @param sf future notifier of connected channel
26      */
27     public SimpleClientInitializer(SettableFuture<Boolean> sf) {
28         this.sf = sf;
29     }
30
31     @Override
32     public void initChannel(SocketChannel ch) throws Exception {
33         ChannelPipeline pipeline = ch.pipeline();
34         SSLEngine engine =
35             SslContextFactory.getClientContext().createSSLEngine();
36         engine.setUseClientMode(true);
37         pipeline.addLast("ssl", new SslHandler(engine));
38         pipeline.addLast("handler", new SimpleClientHandler(sf));
39         sf = null;
40     }
41 }