Package com.torrent4j.net.peerwire

Source Code of com.torrent4j.net.peerwire.PeerWirePipelineFactory

package com.torrent4j.net.peerwire;

import static io.netty.channel.Channels.pipeline;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.ChannelPipelineFactory;
import io.netty.handler.logging.LoggingHandler;
import io.netty.logging.InternalLogLevel;

import java.util.concurrent.Executor;

import com.torrent4j.TorrentController;
import com.torrent4j.net.peerwire.codec.PeerWireFrameDecoder;
import com.torrent4j.net.peerwire.codec.PeerWireFrameEncoder;
import com.torrent4j.net.peerwire.codec.PeerWireMessageDecoder;
import com.torrent4j.net.peerwire.codec.PeerWireMessageEncoder;
import com.torrent4j.net.peerwire.traffic.PeerTrafficShapingHandler;
import com.torrent4j.net.peerwire.traffic.TorrentTrafficShapingHandler;

public class PeerWirePipelineFactory implements ChannelPipelineFactory {
  private final TorrentController controller;
  private final Executor executor;

  public PeerWirePipelineFactory(TorrentController controller,
      Executor executor) {
    this.controller = controller;
    this.executor = executor;
  }

  @Override
  public ChannelPipeline getPipeline() throws Exception {
    final ChannelPipeline p = pipeline();

    p.addLast("torrent-shaper", new TorrentTrafficShapingHandler(executor));
    p.addLast("traffic-shaper", new PeerTrafficShapingHandler(executor));

    p.addLast("frame-decoder", new PeerWireFrameDecoder());
    p.addLast("frame-encoder", new PeerWireFrameEncoder());

    p.addLast("message-decoder", new PeerWireMessageDecoder());
    p.addLast("message-encoder", new PeerWireMessageEncoder());

    p.addLast("logging", new LoggingHandler(InternalLogLevel.WARN));

    p.addLast("handler", new PeerWireHandler(controller));

    return p;
  }
}
TOP

Related Classes of com.torrent4j.net.peerwire.PeerWirePipelineFactory

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.