1 /* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */
3 package org.opendaylight.openflowjava.protocol.impl.clients;
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;
10 import javax.net.ssl.SSLEngine;
12 import org.opendaylight.openflowjava.protocol.impl.core.SslContextFactory;
14 import com.google.common.util.concurrent.SettableFuture;
16 /** Initializes secured {@link SimpleClient} pipeline
18 * @author michal.polkorab
20 public class SimpleClientInitializer extends ChannelInitializer<SocketChannel> {
22 private SettableFuture<Boolean> isOnlineFuture;
23 private boolean secured;
24 private ScenarioHandler scenarioHandler;
27 * @param isOnlineFuture future notifier of connected channel
28 * @param secured true if {@link SimpleClient} should use encrypted communication
30 public SimpleClientInitializer(SettableFuture<Boolean> isOnlineFuture, boolean secured) {
31 this.isOnlineFuture = isOnlineFuture;
32 this.secured = secured;
36 public void initChannel(SocketChannel ch) throws Exception {
37 ChannelPipeline pipeline = ch.pipeline();
39 SSLEngine engine = SslContextFactory.getClientContext()
41 engine.setUseClientMode(true);
42 pipeline.addLast("ssl", new SslHandler(engine));
43 pipeline.addLast("framer", new SimpleClientFramer());
45 SimpleClientHandler simpleClientHandler = new SimpleClientHandler(isOnlineFuture, scenarioHandler);
46 simpleClientHandler.setScenario(scenarioHandler);
47 pipeline.addLast("handler", simpleClientHandler);
48 isOnlineFuture = null;
53 * @param scenarioHandler handler of scenario events
55 public void setScenario(ScenarioHandler scenarioHandler) {
56 this.scenarioHandler = scenarioHandler;