Package io.grpc.internal
Class MigratingThreadDeframer
java.lang.Object
io.grpc.internal.MigratingThreadDeframer
- All Implemented Interfaces:
Deframer
,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 ClassesModifier and TypeClassDescription(package private) class
(package private) static class
private static interface
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final ApplicationThreadDeframerListener
private final MessageDeframer
private boolean
true
means decoding on transport thread.private final Object
private final MigratingThreadDeframer.DeframeMessageProducer
private boolean
private final MigratingThreadDeframer.MigratingDeframerListener
private final Queue
<MigratingThreadDeframer.Op> private final ApplicationThreadDeframerListener.TransportExecutor
private final MessageDeframer.Listener
-
Constructor Summary
ConstructorsConstructorDescriptionMigratingThreadDeframer
(MessageDeframer.Listener listener, ApplicationThreadDeframerListener.TransportExecutor transportExecutor, MessageDeframer deframer) -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Closes this deframer and frees any resources.void
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
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 Details
-
transportListener
-
appListener
-
migratingListener
-
transportExecutor
-
deframer
-
messageProducer
-
lock
-
deframerOnTransportThread
private boolean deframerOnTransportThreadtrue
means decoding on transport thread.Invariant: if there are outstanding requests, then deframerOnTransportThread=true. Otherwise deframerOnTransportThread=false.
-
opQueue
-
messageProducerEnqueued
private boolean messageProducerEnqueued
-
-
Constructor Details
-
MigratingThreadDeframer
public MigratingThreadDeframer(MessageDeframer.Listener listener, ApplicationThreadDeframerListener.TransportExecutor transportExecutor, MessageDeframer deframer)
-
-
Method Details
-
setMaxInboundMessageSize
public void setMaxInboundMessageSize(int messageSize) - Specified by:
setMaxInboundMessageSize
in interfaceDeframer
-
setDecompressor
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
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
-
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
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
-
close
public void close()Description copied from interface:Deframer
Closes this deframer and frees any resources. After this method is called, additional calls will have no effect.
-