本文整理汇总了Scala中org.jboss.netty.channel.ChannelPipelineFactory类的典型用法代码示例。如果您正苦于以下问题:Scala ChannelPipelineFactory类的具体用法?Scala ChannelPipelineFactory怎么用?Scala ChannelPipelineFactory使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ChannelPipelineFactory类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: StringCodec
//设置package包名称以及导入依赖的类
package com.twitter.finagle.integration
import com.twitter.finagle._
import java.nio.charset.StandardCharsets.UTF_8
import org.jboss.netty.channel.{ChannelPipelineFactory, Channels}
import org.jboss.netty.handler.codec.frame.{DelimiterBasedFrameDecoder, Delimiters}
import org.jboss.netty.handler.codec.string.{StringDecoder, StringEncoder}
object StringCodec extends StringCodec
class StringCodec extends CodecFactory[String, String] {
def server = Function.const {
new Codec[String, String] {
def pipelineFactory = new ChannelPipelineFactory {
def getPipeline = {
val pipeline = Channels.pipeline()
pipeline.addLast("frameDecoder", new DelimiterBasedFrameDecoder(100, Delimiters.lineDelimiter: _*))
pipeline.addLast("stringDecoder", new StringDecoder(UTF_8))
pipeline.addLast("stringEncoder", new StringEncoder(UTF_8))
pipeline
}
}
}
}
def client = Function.const {
new Codec[String, String] {
def pipelineFactory = new ChannelPipelineFactory {
def getPipeline = {
val pipeline = Channels.pipeline()
pipeline.addLast("stringEncode", new StringEncoder(UTF_8))
pipeline.addLast("stringDecode", new StringDecoder(UTF_8))
pipeline
}
}
override def prepareConnFactory(factory: ServiceFactory[String, String], ps: Stack.Params) =
new AddNewlineFilter andThen factory
}
}
class AddNewlineFilter extends SimpleFilter[String, String] {
def apply(request: String, service: Service[String, String]) = service(request + "\n")
}
}
示例2: ThriftServerFramedCodec
//设置package包名称以及导入依赖的类
package com.twitter.finagle.thrift
import com.twitter.finagle._
import com.twitter.finagle.stats.{NullStatsReceiver, StatsReceiver}
import com.twitter.finagle.thrift.transport.netty3.ThriftServerFramedPipelineFactory
import com.twitter.finagle.tracing.TraceInitializerFilter
import org.apache.thrift.protocol.TProtocolFactory
import org.jboss.netty.channel.ChannelPipelineFactory
object ThriftServerFramedCodec {
def apply(statsReceiver: StatsReceiver = NullStatsReceiver): ThriftServerFramedCodecFactory =
new ThriftServerFramedCodecFactory(statsReceiver)
def apply(protocolFactory: TProtocolFactory): ThriftServerFramedCodecFactory =
new ThriftServerFramedCodecFactory(protocolFactory)
def get(): ThriftServerFramedCodecFactory = apply()
}
class ThriftServerFramedCodecFactory(protocolFactory: TProtocolFactory)
extends CodecFactory[Array[Byte], Array[Byte]]#Server
{
def this(statsReceiver: StatsReceiver) =
this(Protocols.binaryFactory(statsReceiver = statsReceiver))
def this() = this(NullStatsReceiver)
def apply(config: ServerCodecConfig): ThriftServerFramedCodec =
new ThriftServerFramedCodec(config, protocolFactory)
}
class ThriftServerFramedCodec(
config: ServerCodecConfig,
protocolFactory: TProtocolFactory = Protocols.binaryFactory()
) extends Codec[Array[Byte], Array[Byte]] {
def pipelineFactory: ChannelPipelineFactory = ThriftServerFramedPipelineFactory
private[this] val preparer = ThriftServerPreparer(
protocolFactory, config.serviceName)
override def prepareConnFactory(
factory: ServiceFactory[Array[Byte],
Array[Byte]], params: Stack.Params
): ServiceFactory[Array[Byte], Array[Byte]] = preparer.prepare(factory, params)
override def newTraceInitializer = TraceInitializerFilter.serverModule[Array[Byte], Array[Byte]]
override val protocolLibraryName: String = "thrift"
}
示例3: ThriftClientFramedPipelineFactory
//设置package包名称以及导入依赖的类
package com.twitter.finagle.thrift.transport.netty3
import org.jboss.netty.channel.{ChannelPipeline, ChannelPipelineFactory, Channels}
private[finagle]
object ThriftClientFramedPipelineFactory extends ChannelPipelineFactory {
def getPipeline(): ChannelPipeline = {
val pipeline = Channels.pipeline()
pipeline.addLast("thriftFrameCodec", new ThriftFrameCodec)
pipeline.addLast("byteEncoder", new ThriftClientChannelBufferEncoder)
pipeline.addLast("byteDecoder", new ThriftChannelBufferDecoder)
pipeline
}
}
示例4: ThriftServerBufferedPipelineFactory
//设置package包名称以及导入依赖的类
package com.twitter.finagle.thrift.transport.netty3
import com.twitter.finagle.thrift.{Protocols, ThriftServerFramedCodec}
import com.twitter.finagle.{CodecFactory, ServerCodecConfig}
import org.apache.thrift.protocol.TProtocolFactory
import org.jboss.netty.channel.{ChannelPipeline, ChannelPipelineFactory}
private[netty3]
case class ThriftServerBufferedPipelineFactory(protocolFactory: TProtocolFactory)
extends ChannelPipelineFactory {
def getPipeline(): ChannelPipeline = {
val pipeline = ThriftServerFramedPipelineFactory.getPipeline()
pipeline.replace(
"thriftFrameCodec", "thriftBufferDecoder",
new ThriftBufferedTransportDecoder(protocolFactory))
pipeline
}
}
def apply(config: ServerCodecConfig): ThriftServerBufferedCodec = {
new ThriftServerBufferedCodec(protocolFactory, config)
}
}
class ThriftServerBufferedCodec(protocolFactory: TProtocolFactory, config: ServerCodecConfig)
extends ThriftServerFramedCodec(config) {
override def pipelineFactory = ThriftServerBufferedPipelineFactory(protocolFactory)
}
示例5: ThriftClientBufferedPipelineFactory
//设置package包名称以及导入依赖的类
package com.twitter.finagle.thrift.transport.netty3
import org.apache.thrift.protocol.TProtocolFactory
import org.jboss.netty.channel.{ChannelPipeline, ChannelPipelineFactory}
private[netty3] case class ThriftClientBufferedPipelineFactory(
protocolFactory: TProtocolFactory)
extends ChannelPipelineFactory {
def getPipeline(): ChannelPipeline = {
val pipeline = ThriftClientFramedPipelineFactory.getPipeline()
pipeline.replace(
"thriftFrameCodec", "thriftBufferDecoder",
new ThriftBufferedTransportDecoder(protocolFactory))
pipeline
}
}
示例6: ServerCodec
//设置package包名称以及导入依赖的类
package org.http4s
package finagle
import com.twitter.finagle.stats.StatsReceiver
import com.twitter.finagle.transport.Transport
import com.twitter.finagle.{ Codec, CodecFactory, Service }
import com.twitter.util.Closable
import org.jboss.netty.channel.{ ChannelPipelineFactory, Channels }
import org.jboss.netty.handler.codec.http.HttpServerCodec
import scalaz.syntax.id._
class ServerCodec(stats: StatsReceiver) extends CodecFactory[Request, Response] {
def server = Function.const {
new Codec[Request, Response] {
def pipelineFactory = new ChannelPipelineFactory {
def getPipeline =
Channels.pipeline() <| { _.addLast("httpCodec", new HttpServerCodec) }
}
override def newServerDispatcher(
transport: Transport[Any, Any],
service: Service[Request, Response]
): Closable =
ServerDispatcher.newServerDispatcher(transport, service, stats)
}
}
def client = throw new RuntimeException()
}
示例7: StringCodec
//设置package包名称以及导入依赖的类
package com.twitter.finagle.integration
import com.twitter.finagle.{Service, SimpleFilter, ServiceFactory, Codec, CodecFactory}
import org.jboss.netty.channel.{Channels, ChannelPipelineFactory}
import org.jboss.netty.handler.codec.frame.{Delimiters, DelimiterBasedFrameDecoder}
import org.jboss.netty.util.CharsetUtil
import org.jboss.netty.handler.codec.string.{StringEncoder, StringDecoder}
object StringCodec extends StringCodec
class StringCodec extends CodecFactory[String, String] {
def server = Function.const {
new Codec[String, String] {
def pipelineFactory = new ChannelPipelineFactory {
def getPipeline = {
val pipeline = Channels.pipeline()
pipeline.addLast("frameDecoder", new DelimiterBasedFrameDecoder(100, Delimiters.lineDelimiter: _*))
pipeline.addLast("stringDecoder", new StringDecoder(CharsetUtil.UTF_8))
pipeline.addLast("stringEncoder", new StringEncoder(CharsetUtil.UTF_8))
pipeline
}
}
}
}
def client = Function.const {
new Codec[String, String] {
def pipelineFactory = new ChannelPipelineFactory {
def getPipeline = {
val pipeline = Channels.pipeline()
pipeline.addLast("stringEncode", new StringEncoder(CharsetUtil.UTF_8))
pipeline.addLast("stringDecode", new StringDecoder(CharsetUtil.UTF_8))
pipeline
}
}
override def prepareConnFactory(factory: ServiceFactory[String, String]) =
(new AddNewlineFilter) andThen factory
}
}
class AddNewlineFilter extends SimpleFilter[String, String] {
def apply(request: String, service: Service[String, String]) = service(request + "\n")
}
}
示例8: StringCodec
//设置package包名称以及导入依赖的类
package com.twitter.finagle.example.echo
import com.twitter.finagle.{Codec, CodecFactory}
import org.jboss.netty.handler.codec.string.{StringEncoder, StringDecoder}
import org.jboss.netty.channel.{Channels, ChannelPipelineFactory}
import org.jboss.netty.handler.codec.frame.{Delimiters, DelimiterBasedFrameDecoder}
import org.jboss.netty.util.CharsetUtil
object StringCodec extends StringCodec
class StringCodec extends CodecFactory[String, String] {
def server = Function.const {
new Codec[String, String] {
def pipelineFactory = new ChannelPipelineFactory {
def getPipeline = {
val pipeline = Channels.pipeline()
pipeline.addLast("line",
new DelimiterBasedFrameDecoder(100, Delimiters.lineDelimiter: _*))
pipeline.addLast("stringDecoder", new StringDecoder(CharsetUtil.UTF_8))
pipeline.addLast("stringEncoder", new StringEncoder(CharsetUtil.UTF_8))
pipeline
}
}
}
}
def client = Function.const {
new Codec[String, String] {
def pipelineFactory = new ChannelPipelineFactory {
def getPipeline = {
val pipeline = Channels.pipeline()
pipeline.addLast("stringEncode", new StringEncoder(CharsetUtil.UTF_8))
pipeline.addLast("stringDecode", new StringDecoder(CharsetUtil.UTF_8))
pipeline
}
}
}
}
}
示例9: apply
//设置package包名称以及导入依赖的类
package com.twitter.finagle.thrift
import org.jboss.netty.channel.ChannelPipelineFactory
import com.twitter.finagle.{CodecFactory, ClientCodecConfig}
import org.apache.thrift.protocol.{TBinaryProtocol, TProtocolFactory}
def apply(config: ClientCodecConfig) = {
new ThriftClientBufferedCodec(new TBinaryProtocol.Factory(), config)
}
}
class ThriftClientBufferedCodec(protocolFactory: TProtocolFactory, config: ClientCodecConfig)
extends ThriftClientFramedCodec(protocolFactory, config)
{
override def pipelineFactory = {
val framedPipelineFactory = super.pipelineFactory
new ChannelPipelineFactory {
def getPipeline() = {
val pipeline = framedPipelineFactory.getPipeline
pipeline.replace(
"thriftFrameCodec", "thriftBufferDecoder",
new ThriftBufferDecoder(protocolFactory))
pipeline
}
}
}
}
示例10: apply
//设置package包名称以及导入依赖的类
package com.twitter.finagle.thrift
import org.jboss.netty.channel.ChannelPipelineFactory
import com.twitter.finagle.{CodecFactory, ServerCodecConfig}
import org.apache.thrift.protocol.{TBinaryProtocol, TProtocolFactory}
def apply(config: ServerCodecConfig) = {
new ThriftServerBufferedCodec(new TBinaryProtocol.Factory(), config)
}
}
class ThriftServerBufferedCodec(
protocolFactory: TProtocolFactory,
config: ServerCodecConfig
)
extends ThriftServerFramedCodec(config)
{
override def pipelineFactory = {
val framedPipelineFactory = super.pipelineFactory
new ChannelPipelineFactory {
def getPipeline() = {
val pipeline = framedPipelineFactory.getPipeline
pipeline.replace(
"thriftFrameCodec", "thriftBufferDecoder",
new ThriftBufferDecoder(protocolFactory))
pipeline
}
}
}
}