Client

public class Client implements AutoCloseable

The gRPC-based gateway for backend services such as CommandService, QueryService, or SubscriptionService.

A connection can be established via host/port combination, or via already available ManagedChannel.

Multitenant applications need to specify TenantId for a new client connection. Single-tenant applications do nothing about it.

Client requests can be created on behalf of a guest user, if the user is not yet authenticated, and on behalf of the current user after the user is authenticated.

Please note that Spine client-side library does not define the authentication process. The Client class simply relies on the fact that UserId passed to the method onBehalfOf represents a valid logged-in user, ID of whom the client application got (presumably as field of a UserLoggedIn event) following due authentication process. The server-side code also needs to make sure that the UserId matches security constraints of the backend services. Security arrangements is not a part of the Spine client-side library either.

Subscriptions to entity states or events must be cancelled when no longer needed to preserve both client-side and backend resources.

The client connection must be closed when the application finishes its work.

Types

Link copied to clipboard
public final class Builder
The builder for the client.

Properties

Link copied to clipboard
public final static UserId DEFAULT_GUEST_ID
Default ID for a guest user.
Link copied to clipboard
public final static Timeout DEFAULT_SHUTDOWN_TIMEOUT
The default amount of time to wait when closing the client.

Functions

Link copied to clipboard
Creates a builder for posting guest requests.
Link copied to clipboard
public void cancel(Subscription s)
Requests cancellation of the passed subscription.
Link copied to clipboard
public void close()
Closes the client by shutting down the gRPC connection.
Link copied to clipboard
public static Client.Builder connectTo(String host, int port)
Creates a builder for a client connected to the specified address.
Link copied to clipboard
public static Client.Builder inProcess(String serverName)
Creates a client which will be connected to the in-process server with the passed name.
Link copied to clipboard
public boolean isOpen()
Verifies if the client connection is open.
Link copied to clipboard
public ClientRequest onBehalfOf(UserId user)
Creates a builder for requests on behalf of the passed user.
Link copied to clipboard
public void shutdown()
Same as close.
Link copied to clipboard
Obtains subscriptions created by this client.
Link copied to clipboard
public Optional<TenantId> tenant()
Obtains the tenant of this client connection in a multitenant application, and empty Optional in a single-tenant one.
Link copied to clipboard
public static Client.Builder usingChannel(ManagedChannel channel)
Creates a builder for a client which will use the passed channel for the communication with the backend services.