Package org.apache.thrift.server
Class AbstractNonblockingServer.FrameBuffer
- java.lang.Object
-
- org.apache.thrift.server.AbstractNonblockingServer.FrameBuffer
-
- Direct Known Subclasses:
AbstractNonblockingServer.AsyncFrameBuffer
- Enclosing class:
- AbstractNonblockingServer
public class AbstractNonblockingServer.FrameBuffer extends java.lang.ObjectClass that implements a sort of state machine around the interaction with a client and an invoker. It manages reading the frame size and frame data, getting it handed off as wrapped transports, and then the writing of response data back to the client. In the process it manages flipping the read and write bits on the selection key for its client.
-
-
Field Summary
Fields Modifier and Type Field Description protected java.nio.ByteBufferbuffer_protected ServerContextcontext_protected TMemoryInputTransportframeTrans_protected TProtocolinProt_protected TTransportinTrans_protected TProtocoloutProt_protected TTransportoutTrans_protected TByteArrayOutputStreamresponse_protected java.nio.channels.SelectionKeyselectionKey_protected AbstractNonblockingServer.AbstractSelectThreadselectThread_protected org.apache.thrift.server.AbstractNonblockingServer.FrameBufferStatestate_protected TNonblockingTransporttrans_
-
Constructor Summary
Constructors Constructor Description FrameBuffer(TNonblockingTransport trans, java.nio.channels.SelectionKey selectionKey, AbstractNonblockingServer.AbstractSelectThread selectThread)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidchangeSelectInterests()Give this FrameBuffer a chance to set its interest to write, once data has come in.voidclose()Shut the connection down.voidinvoke()Actually invoke the method signified by this FrameBuffer.booleanisFrameFullyRead()Check if this FrameBuffer has a full frame read.booleanread()Give this FrameBuffer a chance to read.protected voidrequestSelectInterestChange()When this FrameBuffer needs to change its select interests and execution might not be in its select thread, then this method will make sure the interest change gets done when the select thread wakes back up.voidresponseReady()After the processor has processed the invocation, whatever thread is managing invocations should call this method on this FrameBuffer so we know it's time to start trying to write again.booleanwrite()Give this FrameBuffer a chance to write its output to the final client.
-
-
-
Field Detail
-
trans_
protected final TNonblockingTransport trans_
-
selectionKey_
protected final java.nio.channels.SelectionKey selectionKey_
-
selectThread_
protected final AbstractNonblockingServer.AbstractSelectThread selectThread_
-
state_
protected org.apache.thrift.server.AbstractNonblockingServer.FrameBufferState state_
-
buffer_
protected java.nio.ByteBuffer buffer_
-
response_
protected final TByteArrayOutputStream response_
-
frameTrans_
protected final TMemoryInputTransport frameTrans_
-
inTrans_
protected final TTransport inTrans_
-
outTrans_
protected final TTransport outTrans_
-
inProt_
protected final TProtocol inProt_
-
outProt_
protected final TProtocol outProt_
-
context_
protected final ServerContext context_
-
-
Constructor Detail
-
FrameBuffer
public FrameBuffer(TNonblockingTransport trans, java.nio.channels.SelectionKey selectionKey, AbstractNonblockingServer.AbstractSelectThread selectThread) throws TTransportException
- Throws:
TTransportException
-
-
Method Detail
-
read
public boolean read()
Give this FrameBuffer a chance to read. The selector loop should have received a read event for this FrameBuffer.- Returns:
- true if the connection should live on, false if it should be closed
-
write
public boolean write()
Give this FrameBuffer a chance to write its output to the final client.
-
changeSelectInterests
public void changeSelectInterests()
Give this FrameBuffer a chance to set its interest to write, once data has come in.
-
close
public void close()
Shut the connection down.
-
isFrameFullyRead
public boolean isFrameFullyRead()
Check if this FrameBuffer has a full frame read.
-
responseReady
public void responseReady()
After the processor has processed the invocation, whatever thread is managing invocations should call this method on this FrameBuffer so we know it's time to start trying to write again. Also, if it turns out that there actually isn't any data in the response buffer, we'll skip trying to write and instead go back to reading.
-
invoke
public void invoke()
Actually invoke the method signified by this FrameBuffer.
-
requestSelectInterestChange
protected void requestSelectInterestChange()
When this FrameBuffer needs to change its select interests and execution might not be in its select thread, then this method will make sure the interest change gets done when the select thread wakes back up. When the current thread is this FrameBuffer's select thread, then it just does the interest change immediately.
-
-