Skip to content

Coordinator

The Mosaic coordinator manages queries for Mosaic clients. Internally, the coordinator includes a query manager that maintains a queue of query requests that are issued through a database connector. The coordinator also manages filter groups: collections of clients that share the same filterBy selection. The coordinator responds to selection changes and provides coordinated updates to all linked clients. Where possible, the coordinator also applies optimizations, such as caching and building optimized indices for filter groups involving supported aggregation queries.

coordinator

coordinator()

Get the default global coordinator instance.

constructor

new Coordinator(connector, options)

Create a new Mosaic Coordinator to manage all database communication for clients and handle selection updates. Accepts a database connector and an options object:

  • logger: The logger to use, defaults to console.
  • cache: Boolean flag to enable/disable query caching (default true).
  • consolidate Boolean flag to enable/disable query consolidation (default true).
  • preagg: Pre-aggregation options object. The enabled flag (default true) determines if pre-aggregation optimizations should be used when possible. The schema option (default 'mosaic') indicates the database schema in which materialized view tables should be created for pre-aggregated data.

databaseConnector

coordinator.databaseConnector(connector)

Get or set the connector used by the coordinator to issue queries to a backing data source.

connect

coordinator.connect(client)

Connect a client to this coordinator. Upon connection, the client lifecycle will initiate. If the client exposes a filterBy selection, the coordinator will handle updates to the client when the selection updates.

disconnect

coordinator.disconnect(client)

Disconnect the client from the coordinator and remove all update handling.

logger

coordinator.logger(logger)

Get or set the coordinator's logger. The logger defaults to the standard JavaScript console. A logger instance must support log, info, warn, and error mehthods. If set to null, logging will be suppressed.

clear

coordinator.clear(options)

Resets the state of the coordinator. Supports the following options:

  • clients: A Boolean flag (default true) indicating if all current clients should be disconnected.
  • cache: A Boolean flag (default true) indicating if the query cache should be cleared.

exec

coordinator.exec(query, options)

Request a query and return a request Promise that resolves when the query is complete. No query result will be returned. The input query should produce a SQL query upon string coercion.

The supported options are:

  • priority: A value indicating the query priority, one of: Priority.High, Priority.Normal (the default), or Priority.Low.

query

coordinator.query(query, options)

Request a query and return a request Promise that resolves when the query is complete. A query result table will be returned, with format determined by the type options. The input query should produce a SQL query upon string coercion.

The supported options are:

  • type: The return format type. One of "arrow" (default) or "json".
  • cache: A Boolean flag (default true) indicating if the query result should be cached.
  • priority: A value indicating the query priority, one of: Priority.High, Priority.Normal (the default), or Priority.Low.

Any additional options will be passed through to the backing database. For example, the Mosaic data server will respect a persist option to cache the result on the server's local file system.

prefetch

coordinator.prefetch(query, options)

Request a query to prefetch the results for later use, and return a request Promise that resolves when the query is complete. This method accepts the same options as query(), except that the cache flag will always be true and the priority flag will always be Priority.Low.

If prefetch requests are no longer needed, the cancel method can be used to drop any queued but not yet issued queries.

cancel

coordinator.cancel(requests)

Cancel the provided query requests, a list of one or more request Promise instances returned by earlier exec, query, or prefetch calls.

updateClient

coordinator.updateClient(client, query, priority)

Initiate a client update for a given query and priority (default Priority.Normal), and return a Promise that resolves when the query is complete. The client.queryPending() method will be invoked, followed by client.queryResult() or client.queryError() upon completion.

WARNING

This method is used internally, application code should not call this method directly.

requestQuery

coordinator.requestQuery(client, query)

Request a query update for the provided client. If the query argument is provided, updateClient() is invoked. Otherwise, the client update() method is called immediately.

WARNING

This method is used internally, application code should not call this method directly.