Package com.linecorp.centraldogma.client
Interface Watcher<T>
- Type Parameters:
T- the watch result type
- All Superinterfaces:
AutoCloseable
-
Method Summary
Modifier and TypeMethodDescriptionatJsonPointer(Watcher<JsonNode> watcher, String jsonPointer) Waits for the initial value to be available.awaitInitialValue(long timeout, TimeUnit unit) Waits for the initial value to be available.default TawaitInitialValue(long timeout, TimeUnit unit, T defaultValue) Waits for the initial value to be available and returns the specified default value if failed to retrieve the initial value from the server.voidclose()Stops watching the file specified in theQueryor thePathPatternin the repository.Returns theCompletableFuturewhich is completed when the initial value retrieval is done successfully.latest()default TReturns the latest value ofwatchFile()orwatchRepository()result.default TlatestValue(T defaultValue) Returns the latest value ofwatchFile()orwatchRepository()result.default <U> Watcher<U> default <U> Watcher<U> voidwatch(BiConsumer<? super Revision, ? super T> listener) Registers aBiConsumerthat will be invoked when the value of the watched entry becomes available or changes.voidwatch(BiConsumer<? super Revision, ? super T> listener, Executor executor) Registers aBiConsumerthat will be invoked when the value of the watched entry becomes available or changes.default voidRegisters aConsumerthat will be invoked when the value of the watched entry becomes available or changes.default voidRegisters aConsumerthat will be invoked when the value of the watched entry becomes available or changes.Returns theScheduledExecutorServicethat is used to schedule watch.
-
Method Details
-
atJsonPointer
- Parameters:
jsonPointer- a JSON pointer that is encoded- Returns:
- A new child
Watcher, whose transformation is a JSON pointer query.
-
watchScheduler
ScheduledExecutorService watchScheduler()Returns theScheduledExecutorServicethat is used to schedule watch. -
initialValueFuture
CompletableFuture<Latest<T>> initialValueFuture()Returns theCompletableFuturewhich is completed when the initial value retrieval is done successfully. -
awaitInitialValue
Waits for the initial value to be available.- Returns:
- the
Latestobject that contains the initial value and theRevisionwhere the initial value came from. - Throws:
CancellationException- if this watcher has been closed byclose()EntryNotFoundException- iferrorOnEntryNotFoundistrueand entry isn't found on watching the initial valueInterruptedException
-
awaitInitialValue
default Latest<T> awaitInitialValue(long timeout, TimeUnit unit) throws InterruptedException, TimeoutException Waits for the initial value to be available. Specify the default value withawaitInitialValue(long, TimeUnit, Object)or make sure to handle aTimeoutExceptionproperly if the initial value must be available even when the server is unavailable.- Parameters:
timeout- the maximum amount of time to wait for the initial value. Note that timeout is basically a trade-off. If you specify a smaller timeout, this method will have a higher chance of throwing aTimeoutExceptionwhen the server does not respond in time. If you specify a larger timeout, you will have a better chance of successful retrieval. It is generally recommended to use a value not less than 20 seconds so that the client can retry at least a few times before timing out. Consider usingawaitInitialValue(long, TimeUnit, Object)with a sensible default value if you cannot tolerate a timeout or need to use a small timeout.unit- theTimeUnitoftimeout.- Returns:
- the
Latestobject that contains the initial value and theRevisionwhere the initial value came from. - Throws:
CancellationException- if this watcher has been closed byclose()EntryNotFoundException- iferrorOnEntryNotFoundistrueand entry isn't found on watching the initial valueTimeoutException- if failed to retrieve the initial value within the specified timeoutInterruptedException
-
awaitInitialValue
@Nullable default T awaitInitialValue(long timeout, TimeUnit unit, @Nullable T defaultValue) throws InterruptedException Waits for the initial value to be available and returns the specified default value if failed to retrieve the initial value from the server.- Parameters:
timeout- the maximum amount of time to wait for the initial value. Note that timeout is basically a trade-off. If you specify a smaller timeout, this method will have a higher chance of falling back to thedefaultValuewhen the server does not respond in time. If you specify a larger timeout, you will have a better chance of retrieving an up-to-date initial value. It is generally recommended to use a value not less than 20 seconds so that the client can retry at least a few times before timing out.unit- theTimeUnitoftimeout.defaultValue- the default value to use when timed out.- Returns:
- the initial value, or the default value if timed out.
- Throws:
CancellationException- if this watcher has been closed byclose()EntryNotFoundException- iferrorOnEntryNotFoundistrueand entry isn't found on watching the initial valueInterruptedException
-
latest
- Throws:
IllegalStateException- if the value is not available yet. UseawaitInitialValue(long, TimeUnit)first or add a listener usingwatch(BiConsumer)instead.
-
latestValue
Returns the latest value ofwatchFile()orwatchRepository()result.- Throws:
IllegalStateException- if the value is not available yet. UseawaitInitialValue(long, TimeUnit)first or add a listener usingwatch(BiConsumer)instead.
-
latestValue
Returns the latest value ofwatchFile()orwatchRepository()result.- Parameters:
defaultValue- the default value which is returned when the value is not available yet
-
close
void close()Stops watching the file specified in theQueryor thePathPatternin the repository.- Specified by:
closein interfaceAutoCloseable
-
watch
Registers aBiConsumerthat will be invoked when the value of the watched entry becomes available or changes.Note that the specified
BiConsumeris not called whenerrorOnEntryNotFoundistrueand the target doesn't exist in the Central Dogma server when thisWatchersends the initial watch call. You should useinitialValueFuture()orawaitInitialValue()to check the target exists or not. -
watch
Registers aBiConsumerthat will be invoked when the value of the watched entry becomes available or changes.Note that the specified
BiConsumeris not called whenerrorOnEntryNotFoundistrueand the target doesn't exist in the Central Dogma server when thisWatchersends the initial watch call. You should useinitialValueFuture()orawaitInitialValue()to check the target exists or not.- Parameters:
executor- theExecutorthat executes theBiConsumer
-
watch
Registers aConsumerthat will be invoked when the value of the watched entry becomes available or changes. -
watch
Registers aConsumerthat will be invoked when the value of the watched entry becomes available or changes. -
newChild
-
newChild
-