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

com.datastrato.gravitino.messaging.TopicCatalog Maven / Gradle / Ivy

Go to download

Gravitino is a high-performance, geo-distributed and federated metadata lake.

The newest version!
/*
 * Copyright 2024 Datastrato Pvt Ltd.
 * This software is licensed under the Apache License version 2.
 */
package com.datastrato.gravitino.messaging;

import com.datastrato.gravitino.NameIdentifier;
import com.datastrato.gravitino.Namespace;
import com.datastrato.gravitino.annotation.Evolving;
import com.datastrato.gravitino.exceptions.NoSuchSchemaException;
import com.datastrato.gravitino.exceptions.NoSuchTopicException;
import com.datastrato.gravitino.exceptions.TopicAlreadyExistsException;
import java.util.Map;

/**
 * The {@link TopicCatalog} interface defines the public API for managing topic objects in a schema.
 * If the catalog implementation supports topic objects, it should implement this interface.
 */
@Evolving
public interface TopicCatalog {

  /**
   * List the topics in a schema namespace from the catalog.
   *
   * @param namespace A schema namespace.
   * @return An array of topic identifiers in the namespace.
   * @throws NoSuchSchemaException If the schema does not exist.
   */
  NameIdentifier[] listTopics(Namespace namespace) throws NoSuchSchemaException;

  /**
   * Load topic metadata by {@link NameIdentifier} from the catalog.
   *
   * @param ident A topic identifier.
   * @return The topic metadata.
   * @throws NoSuchTopicException If the topic does not exist.
   */
  Topic loadTopic(NameIdentifier ident) throws NoSuchTopicException;

  /**
   * Check if a topic exists using an {@link NameIdentifier} from the catalog.
   *
   * @param ident A topic identifier.
   * @return true If the topic exists, false otherwise.
   */
  default boolean topicExists(NameIdentifier ident) {
    try {
      loadTopic(ident);
      return true;
    } catch (NoSuchTopicException e) {
      return false;
    }
  }

  /**
   * Create a topic in the catalog.
   *
   * @param ident A topic identifier.
   * @param comment The comment of the topic object. Null is set if no comment is specified.
   * @param dataLayout The message schema of the topic object. Always null because it's not
   *     supported yet.
   * @param properties The properties of the topic object. Empty map is set if no properties are
   *     specified.
   * @return The topic metadata.
   * @throws NoSuchSchemaException If the schema does not exist.
   * @throws TopicAlreadyExistsException If the topic already exists.
   */
  Topic createTopic(
      NameIdentifier ident, String comment, DataLayout dataLayout, Map properties)
      throws NoSuchSchemaException, TopicAlreadyExistsException;

  /**
   * Apply the {@link TopicChange changes} to a topic in the catalog.
   *
   * @param ident A topic identifier.
   * @param changes The changes to apply to the topic.
   * @return The altered topic metadata.
   * @throws NoSuchTopicException If the topic does not exist.
   * @throws IllegalArgumentException If the changes is rejected by the implementation.
   */
  Topic alterTopic(NameIdentifier ident, TopicChange... changes)
      throws NoSuchTopicException, IllegalArgumentException;

  /**
   * Drop a topic from the catalog.
   *
   * @param ident A topic identifier.
   * @return true If the topic is dropped, false if the topic does not exist.
   */
  boolean dropTopic(NameIdentifier ident);
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy