Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
thrift: support for buffered transports, client only.
- Loading branch information
Showing
3 changed files
with
154 additions
and
82 deletions.
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
finagle-thrift/src/main/scala/com/twitter/finagle/thrift/ThriftBufferCodec.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package com.twitter.finagle.thrift | ||
|
||
import org.jboss.netty.channel.{Channel, ChannelHandlerContext} | ||
import org.jboss.netty.buffer.ChannelBuffer | ||
import org.jboss.netty.handler.codec.replay.{ReplayingDecoder, VoidEnum} | ||
|
||
import org.apache.thrift.protocol.{TProtocolFactory, TProtocolUtil, TType} | ||
|
||
class ThriftBufferCodec(protocolFactory: TProtocolFactory) | ||
extends ReplayingDecoder[VoidEnum] | ||
{ | ||
override def decode( | ||
ctx: ChannelHandlerContext, channel: Channel, | ||
buffer: ChannelBuffer, state: VoidEnum | ||
) = { | ||
val transport = new ChannelBufferToTransport(buffer) | ||
val iprot = protocolFactory.getProtocol(transport) | ||
|
||
val beginIndex = buffer.readerIndex | ||
buffer.markReaderIndex() | ||
|
||
iprot.readMessageBegin() | ||
TProtocolUtil.skip(iprot, TType.STRUCT) | ||
iprot.readMessageEnd() | ||
|
||
val endIndex = buffer.readerIndex | ||
buffer.resetReaderIndex() | ||
|
||
buffer.readSlice(endIndex - beginIndex) | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
finagle-thrift/src/main/scala/com/twitter/finagle/thrift/ThriftClientBufferedCodec.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.twitter.finagle.thrift | ||
|
||
import org.jboss.netty.channel.ChannelPipelineFactory | ||
import org.apache.thrift.protocol.TProtocolFactory | ||
|
||
import com.twitter.finagle.Codec | ||
|
||
class ThriftClientBufferedCodec(protocolFactory: TProtocolFactory) | ||
extends Codec[ThriftClientRequest, Array[Byte]] | ||
{ | ||
private[this] val framedCodec = new ThriftClientFramedCodec | ||
|
||
val clientPipelineFactory = { | ||
val framedPipelineFactory = framedCodec.clientPipelineFactory | ||
|
||
new ChannelPipelineFactory { | ||
def getPipeline() = { | ||
val pipeline = framedPipelineFactory.getPipeline | ||
pipeline.replace( | ||
"thriftFrameCodec", "thriftBufferCodec", | ||
new ThriftBufferCodec(protocolFactory)) | ||
pipeline | ||
} | ||
} | ||
} | ||
|
||
val serverPipelineFactory = clientPipelineFactory | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters