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:
java.lang.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.SchemaInfoProviderschemaInfoProvider
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods 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>>clone()voidconfigureSchemaInfo(java.lang.String topicName, java.lang.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 implementationorg.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)voidfetchSchemaIfNeeded(java.lang.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>getKeySchema()Get the Schema of the Key.org.apache.pulsar.common.schema.KeyValueEncodingTypegetKeyValueEncodingType()Get the KeyValueEncodingType.org.apache.pulsar.common.schema.SchemaInfogetSchemaInfo()org.apache.pulsar.client.api.Schema<V>getValueSchema()Get the Schema of the Value.static org.apache.pulsar.client.api.Schema<org.apache.pulsar.common.schema.KeyValue<byte[],byte[]>>kvBytes()static <K,V>
org.apache.pulsar.client.api.Schema<org.apache.pulsar.common.schema.KeyValue<K,V>>of(java.lang.Class<K> key, java.lang.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)booleanrequireFetchingSchemaInfo()voidsetSchemaInfoProvider(org.apache.pulsar.client.api.schema.SchemaInfoProvider schemaInfoProvider)booleansupportSchemaVersioning()java.lang.StringtoString()
-
-
-
Method Detail
-
of
public static <K,V> org.apache.pulsar.client.api.Schema<org.apache.pulsar.common.schema.KeyValue<K,V>> of(java.lang.Class<K> key, java.lang.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:
supportSchemaVersioningin interfaceorg.apache.pulsar.client.api.Schema<K>
-
encode
public byte[] encode(org.apache.pulsar.common.schema.KeyValue<K,V> message)
- Specified by:
encodein interfaceorg.apache.pulsar.client.api.Schema<K>
-
decode
public org.apache.pulsar.common.schema.KeyValue<K,V> decode(byte[] bytes)
- Specified by:
decodein interfaceorg.apache.pulsar.client.api.Schema<K>
-
decode
public org.apache.pulsar.common.schema.KeyValue<K,V> decode(byte[] bytes, byte[] schemaVersion)
- Specified by:
decodein interfaceorg.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:AbstractSchemaDecode a byteBuf into an object using the schema definition and deserializer implementationDo not modify reader/writer index of ByteBuf so, it can be reused to access correct data.
- Specified by:
decodein classAbstractSchema<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:AbstractSchemaDecode a byteBuf into an object using a given version.- Overrides:
decodein classAbstractSchema<org.apache.pulsar.common.schema.KeyValue<K,V>>- Parameters:
byteBuf- the byte array to decodeschemaVersion- 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:
getSchemaInfoin interfaceorg.apache.pulsar.client.api.Schema<K>
-
setSchemaInfoProvider
public void setSchemaInfoProvider(org.apache.pulsar.client.api.schema.SchemaInfoProvider schemaInfoProvider)
- Specified by:
setSchemaInfoProviderin interfaceorg.apache.pulsar.client.api.Schema<K>
-
requireFetchingSchemaInfo
public boolean requireFetchingSchemaInfo()
- Specified by:
requireFetchingSchemaInfoin interfaceorg.apache.pulsar.client.api.Schema<K>
-
configureSchemaInfo
public void configureSchemaInfo(java.lang.String topicName, java.lang.String componentName, org.apache.pulsar.common.schema.SchemaInfo schemaInfo)- Specified by:
configureSchemaInfoin interfaceorg.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:
clonein interfaceorg.apache.pulsar.client.api.Schema<K>- Overrides:
clonein classAbstractSchema<org.apache.pulsar.common.schema.KeyValue<K,V>>
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
atSchemaVersion
public org.apache.pulsar.client.api.Schema<?> atSchemaVersion(byte[] schemaVersion) throws org.apache.pulsar.client.api.SchemaSerializationExceptionDescription copied from class:AbstractSchemaReturn an instance of this schema at the given version.- Overrides:
atSchemaVersionin classAbstractSchema<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.
-
getValueSchema
public org.apache.pulsar.client.api.Schema<V> getValueSchema()
Get the Schema of the Value.
-
getKeyValueEncodingType
public org.apache.pulsar.common.schema.KeyValueEncodingType getKeyValueEncodingType()
Get the KeyValueEncodingType.
-
fetchSchemaIfNeeded
public void fetchSchemaIfNeeded(java.lang.String topicName, org.apache.pulsar.common.protocol.schema.SchemaVersion schemaVersion) throws org.apache.pulsar.client.api.SchemaSerializationExceptionIt 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:
AutoConsumeSchema.fetchSchemaIfNeeded(SchemaVersion)
-
-