dff4c6b58865d58201b16d06ff93b3b9d30da484
[policy/clamp.git] /
1 /*-
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
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
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.
16  *
17  * SPDX-License-Identifier: Apache-2.0
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.policy.clamp.controlloop.common.handler;
22
23 import java.util.HashSet;
24 import java.util.List;
25 import java.util.Set;
26 import lombok.Getter;
27 import lombok.NonNull;
28 import org.onap.policy.common.endpoints.event.comm.TopicSink;
29 import org.onap.policy.common.endpoints.listeners.MessageTypeDispatcher;
30 import org.onap.policy.common.utils.services.Registry;
31 import org.onap.policy.models.provider.PolicyModelsProviderParameters;
32
33 /**
34  * Abstract class for handlers for sub components in the control loop system
35  *
36  * <p>Instances are effectively singletons that are started at system start.
37  */
38 public abstract class ControlLoopHandler {
39     @Getter
40     private final PolicyModelsProviderParameters databaseProviderParameters;
41
42     /**
43      * Create a handler.
44      *
45      * @param databaseProviderParameters the parameters for access to the database
46      */
47     protected ControlLoopHandler(@NonNull PolicyModelsProviderParameters databaseProviderParameters) {
48         this.databaseProviderParameters = databaseProviderParameters;
49
50         Registry.register(this.getClass().getName(), this);
51     }
52
53     public void close() {
54         Registry.unregister(this.getClass().getName());
55     }
56
57     /**
58      * Get the provider classes that are used in instantiation.
59      *
60      * @return the provider classes
61      */
62     public Set<Class<?>> getProviderClasses() {
63         // No REST interfaces are the default
64         return new HashSet<>();
65     }
66
67     /**
68      * Start any topic message listeners for this handler.
69      *
70      * @param msgDispatcher the message dispatcher with which to register the listener
71      */
72     public abstract void startAndRegisterListeners(MessageTypeDispatcher msgDispatcher);
73
74     /**
75      * Start any topic message publishers for this handler.
76      *
77      * @param topicSinks the topic sinks on which the publisher can publish
78      */
79     public abstract void startAndRegisterPublishers(List<TopicSink> topicSinks);
80
81     /**
82      * Start any providers for this handler.
83      */
84     public abstract void startProviders();
85
86     /**
87      * Stop any topic message publishers for this handler.
88      */
89     public abstract void stopAndUnregisterPublishers();
90
91     /**
92      * Stop any topic message listeners for this handler.
93      *
94      * @param msgDispatcher the message dispatcher from which to unregister the listener
95      */
96     public abstract void stopAndUnregisterListeners(MessageTypeDispatcher msgDispatcher);
97
98     /**
99      * Stop any providers for this handler.
100      */
101     public abstract void stopProviders();
102 }