Class AsyncRegistration
- java.lang.Object
-
- io.axoniq.axonserver.connector.impl.AsyncRegistration
-
- All Implemented Interfaces:
Registration
public class AsyncRegistration extends Object implements Registration
Asynchronous implementation of theRegistration.
-
-
Constructor Summary
Constructors Constructor Description AsyncRegistration(CompletableFuture<Void> requestAck, Supplier<CompletableFuture<Void>> cancelAction)Construct aAsyncRegistration, using the givenrequestAckonawaitAck(long, TimeUnit)andonAck(Runnable), and the givencancelActiononcancel().
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description RegistrationawaitAck(long timeout, TimeUnit unit)Wait for the acknowledgement of the original instructionthisRegistrationcorresponds to.CompletableFuture<Void>cancel()Cancel the registration from which this instance was returned.RegistrationonAck(Runnable runnable)Registers the givenrunnabletothisRegistrationto be executed when the acknowledgement ofthisRegistrationis received.RegistrationonAck(Consumer<Optional<Throwable>> action)Registers the givenrunnabletothisRegistrationto be executed when the acknowledgement ofthisRegistrationis received.
-
-
-
Constructor Detail
-
AsyncRegistration
public AsyncRegistration(CompletableFuture<Void> requestAck, Supplier<CompletableFuture<Void>> cancelAction)
Construct aAsyncRegistration, using the givenrequestAckonawaitAck(long, TimeUnit)andonAck(Runnable), and the givencancelActiononcancel().- Parameters:
requestAck- theCompletableFutureto wait for on #awaitAck(long, TimeUnit)cancelAction- theSupplierof theCompletableFutureto retrieve oncancel()
-
-
Method Detail
-
cancel
public CompletableFuture<Void> cancel()
Description copied from interface:RegistrationCancel the registration from which this instance was returned. Does nothing if the registration has already been canceled, or when the registration was undone by another mechanism (such as a new registration overriding this one).- Specified by:
cancelin interfaceRegistration- Returns:
- a
CompletableFutureofVoidto react whenthisRegistrationhas been canceled
-
awaitAck
public Registration awaitAck(long timeout, TimeUnit unit) throws TimeoutException, InterruptedException
Description copied from interface:RegistrationWait for the acknowledgement of the original instructionthisRegistrationcorresponds to. Allows for the addition of further logic tothis Registration, like invokingRegistration.onAck(Runnable)for example.- Specified by:
awaitAckin interfaceRegistration- Parameters:
timeout- the duration to wait until the operation has been acknowledgedunit- theTimeUnitfor the giventimeoutto wait until the operation has been acknowledged- Returns:
- this Registration to support a fluent API
- Throws:
TimeoutException- is thrown when the giventimeoutandunitis surpassedInterruptedException- is thrown when the thread waiting for the acknowledgement is interrupted
-
onAck
public Registration onAck(Runnable runnable)
Description copied from interface:RegistrationRegisters the givenrunnabletothisRegistrationto be executed when the acknowledgement ofthisRegistrationis received. Allows for the addition of further logic tothis Registration, like invokingRegistration.awaitAck(long, TimeUnit)for example.The given
runnableis invoked, regardless of successful or failed acknowledgement. UseRegistration.onAck(Consumer)to register an action that needs to distinguish between successful and failed registration.- Specified by:
onAckin interfaceRegistration- Parameters:
runnable- theRunnableto execute when the acknowledgement ofthisRegistrationis received- Returns:
- this Registration to support a fluent API
-
onAck
public Registration onAck(Consumer<Optional<Throwable>> action)
Description copied from interface:RegistrationRegisters the givenrunnabletothisRegistrationto be executed when the acknowledgement ofthisRegistrationis received. Allows for the addition of further logic tothis Registration, like invokingRegistration.awaitAck(long, TimeUnit)for example.- Specified by:
onAckin interfaceRegistration- Parameters:
action- the action to execute when the acknowledgement ofthisRegistrationis received, either normally or exceptionally.- Returns:
- this Registration to support a fluent API
-
-