Class RecordHandler

The factory method’s for deepstream’s realtime datastore concepts, such as getRecord(recordName), getList(listName), provider functionality such as listen(eventName,listener) and single requests like snapshot(recordName)

Methods

Record getRecord(String recordName)

{{#table mode="java-api"}}
-
  arg: recordName
  typ: String
  des: The name of the record to get
{{/table}}

Returns an existing record or creates a new one. If creating a new one the record will not be in a ready state till it is loaded from the server.

Record record = client.record.getRecord("users/A");

List getList(String listName)

{{#table mode="java-api"}}
-
  arg: listName
  typ: String
  des: The name of the list to retrieve
{{/table}}

Returns an existing List or creates a new one. A list is a specialised type of record that holds an array of recordNames.

Record record = client.record.getList("users");

AnonymousRecord getAnonymousRecord()

Returns an AnonymousRecord. An anonymous record is effectively a wrapper that mimicks the API of a record, but allows for the underlying record to be swapped without losing subscriptions etc.

This is particularly useful when selecting from a number of similarly structured records. E.g. a list of users that can be choosen from a list.

The only API differences to a normal record is an additional setName(name) method.

SnapshotResult snapshot(String recordName)

{{#table mode="java-api"}}
-
  arg: recordName
  typ: String
  des: The name of the record which data to retrieve
{{/table}}

Retrieves a SnapshotResult with the current record data. Using this doesn’t subscribe the client to changes the way getRecord(name) does.

SnapshotResult result = client.record.snapshot("user/B");

boolean has(String recordName) throws DeepstreamError

{{#table mode="java-api"}}
-
  arg: recordName
  typ: String
  des: The name of the record to check
{{/table}}

Returns a HasResult that shows whether or not the record exists.

HasResult result = client.record.has("user/C");

void listen(String pattern, ListenListener listenCallback)” mode=“opensource / enterprise

{{#table mode="java-api"}}
-
  arg: pattern
  typ: String
  des: The pattern to match events which subscription status you want to be informed of
-
  arg: listener
  typ: ListenListener
  des: The Listen Listener
{{/table}}

Allows to listen for record subscriptions made by this or other clients. This is useful to create “active” data providers, e.g. providers that only provide data for a particular record if a user is actually interested in it.

You can only listen to a pattern once, and if multiple listeners match the same pattern only a single one will be notified.

client.event.listen("users/*", new ListenListener() {
  @Override
  public boolean onSubscriptionForPatternAdded(String subscription) {
    if (/* can provide */) {
      return true;
    } else {
      return false;
    }
  }

  @Override
  public void onSubscriptionForPatternRemoved(String subscription) {
    // handle unsubscription
  }
});

void unlisten(String pattern)” mode=“opensource / enterprise

{{#table mode="java-api"}}
-
  arg: pattern
  typ: String
  des: The pattern that has been previously listened to
{{/table}}

Remove the listener added via listen(pattern,listener). This will remove the provider as the active provider and allow another provider to take its place.

client.record.unlisten("users/*", listener);