1bbe5662f60f66f042299bba9aa85fb38838a6eb
[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 void startAndRegisterListeners(MessageTypeDispatcher msgDispatcher) {
73         // Start and register listeners
74     }
75
76     /**
77      * Start any topic message publishers for this handler.
78      *
79      * @param topicSinks the topic sinks on which the publisher can publish
80      */
81     public void startAndRegisterPublishers(List<TopicSink> topicSinks) {
82         // Start and register publishers
83     }
84
85     /**
86      * Stop any topic message publishers for this handler.
87      */
88     public void stopAndUnregisterPublishers() {
89         // Stop and unregister publishers
90     }
91
92     /**
93      * Stop any topic message listeners for this handler.
94      *
95      * @param msgDispatcher the message dispatcher from which to unregister the listener
96      */
97     public void stopAndUnregisterListeners(MessageTypeDispatcher msgDispatcher) {
98         // Stop and unregister listeners
99     }
100
101     /**
102      * Start any providers for this handler.
103      */
104     public abstract void startProviders();
105
106     /**
107      * Stop any providers for this handler.
108      */
109     public abstract void stopProviders();
110 }