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

io.cdap.cdap.internal.app.preview.DataTracerFactoryProvider Maven / Gradle / Ivy

There is a newer version: 6.10.1
Show newest version
/*
 * Copyright © 2016 Cask Data, Inc.
 *
 * 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 io.cdap.cdap.internal.app.preview;

import io.cdap.cdap.app.preview.DataTracerFactory;
import io.cdap.cdap.proto.id.ApplicationId;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * A class which provides {@link DataTracerFactory} based on the {@link ApplicationId}
 */
public final class DataTracerFactoryProvider {
  private static final DataTracerFactory DEFAULT_FACTORY = new NoopDataTracerFactory();
  private static final Map FACTORY_MAP = new ConcurrentHashMap<>();

  private DataTracerFactoryProvider() {
  }

  /**
   * Set the {@link DataTracerFactory} for a {@link ApplicationId} in a map.
   */
  public static void setDataTracerFactory(ApplicationId applicationId, DataTracerFactory dataTracerFactory) {
    FACTORY_MAP.put(applicationId, dataTracerFactory);
  }

  /**
   * Get the {@link DataTracerFactory} for a {@link ApplicationId}
   */
  public static DataTracerFactory get(ApplicationId applicationId) {
    DataTracerFactory factory = FACTORY_MAP.get(applicationId);
    if (factory == null) {
      return DEFAULT_FACTORY;
    }
    return factory;
  }

  /**
   * Remove the {@link DataTracerFactory} for a {@link ApplicationId} from a map.
   */
  public static void removeDataTracerFactory(ApplicationId applicationId) {
    FACTORY_MAP.remove(applicationId);
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy