Java tutorial
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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 org.apache.hadoop.mpich.appmaster.netty; import io.netty.channel.ChannelInitializer; import io.netty.channel.ChannelPipeline; import io.netty.channel.socket.SocketChannel; import io.netty.handler.codec.LineBasedFrameDecoder; import io.netty.handler.codec.string.StringDecoder; import io.netty.handler.codec.string.StringEncoder; import io.netty.handler.logging.LogLevel; import io.netty.handler.logging.LoggingHandler; import org.apache.hadoop.mpich.appmaster.MpiProcessManager; import org.apache.hadoop.mpich.appmaster.pmi.PMIClientCommandHandler; public class ServerChannelInitializer extends ChannelInitializer<SocketChannel> { private MpiProcessManager manager; public ServerChannelInitializer(MpiProcessManager manager) { this.manager = manager; } @Override public void initChannel(SocketChannel ch) throws Exception { ChannelPipeline pipeline = ch.pipeline(); PMIClientCommandHandler handler = new PMIClientCommandHandler(manager, ch); pipeline.addLast(new LineBasedFrameDecoder(256)); pipeline.addLast(new StringEncoder()); pipeline.addLast(new StringDecoder()); pipeline.addLast(new LoggingHandler(LogLevel.INFO)); pipeline.addLast(new ClientChannelHandler(handler)); } }