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
34 * <p>The following parameters are defined: <ol> <li>fileName: The full path to the file from which to read events or to
35 * which to write events. <li>standardIO: If this flag is set to true, then standard input is used to read events in or
36 * standard output is used to write events and the fileName parameter is ignored if present <li>standardError: If this
37 * flag is set to true, then standard error is used to write events <li>streamingMode: If this flag is set to true, then
38 * streaming mode is set for reading events and event handling will wait on the input stream for events until the stream
39 * is closed. If streaming model is off, then event reading completes when the end of input is detected. <li>startDelay:
40 * The amount of milliseconds to wait at startup startup before processing the first event. </ol>
42 * @author Liam Fallon (liam.fallon@ericsson.com)
44 public class FileCarrierTechnologyParameters extends CarrierTechnologyParameters {
46 /** The label of this carrier technology. */
47 public static final String FILE_CARRIER_TECHNOLOGY_LABEL = "FILE";
49 /** The producer plugin class for the FILE carrier technology. */
50 public static final String FILE_EVENT_PRODUCER_PLUGIN_CLASS = ApexFileEventProducer.class.getCanonicalName();
52 /** The consumer plugin class for the FILE carrier technology. */
53 public static final String FILE_EVENT_CONSUMER_PLUGIN_CLASS = ApexFileEventConsumer.class.getCanonicalName();
55 private String fileName;
56 private boolean standardIo = false;
57 private boolean standardError = false;
58 private boolean streamingMode = false;
59 private long startDelay = 0;
63 * Constructor to create a file carrier technology parameters instance and register the instance with the parameter
66 public FileCarrierTechnologyParameters() {
69 // Set the carrier technology properties for the FILE carrier technology
70 this.setLabel(FILE_CARRIER_TECHNOLOGY_LABEL);
71 this.setEventProducerPluginClass(FILE_EVENT_PRODUCER_PLUGIN_CLASS);
72 this.setEventConsumerPluginClass(FILE_EVENT_CONSUMER_PLUGIN_CLASS);
76 * Gets the file name from which to read or to which to write events.
78 * @return the file name from which to read or to which to write events
80 public String getFileName() {
81 return ResourceUtils.getFilePath4Resource(fileName);
85 * Checks if is standard IO should be used for input or output.
87 * @return true, if standard IO should be used for input or output
89 public boolean isStandardIo() {
94 * Checks if is standard error should be used for output.
96 * @return true, if standard error should be used for output
98 public boolean isStandardError() {
103 * Checks if is streaming mode is on.
105 * @return true, if streaming mode is on
107 public boolean isStreamingMode() {
108 return streamingMode;
112 * Sets the file name from which to read or to which to write events.
114 * @param fileName the file name from which to read or to which to write events
116 public void setFileName(final String fileName) {
117 this.fileName = fileName;
121 * Sets if standard IO should be used for event input or output.
123 * @param standardIo if standard IO should be used for event input or output
125 public void setStandardIo(final boolean standardIo) {
126 this.standardIo = standardIo;
130 * Sets if standard error should be used for event output.
132 * @param standardError if standard error should be used for event output
134 public void setStandardError(final boolean standardError) {
135 this.standardError = standardError;
139 * Sets streaming mode.
141 * @param streamingMode the streaming mode value
143 public void setStreamingMode(final boolean streamingMode) {
144 this.streamingMode = streamingMode;
148 * Gets the delay in milliseconds before the plugin starts processing.
152 public long getStartDelay() {
157 * Sets the delay in milliseconds before the plugin starts processing.
159 * @param startDelay the delay
161 public void setStartDelay(final long startDelay) {
162 this.startDelay = startDelay;
168 * @see org.onap.policy.apex.service.parameters.carriertechnology.CarrierTechnologyParameters# toString()
171 public String toString() {
172 return "FILECarrierTechnologyParameters [fileName=" + fileName + ", standardIO=" + standardIo
173 + ", standardError=" + standardError + ", streamingMode=" + streamingMode + ", startDelay="
180 * @see org.onap.policy.common.parameters.ParameterGroup#getName()
183 public String getName() {
184 return this.getLabel();
190 * @see org.onap.policy.apex.apps.uservice.parameters.ApexParameterValidator#validate()
193 public GroupValidationResult validate() {
194 final GroupValidationResult result = super.validate();
196 if (!standardIo && !standardError && (fileName == null || fileName.trim().length() == 0)) {
197 result.setResult("fileName", ValidationStatus.INVALID, "fileName not specified or is blank or null, "
198 + "it must be specified as a valid file location");
201 if (standardIo || standardError) {
202 streamingMode = true;
205 if (startDelay < 0) {
206 result.setResult("startDelay", ValidationStatus.INVALID,
207 "startDelay must be zero or a positive number of milliseconds");