Fix sonars in policy models
[policy/models.git] / models-interactions / model-actors / actorServiceProvider / src / main / java / org / onap / policy / controlloop / actorserviceprovider / impl / OperatorPartial.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP
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
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
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=========================================================
19  */
20
21 package org.onap.policy.controlloop.actorserviceprovider.impl;
22
23 import java.util.Map;
24 import java.util.concurrent.Executor;
25 import lombok.Getter;
26 import org.onap.policy.controlloop.actorserviceprovider.Operator;
27
28 /**
29  * Partial implementation of an operator.
30  */
31 public abstract class OperatorPartial extends StartConfigPartial<Map<String, Object>> implements Operator {
32
33     /**
34      * Executor to be used for tasks that may perform blocking I/O. The default executor
35      * simply launches a new thread for each command that is submitted to it.
36      * <p/>
37      * The "get" method may be overridden by junit tests.
38      */
39     @Getter
40     private final Executor blockingExecutor = command -> {
41         Thread thread = new Thread(command);
42         thread.setDaemon(true);
43         thread.start();
44     };
45
46     @Getter
47     private final String actorName;
48
49     @Getter
50     private final String name;
51
52     /**
53      * Constructs the object.
54      *
55      * @param actorName name of the actor with which this operator is associated
56      * @param name operation name
57      */
58     protected OperatorPartial(String actorName, String name) {
59         super(actorName + "." + name);
60         this.actorName = actorName;
61         this.name = name;
62     }
63
64     /**
65      * Verifies that the operator is running.
66      *
67      * @throws IllegalStateException if it is not running
68      */
69     public void verifyRunning() {
70         if (!isAlive()) {
71             throw new IllegalStateException("operation is not running: " + getFullName());
72         }
73     }
74
75     /**
76      * This method does nothing.
77      */
78     @Override
79     protected void doConfigure(Map<String, Object> parameters) {
80         // do nothing
81     }
82
83     /**
84      * This method does nothing.
85      */
86     @Override
87     protected void doStart() {
88         // do nothing
89     }
90
91     /**
92      * This method does nothing.
93      */
94     @Override
95     protected void doStop() {
96         // do nothing
97     }
98
99     /**
100      * This method does nothing.
101      */
102     @Override
103     protected void doShutdown() {
104         // do nothing
105     }
106 }