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) class
MigratingThreadDeframer.DeframeMessageProducer
(package private) static class
MigratingThreadDeframer.MigratingDeframerListener
private static interface
MigratingThreadDeframer.Op
-
Field Summary
Fields Modifier and Type Field Description private ApplicationThreadDeframerListener
appListener
private MessageDeframer
deframer
private boolean
deframerOnTransportThread
true
means decoding on transport thread.private java.lang.Object
lock
private MigratingThreadDeframer.DeframeMessageProducer
messageProducer
private boolean
messageProducerEnqueued
private MigratingThreadDeframer.MigratingDeframerListener
migratingListener
private java.util.Queue<MigratingThreadDeframer.Op>
opQueue
private ApplicationThreadDeframerListener.TransportExecutor
transportExecutor
private MessageDeframer.Listener
transportListener
-
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 void
close()
Closes this deframer and frees any resources.void
closeWhenComplete()
Close when any messages currently queued have been requested and delivered.void
deframe(ReadableBuffer data)
Adds the given data to this deframer and attempts delivery to the listener.void
request(int numMessages)
Behaves likeDeframer.request(int)
except it can be called from any thread.private void
requestFromTransportThread(int numMessages)
private boolean
runWhereAppropriate(MigratingThreadDeframer.Op op)
private boolean
runWhereAppropriate(MigratingThreadDeframer.Op op, boolean currentThreadIsTransportThread)
void
setDecompressor(Decompressor decompressor)
Sets the decompressor available to use.void
setFullStreamDecompressor(GzipInflatingBuffer fullStreamDecompressor)
Sets the decompressor used for full-stream decompression.void
setMaxInboundMessageSize(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
true
means 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:
setMaxInboundMessageSize
in interfaceDeframer
-
setDecompressor
public void setDecompressor(Decompressor decompressor)
Description copied from interface:Deframer
Sets 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:
setDecompressor
in interfaceDeframer
- Parameters:
decompressor
- the decompressing wrapper.
-
setFullStreamDecompressor
public void setFullStreamDecompressor(GzipInflatingBuffer fullStreamDecompressor)
Description copied from interface:Deframer
Sets the decompressor used for full-stream decompression. Full-stream decompression disables any per-message decompressor set byDeframer.setDecompressor(io.grpc.Decompressor)
.- Specified by:
setFullStreamDecompressor
in 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:ThreadOptimizedDeframer
Behaves likeDeframer.request(int)
except it can be called from any thread. Must not throw exceptions in case of deframer error.- Specified by:
request
in interfaceDeframer
- Specified by:
request
in 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:Deframer
Adds the given data to this deframer and attempts delivery to the listener.
-
closeWhenComplete
public void closeWhenComplete()
Description copied from interface:Deframer
Close when any messages currently queued have been requested and delivered.- Specified by:
closeWhenComplete
in interfaceDeframer
-
-