2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2020 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 * Constructs the object.
48 * Invokes the given functions to start the simulators. Destroys <i>all</i> of the
49 * simulators if any fail to start.
51 * @param builders functions to invoke to build the simulators
53 public void start(SimulatorBuilder... builders) {
55 for (SimulatorBuilder builder : builders) {
56 servers.add(builder.build());
58 } catch (InterruptedException e) {
59 logger.warn("interrupted building the simulators");
61 Thread.currentThread().interrupt();
62 throw new SimulatorException(e);
67 * Stops all of the simulators.
69 public void destroy() {
70 for (HttpServletServer server : servers) {
73 } catch (RuntimeException e) {
74 logger.warn("error stopping simulator {}", server.getName(), e);
82 public static interface SimulatorBuilder {
83 public HttpServletServer build() throws InterruptedException;