public class Client extends Object implements Closeable
| Modifier and Type | Class and Description |
|---|---|
static class |
Client.Builder
Builder object to customize the
Client creation. |
static class |
Client.Environment
The
Client.Environment is responsible to carry various configuration and
state information throughout the lifecycle. |
| Modifier and Type | Method and Description |
|---|---|
static Client.Builder |
builder() |
void |
close()
Disconnects the client.
|
static Client.Builder |
configure()
Deprecated.
in favor of
builder() |
reactor.core.publisher.Mono<Void> |
connect()
Initializes the underlying connections (not the streams) and sets up everything as needed.
|
void |
controlEventHandler(ControlEventHandler controlEventHandler)
Stores a
ControlEventHandler to be called when control events happen. |
void |
dataEventHandler(DataEventHandler dataEventHandler)
Stores a
DataEventHandler to be called when data events happen. |
reactor.core.publisher.Mono<Void> |
disconnect()
Disconnect the
Client and shut down all its owned resources. |
reactor.core.publisher.Mono<io.netty.buffer.ByteBuf> |
failoverLog(int vbid) |
reactor.core.publisher.Flux<io.netty.buffer.ByteBuf> |
failoverLogs(Collection<Integer> vbids)
Helper method to return the failover logs for the given partitions (vbids).
|
reactor.core.publisher.Flux<io.netty.buffer.ByteBuf> |
failoverLogs(Short... vbids)
Deprecated.
Please use
failoverLogs(Collection) instead. |
reactor.core.publisher.Flux<PartitionAndSeqno> |
getSeqnos()
Get the current sequence numbers from all partitions.
|
reactor.core.publisher.Mono<Void> |
initializeState(StreamFrom from,
StreamTo to)
Initialize the
SessionState based on arbitrary time points. |
void |
listener(DatabaseChangeListener listener,
FlowControlMode flowControlMode)
Registers an event listener that will be invoked in a dedicated thread.
|
void |
nonBlockingListener(DatabaseChangeListener listener)
Registers an event listener to be invoked in the Netty I/O event loop thread.
|
int |
numPartitions()
Returns the number of partitions on the remote cluster.
|
reactor.core.publisher.Mono<Void> |
recoverOrInitializeState(StateFormat format,
byte[] persistedState,
StreamFrom from,
StreamTo to)
Recovers or initializes the
SessionState. |
reactor.core.publisher.Mono<Void> |
recoverState(StateFormat format,
byte[] persistedState)
Initializes the
SessionState from a previous snapshot with specific state information. |
reactor.core.publisher.Mono<Void> |
resumeStreaming(Map<Integer,StreamOffset> vbucketToOffset) |
reactor.core.publisher.Mono<Void> |
rollbackAndRestartStream(int partition,
long seqno)
Helper method to rollback the partition state and stop/restart the stream.
|
SessionState |
sessionState()
Returns the current
SessionState, useful for persistence and inspection. |
reactor.core.publisher.Mono<Void> |
startStreaming()
Start streaming for all partitions.
|
reactor.core.publisher.Mono<Void> |
startStreaming(Collection<Integer> vbids)
Start DCP streams based on the initialized state for the given partition IDs (vbids).
|
reactor.core.publisher.Mono<Void> |
startStreaming(Short... vbids)
Deprecated.
Please use
startStreaming(Collection) instead. |
reactor.core.publisher.Mono<Void> |
stopStreaming(Collection<Integer> vbids)
Stop DCP streams for the given partition IDs (vbids).
|
reactor.core.publisher.Mono<Void> |
stopStreaming(Short... vbids)
Deprecated.
Please use
stopStreaming(Collection) instead. |
boolean |
streamIsOpen(int vbid)
Returns true if the stream for the given partition id is currently open.
|
void |
systemEventHandler(SystemEventHandler systemEventHandler)
Stores a
SystemEventHandler to be called when control events happen. |
@Deprecated public static Client.Builder configure()
builder()Client before bootstrap through a Client.Builder.public static Client.Builder builder()
public reactor.core.publisher.Flux<PartitionAndSeqno> getSeqnos()
Flux of partition and sequence number.public SessionState sessionState()
SessionState, useful for persistence and inspection.public void listener(DatabaseChangeListener listener, FlowControlMode flowControlMode)
public void nonBlockingListener(DatabaseChangeListener listener)
Non-blocking listeners always use FlowControlMode.MANUAL.
public void controlEventHandler(ControlEventHandler controlEventHandler)
ControlEventHandler to be called when control events happen.
All events (passed as ByteBufs) that the callback receives need to be handled
and at least released (by using ReferenceCounted.release(), otherwise they will leak.
The following messages can happen and should be handled depending on the needs of the client:
- RollbackMessage: If during a connect phase the server responds with rollback
information, this event is forwarded to the callback. Does not need to be acknowledged.
- DcpSnapshotMarkerRequest: Server transmits data in batches called snapshots
before sending anything, it send marker message, which contains start and end sequence
numbers of the data in it. Need to be acknowledged.
Keep in mind that the callback is executed on the IO thread (netty's thread pool for the event loops) so further synchronization is needed if the data needs to be used on a different thread in a thread safe manner.
controlEventHandler - the event handler to use.public void systemEventHandler(SystemEventHandler systemEventHandler)
SystemEventHandler to be called when control events happen.public void dataEventHandler(DataEventHandler dataEventHandler)
DataEventHandler to be called when data events happen.
All events (passed as ByteBufs) that the callback receives need to be handled
and at least released (by using ReferenceCounted.release(), otherwise they will leak.
The following messages can happen and should be handled depending on the needs of the client:
- DcpMutationMessage: A mutation has occurred. Needs to be acknowledged.
- DcpDeletionMessage: A deletion has occurred. Needs to be acknowledged.
- DcpExpirationMessage: An expiration has occurred. Note that current server versions
(as of 4.5.0) are not emitting this event, but in any case you should at least release it to
be forwards compatible. Needs to be acknowledged.
Keep in mind that the callback is executed on the IO thread (netty's thread pool for the event loops) so further synchronization is needed if the data needs to be used on a different thread in a thread safe manner.
dataEventHandler - the event handler to use.public reactor.core.publisher.Mono<Void> connect()
Mono signaling that the connect phase has been completed or failed.public reactor.core.publisher.Mono<Void> disconnect()
Client and shut down all its owned resources.
If custom state is used (like a shared EventLoopGroup), then they must be closed and managed
separately after this disconnect process has finished.
Mono signaling that the disconnect phase has been completed or failed.public void close()
disconnect()
exists to support try-with-resources.close in interface Closeableclose in interface AutoCloseablepublic reactor.core.publisher.Mono<Void> resumeStreaming(Map<Integer,StreamOffset> vbucketToOffset)
vbucketToOffset - a Map where each key is a vbucket to stream, and the value is the offset from which to resume streaming.Mono that completes when the streams have been successfully opened.@Deprecated public reactor.core.publisher.Mono<Void> startStreaming(Short... vbids)
startStreaming(Collection) instead.public reactor.core.publisher.Mono<Void> startStreaming()
Mono indicating that streaming has started or failed.public reactor.core.publisher.Mono<Void> startStreaming(Collection<Integer> vbids)
If no ids are provided, all initialized partitions will be started.
vbids - the partition ids (0-indexed) to start streaming for.Mono indicating that streaming has started or failed.@Deprecated public reactor.core.publisher.Mono<Void> stopStreaming(Short... vbids)
stopStreaming(Collection) instead.public reactor.core.publisher.Mono<Void> stopStreaming(Collection<Integer> vbids)
If no ids are provided, all partitions will be stopped. Note that you can also use this to "pause" streams
if startStreaming(java.lang.Short...) is called later - since the session state is persisted and streaming
will resume from the current position.
vbids - the partition ids (0-indexed) to stop streaming for.Mono indicating that streaming has stopped or failed.@Deprecated public reactor.core.publisher.Flux<io.netty.buffer.ByteBuf> failoverLogs(Short... vbids)
failoverLogs(Collection) instead.public reactor.core.publisher.Flux<io.netty.buffer.ByteBuf> failoverLogs(Collection<Integer> vbids)
If the list is empty, the failover logs for all partitions will be returned. Note that the returned
ByteBufs can be analyzed using the DcpFailoverLogResponse flyweight.
vbids - the partitions to return the failover logs from.Flux containing all failover logs.public reactor.core.publisher.Mono<io.netty.buffer.ByteBuf> failoverLog(int vbid)
public reactor.core.publisher.Mono<Void> rollbackAndRestartStream(int partition, long seqno)
The stream is stopped (if not already done). Then:
The rollback seqno state is applied. Note that this will also remove all the failover logs for the partition that are higher than the given seqno, since the server told us we are ahead of it.
Finally, the stream is restarted again.
partition - the partition idseqno - the sequence number to rollback topublic int numPartitions()
Note that you must be connected, since the information is loaded from the server configuration. On all OS'es other than OSX it will be 1024, on OSX it is 64. Treat this as an opaque value anyways.
public boolean streamIsOpen(int vbid)
vbid - the partition id.public reactor.core.publisher.Mono<Void> initializeState(StreamFrom from, StreamTo to)
SessionState based on arbitrary time points.
The following combinations are supported and make sense:
- StreamFrom.BEGINNING to StreamTo.NOW
- StreamFrom.BEGINNING to StreamTo.INFINITY
- StreamFrom.NOW to StreamTo.INFINITY
If you already have state captured and you want to resume from this position, use
recoverState(StateFormat, byte[]) or recoverOrInitializeState(StateFormat, byte[], StreamFrom, StreamTo)
instead.
from - where to start streaming from.to - when to stop streaming.Mono indicating the success or failure of the state init.public reactor.core.publisher.Mono<Void> recoverState(StateFormat format, byte[] persistedState)
SessionState from a previous snapshot with specific state information.
If a system needs to be built that withstands outages and needs to resume where left off, this method,
combined with the periodic persistence of the SessionState provides resume capabilities. If you
need to start fresh, take a look at initializeState(StreamFrom, StreamTo) as well as
recoverOrInitializeState(StateFormat, byte[], StreamFrom, StreamTo).
format - the format used when persisting.persistedState - the opaque byte array representing the persisted state.Mono indicating the success or failure of the state recovery.public reactor.core.publisher.Mono<Void> recoverOrInitializeState(StateFormat format, byte[] persistedState, StreamFrom from, StreamTo to)
SessionState.
This method is a convience wrapper around initialization and recovery. It combines both methods and checks if the persisted state byte array is null or empty and if so it starts with the params given. If it is not empty it recovers from there. This acknowledges the fact that ideally the state is persisted somewhere but if its not there you want to start at a specific point in time.
format - the persistence format used.persistedState - the state, may be null or empty.from - from where to start streaming if persisted state is null or empty.to - to where to stream if persisted state is null or empty.Mono indicating the success or failure of the state recovery or init.Copyright © 2021 Couchbase, Inc.. All rights reserved.