2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2020 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;
27 import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpParams;
30 * Operator with typed parameter information.
32 * @param <C> type of configuration data
33 * @param <T> type of operation that the operator creates
35 public abstract class TypedOperator<C, T extends Operation> extends OperatorPartial {
38 * Function to make an operation.
40 private final OperationMaker<C, T> operationMaker;
43 * Current configuration. This is set by {@link #doConfigure(Map)}.
46 private C currentConfig;
50 * Constructs the object.
52 * @param actorName name of the actor with which this operator is associated
53 * @param name operation name
55 protected TypedOperator(String actorName, String name) {
56 this(actorName, name, null);
60 * Constructs the object.
62 * @param actorName name of the actor with which this operator is associated
63 * @param name operation name
64 * @param operationMaker function to make an operation
66 public TypedOperator(String actorName, String name, OperationMaker<C, T> operationMaker) {
67 super(actorName, name);
68 this.operationMaker = operationMaker;
72 * Translates the parameters, saving the relevant configuration data.
75 protected void doConfigure(Map<String, Object> parameters) {
76 currentConfig = makeConfiguration(parameters);
80 * Makes a new configuration using the specified parameters.
82 * @param parameters operator parameters
83 * @return a new configuration
85 protected abstract C makeConfiguration(Map<String, Object> parameters);
88 public T buildOperation(ControlLoopOperationParams params) {
89 if (operationMaker == null) {
90 throw new UnsupportedOperationException("cannot make operation for " + getFullName());
95 return operationMaker.apply(params, currentConfig);