2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2021 Nordix Foundation.
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 package org.onap.policy.clamp.controlloop.runtime.supervision;
23 import java.io.Closeable;
24 import java.io.IOException;
25 import java.util.concurrent.LinkedBlockingQueue;
26 import java.util.concurrent.ThreadPoolExecutor;
27 import java.util.concurrent.TimeUnit;
28 import lombok.RequiredArgsConstructor;
29 import org.aspectj.lang.annotation.After;
30 import org.aspectj.lang.annotation.Aspect;
31 import org.slf4j.Logger;
32 import org.slf4j.LoggerFactory;
33 import org.springframework.scheduling.annotation.Scheduled;
34 import org.springframework.stereotype.Component;
38 @RequiredArgsConstructor
39 public class SupervisionAspect implements Closeable {
41 private static final Logger LOGGER = LoggerFactory.getLogger(SupervisionAspect.class);
43 private final SupervisionScanner supervisionScanner;
45 private ThreadPoolExecutor executor =
46 new ThreadPoolExecutor(1, 1, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>());
49 fixedRateString = "${runtime.participantParameters.heartBeatMs}",
50 initialDelayString = "${runtime.participantParameters.heartBeatMs}")
51 public void schedule() {
52 LOGGER.info("Add scheduled scanning");
53 executor.execute(() -> supervisionScanner.run(true));
57 * Intercept Messages from participant and run Supervision Scan.
59 @After("@annotation(MessageIntercept)")
60 public void doCheck() {
61 if (executor.getQueue().size() < 2) {
62 LOGGER.debug("Add scanning Message");
63 executor.execute(() -> supervisionScanner.run(false));
68 public void close() throws IOException {