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.SocketChannel;
15 import io.netty.handler.ssl.SslHandler;
17 import javax.net.ssl.SSLEngine;
19 import org.opendaylight.openflowjava.protocol.impl.core.SslContextFactory;
21 import com.google.common.util.concurrent.SettableFuture;
23 /** Initializes secured {@link SimpleClient} pipeline
25 * @author michal.polkorab
27 public class SimpleClientInitializer extends ChannelInitializer<SocketChannel> {
29 private SettableFuture<Boolean> isOnlineFuture;
30 private boolean secured;
31 private ScenarioHandler scenarioHandler;
34 * @param isOnlineFuture future notifier of connected channel
35 * @param secured true if {@link SimpleClient} should use encrypted communication
37 public SimpleClientInitializer(SettableFuture<Boolean> isOnlineFuture, boolean secured) {
38 this.isOnlineFuture = isOnlineFuture;
39 this.secured = secured;
43 public void initChannel(SocketChannel ch) throws Exception {
44 ChannelPipeline pipeline = ch.pipeline();
46 SSLEngine engine = SslContextFactory.getClientContext()
48 engine.setUseClientMode(true);
49 pipeline.addLast("ssl", new SslHandler(engine));
50 pipeline.addLast("framer", new SimpleClientFramer());
52 SimpleClientHandler simpleClientHandler = new SimpleClientHandler(isOnlineFuture, scenarioHandler);
53 simpleClientHandler.setScenario(scenarioHandler);
54 pipeline.addLast("handler", simpleClientHandler);
55 isOnlineFuture = null;
60 * @param scenarioHandler handler of scenario events
62 public void setScenario(ScenarioHandler scenarioHandler) {
63 this.scenarioHandler = scenarioHandler;