2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2020-2021 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.onap.policy.controlloop.common.rules.test;
23 import java.util.LinkedList;
24 import java.util.List;
25 import lombok.AccessLevel;
27 import org.onap.policy.common.endpoints.http.server.HttpServletServer;
28 import org.slf4j.Logger;
29 import org.slf4j.LoggerFactory;
32 * Simulator container.
34 public class Simulators {
35 private static final Logger logger = LoggerFactory.getLogger(Simulators.class);
37 @Getter(AccessLevel.PROTECTED)
38 private final List<HttpServletServer> servers = new LinkedList<>();
41 * Invokes the given functions to start the simulators. Destroys <i>all</i> of the
42 * simulators if any fail to start.
44 * @param builders functions to invoke to build the simulators
46 public void start(SimulatorBuilder... builders) {
48 for (SimulatorBuilder builder : builders) {
49 servers.add(builder.build());
51 } catch (InterruptedException e) {
52 logger.warn("interrupted building the simulators");
54 Thread.currentThread().interrupt();
55 throw new SimulatorException(e);
60 * Stops all of the simulators.
62 public void destroy() {
63 for (HttpServletServer server : servers) {
66 } catch (RuntimeException e) {
67 logger.warn("error stopping simulator {}", server.getName(), e);
75 public static interface SimulatorBuilder {
76 public HttpServletServer build() throws InterruptedException;