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

co.decodable.sdk.pipeline.EnvironmentAccess Maven / Gradle / Ivy

Go to download

A software development kit for implementing Apache Flink jobs and running them on Decodable

There is a newer version: 1.0.0.Beta7
Show newest version
/*
 * SPDX-License-Identifier: Apache-2.0
 *
 * Copyright Decodable, Inc.
 *
 * Licensed under the Apache Software License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
 */
package co.decodable.sdk.pipeline;

import co.decodable.sdk.pipeline.util.Incubating;
import java.util.Map;
import java.util.Objects;

/**
 * Provides access to the environment from within a custom Flink job. By default, the system
 * environment is exposed. For testing purposes, a custom environment can be set.
 */
@Incubating
public class EnvironmentAccess {

  private static Environment ENVIRONMENT = new SystemEnvironment();

  private EnvironmentAccess() {}

  /** Sets the given environment as the active one. */
  public static synchronized void setEnvironment(Environment environment) {
    Objects.requireNonNull(environment, "Environment must not be null");
    ENVIRONMENT = environment;
  }

  /** Resets active the environment to the system environment. */
  public static synchronized void resetEnvironment() {
    ENVIRONMENT = new SystemEnvironment();
  }

  /** Returns the current environment. */
  public static synchronized Environment getEnvironment() {
    return ENVIRONMENT;
  }

  /** Exposes the environment variables of the current process. */
  public interface Environment {
    /** Returns the current environment variables, keyed by name. */
    Map getEnvironmentConfiguration();
  }

  private static class SystemEnvironment implements Environment {

    @Override
    public Map getEnvironmentConfiguration() {
      return System.getenv();
    }
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy