Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
import com.google.android.gms.tasks.Task;
import com.mongodb.stitch.android.core.auth.StitchAuth;
import com.mongodb.stitch.android.core.push.StitchPush;
import com.mongodb.stitch.android.core.services.StitchServiceClient;
import com.mongodb.stitch.android.core.services.internal.NamedServiceClientFactory;
import com.mongodb.stitch.android.core.services.internal.ServiceClientFactory;

import java.io.Closeable;
import java.io.IOException;
import java.util.List;
Expand Down Expand Up @@ -71,6 +71,14 @@ public interface StitchAppClient extends Closeable {
*/
<T> T getServiceClient(final ServiceClientFactory<T> factory);

/**
* Gets a general purpose client for the given named service.
*
* @param serviceName the name of the service.
* @return a client to interact with the service.
*/
StitchServiceClient getServiceClient(final String serviceName);

/**
* Calls the specified Stitch function.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.mongodb.stitch.android.core.internal.common.TaskDispatcher;
import com.mongodb.stitch.android.core.push.StitchPush;
import com.mongodb.stitch.android.core.push.internal.StitchPushImpl;
import com.mongodb.stitch.android.core.services.StitchServiceClient;
import com.mongodb.stitch.android.core.services.internal.NamedServiceClientFactory;
import com.mongodb.stitch.android.core.services.internal.ServiceClientFactory;
import com.mongodb.stitch.android.core.services.internal.StitchServiceClientImpl;
Expand All @@ -31,7 +32,7 @@
import com.mongodb.stitch.core.internal.CoreStitchAppClient;
import com.mongodb.stitch.core.internal.net.StitchAppRoutes;
import com.mongodb.stitch.core.internal.net.StitchRequestClient;

import com.mongodb.stitch.core.services.internal.CoreStitchServiceClientImpl;
import java.io.IOException;
import java.util.List;
import java.util.concurrent.Callable;
Expand Down Expand Up @@ -90,36 +91,45 @@ public StitchPush getPush() {
public <T> T getServiceClient(
final NamedServiceClientFactory<T> factory, final String serviceName) {
return factory.getClient(
new StitchServiceClientImpl(
new CoreStitchServiceClientImpl(
auth,
routes.getServiceRoutes(),
serviceName,
info.getCodecRegistry(),
dispatcher),
info.getCodecRegistry()),
info,
dispatcher);
}

@Override
public <T> T getServiceClient(final ServiceClientFactory<T> factory) {
return factory.getClient(
new StitchServiceClientImpl(
auth,
routes.getServiceRoutes(),
"",
info.getCodecRegistry(),
dispatcher),
new CoreStitchServiceClientImpl(
auth,
routes.getServiceRoutes(),
"",
info.getCodecRegistry()),
info,
dispatcher);
}

@Override
public StitchServiceClient getServiceClient(final String serviceName) {
return new StitchServiceClientImpl(
new CoreStitchServiceClientImpl(
auth,
routes.getServiceRoutes(),
serviceName,
info.getCodecRegistry()),
dispatcher);
}

@Override
public Task<Void> callFunction(final String name, final List<?> args) {
return dispatcher.dispatchTask(
new Callable<Void>() {
@Override
public Void call() {
coreClient.callFunctionInternal(name, args, null);
coreClient.callFunction(name, args, null);
return null;
}
});
Expand All @@ -135,7 +145,7 @@ public Task<Void> callFunction(
new Callable<Void>() {
@Override
public Void call() {
coreClient.callFunctionInternal(name, args, requestTimeout);
coreClient.callFunction(name, args, requestTimeout);
return null;
}
});
Expand All @@ -148,7 +158,7 @@ public <ResultT> Task<ResultT> callFunction(
new Callable<ResultT>() {
@Override
public ResultT call() {
return coreClient.callFunctionInternal(name, args, null, resultClass);
return coreClient.callFunction(name, args, null, resultClass);
}
});
}
Expand All @@ -163,7 +173,7 @@ public <ResultT> Task<ResultT> callFunction(
new Callable<ResultT>() {
@Override
public ResultT call() {
return coreClient.callFunctionInternal(name, args, requestTimeout, resultClass);
return coreClient.callFunction(name, args, requestTimeout, resultClass);
}
});
}
Expand All @@ -179,7 +189,7 @@ public <ResultT> Task<ResultT> callFunction(
new Callable<ResultT>() {
@Override
public ResultT call() {
return coreClient.callFunctionInternal(name, args, null, resultClass, codecRegistry);
return coreClient.callFunction(name, args, null, resultClass, codecRegistry);
}
});
}
Expand All @@ -196,7 +206,7 @@ public <ResultT> Task<ResultT> callFunction(
new Callable<ResultT>() {
@Override
public ResultT call() {
return coreClient.callFunctionInternal(
return coreClient.callFunction(
name,
args,
requestTimeout,
Expand All @@ -213,7 +223,7 @@ public <ResultT> Task<ResultT> callFunction(
new Callable<ResultT>() {
@Override
public ResultT call() {
return coreClient.callFunctionInternal(name, args, null, resultDecoder);
return coreClient.callFunction(name, args, null, resultDecoder);
}
});
}
Expand All @@ -228,7 +238,7 @@ public <ResultT> Task<ResultT> callFunction(
new Callable<ResultT>() {
@Override
public ResultT call() {
return coreClient.callFunctionInternal(name, args, requestTimeout, resultDecoder);
return coreClient.callFunction(name, args, requestTimeout, resultDecoder);
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,43 @@
* limitations under the License.
*/

package com.mongodb.stitch.android.core.services.internal;
package com.mongodb.stitch.android.core.services;

import com.google.android.gms.tasks.Task;
import com.mongodb.stitch.core.services.internal.CoreStitchServiceClient;

import java.util.List;
import org.bson.codecs.Decoder;
import org.bson.codecs.configuration.CodecRegistry;

/**
* StitchServiceClient acts as a general purpose client for working with services that either
* not defined or well defined by this SDK. It functions similarly to
* {@link com.mongodb.stitch.android.core.StitchAppClient#callFunction}.
*/
public interface StitchServiceClient {

/**
* Calls the specified Stitch service function.
*
* @param name the name of the Stitch service function to call.
* @param args the arguments to pass to the function.
* @return a {@link Task} that completes when the request completes.
*/
Task<Void> callFunction(
final String name, final List<?> args);

/**
* Calls the specified Stitch service function, and decodes the response into a value using the
* provided {@link Decoder}.
*
* @param name the name of the Stitch service function to call.
* @param args the arguments to pass to the function.
* @param resultDecoder the {@link Decoder} to use to decode the response into a value.
* @param <ResultT> the type into which the response will be decoded.
* @return a {@link Task} containing the decoded value.
*/
<ResultT> Task<ResultT> callFunction(
final String name, final List<?> args, final Decoder<ResultT> resultDecoder);

public interface StitchServiceClient extends CoreStitchServiceClient {
/**
* Calls the specified Stitch service function, and decodes the response into an instance of the
* specified type. The response will be decoded using the codec registry specified when the app
Expand All @@ -41,56 +69,115 @@ <ResultT> Task<ResultT> callFunction(

/**
* Calls the specified Stitch service function, and decodes the response into an instance of the
* specified type. The response will be decoded using the codec registry specified when the app
* client was configured. If no codec registry was configured, a default codec registry will be
* used. The default codec registry supports the mappings specified <a
* href="http://mongodb.github.io/mongo-java-driver/3.1/bson/documents/#document">here</a>
* 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 type. The response will be decoded using the codec registry given.
*
* @param name the name of the Stitch service function to call.
* @param args the arguments to pass to the function.
* @param requestTimeout the number of milliseconds the client should wait for a response from the
* server before failing with an error.
* @param resultClass the class that the response should be decoded as.
* @param codecRegistry the codec registry used for de/serialization of the function call.
* @param <ResultT> the type into which the response will be decoded.
* @return a {@link Task} containing the decoded value.
*/
<ResultT> Task<ResultT> callFunction(
final String name,
final List<?> args,
final Long requestTimeout,
final Class<ResultT> resultClass);
final String name,
final List<?> args,
final Class<ResultT> resultClass,
final CodecRegistry codecRegistry);

/**
* Calls the specified Stitch service 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).
*
* @param name the name of the Stitch service function to call.
* @param args the arguments to pass to the function.
* @param requestTimeout the number of milliseconds the client should wait for a response from the
* server before failing with an error.
* @return a {@link Task} that completes when the request completes.
*/
Task<Void> callFunction(
final String name,
final List<?> args,
final Long requestTimeout);


/**
* Calls the specified Stitch service function, and decodes the response into a value using the
* provided {@link Decoder}.
* provided {@link Decoder}. Also accepts a timeout in milliseconds. Use this for functions that
* may run longer than the client-wide default timeout (15 seconds by default).
*
* @param name the name of the Stitch service function to call.
* @param args the arguments to pass to the function.
* @param requestTimeout the number of milliseconds the client should wait for a response from the
* server before failing with an error.
* @param resultDecoder the {@link Decoder} to use to decode the response into a value.
* @param <ResultT> the type into which the response will be decoded.
* @return a {@link Task} containing the decoded value.
*/
<ResultT> Task<ResultT> callFunction(
final String name, final List<?> args, final Decoder<ResultT> resultDecoder);
final String name,
final List<?> args,
final Long requestTimeout,
final Decoder<ResultT> resultDecoder);

/**
* Calls the specified Stitch service function, and decodes the response into a value using the
* provided {@link Decoder}. Also accepts a timeout in milliseconds. Use this for functions that
* may run longer than the client-wide default timeout (15 seconds by default).
* Calls the specified Stitch service function, and decodes the response into an instance of the
* specified type. The response will be decoded using the codec registry specified when the app
* client was configured. If no codec registry was configured, a default codec registry will be
* used. The default codec registry supports the mappings specified <a
* href="http://mongodb.github.io/mongo-java-driver/3.1/bson/documents/#document">here</a>
* Also accepts a timeout in milliseconds. Use this for functions that may run longer than the
* client-wide default timeout (15 seconds by default).
*
* @param name the name of the Stitch service function to call.
* @param args the arguments to pass to the function.
* @param requestTimeout the number of milliseconds the client should wait for a response from the
* server before failing with an error.
* @param resultDecoder the {@link Decoder} to use to decode the response into a value.
* @param resultClass the class that the response should be decoded as.
* @param <ResultT> the type into which the response will be decoded.
* @return a {@link Task} containing the decoded value.
*/
<ResultT> Task<ResultT> callFunction(
final String name,
final List<?> args,
final Long requestTimeout,
final Decoder<ResultT> resultDecoder);
final Class<ResultT> resultClass);

/**
* Calls the specified Stitch service 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).
*
* @param name the name of the Stitch service function to call.
* @param args the arguments to pass to the function.
* @param requestTimeout the number of milliseconds the client should wait for a response from the
* server before failing with an error.
* @param resultClass the class that the response should be decoded as.
* @param codecRegistry the codec registry used for de/serialization of the function call.
* @param <ResultT> the type into which the response will be decoded.
* @return a {@link Task} containing the decoded value.
*/
<ResultT> Task<ResultT> callFunction(
final String name,
final List<?> args,
final Long requestTimeout,
final Class<ResultT> resultClass,
final CodecRegistry codecRegistry);

/**
* Get the codec registry that will be used to decode responses when a codec registry.
*
* @return the {@link CodecRegistry}
*/
CodecRegistry getCodecRegistry();


/**
* Create a new StitchServiceClient instance with a different codec registry.
*
* @param codecRegistry the new {@link CodecRegistry} for the service client.
* @return a new StitchServiceClient instance with the different codec registry
*/
StitchServiceClient withCodecRegistry(final CodecRegistry codecRegistry);
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@

import com.mongodb.stitch.android.core.internal.common.TaskDispatcher;
import com.mongodb.stitch.core.StitchAppClientInfo;
import com.mongodb.stitch.core.services.internal.CoreStitchServiceClient;

public interface NamedServiceClientFactory<T> {
T getClient(
final StitchServiceClient serviceClient,
final CoreStitchServiceClient serviceClient,
final StitchAppClientInfo appInfo,
final TaskDispatcher dispatcher);
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@

import com.mongodb.stitch.android.core.internal.common.TaskDispatcher;
import com.mongodb.stitch.core.StitchAppClientInfo;
import com.mongodb.stitch.core.services.internal.CoreStitchServiceClient;

public interface ServiceClientFactory<T> {
T getClient(
final StitchServiceClient serviceClient,
final CoreStitchServiceClient serviceClient,
final StitchAppClientInfo appInfo,
final TaskDispatcher dispatcher);
}
Loading