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

com.streamsets.systemexplorer.api.ExplorerLoader Maven / Gradle / Ivy

There is a newer version: 6.3.0
Show newest version
/*
 * Copyright contributors to the StreamSets project
 * StreamSets Inc., an IBM Company 2024
 *
 * Licensed 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 com.streamsets.systemexplorer.api;

import com.streamsets.pipeline.api.ConfigIssue;

import java.util.Collections;
import java.util.List;

/**
 * Loads explorer data to be used for Explorer searches. The loaded data is cached by the engine.
 */
public interface ExplorerLoader {

  /**
   * Returns an empty data set. This method is called to get an 'empty' explorer data instance to be given to
   * the load method.
   */
  ExplorerData getEmptyData();

  /**
   * Initializes the loader using the stage configuration. Invoked before every load.
   */
  default List init(final ExplorerRequestContext explorerRequestContext) {
    return Collections.emptyList();
  }

  /**
   * Loads explorer data constrained by boundaries or unbounded explorer data if boundaries is
   * {@link ExplorerDataBoundaries#NONE}
   *
   * The method replaces parts of the explorer data that were loaded before.
   *
   * @param explorerData - data storage where to load the new data to.
   * @param explorerDataBoundaries - defines the boundaries of the explorer data where the new data will be loaded to.
   * @throws InterruptedException - if the loader was interrupted while loading the data.
   */
  void load(ExplorerData explorerData, ExplorerDataBoundaries explorerDataBoundaries) throws InterruptedException, ExplorerLoaderException;

  /**
   * Destroy the loader. Invoked after every load.
   */
  default void destroy() {
  }

  final class NoOp implements ExplorerLoader {
    private static final ExplorerData NONE = new ExplorerData<>(new Object());

    public static final NoOp NOOP = new NoOp();

    private NoOp() {
    }

    @Override
    public ExplorerData getEmptyData() {
      return NONE;
    }

    @Override
    public void load(final ExplorerData explorerData, final ExplorerDataBoundaries explorerDataBoundaries) {
    }
  }

  class ExplorerLoaderException extends Exception {
    public ExplorerLoaderException() {
    }

    public ExplorerLoaderException(final String message) {
      super(message);
    }

    public ExplorerLoaderException(final String message, final Throwable cause) {
      super(message, cause);
    }

    public ExplorerLoaderException(final Throwable cause) {
      super(cause);
    }

    public ExplorerLoaderException(final String message, final Throwable cause, final boolean enableSuppression, final boolean writableStackTrace) {
      super(message, cause, enableSuppression, writableStackTrace);
    }
  }
}