|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | + * or more contributor license agreements. See the NOTICE file |
| 4 | + * distributed with this work for additional information |
| 5 | + * regarding copyright ownership. The ASF licenses this file |
| 6 | + * to you under the Apache License, Version 2.0 (the |
| 7 | + * "License"); you may not use this file except in compliance |
| 8 | + * with the License. You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, software |
| 13 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | + * See the License for the specific language governing permissions and |
| 16 | + * limitations under the License. |
| 17 | + */ |
| 18 | + |
| 19 | +package org.apache.flink.datastream.impl; |
| 20 | + |
| 21 | +import org.apache.flink.configuration.Configuration; |
| 22 | +import org.apache.flink.core.execution.PipelineExecutorServiceLoader; |
| 23 | +import org.apache.flink.datastream.api.ExecutionEnvironment; |
| 24 | + |
| 25 | +/** |
| 26 | + * Special {@link ExecutionEnvironment} that will be used in cases where the CLI client or testing |
| 27 | + * utilities create a {@link ExecutionEnvironment} that should be used when {@link |
| 28 | + * ExecutionEnvironment#getInstance()} ()} is called. |
| 29 | + */ |
| 30 | +public class ExecutionContextEnvironment extends ExecutionEnvironmentImpl { |
| 31 | + public ExecutionContextEnvironment( |
| 32 | + final PipelineExecutorServiceLoader executorServiceLoader, |
| 33 | + final Configuration configuration, |
| 34 | + final ClassLoader userCodeClassLoader) { |
| 35 | + super(executorServiceLoader, configuration, userCodeClassLoader); |
| 36 | + } |
| 37 | + |
| 38 | + // -------------------------------------------------------------------------------------------- |
| 39 | + |
| 40 | + public static void setAsContext( |
| 41 | + final PipelineExecutorServiceLoader executorServiceLoader, |
| 42 | + final Configuration clusterConfiguration, |
| 43 | + final ClassLoader userCodeClassLoader) { |
| 44 | + final ExecutionEnvironmentFactory factory = |
| 45 | + envInitConfig -> { |
| 46 | + final Configuration mergedEnvConfig = new Configuration(); |
| 47 | + mergedEnvConfig.addAll(clusterConfiguration); |
| 48 | + mergedEnvConfig.addAll(envInitConfig); |
| 49 | + return new ExecutionContextEnvironment( |
| 50 | + executorServiceLoader, mergedEnvConfig, userCodeClassLoader); |
| 51 | + }; |
| 52 | + initializeContextEnvironment(factory); |
| 53 | + } |
| 54 | + |
| 55 | + public static void unsetAsContext() { |
| 56 | + resetContextEnvironment(); |
| 57 | + } |
| 58 | +} |
0 commit comments