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 classprivate static interface -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final ApplicationThreadDeframerListenerprivate final MessageDeframerprivate booleantruemeans decoding on transport thread.private final Objectprivate final MigratingThreadDeframer.DeframeMessageProducerprivate booleanprivate final MigratingThreadDeframer.MigratingDeframerListenerprivate final Queue<MigratingThreadDeframer.Op> private final ApplicationThreadDeframerListener.TransportExecutorprivate final MessageDeframer.Listener -
Constructor Summary
ConstructorsConstructorDescriptionMigratingThreadDeframer(MessageDeframer.Listener listener, ApplicationThreadDeframerListener.TransportExecutor transportExecutor, MessageDeframer deframer) -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Closes this deframer and frees any resources.voidClose 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 booleanprivate 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 Details
-
transportListener
-
appListener
-
migratingListener
-
transportExecutor
-
deframer
-
messageProducer
-
lock
-
deframerOnTransportThread
private boolean deframerOnTransportThreadtruemeans 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:
setMaxInboundMessageSizein interfaceDeframer
-
setDecompressor
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
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
-
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
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
-
close
public void close()Description copied from interface:DeframerCloses this deframer and frees any resources. After this method is called, additional calls will have no effect.
-