2 * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved.
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
10 package org.opendaylight.openflowjava.protocol.impl.clients;
12 import io.netty.channel.ChannelInitializer;
13 import io.netty.channel.ChannelPipeline;
14 import io.netty.channel.socket.nio.NioSocketChannel;
15 import io.netty.handler.ssl.SslHandler;
17 import javax.net.ssl.SSLEngine;
19 import com.google.common.util.concurrent.SettableFuture;
21 /** Initializes secured {@link SimpleClient} pipeline
23 * @author michal.polkorab
25 public class SimpleClientInitializer extends ChannelInitializer<NioSocketChannel> {
27 private SettableFuture<Boolean> isOnlineFuture;
28 private boolean secured;
29 private ScenarioHandler scenarioHandler;
32 * @param isOnlineFuture future notifier of connected channel
33 * @param secured true if {@link SimpleClient} should use encrypted communication
35 public SimpleClientInitializer(SettableFuture<Boolean> isOnlineFuture, boolean secured) {
36 this.isOnlineFuture = isOnlineFuture;
37 this.secured = secured;
41 public void initChannel(NioSocketChannel ch) throws Exception {
42 ChannelPipeline pipeline = ch.pipeline();
44 SSLEngine engine = ClientSslContextFactory.getClientContext()
46 engine.setUseClientMode(true);
47 pipeline.addLast("ssl", new SslHandler(engine));
49 SimpleClientHandler simpleClientHandler = new SimpleClientHandler(isOnlineFuture, scenarioHandler);
50 simpleClientHandler.setScenario(scenarioHandler);
51 pipeline.addLast("framer", new SimpleClientFramer());
52 pipeline.addLast("handler", simpleClientHandler);
53 isOnlineFuture = null;
58 * @param scenarioHandler handler of scenario events
60 public void setScenario(ScenarioHandler scenarioHandler) {
61 this.scenarioHandler = scenarioHandler;