2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.openecomp.sdc.generator;
23 import org.openecomp.core.logging.api.Logger;
24 import org.openecomp.core.logging.api.LoggerFactory;
25 import org.openecomp.sdc.generator.data.Artifact;
26 import org.openecomp.sdc.generator.data.GenerationData;
27 import org.openecomp.sdc.generator.intf.ArtifactGenerator;
29 import java.util.LinkedList;
30 import java.util.List;
32 import java.util.concurrent.RecursiveTask;
34 public class GeneratorTask extends RecursiveTask<GenerationData> {
36 private static Logger log = LoggerFactory.getLogger(GeneratorTask.class.getName());
39 List<ArtifactGenerator> generators;
40 Map<String, String> additionalParams;
43 * Instantiates a new Generator task.
45 * @param generators the generators
46 * @param input the input
47 * @param additionalParams the additional params
49 public GeneratorTask(List<ArtifactGenerator> generators, List<Artifact> input,
50 Map<String, String> additionalParams ) {
52 this.generators = generators;
53 this.additionalParams = additionalParams;
57 protected GenerationData compute() {
58 if (generators.size() == 1) {
59 log.debug("Instantiating Generator : " + generators.get(0).getClass().getName());
60 return generators.remove(0).generateArtifact(input, additionalParams);
62 LinkedList<ArtifactGenerator> generator = new LinkedList<>();
63 generator.add(generators.remove(0));
64 GeneratorTask tobeDone = new GeneratorTask(generator, input, additionalParams);
65 GeneratorTask tobeForked =
66 new GeneratorTask(new LinkedList<ArtifactGenerator>(generators), input, additionalParams);
68 GenerationData output = tobeDone.compute();
69 output.add(tobeForked.join());