2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2016-2018 Ericsson. All rights reserved.
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 package org.onap.policy.apex.service.engine.event.impl.filecarrierplugin;
23 import org.onap.policy.apex.service.engine.event.impl.filecarrierplugin.consumer.ApexFileEventConsumer;
24 import org.onap.policy.apex.service.engine.event.impl.filecarrierplugin.producer.ApexFileEventProducer;
25 import org.onap.policy.apex.service.parameters.carriertechnology.CarrierTechnologyParameters;
26 import org.onap.policy.common.parameters.GroupValidationResult;
27 import org.onap.policy.common.parameters.ValidationStatus;
28 import org.onap.policy.common.utils.resources.ResourceUtils;
31 * This class holds the parameters that allows transport of events into and out of Apex using files and standard input
35 * The following parameters are defined:
37 * <li>fileName: The full path to the file from which to read events or to which to write events.
38 * <li>standardIO: If this flag is set to true, then standard input is used to read events in or standard output is used
39 * to write events and the fileName parameter is ignored if present
40 * <li>standardError: If this flag is set to true, then standard error is used to write events
41 * <li>streamingMode: If this flag is set to true, then streaming mode is set for reading events and event handling will
42 * wait on the input stream for events until the stream is closed. If streaming model is off, then event reading
43 * completes when the end of input is detected.
44 * <li>startDelay: The amount of milliseconds to wait at startup startup before processing the first event.
47 * @author Liam Fallon (liam.fallon@ericsson.com)
49 public class FILECarrierTechnologyParameters extends CarrierTechnologyParameters {
51 /** The label of this carrier technology. */
52 public static final String FILE_CARRIER_TECHNOLOGY_LABEL = "FILE";
54 /** The producer plugin class for the FILE carrier technology. */
55 public static final String FILE_EVENT_PRODUCER_PLUGIN_CLASS = ApexFileEventProducer.class.getCanonicalName();
57 /** The consumer plugin class for the FILE carrier technology. */
58 public static final String FILE_EVENT_CONSUMER_PLUGIN_CLASS = ApexFileEventConsumer.class.getCanonicalName();
60 private String fileName;
61 private boolean standardIO = false;
62 private boolean standardError = false;
63 private boolean streamingMode = false;
64 private long startDelay = 0;
68 * Constructor to create a file carrier technology parameters instance and register the instance with the parameter
71 public FILECarrierTechnologyParameters() {
74 // Set the carrier technology properties for the FILE carrier technology
75 this.setLabel(FILE_CARRIER_TECHNOLOGY_LABEL);
76 this.setEventProducerPluginClass(FILE_EVENT_PRODUCER_PLUGIN_CLASS);
77 this.setEventConsumerPluginClass(FILE_EVENT_CONSUMER_PLUGIN_CLASS);
81 * Gets the file name from which to read or to which to write events.
83 * @return the file name from which to read or to which to write events
85 public String getFileName() {
86 return ResourceUtils.getFilePath4Resource(fileName);
90 * Checks if is standard IO should be used for input or output.
92 * @return true, if standard IO should be used for input or output
94 public boolean isStandardIO() {
99 * Checks if is standard error should be used for output.
101 * @return true, if standard error should be used for output
103 public boolean isStandardError() {
104 return standardError;
108 * Checks if is streaming mode is on.
110 * @return true, if streaming mode is on
112 public boolean isStreamingMode() {
113 return streamingMode;
117 * Sets the file name from which to read or to which to write events.
119 * @param fileName the file name from which to read or to which to write events
121 public void setFileName(final String fileName) {
122 this.fileName = fileName;
126 * Sets if standard IO should be used for event input or output.
128 * @param standardIO if standard IO should be used for event input or output
130 public void setStandardIO(final boolean standardIO) {
131 this.standardIO = standardIO;
135 * Sets if standard error should be used for event output.
137 * @param standardError if standard error should be used for event output
139 public void setStandardError(final boolean standardError) {
140 this.standardError = standardError;
144 * Sets streaming mode.
146 * @param streamingMode the streaming mode value
148 public void setStreamingMode(final boolean streamingMode) {
149 this.streamingMode = streamingMode;
153 * Gets the delay in milliseconds before the plugin starts processing.
157 public long getStartDelay() {
162 * Sets the delay in milliseconds before the plugin starts processing.
164 * @param startDelay the delay
166 public void setStartDelay(final long startDelay) {
167 this.startDelay = startDelay;
173 * @see org.onap.policy.apex.service.parameters.carriertechnology.CarrierTechnologyParameters# toString()
176 public String toString() {
177 return "FILECarrierTechnologyParameters [fileName=" + fileName + ", standardIO=" + standardIO
178 + ", standardError=" + standardError + ", streamingMode=" + streamingMode + ", startDelay="
185 * @see org.onap.policy.common.parameters.ParameterGroup#getName()
188 public String getName() {
189 return this.getLabel();
195 * @see org.onap.policy.apex.apps.uservice.parameters.ApexParameterValidator#validate()
198 public GroupValidationResult validate() {
199 final GroupValidationResult result = super.validate();
201 if (!standardIO && !standardError && (fileName == null || fileName.trim().length() == 0)) {
202 result.setResult("fileName", ValidationStatus.INVALID,
203 "fileName not specified or is blank or null, it must be specified as a valid file location");
206 if (standardIO || standardError) {
207 streamingMode = true;
210 if (startDelay < 0) {
211 result.setResult("startDelay", ValidationStatus.INVALID,
212 "startDelay must be zero or a positive number of milliseconds");