Package org.apache.pulsar.functions.api
Interface Context
-
@Public @Stable public interface ContextContext provides contextual information to the executing function. Features like which message id we are handling, whats the topic name of the message, what are our operating constraints, etc can be accessed by the executing function
-
-
Method Summary
All Methods Instance Methods Abstract Methods Deprecated Methods Modifier and Type Method Description voiddeleteState(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 completedlonggetCounter(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 completedRecord<?>getCurrentRecord()Access the record associated with the current input value.java.lang.StringgetFunctionId()The id of the function that we are executingjava.lang.StringgetFunctionName()The name of the function that we are executing.java.lang.StringgetFunctionVersion()The version of the function that we are executing.java.util.Collection<java.lang.String>getInputTopics()Get a list of all input topics.intgetInstanceId()The id of the instance that invokes this function.org.slf4j.LoggergetLogger()The logger object that can be used to log in a function.java.lang.StringgetNamespace()The namespace this function belongs to.intgetNumInstances()Get the number of instances that invoke this function.java.lang.StringgetOutputSchemaType()Get output schema builtin type or custom class name.java.lang.StringgetOutputTopic()Get the output topic of the function.org.apache.pulsar.client.admin.PulsarAdmingetPulsarAdmin()Get the pulsar admin client.java.lang.StringgetSecret(java.lang.String secretName)Get the secret associated with this key.java.nio.ByteBuffergetState(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 completed<S extends StateStore>
SgetStateStore(java.lang.String name)Get the state store with the provided store name in the function tenant & namespace.<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.StringgetTenant()The tenant this function belongs to.java.util.Map<java.lang.String,java.lang.Object>getUserConfigMap()Get a map of all user-defined key/value configs for the function.java.util.Optional<java.lang.Object>getUserConfigValue(java.lang.String key)Get any user-defined key/value.java.lang.ObjectgetUserConfigValueOrDefault(java.lang.String key, java.lang.Object defaultValue)Get any user-defined key/value or a default value if none is present.voidincrCounter(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 operation<O> org.apache.pulsar.client.api.ConsumerBuilder<O>newConsumerBuilder(org.apache.pulsar.client.api.Schema<O> schema)Create a ConsumerBuilder with the schema.<O> org.apache.pulsar.client.api.TypedMessageBuilder<O>newOutputMessage(java.lang.String topicName, org.apache.pulsar.client.api.Schema<O> schema)New output message using schema for serializing to the topic<O> java.util.concurrent.CompletableFuture<java.lang.Void>publish(java.lang.String topicName, O object)Deprecated.in favor of usingnewOutputMessage(String, Schema)<O> java.util.concurrent.CompletableFuture<java.lang.Void>publish(java.lang.String topicName, O object, java.lang.String schemaOrSerdeClassName)Deprecated.in favor of usingnewOutputMessage(String, Schema)voidputState(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 completedvoidrecordMetric(java.lang.String metricName, double value)Record a user defined metric.
-
-
-
Method Detail
-
getCurrentRecord
Record<?> getCurrentRecord()
Access the record associated with the current input value.- Returns:
-
getInputTopics
java.util.Collection<java.lang.String> getInputTopics()
Get a list of all input topics.- Returns:
- a list of all input topics
-
getOutputTopic
java.lang.String getOutputTopic()
Get the output topic of the function.- Returns:
- output topic name
-
getOutputSchemaType
java.lang.String getOutputSchemaType()
Get output schema builtin type or custom class name.- Returns:
- output schema builtin type or custom class name
-
getTenant
java.lang.String getTenant()
The tenant this function belongs to.- Returns:
- the tenant this function belongs to
-
getNamespace
java.lang.String getNamespace()
The namespace this function belongs to.- Returns:
- the namespace this function belongs to
-
getFunctionName
java.lang.String getFunctionName()
The name of the function that we are executing.- Returns:
- The Function name
-
getFunctionId
java.lang.String getFunctionId()
The id of the function that we are executing- Returns:
- The function id
-
getInstanceId
int getInstanceId()
The id of the instance that invokes this function.- Returns:
- the instance id
-
getNumInstances
int getNumInstances()
Get the number of instances that invoke this function.- Returns:
- the number of instances that invoke this function.
-
getFunctionVersion
java.lang.String getFunctionVersion()
The version of the function that we are executing.- Returns:
- The version id
-
getLogger
org.slf4j.Logger getLogger()
The logger object that can be used to log in a function.- Returns:
- the logger object
-
getStateStore
<S extends StateStore> S getStateStore(java.lang.String name)
Get the state store with the provided store name in the function 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
<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.
-
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
-
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
-
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
-
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.
-
getUserConfigMap
java.util.Map<java.lang.String,java.lang.Object> getUserConfigMap()
Get a map of all user-defined key/value configs for the function.- Returns:
- The full map of user-defined config values
-
getUserConfigValue
java.util.Optional<java.lang.Object> getUserConfigValue(java.lang.String key)
Get any user-defined key/value.- Parameters:
key- The key- Returns:
- The Optional value specified by the user for that key.
-
getUserConfigValueOrDefault
java.lang.Object getUserConfigValueOrDefault(java.lang.String key, java.lang.Object defaultValue)Get any user-defined key/value or a default value if none is present.- Parameters:
key-defaultValue-- Returns:
- Either the user config value associated with a given key or a supplied default value
-
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
-
getPulsarAdmin
org.apache.pulsar.client.admin.PulsarAdmin getPulsarAdmin()
Get the pulsar admin client.- Returns:
- The instance of pulsar admin client
-
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
-
publish
<O> java.util.concurrent.CompletableFuture<java.lang.Void> publish(java.lang.String topicName, O object, java.lang.String schemaOrSerdeClassName)Deprecated.in favor of usingnewOutputMessage(String, Schema)Publish an object using serDe or schema class for serializing to the topic.- Parameters:
topicName- The name of the topic for publishingobject- The object that needs to be publishedschemaOrSerdeClassName- Either a builtin schema type (eg: "avro", "json", "protobuf") or the class name of the custom schema class- Returns:
- A future that completes when the framework is done publishing the message
-
publish
<O> java.util.concurrent.CompletableFuture<java.lang.Void> publish(java.lang.String topicName, O object)Deprecated.in favor of usingnewOutputMessage(String, Schema)Publish an object to the topic using default schemas.- Parameters:
topicName- The name of the topic for publishingobject- The object that needs to be published- Returns:
- A future that completes when the framework is done publishing the message
-
newOutputMessage
<O> org.apache.pulsar.client.api.TypedMessageBuilder<O> newOutputMessage(java.lang.String topicName, org.apache.pulsar.client.api.Schema<O> schema) throws org.apache.pulsar.client.api.PulsarClientExceptionNew output message using schema for serializing to the topic- Type Parameters:
O-- Parameters:
topicName- The name of the topic for output messageschema- provide a way to convert between serialized data and domain objects- Returns:
- the message builder instance
- Throws:
org.apache.pulsar.client.api.PulsarClientException
-
newConsumerBuilder
<O> org.apache.pulsar.client.api.ConsumerBuilder<O> newConsumerBuilder(org.apache.pulsar.client.api.Schema<O> schema) throws org.apache.pulsar.client.api.PulsarClientExceptionCreate a ConsumerBuilder with the schema.- Type Parameters:
O-- Parameters:
schema- provide a way to convert between serialized data and domain objects- Returns:
- the consumer builder instance
- Throws:
org.apache.pulsar.client.api.PulsarClientException
-
-