import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
@Setter(AccessLevel.PROTECTED)
private String subRequestId;
+ @Getter
+ private final List<String> propertyNames;
+
+ /**
+ * Values for the properties identified by {@link #getPropertyNames()}.
+ */
+ private final Map<String, Object> properties = new HashMap<>();
+
/**
* Constructs the object.
*
* @param params operation parameters
* @param config configuration for this operation
+ * @param propertyNames names of properties required by this operation
*/
- public OperationPartial(ControlLoopOperationParams params, OperatorConfig config) {
+ public OperationPartial(ControlLoopOperationParams params, OperatorConfig config, List<String> propertyNames) {
this.params = params;
this.config = config;
this.fullName = params.getActor() + "." + params.getOperation();
+ this.propertyNames = propertyNames;
}
public Executor getBlockingExecutor() {
return params.getOperation();
}
+ /**
+ * Determines if a property has been assigned for the operation.
+ *
+ * @param name property name
+ * @return {@code true} if the given property has been assigned for the operation,
+ * {@code false} otherwise
+ */
+ public boolean containsProperty(String name) {
+ return properties.containsKey(name);
+ }
+
+ /**
+ * Sets a property.
+ *
+ * @param name property name
+ * @param value new value
+ */
+ public void setProperty(String name, Object value) {
+ properties.put(name, value);
+ }
+
+ /**
+ * Gets a property's value.
+ *
+ * @param name name of the property of interest
+ * @return the property's value, or {@code null} if it has no value
+ */
+ @SuppressWarnings("unchecked")
+ public <T> T getProperty(String name) {
+ return (T) properties.get(name);
+ }
+
@Override
public CompletableFuture<OperationOutcome> start() {
// allocate a controller for the entire operation
* {@code null} if this operation has no guard
*/
protected CompletableFuture<OperationOutcome> startGuardAsync() {
+ if (params.isPreprocessed()) {
+ return null;
+ }
+
// get the guard payload
Map<String, Object> payload = makeGuardPayload();
* @return a new guard payload
*/
protected Map<String, Object> makeGuardPayload() {
+ // TODO delete this once preprocessing is done by the application
Map<String, Object> guard = new LinkedHashMap<>();
guard.put("actor", params.getActor());
guard.put("operation", params.getOperation());
/**
* Generates and sets {@link #subRequestId} to a new subrequest ID.
+ *
* @param attempt attempt number, typically starting with 1
*/
public void generateSubRequestId(int attempt) {
return message.toString();
} else {
try {
- return makeCoder().encode(message, true);
+ return getCoder().encode(message, true);
} catch (CoderException e) {
throw new IllegalArgumentException("cannot encode message", e);
}
// these may be overridden by junit tests
- protected Coder makeCoder() {
+ protected Coder getCoder() {
return coder;
}
}