2 * ============LICENSE_START=======================================================
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
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.actorserviceprovider.impl;
25 import org.onap.policy.controlloop.actorserviceprovider.Operation;
26 import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOperationParams;
29 * Operator with typed parameter information.
31 * @param <C> type of configuration data
32 * @param <T> type of operation that the operator creates
34 public abstract class TypedOperator<C, T extends Operation> extends OperatorPartial {
37 * Function to make an operation.
39 private final OperationMaker<C, T> operationMaker;
42 * Current configuration. This is set by {@link #doConfigure(Map)}.
45 private C currentConfig;
49 * Constructs the object.
51 * @param actorName name of the actor with which this operator is associated
52 * @param name operation name
54 protected TypedOperator(String actorName, String name) {
55 this(actorName, name, null);
59 * Constructs the object.
61 * @param actorName name of the actor with which this operator is associated
62 * @param name operation name
63 * @param operationMaker function to make an operation
65 protected TypedOperator(String actorName, String name, OperationMaker<C, T> operationMaker) {
66 super(actorName, name);
67 this.operationMaker = operationMaker;
71 * Translates the parameters, saving the relevant configuration data.
74 protected void doConfigure(Map<String, Object> parameters) {
75 currentConfig = makeConfiguration(parameters);
79 * Makes a new configuration using the specified parameters.
81 * @param parameters operator parameters
82 * @return a new configuration
84 protected abstract C makeConfiguration(Map<String, Object> parameters);
87 public T buildOperation(ControlLoopOperationParams params) {
88 if (operationMaker == null) {
89 throw new UnsupportedOperationException("cannot make operation for " + getFullName());
94 return operationMaker.apply(params, currentConfig);