Class KeyValueSchemaImpl<K,V>

java.lang.Object
org.apache.pulsar.client.impl.schema.AbstractSchema<org.apache.pulsar.common.schema.KeyValue<K,V>>
org.apache.pulsar.client.impl.schema.KeyValueSchemaImpl<K,V>
All Implemented Interfaces:
Cloneable, org.apache.pulsar.client.api.Schema<org.apache.pulsar.common.schema.KeyValue<K,V>>, org.apache.pulsar.client.api.schema.KeyValueSchema<K,V>

public class KeyValueSchemaImpl<K,V> extends AbstractSchema<org.apache.pulsar.common.schema.KeyValue<K,V>> implements org.apache.pulsar.client.api.schema.KeyValueSchema<K,V>
[Key, Value] pair schema definition.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected org.apache.pulsar.client.api.schema.SchemaInfoProvider
     

    Fields inherited from interface org.apache.pulsar.client.api.Schema

    BOOL, BYTEBUFFER, BYTES, DATE, DOUBLE, FLOAT, INSTANT, INT16, INT32, INT64, INT8, LOCAL_DATE, LOCAL_DATE_TIME, LOCAL_TIME, STRING, TIME, TIMESTAMP
  • Method Summary

    Modifier and Type
    Method
    Description
    org.apache.pulsar.client.api.Schema<?>
    atSchemaVersion(byte[] schemaVersion)
    Return an instance of this schema at the given version.
    org.apache.pulsar.client.api.Schema<org.apache.pulsar.common.schema.KeyValue<K,V>>
     
    void
    configureSchemaInfo(String topicName, String componentName, org.apache.pulsar.common.schema.SchemaInfo schemaInfo)
     
    org.apache.pulsar.common.schema.KeyValue<K,V>
    decode(byte[] bytes)
     
    org.apache.pulsar.common.schema.KeyValue<K,V>
    decode(byte[] bytes, byte[] schemaVersion)
     
    org.apache.pulsar.common.schema.KeyValue<K,V>
    decode(byte[] keyBytes, byte[] valueBytes, byte[] schemaVersion)
     
    org.apache.pulsar.common.schema.KeyValue<K,V>
    decode(io.netty.buffer.ByteBuf byteBuf)
    Decode a byteBuf into an object using the schema definition and deserializer implementation
    org.apache.pulsar.common.schema.KeyValue<K,V>
    decode(io.netty.buffer.ByteBuf byteBuf, byte[] schemaVersion)
    Decode a byteBuf into an object using a given version.
    byte[]
    encode(org.apache.pulsar.common.schema.KeyValue<K,V> message)
     
    void
    fetchSchemaIfNeeded(String topicName, org.apache.pulsar.common.protocol.schema.SchemaVersion schemaVersion)
    It may happen that the schema is not loaded but we need it, for instance in order to call getSchemaInfo() We cannot call this method in getSchemaInfo.
    org.apache.pulsar.client.api.Schema<K>
    Get the Schema of the Key.
    org.apache.pulsar.common.schema.KeyValueEncodingType
    Get the KeyValueEncodingType.
    org.apache.pulsar.common.schema.SchemaInfo
     
    org.apache.pulsar.client.api.Schema<V>
    Get the Schema of the Value.
    static org.apache.pulsar.client.api.Schema<org.apache.pulsar.common.schema.KeyValue<byte[],byte[]>>
     
    static <K, V> org.apache.pulsar.client.api.Schema<org.apache.pulsar.common.schema.KeyValue<K,V>>
    of(Class<K> key, Class<V> value, org.apache.pulsar.common.schema.SchemaType type)
    Key Value Schema using passed in schema type, support JSON and AVRO currently.
    static <K, V> org.apache.pulsar.client.api.Schema<org.apache.pulsar.common.schema.KeyValue<K,V>>
    of(org.apache.pulsar.client.api.Schema<K> keySchema, org.apache.pulsar.client.api.Schema<V> valueSchema)
     
    static <K, V> org.apache.pulsar.client.api.Schema<org.apache.pulsar.common.schema.KeyValue<K,V>>
    of(org.apache.pulsar.client.api.Schema<K> keySchema, org.apache.pulsar.client.api.Schema<V> valueSchema, org.apache.pulsar.common.schema.KeyValueEncodingType keyValueEncodingType)
     
    boolean
     
    void
    setSchemaInfoProvider(org.apache.pulsar.client.api.schema.SchemaInfoProvider schemaInfoProvider)
     
    boolean
     
     

    Methods inherited from class java.lang.Object

    equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait

    Methods inherited from interface org.apache.pulsar.client.api.Schema

    decode, decode, getNativeSchema, validate
  • Field Details

    • schemaInfoProvider

      protected org.apache.pulsar.client.api.schema.SchemaInfoProvider schemaInfoProvider
  • Method Details

    • of

      public static <K, V> org.apache.pulsar.client.api.Schema<org.apache.pulsar.common.schema.KeyValue<K,V>> of(Class<K> key, Class<V> value, org.apache.pulsar.common.schema.SchemaType type)
      Key Value Schema using passed in schema type, support JSON and AVRO currently.
    • of

      public static <K, V> org.apache.pulsar.client.api.Schema<org.apache.pulsar.common.schema.KeyValue<K,V>> of(org.apache.pulsar.client.api.Schema<K> keySchema, org.apache.pulsar.client.api.Schema<V> valueSchema)
    • of

      public static <K, V> org.apache.pulsar.client.api.Schema<org.apache.pulsar.common.schema.KeyValue<K,V>> of(org.apache.pulsar.client.api.Schema<K> keySchema, org.apache.pulsar.client.api.Schema<V> valueSchema, org.apache.pulsar.common.schema.KeyValueEncodingType keyValueEncodingType)
    • kvBytes

      public static org.apache.pulsar.client.api.Schema<org.apache.pulsar.common.schema.KeyValue<byte[],byte[]>> kvBytes()
    • supportSchemaVersioning

      public boolean supportSchemaVersioning()
      Specified by:
      supportSchemaVersioning in interface org.apache.pulsar.client.api.Schema<K>
    • encode

      public byte[] encode(org.apache.pulsar.common.schema.KeyValue<K,V> message)
      Specified by:
      encode in interface org.apache.pulsar.client.api.Schema<K>
    • decode

      public org.apache.pulsar.common.schema.KeyValue<K,V> decode(byte[] bytes)
      Specified by:
      decode in interface org.apache.pulsar.client.api.Schema<K>
    • decode

      public org.apache.pulsar.common.schema.KeyValue<K,V> decode(byte[] bytes, byte[] schemaVersion)
      Specified by:
      decode in interface org.apache.pulsar.client.api.Schema<K>
    • decode

      public org.apache.pulsar.common.schema.KeyValue<K,V> decode(io.netty.buffer.ByteBuf byteBuf)
      Description copied from class: AbstractSchema
      Decode a byteBuf into an object using the schema definition and deserializer implementation

      Do not modify reader/writer index of ByteBuf so, it can be reused to access correct data.

      Specified by:
      decode in class AbstractSchema<org.apache.pulsar.common.schema.KeyValue<K,V>>
      Parameters:
      byteBuf - the byte buffer to decode
      Returns:
      the deserialized object
    • decode

      public org.apache.pulsar.common.schema.KeyValue<K,V> decode(io.netty.buffer.ByteBuf byteBuf, byte[] schemaVersion)
      Description copied from class: AbstractSchema
      Decode a byteBuf into an object using a given version.
      Overrides:
      decode in class AbstractSchema<org.apache.pulsar.common.schema.KeyValue<K,V>>
      Parameters:
      byteBuf - the byte array to decode
      schemaVersion - the schema version to decode the object. null indicates using latest version.
      Returns:
      the deserialized object
    • decode

      public org.apache.pulsar.common.schema.KeyValue<K,V> decode(byte[] keyBytes, byte[] valueBytes, byte[] schemaVersion)
    • getSchemaInfo

      public org.apache.pulsar.common.schema.SchemaInfo getSchemaInfo()
      Specified by:
      getSchemaInfo in interface org.apache.pulsar.client.api.Schema<K>
    • setSchemaInfoProvider

      public void setSchemaInfoProvider(org.apache.pulsar.client.api.schema.SchemaInfoProvider schemaInfoProvider)
      Specified by:
      setSchemaInfoProvider in interface org.apache.pulsar.client.api.Schema<K>
    • requireFetchingSchemaInfo

      public boolean requireFetchingSchemaInfo()
      Specified by:
      requireFetchingSchemaInfo in interface org.apache.pulsar.client.api.Schema<K>
    • configureSchemaInfo

      public void configureSchemaInfo(String topicName, String componentName, org.apache.pulsar.common.schema.SchemaInfo schemaInfo)
      Specified by:
      configureSchemaInfo in interface org.apache.pulsar.client.api.Schema<K>
    • clone

      public org.apache.pulsar.client.api.Schema<org.apache.pulsar.common.schema.KeyValue<K,V>> clone()
      Specified by:
      clone in interface org.apache.pulsar.client.api.Schema<K>
      Overrides:
      clone in class AbstractSchema<org.apache.pulsar.common.schema.KeyValue<K,V>>
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • atSchemaVersion

      public org.apache.pulsar.client.api.Schema<?> atSchemaVersion(byte[] schemaVersion) throws org.apache.pulsar.client.api.SchemaSerializationException
      Description copied from class: AbstractSchema
      Return an instance of this schema at the given version.
      Overrides:
      atSchemaVersion in class AbstractSchema<org.apache.pulsar.common.schema.KeyValue<K,V>>
      Parameters:
      schemaVersion - the version
      Returns:
      the schema at that specific version
      Throws:
      org.apache.pulsar.client.api.SchemaSerializationException - in case of unknown schema version
    • getKeySchema

      public org.apache.pulsar.client.api.Schema<K> getKeySchema()
      Get the Schema of the Key.
      Specified by:
      getKeySchema in interface org.apache.pulsar.client.api.schema.KeyValueSchema<K,V>
      Returns:
      the Schema of the Key
    • getValueSchema

      public org.apache.pulsar.client.api.Schema<V> getValueSchema()
      Get the Schema of the Value.
      Specified by:
      getValueSchema in interface org.apache.pulsar.client.api.schema.KeyValueSchema<K,V>
      Returns:
      the Schema of the Value
    • getKeyValueEncodingType

      public org.apache.pulsar.common.schema.KeyValueEncodingType getKeyValueEncodingType()
      Get the KeyValueEncodingType.
      Specified by:
      getKeyValueEncodingType in interface org.apache.pulsar.client.api.schema.KeyValueSchema<K,V>
      Returns:
      the KeyValueEncodingType
      See Also:
      • KeyValueEncodingType.INLINE
      • KeyValueEncodingType.SEPARATED
    • fetchSchemaIfNeeded

      public void fetchSchemaIfNeeded(String topicName, org.apache.pulsar.common.protocol.schema.SchemaVersion schemaVersion) throws org.apache.pulsar.client.api.SchemaSerializationException
      It may happen that the schema is not loaded but we need it, for instance in order to call getSchemaInfo() We cannot call this method in getSchemaInfo.
      Throws:
      org.apache.pulsar.client.api.SchemaSerializationException
      See Also: