Skip to content

Java SDK Query API

​ The Java SDK Query API is can be downloaded from the same location as the assemblies see here for the location of the files.

The primary class used for querying data from insights is the DataAccessClient class.

Below is a description of the methods available in the DataAccessClient class:

Constructors

DataAccessClient()

If this constructor is used all of the components will be built using data from environment variables that must be supplied to the process that is using the SDK.

Sample

import kx.insights.dataaccess.DataAccessClient;
...
DataAccessClient dac = new DataAccessClient();

DataAccessClient(HttpsConfigRequestor configRequestor, SSLContextManager sslManager, QConnectionFactory qConnectionFactory, DataAccessTokenFactory credentialsFactory)

With this constructor you must supply all of the dependencies of the DataAccessClient.

Sample

import kx.insights.dataaccess.DataAccessClient;
import kx.insights.dataaccess.DataAccessTokenFactory;
...
String configUrl = "https://{INSIGHTS_HOSTNAME}/informationservice/details/{KC_CLIENT_ID}";
HttpsConfigRequestor configRequestor = new HttpsConfigRequestor(configUrl);
SSLContextManager sslManager = new SSLContextManager();
QConnectionFactory qConnectionFactory = new QConnectionFactory();
InsightsDataAccessTokenFactory credFactory = new InsightsDataAccessTokenFactory(configUrl);
credFactory.setClientIdAndSecret(clientId, clientSecret);
DataAccessClient dac = new DataAccessClient(configRequestor, sslManager, qConnectionFactory, credFactory);

connect

DataAccessClient.connect()

This is called to establish a connection to the Insights Platform.

Note

It must be called before any requests can be called. Calling these methods before calling connect() will result in an exception being thrown.

Sample

DataAccessClient dac = new DataAccessClient();
dac.connect();

getMeta

DataAccessClient.getMeta()

This returns the result of the getMeta() call. This is returned as an object, and will need to be parsed by the caller. More information can be found here.

Sample

DataAccessClient dac = new DataAccessClient();
dac.connect();
dac.getMeta();

getData

DataAccessClient.getData(String table, Timestamp startTS, Timestamp endTS)

Returns the result of the getData call on the specified table for the specified time range. More information can be found here.

Sample

DataAccessClient dac = new DataAccessClient();
dac.connect();
Timestamp oneHourAgo = new Timestamp(System.currenttimemillis() - 3600000);
Timestamp now = new Timestamp(System.currenttimemillis());
Object result = dac.getData("trace", oneHourAgo, now);

DataAccessClient.getData(Map argsMap)

Returns the result of the getData call on the specified parameters. More information can be found here.

Sample

DataAccessClient dac = new DataAccessClient();
dac.connect();
HashMap<String, Object> getDataArgs = new HashMap();
getDataArgs.put("startTS", startTime);
getDataArgs.put("endTS", endTime);
getDataArgs.put("table", "trace");
Object result = dac.getData(getDataArgs);

ping

DataAccessClient.ping()

Runs the ping command. More information can be found here.

Sample

DataAccessClient dac = new DataAccessClient();
dac.connect();
boolean pingResult = dac.ping(); //Should always be true

isConnected

DataAccessClient.isConnected()

Returns true if the client is connected. Otherwise returns false.

Sample

DataAccessClient dac = new DataAccessClient();
...
if(!dac.isConnected())
{
    dac.connect();
}

Environment variables

These are the environment variables that are used by the basic form of the DataAccessClient() constructor.

variable required details
KXI_CONFIG_URL Mandatory This is the Information Services URL that is used to pull the information needed to start the replicators. This is in the form: https://{INSIGHTS_HOSTNAME}/informationservice/details/{KC_CLIENT_ID}
KXI_QUERY_USER Conditional The keycloak client that will be used to generate bearer tokens to log in for query. Must be set if KXI_QUERY_TOKEN is not.
KXI_QUERY_SECRET Conditional The keycloak client secret that will be used to generate bearer tokens for query. Must be set if KXI_QUERY_TOKEN is not.
KXI_QUERY_TOKEN Conditional A bearer token used for authentication when making queries. If this is set, then KXI_QUERY_USER and KXI_QUERY_SECRET are ignored.