Package org.apache.pulsar.functions.api
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 Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description void
deleteState(java.lang.String key)
Delete the state value for the key.java.util.concurrent.CompletableFuture<java.lang.Void>
deleteStateAsync(java.lang.String key)
Delete the state value for the key, but don't wait for the operation to be completedlong
getCounter(java.lang.String key)
Retrieve the counter value for the key.java.util.concurrent.CompletableFuture<java.lang.Long>
getCounterAsync(java.lang.String key)
Retrieve the counter value for the key, but don't wait for the operation to be completedint
getInstanceId()
The id of the instance that invokes this component.org.slf4j.Logger
getLogger()
The logger object that can be used to log in a component.java.lang.String
getNamespace()
The namespace this component belongs to.int
getNumInstances()
Get the number of instances that invoke this component.default org.apache.pulsar.client.api.PulsarClient
getPulsarClient()
Get the pre-configured pulsar client.default org.apache.pulsar.client.api.ClientBuilder
getPulsarClientBuilder()
Get the pre-configured pulsar client builder.java.lang.String
getSecret(java.lang.String secretName)
Get the secret associated with this key.java.nio.ByteBuffer
getState(java.lang.String key)
Retrieve the state value for the key.java.util.concurrent.CompletableFuture<java.nio.ByteBuffer>
getStateAsync(java.lang.String key)
Retrieve the state value for the key, but don't wait for the operation to be completeddefault <S extends StateStore>
SgetStateStore(java.lang.String name)
Get the state store with the provided store name in the tenant & namespace.default <S extends StateStore>
SgetStateStore(java.lang.String tenant, java.lang.String ns, java.lang.String name)
Get the state store with the provided store name.java.lang.String
getTenant()
The tenant this component belongs to.void
incrCounter(java.lang.String key, long amount)
Increment the builtin distributed counter referred by key.java.util.concurrent.CompletableFuture<java.lang.Void>
incrCounterAsync(java.lang.String key, long amount)
Increment the builtin distributed counter referred by key but dont wait for the completion of the increment operationvoid
putState(java.lang.String key, java.nio.ByteBuffer value)
Update the state value for the key.java.util.concurrent.CompletableFuture<java.lang.Void>
putStateAsync(java.lang.String key, java.nio.ByteBuffer value)
Update the state value for the key, but don't wait for the operation to be completedvoid
recordMetric(java.lang.String metricName, double value)
Record a user defined metric
-
-
-
Method Detail
-
getTenant
java.lang.String getTenant()
The tenant this component belongs to.- Returns:
- the tenant this component belongs to
-
getNamespace
java.lang.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
java.lang.String getSecret(java.lang.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 <S extends StateStore> S getStateStore(java.lang.String name)
Get the state store with the provided store name in the tenant & namespace.- Type Parameters:
S
- the type of interface of the store to return- Parameters:
name
- the state store name- Returns:
- the state store instance.
- Throws:
java.lang.ClassCastException
- if the return type isn't a type or interface of the actual returned store.
-
getStateStore
default <S extends StateStore> S getStateStore(java.lang.String tenant, java.lang.String ns, java.lang.String name)
Get the state store with the provided store name.- Type Parameters:
S
- the type of interface of the store to return- Parameters:
tenant
- the state tenant namens
- the state namespace namename
- the state store name- Returns:
- the state store instance.
- Throws:
java.lang.ClassCastException
- if the return type isn't a type or interface of the actual returned store.
-
putState
void putState(java.lang.String key, java.nio.ByteBuffer value)
Update the state value for the key.- Parameters:
key
- name of the keyvalue
- state value of the key
-
putStateAsync
java.util.concurrent.CompletableFuture<java.lang.Void> putStateAsync(java.lang.String key, java.nio.ByteBuffer value)
Update the state value for the key, but don't wait for the operation to be completed- Parameters:
key
- name of the keyvalue
- state value of the key
-
getState
java.nio.ByteBuffer getState(java.lang.String key)
Retrieve the state value for the key.- Parameters:
key
- name of the key- Returns:
- the state value for the key.
-
getStateAsync
java.util.concurrent.CompletableFuture<java.nio.ByteBuffer> getStateAsync(java.lang.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(java.lang.String key)
Delete the state value for the key.- Parameters:
key
- name of the key
-
deleteStateAsync
java.util.concurrent.CompletableFuture<java.lang.Void> deleteStateAsync(java.lang.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(java.lang.String key, long amount)
Increment the builtin distributed counter referred by key.- Parameters:
key
- The name of the keyamount
- The amount to be incremented
-
incrCounterAsync
java.util.concurrent.CompletableFuture<java.lang.Void> incrCounterAsync(java.lang.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 keyamount
- The amount to be incremented
-
getCounter
long getCounter(java.lang.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
java.util.concurrent.CompletableFuture<java.lang.Long> getCounterAsync(java.lang.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(java.lang.String metricName, double value)
Record a user defined metric- Parameters:
metricName
- The name of the metricvalue
- The value of the metric
-
getPulsarClient
default org.apache.pulsar.client.api.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 org.apache.pulsar.client.api.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.
-
-