• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Scala Channels类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Scala中org.jboss.netty.channel.Channels的典型用法代码示例。如果您正苦于以下问题:Scala Channels类的具体用法?Scala Channels怎么用?Scala Channels使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Channels类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Scala代码示例。

示例1: RedisCodec

//设置package包名称以及导入依赖的类
package com.twitter.finagle.redis.server.protocol

import com.twitter.finagle.Failure
import com.twitter.finagle.netty3.BufChannelBuffer
import com.twitter.io.Buf
import com.twitter.io.Buf.ByteArray
import org.jboss.netty.channel.{ChannelHandlerContext, Channels, MessageEvent, SimpleChannelHandler}

import scala.collection.JavaConversions._

class RedisCodec extends SimpleChannelHandler {
  override def writeRequested(ctx: ChannelHandlerContext, e: MessageEvent): Unit =
    e.getMessage match {
      case b: Buf => Channels.write(ctx, e.getFuture, BufChannelBuffer(b))
      case typ => e.getFuture.setFailure(Failure(
        s"unexpected type ${typ.getClass.getSimpleName} when encoding to ChannelBuffer"))
    }

  override def messageReceived(ctx: ChannelHandlerContext, e: MessageEvent): Unit =
    e.getMessage match {
      case frame: RedisFrame =>
        val message: List[Buf] = frame.getParts.toList.map(ByteArray.Owned.apply)
        Channels.fireMessageReceived(ctx, message)
      case typ => Channels.fireExceptionCaught(ctx, Failure(
        s"unexpected type ${typ.getClass.getSimpleName} when encoding to Buf"))
    }
} 
开发者ID:gustavoamigo,项目名称:finagle-redis-server,代码行数:28,代码来源:RedisCodec.scala


示例2: 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")
  }
} 
开发者ID:wenkeyang,项目名称:finagle,代码行数:46,代码来源:StringCodec.scala


示例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
  }
} 
开发者ID:wenkeyang,项目名称:finagle,代码行数:16,代码来源:ThriftClientFramedPipelineFactory.scala


示例4: 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()
} 
开发者ID:lukiano,项目名称:finagle-http4s,代码行数:30,代码来源:ServerCodec.scala


示例5: 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")
  }
} 
开发者ID:deenar,项目名称:fintest,代码行数:46,代码来源:StringCodec.scala


示例6: 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
        }
      }
    }
  }
} 
开发者ID:deenar,项目名称:fintest,代码行数:41,代码来源:StringCodec.scala


示例7: RequestDecoder

//设置package包名称以及导入依赖的类
package com.twitter.finagle.http.codec

import com.twitter.logging.Logger
import com.twitter.finagle.http.Request
import org.jboss.netty.channel.{Channels, ChannelHandlerContext, MessageEvent, SimpleChannelHandler}
import org.jboss.netty.handler.codec.http.HttpRequest



class RequestDecoder extends SimpleChannelHandler {
  private[this] val log = Logger("finagle-http")

  override def messageReceived(ctx: ChannelHandlerContext, e: MessageEvent) {
    e.getMessage match {
      case httpRequest: HttpRequest if !httpRequest.isChunked =>
        val request = Request(httpRequest, e.getChannel)
        Channels.fireMessageReceived(ctx, request)
      case unknown =>
        log.warning("RequestDecoder: illegal message type: %s", unknown)
        Channels.disconnect(ctx.getChannel)
    }
  }
} 
开发者ID:deenar,项目名称:fintest,代码行数:24,代码来源:RequestDecoder.scala


示例8: ResponseDecoder

//设置package包名称以及导入依赖的类
package com.twitter.finagle.http.codec

import com.twitter.finagle.http.Response
import com.twitter.logging.Logger
import org.jboss.netty.channel.{Channels, ChannelHandlerContext, MessageEvent, SimpleChannelHandler}
import org.jboss.netty.handler.codec.http.HttpResponse


class ResponseDecoder extends SimpleChannelHandler {
  private[this] val log = Logger("finagle-http")

  override def messageReceived(ctx: ChannelHandlerContext, e: MessageEvent) {
    e.getMessage match {
      case finagleResponse: Response =>
        Channels.fireMessageReceived(ctx, finagleResponse)

      case httpResponse: HttpResponse =>
        Channels.fireMessageReceived(ctx, Response(httpResponse))

      case unknown =>
        log.warning("ClientRequestDecoder: illegal message type: %s", unknown.getClass())
        Channels.disconnect(ctx.getChannel)
    }
  }
} 
开发者ID:deenar,项目名称:fintest,代码行数:26,代码来源:ResponseDecoder.scala


示例9: HttpDechunkerSpec

//设置package包名称以及导入依赖的类
package com.twitter.finagle.stream

import org.specs.SpecificationWithJUnit
import com.twitter.finagle.{SunkChannel, SunkChannelFactory}
import org.jboss.netty.buffer.ChannelBuffers
import org.jboss.netty.channel.{Channels, MessageEvent}
import org.jboss.netty.handler.codec.http._
import com.twitter.conversions.time._
import java.nio.charset.Charset

class HttpDechunkerSpec extends SpecificationWithJUnit {

  "HttpDechunker" should {
    "wait until last message is synced before sending EOF" in {
      val cf = new SunkChannelFactory
      val pipeline = Channels.pipeline
      val dechunker = new HttpDechunker
      pipeline.addLast("dechunker", dechunker)
      val channel = new SunkChannel(cf, pipeline, cf.sink)

      val httpResponse = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK)
      httpResponse.setChunked(true)

      Channels.fireMessageReceived(channel, httpResponse)

      val streamResponse = (channel.upstreamEvents.headOption match {
        case Some(m: MessageEvent) => m.getMessage match {
          case s: StreamResponse => s
        }
        case _ => throw new Exception("No upstream message received")
      })

      val messages = streamResponse.messages
      val error = streamResponse.error

      Channels.fireMessageReceived(channel, new DefaultHttpChunk(ChannelBuffers.wrappedBuffer("1".getBytes)))
      messages.sync()(1.second).toString(Charset.defaultCharset) must_== "1"

      Channels.fireMessageReceived(channel, new DefaultHttpChunk(ChannelBuffers.wrappedBuffer("2".getBytes)))
      Channels.fireMessageReceived(channel, HttpChunk.LAST_CHUNK)
      val receiveError = error.sync()
      receiveError.isDefined must_== false
      messages.sync()(1.second).toString(Charset.defaultCharset) must_== "2"
      receiveError.isDefined must_== true
      receiveError(1.second) must_== EOF
    }
  }
} 
开发者ID:deenar,项目名称:fintest,代码行数:49,代码来源:HttpDechunkerSpec.scala



注:本文中的org.jboss.netty.channel.Channels类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Scala CharStreams类代码示例发布时间:2022-05-23
下一篇:
Scala JvmPlugin类代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap