2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved.
6 * Modifications Copyright (C) 2024 Nordix Foundation.
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
22 package org.onap.policy.controlloop.common.rules.test;
24 import java.util.LinkedList;
25 import java.util.List;
26 import lombok.AccessLevel;
28 import org.onap.policy.common.endpoints.http.server.HttpServletServer;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
33 * Simulator container.
35 public class Simulators {
36 private static final Logger logger = LoggerFactory.getLogger(Simulators.class);
38 @Getter(AccessLevel.PROTECTED)
39 private final List<HttpServletServer> servers = new LinkedList<>();
42 * Invokes the given functions to start the simulators. Destroys <i>all</i> of the
43 * simulators if any fail to start.
45 * @param builders functions to invoke to build the simulators
47 public void start(SimulatorBuilder... builders) {
49 for (SimulatorBuilder builder : builders) {
50 servers.add(builder.build());
52 } catch (InterruptedException e) {
53 logger.warn("interrupted building the simulators");
55 Thread.currentThread().interrupt();
56 throw new SimulatorException(e);
61 * Stops all the simulators.
63 public void destroy() {
64 for (HttpServletServer server : servers) {
67 } catch (RuntimeException e) {
68 logger.warn("error stopping simulator {}", server.getName(), e);
76 public interface SimulatorBuilder {
77 HttpServletServer build() throws InterruptedException;