Package org.apache.pulsar.functions.api
Interface BaseContext
- All Known Subinterfaces:
Context
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
Modifier and TypeMethodDescriptionvoid
deleteState
(String key) Delete the state value for the key.deleteStateAsync
(String key) Delete the state value for the key, but don't wait for the operation to be completed.long
getCounter
(String key) Retrieve the counter value for the key.getCounterAsync
(String key) Retrieve the counter value for the key, but don't wait for the operation to be completed.int
The id of the instance that invokes this component.org.slf4j.Logger
The logger object that can be used to log in a component.The namespace this component belongs to.int
Get the number of instances that invoke this component.default PulsarClient
Get the pre-configured pulsar client.default ClientBuilder
Get the pre-configured pulsar client builder.Get the secret associated with this key.Retrieve the state value for the key.getStateAsync
(String key) Retrieve the state value for the key, but don't wait for the operation to be completed.default <X extends StateStore>
XgetStateStore
(String name) Get the state store with the provided store name in the tenant & namespace.default <X extends StateStore>
XgetStateStore
(String tenant, String ns, String name) Get the state store with the provided store name.The tenant this component belongs to.void
incrCounter
(String key, long amount) Increment the builtin distributed counter referred by key.incrCounterAsync
(String key, long amount) Increment the builtin distributed counter referred by key but dont wait for the completion of the increment operation.void
putState
(String key, ByteBuffer value) Update the state value for the key.putStateAsync
(String key, ByteBuffer value) Update the state value for the key, but don't wait for the operation to be completed.void
recordMetric
(String metricName, double value) Record a user defined metric.
-
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
Get the secret associated with this key.- Parameters:
secretName
- The name of the secret- Returns:
- The secret if anything was found or null
-
getStateStore
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
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 namens
- the state namespace namename
- 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
Update the state value for the key.- Parameters:
key
- name of the keyvalue
- state value of the key
-
putStateAsync
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
Retrieve the state value for the key.- Parameters:
key
- name of the key- Returns:
- the state value for the key.
-
getStateAsync
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
Delete the state value for the key.- Parameters:
key
- name of the key
-
deleteStateAsync
Delete the state value for the key, but don't wait for the operation to be completed.- Parameters:
key
- name of the key
-
incrCounter
Increment the builtin distributed counter referred by key.- Parameters:
key
- The name of the keyamount
- The amount to be incremented
-
incrCounterAsync
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
Retrieve the counter value for the key.- Parameters:
key
- name of the key- Returns:
- the amount of the counter value for this key
-
getCounterAsync
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
Record a user defined metric.- Parameters:
metricName
- The name of the metricvalue
- The value of the metric
-
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
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.
-