Class AutoConsumeSchema

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

    public class AutoConsumeSchema
    extends java.lang.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
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected org.apache.pulsar.client.api.schema.GenericRecord adapt​(java.lang.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> clone()  
      void configureSchemaInfo​(java.lang.String topicName, java.lang.String componentName, org.apache.pulsar.common.schema.SchemaInfo schemaInfo)  
      org.apache.pulsar.client.api.schema.GenericRecord decode​(byte[] bytes, 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<?> getInternalSchema()  
      org.apache.pulsar.client.api.Schema<?> getInternalSchema​(byte[] schemaVersion)  
      java.util.Optional<java.lang.Object> getNativeSchema()  
      static org.apache.pulsar.client.api.Schema<?> getSchema​(org.apache.pulsar.common.schema.SchemaInfo schemaInfo)  
      org.apache.pulsar.common.schema.SchemaInfo getSchemaInfo()  
      org.apache.pulsar.common.schema.SchemaInfo getSchemaInfo​(byte[] schemaVersion)  
      boolean requireFetchingSchemaInfo()  
      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 supportSchemaVersioning()  
      java.lang.String toString()  
      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​(java.lang.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 Detail

      • AutoConsumeSchema

        public AutoConsumeSchema()
    • Method Detail

      • 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>
      • 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​(java.lang.String topicName,
                                        java.lang.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 java.util.Optional<java.lang.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 java.lang.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​(java.lang.Object value,
                                                                          byte[] schemaVersion)
      • wrapPrimitiveObject

        public static org.apache.pulsar.client.api.schema.GenericRecord wrapPrimitiveObject​(java.lang.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:
        atSchemaVersion(byte[])
      • 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 java.lang.String toString()
        Overrides:
        toString in class java.lang.Object