Moving common polling code into HttpOperation
[policy/models.git] / models-interactions / model-actors / actorServiceProvider / src / main / java / org / onap / policy / controlloop / actorserviceprovider / impl / HttpOperator.java
index 9e446a7..f731a2c 100644 (file)
 package org.onap.policy.controlloop.actorserviceprovider.impl;
 
 import java.util.Map;
-import lombok.Getter;
 import org.onap.policy.common.endpoints.http.client.HttpClientFactory;
 import org.onap.policy.common.endpoints.http.client.HttpClientFactoryInstance;
 import org.onap.policy.common.parameters.ValidationResult;
-import org.onap.policy.controlloop.actorserviceprovider.Operation;
 import org.onap.policy.controlloop.actorserviceprovider.Util;
-import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOperationParams;
 import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpConfig;
 import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpParams;
 import org.onap.policy.controlloop.actorserviceprovider.parameters.ParameterValidationRuntimeException;
@@ -35,20 +32,7 @@ import org.onap.policy.controlloop.actorserviceprovider.parameters.ParameterVali
 /**
  * Operator that uses HTTP. The operator's parameters must be an {@link HttpParams}.
  */
-public class HttpOperator extends OperatorPartial {
-
-    /**
-     * Function to make an operation.
-     */
-    @SuppressWarnings("rawtypes")
-    private final OperationMaker<HttpConfig, HttpOperation> operationMaker;
-
-    /**
-     * Current configuration. This is set by {@link #doConfigure(Map)}.
-     */
-    @Getter
-    private HttpConfig currentConfig;
-
+public class HttpOperator extends TypedOperator<HttpConfig,HttpOperation<?>> {
 
     /**
      * Constructs the object.
@@ -68,18 +52,8 @@ public class HttpOperator extends OperatorPartial {
      * @param operationMaker function to make an operation
      */
     public HttpOperator(String actorName, String name,
-                    @SuppressWarnings("rawtypes") OperationMaker<HttpConfig, HttpOperation> operationMaker) {
-        super(actorName, name);
-        this.operationMaker = operationMaker;
-    }
-
-    /**
-     * Translates the parameters to an {@link HttpParams} and then extracts the relevant
-     * values.
-     */
-    @Override
-    protected void doConfigure(Map<String, Object> parameters) {
-        currentConfig = makeConfiguration(parameters);
+                    OperationMaker<HttpConfig, HttpOperation<?>> operationMaker) {
+        super(actorName, name, operationMaker);
     }
 
     /**
@@ -98,17 +72,6 @@ public class HttpOperator extends OperatorPartial {
         return new HttpConfig(getBlockingExecutor(), params, getClientFactory());
     }
 
-    @Override
-    public Operation buildOperation(ControlLoopOperationParams params) {
-        if (operationMaker == null) {
-            throw new UnsupportedOperationException("cannot make operation for " + getFullName());
-        }
-
-        verifyRunning();
-
-        return operationMaker.apply(params, currentConfig);
-    }
-
     // these may be overridden by junit tests
 
     protected HttpClientFactory getClientFactory() {