This SDK is intended for client libraries, e.g.:
-
Android - so you have control over how frequently feature updates are requested, making sure the battery would not drain quickly on the device
-
lambdas or cloud functions where control over the HTTP request object is desired and you only need to get the state once during the lifetime.
-
other situations where updating the state of the internal repository is intermittent or desired to be consistent
The REST SDK does not poll. It allows the user of the SDK to create a polling mechanism which suites their application.
The SDK provides a standard interface to make HTTP GET requests for the data but sets a period for which it will hold off making new requests (a timeout, which you can set to 0 if you have your own timer).
This will allow you to keep requesting updates but they will not actually issue REST calls to the FeatureHub Edge server unless the Client Context changes or the timeout has occurred.
Visit our official web page for more information about the platform here
When using the REST client, simply including it and following the standard pattern works and is generally recommended when you are happy with the OKHttpClient defaults. This pattern is as follows:
String edgeUrl = "http://localhost:8085/";
String apiKey = "71ed3c04-122b-4312-9ea8-06b2b8d6ceac/fsTmCrcZZoGyl56kPHxfKAkbHrJ7xZMKO3dlBiab5IqUXjgKvqpjxYdI8zdXiJqYCpv92Jrki0jY5taE";
FeatureHubConfig fhConfig = new EdgeFeatureHubConfig(edgeUrl, apiKey);
fhConfig.init();
The init
method creates the FeatureHubClient
via the default method using Java services, and calls
the initial poll
method on it.
It is recommended that developers use this SDK directly if they wish to have full control. Using it directly allows you complete control over the OKHttpConfig object that is passed, being able to set connect and request timeouts, interceptors for adding any extra parameters and so forth.
// create the central config
FeatureHubConfig fhConfig = new EdgeFeatureHubConfig(edgeUrl, apiKey);
// create and override the http client
OkHttpClient httpClient = new OkHttpClient.Builder()
.connectTimeout(1, TimeUnit.SECONDS)
.readTimeout(1, TimeUnit.SECONDS).build();
// construct the new client
FeatureHubClient client = new FeatureHubClient(fhConfig.baseUrl(), Collections.singletonList(fhConfig.apiKey()config.getRepository(), httpClient, fhConfig));
// tell the config to use this client in all its dealings
fhConfig.setEdgeService(() -> client);
Because you have the REST client, you can make arbitrary calls on it any time. If you need to change it out part way through for any reason, just calling:
fhConfig.setEdgeService(() -> client);
will let you replace the client.
As it requires internet access, you will need to add to your AndroidManifest.xml
the usual:
<uses-permission android:name="android.permission.INTERNET"/>
If you are using it locally and not behind https, you will also need to specify an attribute on your <application>
tag,
which allows clear text traffic.
android:usesCleartextTraffic="true"
You will need to store your repository in a central location, using a static or via a DI tool like Dagger.Using a static might look something like this:
Core uses Java’s ServiceLoader capability to automatically discover the JerseyClient implementation. Please simply follow the instructions in the Java Core library.
As per that documentation you can manually configure the Edge provider to be the AndroidFeatureHubClientFactory
if
you wish.