Class BaseChunkResponseParser<H extends ChunkHeader,ROW extends ChunkRow,T extends ChunkTrailer>
- java.lang.Object
-
- com.couchbase.client.core.io.netty.chunk.BaseChunkResponseParser<H,ROW,T>
-
- All Implemented Interfaces:
ChunkResponseParser<H,ROW,T>
- Direct Known Subclasses:
AnalyticsChunkResponseParser
,QueryChunkResponseParser
,SearchChunkResponseParser
,ViewChunkResponseParser
public abstract class BaseChunkResponseParser<H extends ChunkHeader,ROW extends ChunkRow,T extends ChunkTrailer> extends Object implements ChunkResponseParser<H,ROW,T>
Provides a common, abstract implementation of theChunkResponseParser
interface.
-
-
Constructor Summary
Constructors Constructor Description BaseChunkResponseParser()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method 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.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.couchbase.client.core.io.netty.chunk.ChunkResponseParser
error, header
-
-
-
-
Method Detail
-
parserBuilder
protected abstract JsonStreamParser.Builder parserBuilder()
Subclass implements this to return the "meat" of the decoding, the chunk parser.
-
cleanup
public final void cleanup()
Description copied from interface:ChunkResponseParser
Releases resources managed by the parser and prepares it for reuse.- Specified by:
cleanup
in interfaceChunkResponseParser<H extends ChunkHeader,ROW extends ChunkRow,T extends ChunkTrailer>
-
updateRequestContext
public void updateRequestContext(RequestContext requestContext)
Description copied from interface:ChunkResponseParser
Sets the request context for the current request in the parser, can be used for error handling.- Specified by:
updateRequestContext
in interfaceChunkResponseParser<H extends ChunkHeader,ROW extends ChunkRow,T extends ChunkTrailer>
-
requestContext
protected RequestContext requestContext()
-
updateResponseHeader
public void updateResponseHeader(com.couchbase.client.core.deps.io.netty.handler.codec.http.HttpResponse responseHeader)
Description copied from interface:ChunkResponseParser
Sets the current response header if present.- Specified by:
updateResponseHeader
in interfaceChunkResponseParser<H extends ChunkHeader,ROW extends ChunkRow,T extends ChunkTrailer>
-
responseHeader
protected com.couchbase.client.core.deps.io.netty.handler.codec.http.HttpResponse responseHeader()
-
markHeaderComplete
protected void markHeaderComplete()
-
isHeaderComplete
protected boolean isHeaderComplete()
Only for use by subclasses. External collaborators should callChunkResponseParser.header(boolean)
to see if the header is ready.
-
doCleanup
protected abstract void doCleanup()
Give subclasses a chance to reset their state.
-
feed
public void feed(com.couchbase.client.core.deps.io.netty.buffer.ByteBuf input)
Description copied from interface:ChunkResponseParser
Parses the given JSON document fragment. The parser takes ownership of the buffer and is responsible for releasing it.- Specified by:
feed
in interfaceChunkResponseParser<H extends ChunkHeader,ROW extends ChunkRow,T extends ChunkTrailer>
-
initialize
public void initialize(com.couchbase.client.core.deps.io.netty.channel.ChannelConfig channelConfig)
Initializes the parser to a fresh state.- Specified by:
initialize
in interfaceChunkResponseParser<H extends ChunkHeader,ROW extends ChunkRow,T extends ChunkTrailer>
- Parameters:
channelConfig
- the channel config used for backpressure auto-read.
-
rows
public Flux<ROW> rows()
Description copied from interface:ChunkResponseParser
Returns the currently assigned flux for the rows.- Specified by:
rows
in interfaceChunkResponseParser<H extends ChunkHeader,ROW extends ChunkRow,T extends ChunkTrailer>
-
trailer
public Mono<T> trailer()
Description copied from interface:ChunkResponseParser
Returns the currently assigned mono for the trailer bits.- Specified by:
trailer
in interfaceChunkResponseParser<H extends ChunkHeader,ROW extends ChunkRow,T extends ChunkTrailer>
-
endOfInput
public void endOfInput()
Description copied from interface:ChunkResponseParser
Indicates the complete JSON document has been fed to the parser.- Specified by:
endOfInput
in interfaceChunkResponseParser<H extends ChunkHeader,ROW extends ChunkRow,T extends ChunkTrailer>
-
decodingFailure
public Optional<CouchbaseException> decodingFailure()
Description copied from interface:ChunkResponseParser
If the parser fails due to malformed input the cause is returned here.- Specified by:
decodingFailure
in interfaceChunkResponseParser<H extends ChunkHeader,ROW extends ChunkRow,T extends ChunkTrailer>
-
signalComplete
protected abstract void signalComplete()
Called when the JSON stream has been parsed completely and successfully.
-
emitRow
protected void emitRow(ROW row)
Emits a single row into the rows flux.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.
- Parameters:
row
- the row to emit.
-
failRows
protected void failRows(Throwable t)
Fails the row flux with the given message.- Parameters:
t
- the throwable with which to fail the rows.
-
completeRows
protected void completeRows()
Completes the row flux.
-
completeTrailer
protected void completeTrailer(T trailer)
Called from the child implementation to complete the trailing bits.- Parameters:
trailer
- the trailer value to be fed into the mono.
-
-