net.snowflake.client.jdbc.telemetry

## Class TelemetryClient

- java.lang.Object
- - net.snowflake.client.jdbc.telemetry.TelemetryClient

All Implemented Interfaces:
  Telemetry

    public class TelemetryClient
    extends Object
    implements Telemetry

Copyright (c) 2018-2019 Snowflake Computing Inc. All rights reserved.

Telemetry Service Interface

### Method Summary

All Methods Static Methods Instance Methods Concrete Methods
`void` `addLogToBatch(com.fasterxml.jackson.databind.node.ObjectNode message, long timeStamp)` Add log to batch to be submitted to telemetry.
`void` `addLogToBatch(TelemetryData log)` Add log to batch to be submitted to telemetry.
`int` `bufferSize()` For test use only
`void` `close()` Close telemetry connector and send any unsubmitted logs
`static Telemetry` `createTelemetry(Connection conn)` Initialize the telemetry connector
`static Telemetry` `createTelemetry(Connection conn, int flushSize)` Initialize the telemetry connector
`static Telemetry` `createTelemetry(SFSession session)` Initialize the telemetry connector
`static Telemetry` `createTelemetry(SFSession session, int flushSize)` Initialize the telemetry connector
`void` `disableTelemetry()` Disable any use of the client to add/send metrics
`boolean` `isClosed()` Return whether the client has been closed
`boolean` `isTelemetryEnabled()` Return whether the client can be used to add/send metrics
`LinkedList<TelemetryData>` `logBuffer()` For test use only
`boolean` `sendBatch()` Send all cached logs to server
`boolean` `sendLog(com.fasterxml.jackson.databind.node.ObjectNode message, long timeStamp)` Send a log to the server, along with any existing logs waiting to be sent
`boolean` `sendLog(TelemetryData log)` Send a log to the server, along with any existing logs waiting to be sent
`void` `tryAddLogToBatch(TelemetryData log)` Attempt to add log to batch, and suppress exceptions thrown in case of failure

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Method Detail

#### isTelemetryEnabled

    public boolean isTelemetryEnabled()

Return whether the client can be used to add/send metrics

Returns:
  whether client is enabled

#### disableTelemetry

    public void disableTelemetry()

Disable any use of the client to add/send metrics

#### createTelemetry

    public static Telemetry createTelemetry(Connection conn,
                                            int flushSize)

Initialize the telemetry connector

Parameters:
  `conn` - connection with the session to use for the connector
  `flushSize` - maximum size of telemetry batch before flush
Returns:
  a telemetry connector

#### createTelemetry

    public static Telemetry createTelemetry(Connection conn)

Initialize the telemetry connector

Parameters:
  `conn` - connection with the session to use for the connector
Returns:
  a telemetry connector

#### createTelemetry

    public static Telemetry createTelemetry(SFSession session)

Initialize the telemetry connector

Parameters:
  `session` - session to use for telemetry dumps
Returns:
  a telemetry connector

#### createTelemetry

    public static Telemetry createTelemetry(SFSession session,
                                            int flushSize)

Initialize the telemetry connector

Parameters:
  `session` - session to use for telemetry dumps
  `flushSize` - maximum size of telemetry batch before flush
Returns:
  a telemetry connector

#### addLogToBatch

    public void addLogToBatch(TelemetryData log)
                       throws IOException

Add log to batch to be submitted to telemetry. Send batch if forceFlushSize reached

Specified by:
  `addLogToBatch` in interface `Telemetry`
Parameters:
  `log` - entry to add
Throws:
  `IOException` - if closed or uploading batch fails

#### addLogToBatch

    public void addLogToBatch(com.fasterxml.jackson.databind.node.ObjectNode message,
                              long timeStamp)
                       throws IOException

Add log to batch to be submitted to telemetry. Send batch if forceFlushSize reached

Parameters:
  `message` - json node of log
  `timeStamp` - timestamp to use for log
Throws:
  `IOException` - if closed or uploading batch fails

#### tryAddLogToBatch

    public void tryAddLogToBatch(TelemetryData log)

Attempt to add log to batch, and suppress exceptions thrown in case of failure

Specified by:
  `tryAddLogToBatch` in interface `Telemetry`
Parameters:
  `log` - entry to add

#### close

    public void close()
               throws IOException

Close telemetry connector and send any unsubmitted logs

Specified by:
  `close` in interface `Telemetry`
Throws:
  `IOException` - if closed or uploading batch fails

#### isClosed

    public boolean isClosed()

Return whether the client has been closed

Returns:
  whether client is closed

#### sendBatch

    public boolean sendBatch()
                      throws IOException

Send all cached logs to server

Specified by:
  `sendBatch` in interface `Telemetry`
Returns:
  whether the logs were sent successfully
Throws:
  `IOException` - if closed or uploading batch fails

#### sendLog

    public boolean sendLog(TelemetryData log)
                    throws IOException

Send a log to the server, along with any existing logs waiting to be sent

Parameters:
  `log` - entry to send
Returns:
  whether the logs were sent successfully
Throws:
  `IOException` - if closed or uploading batch fails

#### sendLog

    public boolean sendLog(com.fasterxml.jackson.databind.node.ObjectNode message,
                           long timeStamp)
                    throws IOException

Send a log to the server, along with any existing logs waiting to be sent

Parameters:
  `message` - json node of log
  `timeStamp` - timestamp to use for log
Returns:
  whether the logs were sent successfully
Throws:
  `IOException` - if closed or uploading batch fails

#### bufferSize

    public int bufferSize()

For test use only

Returns:
  the number of cached logs

#### logBuffer

    public LinkedList<TelemetryData> logBuffer()

For test use only

Returns:
  a copy of the logs currently in the buffer