public class LagomClientFactory extends Object implements Closeable
Generally, there should be only one instance of this per system. Additionally, since it holds
thread and connection pools, it must be shutdown, by calling the close()
method, when no
longer needed.
Modifier and Type | Method and Description |
---|---|
void |
close()
Close all resources associated with this client factory.
|
static LagomClientFactory |
create(String serviceName,
ClassLoader classLoader)
Creates a Lagom client factory.
|
static LagomClientFactory |
create(String serviceName,
ClassLoader classLoader,
akka.actor.ActorSystem actorSystem,
akka.stream.Materializer materializer)
Creates a Lagom client factory.
|
<T> T |
createClient(Class<T> clientInterface,
Collection<URI> serviceUris)
Create a Lagom service client that uses the given URIs.
|
<T> T |
createClient(Class<T> clientInterface,
ServiceLocator serviceLocator)
Create a Lagom service client for the given client interface using the given service locator.
|
<T> T |
createClient(Class<T> clientInterface,
URI serviceUri)
Create a Lagom service client that uses the given URI.
|
<T> T |
createDevClient(Class<T> clientInterface)
Create a Lagom service client that uses the Lagom dev mode service locator to locate the
service.
|
<T> T |
createDevClient(Class<T> clientInterface,
URI serviceLocatorUri)
Create a Lagom service client that uses the Lagom dev mode service locator to locate the
service.
|
public <T> T createClient(Class<T> clientInterface, ServiceLocator serviceLocator)
clientInterface
- The client interface for the service.serviceLocator
- The service locator.public <T> T createClient(Class<T> clientInterface, URI serviceUri)
clientInterface
- The client interface for the service.serviceUri
- The URI that the service lives at.public <T> T createClient(Class<T> clientInterface, Collection<URI> serviceUris)
The URIs are used in a round robin fashion. No validation is done to verify that a particular URI is still valid.
clientInterface
- The client interface for the service.serviceUris
- The URIs that the service lives at. A copy of this collection will be used,
so changes to the collection after invoking this have no effect.public <T> T createDevClient(Class<T> clientInterface)
This uses the default Lagom service locator port, that is, localhost:9008.
clientInterface
- The client interface for the service.public <T> T createDevClient(Class<T> clientInterface, URI serviceLocatorUri)
clientInterface
- The client interface for the service.serviceLocatorUri
- The URI of the Lagom dev mode service locator - usually
http://localhost:9008.public void close()
This must be invoked when the client factory is no longer needed, otherwise threads and connections will leak.
close
in interface Closeable
close
in interface AutoCloseable
public static LagomClientFactory create(String serviceName, ClassLoader classLoader, akka.actor.ActorSystem actorSystem, akka.stream.Materializer materializer)
Generally, there should be only one instance of this per system. Additionally, since it
holds thread and connection pools, it must be shutdown, by calling the close()
method,
when no longer needed.
This method should be used whenever your application has already a running ActorSystem. In
that case it's preferable to reuse it inside LagomClientFactory instead to let the factory
create and manage its own (see create(String, ClassLoader)
).
Calling close()
on a LagomClientFactory
created using this method will NOT
terminated the passed ActorSystem
and Akka Streams Materializer
.
serviceName
- The name of this service that is going to be accessing the services created
by this factory.classLoader
- A classloader, it will be used to create the service proxy and needs to have
the API for the client in it.actorSystem
- An existing ActorSystem
materializer
- An existing Akka Streams Materializer
public static LagomClientFactory create(String serviceName, ClassLoader classLoader)
Generally, there should be only one instance of this per system. Additionally, since it
holds thread and connection pools, it must be shutdown, by calling the close()
method,
when no longer needed.
This method should be used whenever your application does NOT have a running ActorSystem
and you don't want to manage one yourself.
Internally, this method will create a new ActorSystem
that will be attached to the
lifecycle of this factory. In other words, the internal ActorSystem
will terminate upon
calling close()
.
In case your application already have a running ActorSystem
, we recommend to use
create(String, ClassLoader, ActorSystem, Materializer)
) instead.
serviceName
- The name of this service that is going to be accessing the services created
by this factory.classLoader
- A classloader, it will be used to create the service proxy and needs to have
the API for the client in it.