Sunbird Obsrv
  • Introduction
    • The Value of Data
    • Data Value Chain
    • Challenges
    • The Solution: Obsrv
  • Core Concepts
    • Obsrv Overview
    • Key Capabilities
    • Datasets
    • Connectors
    • High Level Architecture
    • Tech Stack
    • Monitoring
  • Explore
    • Roadmap
    • Case Studies
      • Agri Climate Advisory
      • Learning Analytics at Population Scale
      • IOT Observations Infra
      • Data Driven Features in Learning Platform
      • Network Observability
      • Fraud Detection
    • Performance Benchmarks
  • Guides
    • Installation
      • AWS Installation Guide
      • Azure Installation Guide
      • GCP Installation Guide
      • OCI Installation Guide
      • Data Center Installation Guide
    • Dataset Management APIs
    • Dataset Management Console
    • Connector APIs
    • Data In & Out APIs
    • Alerts and Notification Channels APIs
    • Developer Guide
    • Example Datasets
    • Connectors Developer Guide
      • SDK Assumptions
      • Required Files
        • metadata.json
        • ui-config.json
        • metrics.yaml
        • alerts.yaml
      • Obsrv Base Setup
      • Dev Requirements
      • Interfaces
        • Stream Interfaces
        • Batch Interfaces
      • Classes
        • ConnectorContext Class
        • ConnectorStats Class
        • ConnectorState Class
        • ErrorData Class
        • MetricData Class
      • Verifying
      • Packaging Guide
      • Reference Implementations
    • Coming Soon!
  • Community
  • Previous Versions
    • SB-5.0 Version
      • Overview
      • USE
        • Release Notes
          • Obsrv 2.0-Beta
          • Obsrv 2.1.0
          • Obsrv 2.2.0
          • Obsrv 2.0.0-GA
          • Obsrv 5.3.0-GA
          • Release V 5.1.0
          • Release V 5.1.2
          • Release V 5.1.3
          • Release V 5.0.0
          • Release V 4.10.0
        • Installation Guide
        • Obsrv 2.0 Installation Guide
          • Getting Started with Obsrv Deployment Using Helm
        • System Requirements
      • LEARN
        • Functional Capabilities
        • Dependencies
        • Product Roadmap
        • Product & Developer Guide
          • Telemetry Service
          • Data Pipeline
          • Data Service
          • Data Product
            • On Demand Druid Exhaust Job
              • Component Diagram
              • ML CSV Reports
              • Folder Struture
          • Report Service
          • Report Configurator
          • Summarisers
      • ENGAGE
        • Discuss
        • Contribute to Obsrv
      • Raise an Issue
  • Release Notes
    • Obsrv 1.1.0 Beta Release
    • Obsrv 1.2.0-RC Release
Powered by GitBook
On this page
  • Overview
  • Class Definition
  • Args
  • Methods
  • Usage

Was this helpful?

Edit on GitHub
  1. Guides
  2. Connectors Developer Guide
  3. Classes

ConnectorState Class

PreviousConnectorStats ClassNextErrorData Class

Last updated 5 months ago

Was this helpful?

Overview

The ConnectorState class is a part of the org.sunbird.obsrv.connector.model package. It encapsulates the state information for a connector instance, allowing for the tracking and management of various state attributes associated with the connector's lifecycle.

Class Definition

Ref:

Args

connectorInstanceId: String

  • Description: The unique identifier for the specific instance of the connector.

stateJson: Option[String]

  • Description: The JSON representation of the state for the connector instance.

state: mutable.Map[String, AnyRef]

  • Description: A mutable map that holds the state attributes for the connector instance.

Methods

getState[T](attribute: String): Option[T]

  • Description: Retrieves the value of the specified state attribute.

  • Parameters: attribute - The name of the state attribute to retrieve.

  • Returns: An Option containing the value of the state attribute, if it exists.

getState[T](attribute: String, defaultValue: T): T

  • Description: Retrieves the value of the specified state attribute, or returns a default value if the attribute does not exist.

  • Parameters:

    • attribute - The name of the state attribute to retrieve.

    • defaultValue - The default value to return if the attribute does not exist.

  • Returns: The value of the state attribute, or the default value.

putState[T <: AnyRef](attrib: String, value: T): Unit

  • Description: Adds or updates the value of the specified state attribute.

  • Parameters:

    • attrib - The name of the state attribute to add or update.

    • value - The value to set for the state attribute.

removeState(attrib: String): Option[AnyRef]

  • Description: Removes the specified state attribute from the state.

  • Parameters: attrib - The name of the state attribute to remove.

  • Returns: An Option containing the removed value, if it existed.

contains(attrib: String): Boolean

  • Description: Checks if the specified state attribute exists in the state.

  • Parameters: attrib - The name of the state attribute to check.

  • Returns: true if the attribute exists, false otherwise.

toJson(): String

  • Description: Serializes the state to a JSON string.

  • Returns: A JSON string representation of the state.

saveState(): Unit

  • Description: Saves the current state to the database.

  • Throws: ObsrvException if the state could not be saved.

Usage

The ConnectorState class is used to manage and track the state attributes of a connector instance. It provides methods to access, update, and persist these attributes.

Example

import org.sunbird.obsrv.connector.model.ConnectorState
import org.sunbird.obsrv.job.util.PostgresConnectionConfig

implicit val postgresConfig: PostgresConnectionConfig = // initialize config

val state = new ConnectorState("connectorInstanceId", None)

// Accessing and updating state
state.putState("attribute1", "value1".asInstanceOf[AnyRef])
println(state.getState[String]("attribute1"))
state.saveState()
https://github.com/Sunbird-Obsrv/connector-sdk-scala/blob/main/connector-sdk-core/src/main/scala/org/sunbird/obsrv/connector/model/ConnectorState.scala