接口 BaseContext
- 所有已知子接口:
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.
-
方法概要
修饰符和类型方法说明voiddeleteState(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 completedlonggetCounter(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 completedintThe id of the instance that invokes this component.org.slf4j.LoggerThe logger object that can be used to log in a component.The namespace this component belongs to.intGet the number of instances that invoke this component.default org.apache.pulsar.client.api.PulsarClientGet the pre-configured pulsar client.default org.apache.pulsar.client.api.ClientBuilderGet 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 completeddefault <S extends StateStore>
SgetStateStore(String name) Get the state store with the provided store name in the tenant & namespace.default <S extends StateStore>
SgetStateStore(String tenant, String ns, String name) Get the state store with the provided store name.The tenant this component belongs to.voidincrCounter(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 operationvoidputState(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 completedvoidrecordMetric(String metricName, double value) Record a user defined metric
-
方法详细资料
-
getTenant
String getTenant()The tenant this component belongs to.- 返回:
- the tenant this component belongs to
-
getNamespace
String getNamespace()The namespace this component belongs to.- 返回:
- the namespace this component belongs to
-
getInstanceId
int getInstanceId()The id of the instance that invokes this component.- 返回:
- the instance id
-
getNumInstances
int getNumInstances()Get the number of instances that invoke this component.- 返回:
- 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.- 返回:
- the logger object
-
getSecret
Get the secret associated with this key.- 参数:
secretName- The name of the secret- 返回:
- The secret if anything was found or null
-
getStateStore
Get the state store with the provided store name in the tenant & namespace.- 类型参数:
S- the type of interface of the store to return- 参数:
name- the state store name- 返回:
- the state store instance.
- 抛出:
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.- 类型参数:
S- the type of interface of the store to return- 参数:
tenant- the state tenant namens- the state namespace namename- the state store name- 返回:
- the state store instance.
- 抛出:
ClassCastException- if the return type isn't a type or interface of the actual returned store.
-
putState
Update the state value for the key.- 参数:
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- 参数:
key- name of the keyvalue- state value of the key
-
getState
Retrieve the state value for the key.- 参数:
key- name of the key- 返回:
- the state value for the key.
-
getStateAsync
Retrieve the state value for the key, but don't wait for the operation to be completed- 参数:
key- name of the key- 返回:
- the state value for the key.
-
deleteState
Delete the state value for the key.- 参数:
key- name of the key
-
deleteStateAsync
Delete the state value for the key, but don't wait for the operation to be completed- 参数:
key- name of the key
-
incrCounter
Increment the builtin distributed counter referred by key.- 参数:
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- 参数:
key- The name of the keyamount- The amount to be incremented
-
getCounter
Retrieve the counter value for the key.- 参数:
key- name of the key- 返回:
- 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- 参数:
key- name of the key- 返回:
- the amount of the counter value for this key
-
recordMetric
Record a user defined metric- 参数:
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.- 返回:
- 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.- 返回:
- the instance of pulsar client builder.
-