diff --git a/finagle-thrift/src/main/scala/com/twitter/finagle/thrift/ClientFunction.scala b/finagle-thrift/src/main/scala/com/twitter/finagle/thrift/ClientFunction.scala index e6d9cb6c18..4080aebc2a 100644 --- a/finagle-thrift/src/main/scala/com/twitter/finagle/thrift/ClientFunction.scala +++ b/finagle-thrift/src/main/scala/com/twitter/finagle/thrift/ClientFunction.scala @@ -104,7 +104,7 @@ object ClientFunction { tlReusableBuffer: TReusableBuffer, protocolFactory: TProtocolFactory ): ThriftClientRequest = { - val memoryBuffer = tlReusableBuffer.get() + val memoryBuffer = tlReusableBuffer.take() try { val oprot = protocolFactory.getProtocol(memoryBuffer) diff --git a/finagle-thrift/src/main/scala/com/twitter/finagle/thrift/exp/partitioning/ThriftRequestSerializer.scala b/finagle-thrift/src/main/scala/com/twitter/finagle/thrift/exp/partitioning/ThriftRequestSerializer.scala index c0cc2e280f..5f5b6718ec 100644 --- a/finagle-thrift/src/main/scala/com/twitter/finagle/thrift/exp/partitioning/ThriftRequestSerializer.scala +++ b/finagle-thrift/src/main/scala/com/twitter/finagle/thrift/exp/partitioning/ThriftRequestSerializer.scala @@ -2,11 +2,16 @@ package com.twitter.finagle.thrift.exp.partitioning import com.twitter.finagle.Stack import com.twitter.finagle.Thrift.param -import com.twitter.finagle.thrift.{RichClientParam, ThriftClientRequest} -import com.twitter.scrooge.{TReusableBuffer, ThriftStruct, ThriftStructIface} +import com.twitter.finagle.thrift.RichClientParam +import com.twitter.finagle.thrift.ThriftClientRequest +import com.twitter.scrooge.TReusableBuffer +import com.twitter.scrooge.ThriftStruct +import com.twitter.scrooge.ThriftStructIface import java.util import org.apache.thrift.TBase -import org.apache.thrift.protocol.{TMessage, TMessageType, TProtocolFactory} +import org.apache.thrift.protocol.TMessage +import org.apache.thrift.protocol.TMessageType +import org.apache.thrift.protocol.TProtocolFactory /** * Used by ThriftPartitioningService for message fan-out. @@ -34,7 +39,7 @@ private[partitioning] class ThriftRequestSerializer(params: Stack.Params) { args: ThriftStructIface, oneWay: Boolean ): ThriftClientRequest = { - val memoryBuffer = thriftReusableBuffer.get() + val memoryBuffer = thriftReusableBuffer.take() try { val oprot = protocolFactory.getProtocol(memoryBuffer) oprot.writeMessageBegin(new TMessage(methodName, TMessageType.CALL, 0)) @@ -50,6 +55,8 @@ private[partitioning] class ThriftRequestSerializer(params: Stack.Params) { oprot.getTransport().flush() val bytes = util.Arrays.copyOfRange(memoryBuffer.getArray(), 0, memoryBuffer.length()) new ThriftClientRequest(bytes, oneWay) - } finally thriftReusableBuffer.reset() + } finally { + thriftReusableBuffer.reset() + } } } diff --git a/finagle-thrift/src/main/scala/com/twitter/finagle/thrift/service/ThriftCodec.scala b/finagle-thrift/src/main/scala/com/twitter/finagle/thrift/service/ThriftCodec.scala index a93659ba78..9cf6030596 100644 --- a/finagle-thrift/src/main/scala/com/twitter/finagle/thrift/service/ThriftCodec.scala +++ b/finagle-thrift/src/main/scala/com/twitter/finagle/thrift/service/ThriftCodec.scala @@ -1,13 +1,25 @@ package com.twitter.finagle.thrift.service import com.twitter.finagle.context.Contexts -import com.twitter.finagle.thrift.{ClientDeserializeCtx, ThriftClientRequest, maxReusableBufferSize} -import com.twitter.finagle.{Filter, Service, SourcedException} -import com.twitter.scrooge.{TReusableBuffer, ThriftMethod, ThriftStruct, ThriftStructCodec} -import com.twitter.util.{Future, Return, Throw, Try} +import com.twitter.finagle.thrift.ClientDeserializeCtx +import com.twitter.finagle.thrift.ThriftClientRequest +import com.twitter.finagle.thrift.maxReusableBufferSize +import com.twitter.finagle.Filter +import com.twitter.finagle.Service +import com.twitter.finagle.SourcedException +import com.twitter.scrooge.TReusableBuffer +import com.twitter.scrooge.ThriftMethod +import com.twitter.scrooge.ThriftStruct +import com.twitter.scrooge.ThriftStructCodec +import com.twitter.util.Future +import com.twitter.util.Return +import com.twitter.util.Throw +import com.twitter.util.Try import java.util.Arrays import org.apache.thrift.TApplicationException -import org.apache.thrift.protocol.{TMessage, TMessageType, TProtocolFactory} +import org.apache.thrift.protocol.TMessage +import org.apache.thrift.protocol.TMessageType +import org.apache.thrift.protocol.TProtocolFactory import org.apache.thrift.transport.TMemoryInputTransport object ThriftCodec { @@ -63,7 +75,7 @@ object ThriftCodec { pf: TProtocolFactory, oneway: Boolean ): ThriftClientRequest = { - val buf = tlReusableBuffer.get() + val buf = tlReusableBuffer.take() val oprot = pf.getProtocol(buf) oprot.writeMessageBegin(new TMessage(methodName, TMessageType.CALL, 0))