Package io.grpc.internal
Class MigratingThreadDeframer
- java.lang.Object
-
- io.grpc.internal.MigratingThreadDeframer
-
- All Implemented Interfaces:
Deframer,ThreadOptimizedDeframer
final class MigratingThreadDeframer extends java.lang.Object implements ThreadOptimizedDeframer
A deframer that moves decoding between the transport and app threads based on which is more efficient at that moment.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) classMigratingThreadDeframer.DeframeMessageProducer(package private) static classMigratingThreadDeframer.MigratingDeframerListenerprivate static interfaceMigratingThreadDeframer.Op
-
Field Summary
Fields Modifier and Type Field Description private ApplicationThreadDeframerListenerappListenerprivate MessageDeframerdeframerprivate booleandeframerOnTransportThreadtruemeans decoding on transport thread.private java.lang.Objectlockprivate MigratingThreadDeframer.DeframeMessageProducermessageProducerprivate booleanmessageProducerEnqueuedprivate MigratingThreadDeframer.MigratingDeframerListenermigratingListenerprivate java.util.Queue<MigratingThreadDeframer.Op>opQueueprivate ApplicationThreadDeframerListener.TransportExecutortransportExecutorprivate MessageDeframer.ListenertransportListener
-
Constructor Summary
Constructors Constructor Description MigratingThreadDeframer(MessageDeframer.Listener listener, ApplicationThreadDeframerListener.TransportExecutor transportExecutor, MessageDeframer deframer)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Closes this deframer and frees any resources.voidcloseWhenComplete()Close when any messages currently queued have been requested and delivered.voiddeframe(ReadableBuffer data)Adds the given data to this deframer and attempts delivery to the listener.voidrequest(int numMessages)Behaves likeDeframer.request(int)except it can be called from any thread.private voidrequestFromTransportThread(int numMessages)private booleanrunWhereAppropriate(MigratingThreadDeframer.Op op)private booleanrunWhereAppropriate(MigratingThreadDeframer.Op op, boolean currentThreadIsTransportThread)voidsetDecompressor(Decompressor decompressor)Sets the decompressor available to use.voidsetFullStreamDecompressor(GzipInflatingBuffer fullStreamDecompressor)Sets the decompressor used for full-stream decompression.voidsetMaxInboundMessageSize(int messageSize)
-
-
-
Field Detail
-
transportListener
private final MessageDeframer.Listener transportListener
-
appListener
private final ApplicationThreadDeframerListener appListener
-
migratingListener
private final MigratingThreadDeframer.MigratingDeframerListener migratingListener
-
transportExecutor
private final ApplicationThreadDeframerListener.TransportExecutor transportExecutor
-
deframer
private final MessageDeframer deframer
-
messageProducer
private final MigratingThreadDeframer.DeframeMessageProducer messageProducer
-
lock
private final java.lang.Object lock
-
deframerOnTransportThread
private boolean deframerOnTransportThread
truemeans decoding on transport thread.Invariant: if there are outstanding requests, then deframerOnTransportThread=true. Otherwise deframerOnTransportThread=false.
-
opQueue
private final java.util.Queue<MigratingThreadDeframer.Op> opQueue
-
messageProducerEnqueued
private boolean messageProducerEnqueued
-
-
Constructor Detail
-
MigratingThreadDeframer
public MigratingThreadDeframer(MessageDeframer.Listener listener, ApplicationThreadDeframerListener.TransportExecutor transportExecutor, MessageDeframer deframer)
-
-
Method Detail
-
setMaxInboundMessageSize
public void setMaxInboundMessageSize(int messageSize)
- Specified by:
setMaxInboundMessageSizein interfaceDeframer
-
setDecompressor
public void setDecompressor(Decompressor decompressor)
Description copied from interface:DeframerSets the decompressor available to use. The message encoding for the stream comes later in time, and thus will not be available at the time of construction. This should only be set once, since the compression codec cannot change after the headers have been sent.- Specified by:
setDecompressorin interfaceDeframer- Parameters:
decompressor- the decompressing wrapper.
-
setFullStreamDecompressor
public void setFullStreamDecompressor(GzipInflatingBuffer fullStreamDecompressor)
Description copied from interface:DeframerSets the decompressor used for full-stream decompression. Full-stream decompression disables any per-message decompressor set byDeframer.setDecompressor(io.grpc.Decompressor).- Specified by:
setFullStreamDecompressorin interfaceDeframer- Parameters:
fullStreamDecompressor- the decompressing wrapper
-
runWhereAppropriate
private boolean runWhereAppropriate(MigratingThreadDeframer.Op op)
-
runWhereAppropriate
private boolean runWhereAppropriate(MigratingThreadDeframer.Op op, boolean currentThreadIsTransportThread)
-
request
public void request(int numMessages)
Description copied from interface:ThreadOptimizedDeframerBehaves likeDeframer.request(int)except it can be called from any thread. Must not throw exceptions in case of deframer error.- Specified by:
requestin interfaceDeframer- Specified by:
requestin interfaceThreadOptimizedDeframer- Parameters:
numMessages- the requested number of messages to be delivered to the listener.
-
requestFromTransportThread
private void requestFromTransportThread(int numMessages)
-
deframe
public void deframe(ReadableBuffer data)
Description copied from interface:DeframerAdds the given data to this deframer and attempts delivery to the listener.
-
closeWhenComplete
public void closeWhenComplete()
Description copied from interface:DeframerClose when any messages currently queued have been requested and delivered.- Specified by:
closeWhenCompletein interfaceDeframer
-
-