All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.apache.pulsar.broker.service.schema.SchemaRegistry Maven / Gradle / Ivy

There is a newer version: 4.0.0.10
Show newest version
/**
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */
package org.apache.pulsar.broker.service.schema;

import com.google.common.base.MoreObjects;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.CompletableFuture;
import org.apache.pulsar.common.policies.data.SchemaCompatibilityStrategy;
import org.apache.pulsar.common.protocol.schema.SchemaData;
import org.apache.pulsar.common.protocol.schema.SchemaVersion;

public interface SchemaRegistry extends AutoCloseable {

    CompletableFuture getSchema(String schemaId);

    CompletableFuture getSchema(String schemaId, SchemaVersion version);

    CompletableFuture>> getAllSchemas(String schemaId);

    CompletableFuture putSchemaIfAbsent(String schemaId, SchemaData schema,
                                                       SchemaCompatibilityStrategy strategy);

    CompletableFuture deleteSchema(String schemaId, String user);

    CompletableFuture deleteSchemaStorage(String schemaId);

    CompletableFuture deleteSchemaStorage(String schemaId, boolean forcefully);

    CompletableFuture isCompatible(String schemaId, SchemaData schema,
                                            SchemaCompatibilityStrategy strategy);

    CompletableFuture checkCompatible(String schemaId, SchemaData schema,
                                                             SchemaCompatibilityStrategy strategy);

    CompletableFuture> trimDeletedSchemaAndGetList(String schemaId);

    CompletableFuture findSchemaVersion(String schemaId, SchemaData schemaData);

    CompletableFuture checkConsumerCompatibility(String schemaId, SchemaData schemaData,
                                                       SchemaCompatibilityStrategy strategy);

    CompletableFuture getSchemaVersionBySchemaData(List schemaAndMetadataList,
                                                                  SchemaData schemaData);

    SchemaVersion versionFromBytes(byte[] version);

    class SchemaAndMetadata {
        public final String id;
        public final SchemaData schema;
        public final SchemaVersion version;

        SchemaAndMetadata(String id, SchemaData schema, SchemaVersion version) {
            this.id = id;
            this.schema = schema;
            this.version = version;
        }

        @Override
        public boolean equals(Object o) {
            if (this == o) {
                return true;
            }
            if (o == null || getClass() != o.getClass()) {
                return false;
            }
            SchemaAndMetadata that = (SchemaAndMetadata) o;
            return version == that.version
                    && Objects.equals(id, that.id)
                    && Objects.equals(schema, that.schema);
        }

        @Override
        public int hashCode() {
            return Objects.hash(id, schema, version);
        }

        @Override
        public String toString() {
            return MoreObjects.toStringHelper(this)
                .add("id", id)
                .add("schema", schema)
                .add("version", version)
                .toString();
        }
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy