Class AutoConsumeSchema

java.lang.Object
org.apache.pulsar.client.impl.schema.AutoConsumeSchema
All Implemented Interfaces:
Cloneable, org.apache.pulsar.client.api.Schema<org.apache.pulsar.client.api.schema.GenericRecord>

public class AutoConsumeSchema extends Object implements org.apache.pulsar.client.api.Schema<org.apache.pulsar.client.api.schema.GenericRecord>
Auto detect schema, returns only GenericRecord instances.
  • Field Summary

    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
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected org.apache.pulsar.client.api.schema.GenericRecord
    adapt(Object value, byte[] schemaVersion)
     
    org.apache.pulsar.client.api.Schema<?>
    atSchemaVersion(byte[] schemaVersion)
     
    org.apache.pulsar.client.api.Schema<org.apache.pulsar.client.api.schema.GenericRecord>
     
    void
    configureSchemaInfo(String topicName, String componentName, org.apache.pulsar.common.schema.SchemaInfo schemaInfo)
     
    org.apache.pulsar.client.api.schema.GenericRecord
    decode(byte[] bytes, byte[] schemaVersion)
     
    org.apache.pulsar.client.api.schema.GenericRecord
    decode(ByteBuffer buffer, byte[] schemaVersion)
     
    byte[]
    encode(org.apache.pulsar.client.api.schema.GenericRecord message)
     
    void
    fetchSchemaIfNeeded(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, because getSchemaInfo is called in many places and we will introduce lots of deadlocks.
    org.apache.pulsar.client.api.Schema<?>
     
    org.apache.pulsar.client.api.Schema<?>
    getInternalSchema(byte[] schemaVersion)
     
     
    static org.apache.pulsar.client.api.Schema<?>
    getSchema(org.apache.pulsar.common.schema.SchemaInfo schemaInfo)
     
    org.apache.pulsar.common.schema.SchemaInfo
     
    org.apache.pulsar.common.schema.SchemaInfo
    getSchemaInfo(byte[] schemaVersion)
     
    boolean
     
    void
    setSchema(org.apache.pulsar.client.api.Schema<?> schema)
     
    void
    setSchema(org.apache.pulsar.common.protocol.schema.SchemaVersion schemaVersion, org.apache.pulsar.client.api.Schema<?> schema)
     
    void
    setSchemaInfoProvider(org.apache.pulsar.client.api.schema.SchemaInfoProvider schemaInfoProvider)
     
    boolean
     
     
    org.apache.pulsar.client.api.Schema<?>
    unwrapInternalSchema(byte[] schemaVersion)
    Get a specific schema version, fetching from the Registry if it is not loaded yet.
    void
    validate(byte[] message)
     
    void
    validate(byte[] message, byte[] schemaVersion)
     
    static org.apache.pulsar.client.api.schema.GenericRecord
    wrapPrimitiveObject(Object value, org.apache.pulsar.common.schema.SchemaType type, byte[] schemaVersion)
     

    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
  • Constructor Details

    • AutoConsumeSchema

      public AutoConsumeSchema()
  • Method Details

    • setSchema

      public void setSchema(org.apache.pulsar.common.protocol.schema.SchemaVersion schemaVersion, org.apache.pulsar.client.api.Schema<?> schema)
    • setSchema

      public void setSchema(org.apache.pulsar.client.api.Schema<?> schema)
    • validate

      public void validate(byte[] message)
      Specified by:
      validate in interface org.apache.pulsar.client.api.Schema<org.apache.pulsar.client.api.schema.GenericRecord>
    • validate

      public void validate(byte[] message, byte[] schemaVersion)
    • encode

      public byte[] encode(org.apache.pulsar.client.api.schema.GenericRecord message)
      Specified by:
      encode in interface org.apache.pulsar.client.api.Schema<org.apache.pulsar.client.api.schema.GenericRecord>
    • supportSchemaVersioning

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

      public org.apache.pulsar.client.api.Schema<?> atSchemaVersion(byte[] schemaVersion)
    • decode

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

      public org.apache.pulsar.client.api.schema.GenericRecord decode(ByteBuffer buffer, byte[] schemaVersion)
      Specified by:
      decode in interface org.apache.pulsar.client.api.Schema<org.apache.pulsar.client.api.schema.GenericRecord>
    • setSchemaInfoProvider

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

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

      public org.apache.pulsar.common.schema.SchemaInfo getSchemaInfo(byte[] schemaVersion)
    • 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<org.apache.pulsar.client.api.schema.GenericRecord>
    • getNativeSchema

      public Optional<Object> getNativeSchema()
      Specified by:
      getNativeSchema in interface org.apache.pulsar.client.api.Schema<org.apache.pulsar.client.api.schema.GenericRecord>
    • getSchema

      public static org.apache.pulsar.client.api.Schema<?> getSchema(org.apache.pulsar.common.schema.SchemaInfo schemaInfo)
    • clone

      public org.apache.pulsar.client.api.Schema<org.apache.pulsar.client.api.schema.GenericRecord> clone()
      Specified by:
      clone in interface org.apache.pulsar.client.api.Schema<org.apache.pulsar.client.api.schema.GenericRecord>
      Overrides:
      clone in class Object
    • requireFetchingSchemaInfo

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

      protected org.apache.pulsar.client.api.schema.GenericRecord adapt(Object value, byte[] schemaVersion)
    • wrapPrimitiveObject

      public static org.apache.pulsar.client.api.schema.GenericRecord wrapPrimitiveObject(Object value, org.apache.pulsar.common.schema.SchemaType type, byte[] schemaVersion)
    • getInternalSchema

      public org.apache.pulsar.client.api.Schema<?> getInternalSchema()
    • getInternalSchema

      public org.apache.pulsar.client.api.Schema<?> getInternalSchema(byte[] schemaVersion)
    • unwrapInternalSchema

      public org.apache.pulsar.client.api.Schema<?> unwrapInternalSchema(byte[] schemaVersion)
      Get a specific schema version, fetching from the Registry if it is not loaded yet. This method is not intended to be used by applications.
      Parameters:
      schemaVersion - the version
      Returns:
      the Schema at the specific version
      See Also:
    • fetchSchemaIfNeeded

      public void fetchSchemaIfNeeded(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, because getSchemaInfo is called in many places and we will introduce lots of deadlocks.
      Throws:
      org.apache.pulsar.client.api.SchemaSerializationException
    • toString

      public String toString()
      Overrides:
      toString in class Object