Package csw.location.api.javadsl
Interface ILocationService
public interface ILocationService
A LocationService interface to manage connections and their registrations. All operations are non-blocking.
-
Method Summary
Modifier and TypeMethodDescriptioncsw.location.api.scaladsl.LocationService
asScala()
Returns the Scala API for this instance of location service<L extends Location>
CompletableFuture<Optional<L>>find
(TypedConnection<L> connection) Resolve the location for a connection from the local cachelist()
Lists all locations registeredlist
(ComponentType componentType) Filters all locations registered based on a component typelist
(ConnectionType connectionType) Filters all locations registered based on a connection typeFilters all locations registered based on a hostnamelistByPrefix
(String prefix) Filters all locations registered based on a prefix.register
(Registration registration) Registers a connection to location<L extends Location>
CompletableFuture<Optional<L>>resolve
(TypedConnection<L> connection, Duration within) Resolves the location based on the given connectionmsocket.api.Subscription
subscribe
(Connection connection, Consumer<TrackingEvent> consumer) Subscribe to tracking events for a connection by providing a consumer For each event accept method of consumer interface is invoked.akka.stream.javadsl.Source<TrackingEvent,
msocket.api.Subscription> track
(Connection connection) Tracks the connection and send events for modification or removal of its locationCompletableFuture<akka.Done>
unregister
(Connection connection) Unregisters the connectionCompletableFuture<akka.Done>
Unregisters all connections registered
-
Method Details
-
asScala
csw.location.api.scaladsl.LocationService asScala()Returns the Scala API for this instance of location service- Returns:
- (undocumented)
-
find
Resolve the location for a connection from the local cache- Parameters:
connection
- a connection to resolve to with its registered location- Returns:
- a CompletableFuture which completes with the resolved location if found or Empty otherwise. It can fail with
RegistrationListingFailed
.
-
list
CompletableFuture<List<Location>> list()Lists all locations registered- Returns:
- a CompletableFuture which completes with a List of all registered locations or can fail with
RegistrationListingFailed
-
list
Filters all locations registered based on a component type- Parameters:
componentType
- list components of thiscomponentType
- Returns:
- a CompletableFuture which completes with filtered locations or can fail with
RegistrationListingFailed
-
list
Filters all locations registered based on a hostname- Parameters:
hostname
- list components running on thishostname
- Returns:
- a CompletableFuture which completes with filtered locations or can fail with
RegistrationListingFailed
-
list
Filters all locations registered based on a connection type- Parameters:
connectionType
- list components of thisconnectionType
- Returns:
- a CompletableFuture which completes with filtered locations or can fail with
RegistrationListingFailed
-
listByPrefix
Filters all locations registered based on a prefix.Note that all locations having subsystem prefix that starts with the given prefix value will be listed
- Parameters:
prefix
- list components by thisprefix
- Returns:
- a CompletableFuture which completes with filtered locations or can fail with
RegistrationListingFailed
-
register
Registers a connection to location- Parameters:
registration
- the Registration holding connection and it's corresponding location to register withLocationService
- Returns:
- a CompletableFuture which completes with Registration result or can fail with
RegistrationFailed
orOtherLocationIsRegistered
-
resolve
<L extends Location> CompletableFuture<Optional<L>> resolve(TypedConnection<L> connection, Duration within) Resolves the location based on the given connection- Parameters:
connection
- a connection to resolve to with its registered locationwithin
- the time for which a connection is looked-up withinLocationService
- Returns:
- a CompletableFuture which completes with the resolved location if found or None otherwise. It can fail with
RegistrationListingFailed
.
-
subscribe
Subscribe to tracking events for a connection by providing a consumer For each event accept method of consumer interface is invoked. Use this method if you do not want to handle materialization and happy with a side-effecting callback insteadNote that callbacks are not thread-safe on the JVM. If you are doing side effects/mutations inside the callback, you should ensure that it is done in a thread-safe way inside an actor.
- Parameters:
connection
- theconnection
that is to be trackedconsumer
- theConsumer
function that consumesTrakingEvent
- Returns:
- a killswitch which can be shutdown to unsubscribe the consumer
-
track
Tracks the connection and send events for modification or removal of its location- Parameters:
connection
- theconnection
that is to be tracked- Returns:
- A stream that emits events related to the connection. It can be cancelled using KillSwitch. This will stop giving events for earlier tracked connection
-
unregister
Unregisters the connectionNote that this method is idempotent, which means multiple calls to unregister the same connection will be no-op once successfully unregistered from location service
- Parameters:
connection
- an already registered connection- Returns:
- a CompletableFuture which completes after un-registration happens successfully and fails otherwise with
UnregistrationFailed
-
unregisterAll
CompletableFuture<akka.Done> unregisterAll()Unregisters all connections registeredNote that it is highly recommended to use this method for testing purpose only
- Returns:
- a CompletableFuture which completes after all connections are unregistered successfully or fails otherwise
with
RegistrationListingFailed
-