Class StitchAppClientImpl
- java.lang.Object
-
- com.mongodb.stitch.server.core.internal.StitchAppClientImpl
-
- All Implemented Interfaces:
AuthMonitor,StitchAppClient,Closeable,AutoCloseable
public final class StitchAppClientImpl extends Object implements StitchAppClient, AuthMonitor
-
-
Constructor Summary
Constructors Constructor Description StitchAppClientImpl(String clientAppId, StitchAppClientConfiguration config)Constructs an app client with the given configuration.
-
Method Summary
Modifier and Type Method Description voidcallFunction(String name, List<?> args)Calls the specified Stitch function.<ResultT> ResultTcallFunction(String name, List<?> args, Class<ResultT> resultClass)Calls the specified Stitch function, and decodes the response into an instance of the specified type.<ResultT> ResultTcallFunction(String name, List<?> args, Class<ResultT> resultClass, CodecRegistry codecRegistry)Calls the specified Stitch function, and decodes the response into an instance of the specified type.voidcallFunction(String name, List<?> args, Long requestTimeout)Calls the specified Stitch function.<ResultT> ResultTcallFunction(String name, List<?> args, Long requestTimeout, Class<ResultT> resultClass)Calls the specified Stitch function, and decodes the response into an instance of the specified type.<ResultT> ResultTcallFunction(String name, List<?> args, Long requestTimeout, Class<ResultT> resultClass, CodecRegistry codecRegistry)Calls the specified Stitch function, and decodes the response into an instance of the specified type.<ResultT> ResultTcallFunction(String name, List<?> args, Long requestTimeout, Decoder<ResultT> resultDecoder)<ResultT> ResultTcallFunction(String name, List<?> args, Decoder<ResultT> resultDecoder)voidclose()Closes the client and shuts down all background operations.StringgetActiveUserId()Get the active user id from the applications auth request client.StitchAuthgetAuth()Gets the authentication component of the app.<T> TgetServiceClient(NamedServiceClientFactory<T> factory, String serviceName)Gets a client for the given named service.<T> TgetServiceClient(ServiceClientFactory<T> factory)Gets a client for the given service.StitchServiceClientgetServiceClient(String serviceName)Gets a general purpose client for the given named service.booleanisLoggedIn()Get whether or not the application client is currently logged in.booleantryIsLoggedIn()Get whether or not the application client is currently logged in.
-
-
-
Constructor Detail
-
StitchAppClientImpl
public StitchAppClientImpl(String clientAppId, StitchAppClientConfiguration config)
Constructs an app client with the given configuration.- Parameters:
clientAppId- the client app id for the app.config- the configuration to use for the app client.
-
-
Method Detail
-
getAuth
public StitchAuth getAuth()
Description copied from interface:StitchAppClientGets the authentication component of the app. This is used for logging in and managing users.- Specified by:
getAuthin interfaceStitchAppClient- Returns:
- the authentication component of the app.
-
getServiceClient
public <T> T getServiceClient(NamedServiceClientFactory<T> factory, String serviceName)
Description copied from interface:StitchAppClientGets a client for the given named service.- Specified by:
getServiceClientin interfaceStitchAppClient- Type Parameters:
T- the type of client to be returned by the factory.- Parameters:
factory- the factory that will create a client for the service.serviceName- the name of the service.- Returns:
- A client to interact with the service.
-
getServiceClient
public <T> T getServiceClient(ServiceClientFactory<T> factory)
Description copied from interface:StitchAppClientGets a client for the given service. Only some services offer a factory that requires no service name.- Specified by:
getServiceClientin interfaceStitchAppClient- Type Parameters:
T- the type of client to be returned by the factory.- Parameters:
factory- the factory that will create a client for the service.- Returns:
- A client to interact with the service.
-
getServiceClient
public StitchServiceClient getServiceClient(String serviceName)
Description copied from interface:StitchAppClientGets a general purpose client for the given named service.- Specified by:
getServiceClientin interfaceStitchAppClient- Parameters:
serviceName- the name of the service.- Returns:
- a client to interact with the service.
-
callFunction
public void callFunction(String name, List<?> args)
Description copied from interface:StitchAppClientCalls the specified Stitch function.- Specified by:
callFunctionin interfaceStitchAppClient- Parameters:
name- the name of the Stitch function to call.args- the arguments to pass to the function.
-
callFunction
public void callFunction(String name, List<?> args, Long requestTimeout)
Description copied from interface:StitchAppClientCalls the specified Stitch function. Also accepts a timeout in milliseconds. Use this for functions that may run longer than the client-wide default timeout (15 seconds by default).- Specified by:
callFunctionin interfaceStitchAppClient- Parameters:
name- the name of the Stitch function to call.args- the arguments to pass to the function.requestTimeout- the number of milliseconds the client should wait for a response from the server before failing with an error.
-
callFunction
public <ResultT> ResultT callFunction(String name, List<?> args, Class<ResultT> resultClass)
Description copied from interface:StitchAppClientCalls the specified Stitch function, and decodes the response into an instance of the specified type. The response will be decoded using the codec registry specified when the client was configured. If no codec registry was configured, a default codec registry will be used. The default codec registry supports the mappings specified here- Specified by:
callFunctionin interfaceStitchAppClient- Type Parameters:
ResultT- the type into which the Stitch response will be decoded.- Parameters:
name- the name of the Stitch function to call.args- the arguments to pass to the function.resultClass- the class that the response should be decoded as.- Returns:
- the decoded value.
-
callFunction
public <ResultT> ResultT callFunction(String name, List<?> args, Long requestTimeout, Class<ResultT> resultClass)
Description copied from interface:StitchAppClientCalls the specified Stitch function, and decodes the response into an instance of the specified type. The response will be decoded using the codec registry specified when the client was configured. If no codec registry was configured, a default codec registry will be used. The default codec registry supports the mappings specified here Also accepts a timeout in milliseconds. Use this for functions that may run longer than the client-wide default timeout (15 seconds by default).- Specified by:
callFunctionin interfaceStitchAppClient- Type Parameters:
ResultT- the type into which the Stitch response will be decoded.- Parameters:
name- the name of the Stitch function to call.args- the arguments to pass to the function.requestTimeout- the number of milliseconds the client should wait for a response from the server before failing with an error.resultClass- the class that the response should be decoded as.- Returns:
- the decoded value.
-
callFunction
public <ResultT> ResultT callFunction(String name, List<?> args, Class<ResultT> resultClass, CodecRegistry codecRegistry)
Description copied from interface:StitchAppClientCalls the specified Stitch function, and decodes the response into an instance of the specified type. The response will be decoded using the codec registry given.- Specified by:
callFunctionin interfaceStitchAppClient- Type Parameters:
ResultT- the type into which the Stitch response will be decoded.- Parameters:
name- the name of the Stitch function to call.args- the arguments to pass to the function.resultClass- the class that the response should be decoded as.codecRegistry- the codec registry used for de/serialization of the function call.- Returns:
- the decoded value.
-
callFunction
public <ResultT> ResultT callFunction(String name, List<?> args, Long requestTimeout, Class<ResultT> resultClass, CodecRegistry codecRegistry)
Description copied from interface:StitchAppClientCalls the specified Stitch function, and decodes the response into an instance of the specified type. The response will be decoded using the codec registry given. Also accepts a timeout in milliseconds. Use this for functions that may run longer than the client-wide default timeout (15 seconds by default).- Specified by:
callFunctionin interfaceStitchAppClient- Type Parameters:
ResultT- the type into which the Stitch response will be decoded.- Parameters:
name- the name of the Stitch function to call.args- the arguments to pass to the function.requestTimeout- the number of milliseconds the client should wait for a response from the server before failing with an error.resultClass- the class that the response should be decoded as.codecRegistry- the codec registry used for de/serialization of the function call.- Returns:
- the decoded value.
-
callFunction
public <ResultT> ResultT callFunction(String name, List<?> args, Decoder<ResultT> resultDecoder)
Description copied from interface:StitchAppClientCalls the specified Stitch function, and decodes the response into a value using the providedDecoderorCodec.- Specified by:
callFunctionin interfaceStitchAppClient- Type Parameters:
ResultT- the type into which the response will be decoded.- Parameters:
name- the name of the Stitch function to call.args- the arguments to pass to the function.resultDecoder- theDecoderorCodecto use to decode the response into a value.- Returns:
- the decoded value.
-
callFunction
public <ResultT> ResultT callFunction(String name, List<?> args, Long requestTimeout, Decoder<ResultT> resultDecoder)
Description copied from interface:StitchAppClientCalls the specified Stitch function, and decodes the response into a value using the providedDecoderorCodec. Also accepts a timeout in milliseconds. Use this for functions that may run longer than the client-wide default timeout (15 seconds by default).- Specified by:
callFunctionin interfaceStitchAppClient- Type Parameters:
ResultT- the type into which the response will be decoded.- Parameters:
name- the name of the Stitch function to call.args- the arguments to pass to the function.requestTimeout- the number of milliseconds the client should wait for a response from the server before failing with an error.resultDecoder- theDecoderorCodecto use to decode the response into a value.- Returns:
- the decoded value.
-
isLoggedIn
public boolean isLoggedIn() throws InterruptedExceptionDescription copied from interface:AuthMonitorGet whether or not the application client is currently logged in.- Specified by:
isLoggedInin interfaceAuthMonitor- Returns:
- whether or not the application client is logged in
- Throws:
InterruptedException- will throw interruptibly
-
tryIsLoggedIn
public boolean tryIsLoggedIn()
Description copied from interface:AuthMonitorGet whether or not the application client is currently logged in.- Specified by:
tryIsLoggedInin interfaceAuthMonitor- Returns:
- whether or not the application client is logged in, or false if the thread was interrupted
-
getActiveUserId
@Nullable public String getActiveUserId()
Description copied from interface:AuthMonitorGet the active user id from the applications auth request client.- Specified by:
getActiveUserIdin interfaceAuthMonitor- Returns:
- active user id if there is one, null if not
-
close
public void close() throws IOExceptionCloses the client and shuts down all background operations.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein interfaceStitchAppClient- Throws:
IOException- if any thread shutdown errors happen.
-
-