public abstract class BaseChunkResponseParser<H extends ChunkHeader,ROW extends ChunkRow,T extends ChunkTrailer> extends Object implements ChunkResponseParser<H,ROW,T>
ChunkResponseParser
interface.Constructor and Description |
---|
BaseChunkResponseParser() |
Modifier and Type | Method and Description |
---|---|
void |
cleanup()
Releases resources managed by the parser and prepares it for reuse.
|
protected void |
completeRows()
Completes the row flux.
|
protected void |
completeTrailer(T trailer)
Called from the child implementation to complete the trailing bits.
|
Optional<CouchbaseException> |
decodingFailure()
If the parser fails due to malformed input the cause is returned here.
|
protected abstract void |
doCleanup()
Give subclasses a chance to reset their state.
|
protected void |
emitRow(ROW row)
Emits a single row into the rows flux.
|
void |
endOfInput()
Indicates the complete JSON document has been fed to the parser.
|
protected void |
failRows(Throwable t)
Fails the row flux with the given message.
|
void |
feed(com.couchbase.client.core.deps.io.netty.buffer.ByteBuf input)
Parses the given JSON document fragment.
|
void |
initialize(com.couchbase.client.core.deps.io.netty.channel.ChannelConfig channelConfig)
Initializes the parser to a fresh state.
|
protected boolean |
isHeaderComplete()
Only for use by subclasses.
|
protected void |
markHeaderComplete() |
protected abstract JsonStreamParser.Builder |
parserBuilder()
Subclass implements this to return the "meat" of the decoding, the chunk parser.
|
protected RequestContext |
requestContext() |
protected com.couchbase.client.core.deps.io.netty.handler.codec.http.HttpResponse |
responseHeader() |
Flux<ROW> |
rows()
Returns the currently assigned flux for the rows.
|
protected abstract void |
signalComplete()
Called when the JSON stream has been parsed completely and successfully.
|
Mono<T> |
trailer()
Returns the currently assigned mono for the trailer bits.
|
void |
updateRequestContext(RequestContext requestContext)
Sets the request context for the current request in the parser, can be used for error handling.
|
void |
updateResponseHeader(com.couchbase.client.core.deps.io.netty.handler.codec.http.HttpResponse responseHeader)
Sets the current response header if present.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
error, header
protected abstract JsonStreamParser.Builder parserBuilder()
public final void cleanup()
ChunkResponseParser
cleanup
in interface ChunkResponseParser<H extends ChunkHeader,ROW extends ChunkRow,T extends ChunkTrailer>
public void updateRequestContext(RequestContext requestContext)
ChunkResponseParser
updateRequestContext
in interface ChunkResponseParser<H extends ChunkHeader,ROW extends ChunkRow,T extends ChunkTrailer>
protected RequestContext requestContext()
public void updateResponseHeader(com.couchbase.client.core.deps.io.netty.handler.codec.http.HttpResponse responseHeader)
ChunkResponseParser
updateResponseHeader
in interface ChunkResponseParser<H extends ChunkHeader,ROW extends ChunkRow,T extends ChunkTrailer>
protected com.couchbase.client.core.deps.io.netty.handler.codec.http.HttpResponse responseHeader()
protected void markHeaderComplete()
protected boolean isHeaderComplete()
ChunkResponseParser#header()
to see if the header is ready.protected abstract void doCleanup()
public void feed(com.couchbase.client.core.deps.io.netty.buffer.ByteBuf input)
ChunkResponseParser
feed
in interface ChunkResponseParser<H extends ChunkHeader,ROW extends ChunkRow,T extends ChunkTrailer>
public void initialize(com.couchbase.client.core.deps.io.netty.channel.ChannelConfig channelConfig)
initialize
in interface ChunkResponseParser<H extends ChunkHeader,ROW extends ChunkRow,T extends ChunkTrailer>
channelConfig
- the channel config used for backpressure auto-read.public Flux<ROW> rows()
ChunkResponseParser
rows
in interface ChunkResponseParser<H extends ChunkHeader,ROW extends ChunkRow,T extends ChunkTrailer>
public Mono<T> trailer()
ChunkResponseParser
trailer
in interface ChunkResponseParser<H extends ChunkHeader,ROW extends ChunkRow,T extends ChunkTrailer>
public void endOfInput()
ChunkResponseParser
endOfInput
in interface ChunkResponseParser<H extends ChunkHeader,ROW extends ChunkRow,T extends ChunkTrailer>
public Optional<CouchbaseException> decodingFailure()
ChunkResponseParser
decodingFailure
in interface ChunkResponseParser<H extends ChunkHeader,ROW extends ChunkRow,T extends ChunkTrailer>
protected abstract void signalComplete()
protected void emitRow(ROW row)
Note that this method also handles the backpressure stalling side. If we find that someone is subscribed to this flux but has not requested any further rows, the channel auto-read is going to be paused until further rows are requested or the subscriber unsubscribes.
row
- the row to emit.protected void failRows(Throwable t)
t
- the throwable with which to fail the rows.protected void completeRows()
protected void completeTrailer(T trailer)
trailer
- the trailer value to be fed into the mono.Copyright © 2020 Couchbase, Inc.. All rights reserved.