SDK
SDK Android v3.x
1

You are currently looking at the documentation of a previous version of Kuzzle. We strongly recommend that you use the latest version. You can also use the version selector in the top menu.

Constructor #

This is the main entry point to communicate with Kuzzle. Every other object inherits properties from the Kuzzle object.


Kuzzle(host, [options], [callback]) #

ArgumentsTypeDescription
hoststringThe server name (or the IP address) of a Kuzzle server installation
optionsJSON objectOptional Kuzzle connection configuration
callbackfunctionOptional callback

Options #

OptionTypeDescriptionDefault
autoQueuebooleanAutomatically queue all requests during offline modefalse
autoReconnectbooleanAutomatically reconnect after a connection losstrue
autoReplaybooleanAutomatically replay queued requests on a reconnected eventfalse
autoResubscribebooleanAutomatically renew all subscriptions on a reconnected eventtrue
connectstringManually or automatically connect to the Kuzzle instanceauto
defaultIndexstringSet the default index to use
headersJSON objectCommon headers for all sent documents
volatileJSON objectCommon volatile data, will be sent to all future requests
offlineModestringOffline mode configurationmanual
portintegerKuzzle network port7512
queueTTLintegerTime a queued request is kept during offline mode, in milliseconds120000
queueMaxSizeintegerNumber of maximum requests kept during offline mode500
replayIntervalintegerDelay between each replayed requests, in milliseconds10
reconnectionDelayintegernumber of milliseconds between reconnection attempts1000
sslbooleanSwitch Kuzzle connection to SSL modefalse

Notes:

  • the offlineMode option only accepts the manual and auto values

Properties #

Property nameTypeDescriptionWritable?
autoQueuebooleanAutomatically queue all requests during offline modeYes
autoReconnectbooleanAutomatically reconnect after a connection lossNo
autoReplaybooleanAutomatically replay queued requests on a reconnected eventYes
autoResubscribebooleanAutomatically renew all subscriptions on a reconnected eventNo
defaultIndexstringKuzzle's default index to useYes
headersJSON objectCommon headers for all sent documents.Yes
hoststringTarget Kuzzle host name/addressNo
jwtTokenstringToken used in requests for authentication.Yes
offlineQueueJSON objectContains the queued requests during offline modeNo
offlineQueueLoaderfunctionCalled before dequeuing requests after exiting offline mode, to add items at the beginning of the offline queueYes
portintegerKuzzle network portNo
queueFilterfunctionCalled during offline mode. Takes a request object as arguments and returns a boolean, indicating if a request can be queuedYes
queueMaxSizeintegerNumber of maximum requests kept during offline modeYes
queueTTLintegerTime a queued request is kept during offline mode, in millisecondsYes
replayIntervalintegerDelay between each replayed requestsYes
reconnectionDelayintegerNumber of milliseconds between reconnection attemptsNo
sslbooleanConnect to Kuzzle using SSLNo
volatileJSON objectCommon volatile data, will be sent to all future requestsYes

Notes:

  • if connect is set to manual, the connect method will have to be called manually
  • the kuzzle instance will automatically queue all requests, and play them automatically once a first connection is established, regardless of the connect or offline mode option values.
  • multiple methods allow passing specific volatile data. These volatile data will be merged with the global Kuzzle volatile object when sending the request, with the request specific volatile taking priority over the global ones.
  • the queueFilter property is a function taking a JSON object as an argument. This object is the request sent to Kuzzle, following the Kuzzle API format
  • if queueTTL is set to 0, requests are kept indefinitely
  • The offline buffer acts like a first-in first-out (FIFO) queue, meaning that if the queueMaxSize limit is reached, older requests are discarded to make room for new requests
  • if queueMaxSize is set to 0, an unlimited number of requests is kept until the buffer is flushed
  • the offlineQueueLoader must be set with a function, taking no argument, and returning an array of objects containing a query member with a Kuzzle query to be replayed, and an optional cb member with the corresponding callback to invoke with the query result
  • updates to host, port, autoReconnect, reconnectionDelay and sslConnection properties will only take effect on next connect call

Callback response #

If the connection succeeds, resolves to the Kuzzle object itself. If the connect option is set to manual, the callback will be called after the connect method is resolved.

Usage #

import io.kuzzle.sdk.core.Kuzzle;
import io.kuzzle.sdk.core.Options;
Options options = new Options();
options.setDefaultIndex("some index")
  .setAutoReconnect(true),
  .setHeaders(new JSONObject().put("someheader", "value"))
  .setPort(7512);
Kuzzle kuzzle = new Kuzzle("localhost", options, new ResponseListener<Void>() {
  @Override
  public void onSuccess(Void object) {
    // invoked once connected, object contains the kuzzle instance
  }
  @Override
  public void onError(JSONObject error) {
    // Handle connection error
  }
});