Interface BaseContext

All Known Subinterfaces:
Context

@Public @Stable public interface BaseContext
BaseContext provides base contextual information to the executing function/source/sink. It allows to propagate information, such as pulsar environment, logs, metrics, states etc.
  • Method Details

    • getTenant

      String getTenant()
      The tenant this component belongs to.
      Returns:
      the tenant this component belongs to
    • getNamespace

      String getNamespace()
      The namespace this component belongs to.
      Returns:
      the namespace this component belongs to
    • getInstanceId

      int getInstanceId()
      The id of the instance that invokes this component.
      Returns:
      the instance id
    • getNumInstances

      int getNumInstances()
      Get the number of instances that invoke this component.
      Returns:
      the number of instances that invoke this component.
    • getLogger

      org.slf4j.Logger getLogger()
      The logger object that can be used to log in a component.
      Returns:
      the logger object
    • getSecret

      String getSecret(String secretName)
      Get the secret associated with this key.
      Parameters:
      secretName - The name of the secret
      Returns:
      The secret if anything was found or null
    • getStateStore

      default <X extends StateStore> X getStateStore(String name)
      Get the state store with the provided store name in the tenant & namespace.
      Type Parameters:
      X - the type of interface of the store to return
      Parameters:
      name - the state store name
      Returns:
      the state store instance.
      Throws:
      ClassCastException - if the return type isn't a type or interface of the actual returned store.
    • getStateStore

      default <X extends StateStore> X getStateStore(String tenant, String ns, String name)
      Get the state store with the provided store name.
      Type Parameters:
      X - the type of interface of the store to return
      Parameters:
      tenant - the state tenant name
      ns - the state namespace name
      name - the state store name
      Returns:
      the state store instance.
      Throws:
      ClassCastException - if the return type isn't a type or interface of the actual returned store.
    • putState

      void putState(String key, ByteBuffer value)
      Update the state value for the key.
      Parameters:
      key - name of the key
      value - state value of the key
    • putStateAsync

      CompletableFuture<Void> putStateAsync(String key, ByteBuffer value)
      Update the state value for the key, but don't wait for the operation to be completed.
      Parameters:
      key - name of the key
      value - state value of the key
    • getState

      ByteBuffer getState(String key)
      Retrieve the state value for the key.
      Parameters:
      key - name of the key
      Returns:
      the state value for the key.
    • getStateAsync

      CompletableFuture<ByteBuffer> getStateAsync(String key)
      Retrieve the state value for the key, but don't wait for the operation to be completed.
      Parameters:
      key - name of the key
      Returns:
      the state value for the key.
    • deleteState

      void deleteState(String key)
      Delete the state value for the key.
      Parameters:
      key - name of the key
    • deleteStateAsync

      CompletableFuture<Void> deleteStateAsync(String key)
      Delete the state value for the key, but don't wait for the operation to be completed.
      Parameters:
      key - name of the key
    • incrCounter

      void incrCounter(String key, long amount)
      Increment the builtin distributed counter referred by key.
      Parameters:
      key - The name of the key
      amount - The amount to be incremented
    • incrCounterAsync

      CompletableFuture<Void> incrCounterAsync(String key, long amount)
      Increment the builtin distributed counter referred by key but dont wait for the completion of the increment operation.
      Parameters:
      key - The name of the key
      amount - The amount to be incremented
    • getCounter

      long getCounter(String key)
      Retrieve the counter value for the key.
      Parameters:
      key - name of the key
      Returns:
      the amount of the counter value for this key
    • getCounterAsync

      CompletableFuture<Long> getCounterAsync(String key)
      Retrieve the counter value for the key, but don't wait for the operation to be completed.
      Parameters:
      key - name of the key
      Returns:
      the amount of the counter value for this key
    • recordMetric

      void recordMetric(String metricName, double value)
      Record a user defined metric.
      Parameters:
      metricName - The name of the metric
      value - The value of the metric
    • getPulsarClient

      default PulsarClient getPulsarClient()
      Get the pre-configured pulsar client. You can use this client to access Pulsar cluster. The Function will be responsible for disposing this client.
      Returns:
      the instance of pulsar client
    • getPulsarClientBuilder

      default ClientBuilder getPulsarClientBuilder()
      Get the pre-configured pulsar client builder. You can use this Builder to setup client to connect to the Pulsar cluster. But you need to close client properly after using it.
      Returns:
      the instance of pulsar client builder.