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;
23 import java.util.Arrays;
24 import java.util.List;
26 import org.onap.policy.common.parameters.ValidationResult;
27 import org.onap.policy.controlloop.actorserviceprovider.Util;
28 import org.onap.policy.controlloop.actorserviceprovider.parameters.BidirectionalTopicConfig;
29 import org.onap.policy.controlloop.actorserviceprovider.parameters.BidirectionalTopicParams;
30 import org.onap.policy.controlloop.actorserviceprovider.parameters.ParameterValidationRuntimeException;
31 import org.onap.policy.controlloop.actorserviceprovider.topic.BidirectionalTopicHandler;
32 import org.onap.policy.controlloop.actorserviceprovider.topic.BidirectionalTopicManager;
33 import org.onap.policy.controlloop.actorserviceprovider.topic.SelectorKey;
36 * Operator that uses a bidirectional topic. Topic operators may share a
37 * {@link BidirectionalTopicHandler}.
39 public class BidirectionalTopicOperator
40 extends TypedOperator<BidirectionalTopicConfig, BidirectionalTopicOperation<?, ?>> {
43 * Manager from which to get the topic handlers.
45 private final BidirectionalTopicManager topicManager;
48 * Keys used to extract the fields used to select responses for this operator.
50 private final List<SelectorKey> selectorKeys;
54 * Constructs the object.
56 * @param actorName name of the actor with which this operator is associated
57 * @param name operation name
58 * @param topicManager manager from which to get the topic handler
59 * @param selectorKeys keys used to extract the fields used to select responses for
62 protected BidirectionalTopicOperator(String actorName, String name, BidirectionalTopicManager topicManager,
63 List<SelectorKey> selectorKeys) {
64 this(actorName, name, topicManager, selectorKeys, null);
68 * Constructs the object.
70 * @param actorName name of the actor with which this operator is associated
71 * @param name operation name
72 * @param topicManager manager from which to get the topic handler
73 * @param selectorKeys keys used to extract the fields used to select responses for
76 public BidirectionalTopicOperator(String actorName, String name, BidirectionalTopicManager topicManager,
77 List<SelectorKey> selectorKeys,
78 OperationMaker<BidirectionalTopicConfig, BidirectionalTopicOperation<?, ?>> operationMaker) {
80 super(actorName, name, operationMaker);
81 this.topicManager = topicManager;
82 this.selectorKeys = selectorKeys;
86 * Constructs the object.
88 * @param actorName name of the actor with which this operator is associated
89 * @param name operation name
90 * @param topicManager manager from which to get the topic handler
91 * @param selectorKeys keys used to extract the fields used to select responses for
94 public BidirectionalTopicOperator(String actorName, String name, BidirectionalTopicManager topicManager,
95 OperationMaker<BidirectionalTopicConfig, BidirectionalTopicOperation<?, ?>> operationMaker,
96 SelectorKey... selectorKeys) {
97 this(actorName, name, topicManager, Arrays.asList(selectorKeys), operationMaker);
101 * Makes a new configuration using the specified parameters.
103 * @param parameters operator parameters
104 * @return a new configuration
106 protected BidirectionalTopicConfig makeConfiguration(Map<String, Object> parameters) {
107 BidirectionalTopicParams params = Util.translate(getFullName(), parameters, BidirectionalTopicParams.class);
108 ValidationResult result = params.validate(getFullName());
109 if (!result.isValid()) {
110 throw new ParameterValidationRuntimeException("invalid parameters", result);
113 return new BidirectionalTopicConfig(getBlockingExecutor(), params, topicManager, selectorKeys);