com.hazelcast.openshift.TunnelClient.java Source code

Java tutorial

Introduction

Here is the source code for com.hazelcast.openshift.TunnelClient.java

Source

/*
 * Copyright (c) 2008-2015, Hazelcast, Inc. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.hazelcast.openshift;

import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelOption;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import io.netty.channel.socket.nio.NioServerSocketChannel;

public class TunnelClient extends AbstractTunnel {

    private final String httpHost;
    private final int httpPort;
    private final boolean httpSsl;

    public TunnelClient(int localPort, String httpHost, int httpPort, boolean httpSsl) {
        super(localPort);

        this.httpHost = httpHost;
        this.httpPort = httpPort;
        this.httpSsl = httpSsl;
    }

    public ServerBootstrap createBootstrap(int localPort) throws Exception {
        System.out.println(
                "Creating clientside plain-socket: (" + localPort + ") => (" + httpHost + ":" + httpPort + ")");
        return new ServerBootstrap().option(ChannelOption.SO_BACKLOG, 20).group(getBossGroup(), getWorkerGroup())
                .channel(NioServerSocketChannel.class).childHandler(new ChannelInitializer<SocketChannel>() {

                    @Override
                    protected void initChannel(SocketChannel channel) throws Exception {
                        ChannelPipeline pipeline = channel.pipeline();
                        pipeline.addLast(new TunnelServerConnector(getWorkerGroup(), httpHost, httpPort, httpSsl));
                    }
                });

    }
}