aboutsummaryrefslogtreecommitdiffstats
path: root/gui-editors
diff options
context:
space:
mode:
Diffstat (limited to 'gui-editors')
-rw-r--r--gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/ApexEditorMain.java48
1 files changed, 26 insertions, 22 deletions
diff --git a/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/ApexEditorMain.java b/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/ApexEditorMain.java
index 1d8f1d3..dd9710f 100644
--- a/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/ApexEditorMain.java
+++ b/gui-editors/gui-editor-apex/src/main/java/org/onap/policy/gui/editors/apex/rest/ApexEditorMain.java
@@ -29,7 +29,6 @@ import org.slf4j.ext.XLoggerFactory;
/**
* This class is the main class that is used to launch the Apex editor from the command line.
- *
*/
public class ApexEditorMain {
// Logger for this class
@@ -43,25 +42,33 @@ public class ApexEditorMain {
*/
// Editor state
public enum EditorState {
- /** The editor is stopped. */
+ /**
+ * The editor is stopped.
+ */
STOPPED,
- /** The editor is ready to run. */
+ /**
+ * The editor is ready to run.
+ */
READY,
- /** The editor is getting ready to run. */
+ /**
+ * The editor is getting ready to run.
+ */
INITIALIZING,
- /** The editor is running. */
+ /**
+ * The editor is running.
+ */
RUNNING
}
private static final int EDITOR_RNNING_CHECK_TIMEOUT = 1000;
- private EditorState state = EditorState.STOPPED;
+ private EditorState state;
// The Apex editor this class is running
private ApexEditor apexEditor = null;
// The parameters for the editor
- private static AtomicReference<ApexEditorParameters> parameters = new AtomicReference<>();
+ private static final AtomicReference<ApexEditorParameters> parameters = new AtomicReference<>();
// Output and error streams for messages
private final PrintStream outStream;
@@ -83,7 +90,7 @@ public class ApexEditorMain {
// Get and check the parameters
parameters.set(parser.parse(args));
} catch (final ApexEditorParameterException e) {
- throw new ApexEditorParameterException(REST_ENDPOINT_PREFIX + this.toString() + ") parameter error, "
+ throw new ApexEditorParameterException(REST_ENDPOINT_PREFIX + this + ") parameter error, "
+ e.getMessage() + '\n' + parser.getHelp(ApexEditorMain.class.getName()), e);
}
if (parameters.get().isHelp()) {
@@ -93,7 +100,7 @@ public class ApexEditorMain {
// Validate the parameters
final String validationMessage = parameters.get().validate();
if (validationMessage.length() > 0) {
- throw new ApexEditorParameterException(REST_ENDPOINT_PREFIX + this.toString() + ") parameters invalid, "
+ throw new ApexEditorParameterException(REST_ENDPOINT_PREFIX + this + ") parameters invalid, "
+ validationMessage + '\n' + parser.getHelp(ApexEditorMain.class.getName()));
}
@@ -104,8 +111,8 @@ public class ApexEditorMain {
* Initialize the Apex editor.
*/
public void init() {
- outStream.println(REST_ENDPOINT_PREFIX + this.toString() + ") starting at "
- + parameters.get().getBaseUri().toString() + " . . .");
+ outStream.println(REST_ENDPOINT_PREFIX + this + ") starting at "
+ + parameters.get().getBaseUri().toString() + " . . .");
try {
state = EditorState.INITIALIZING;
@@ -119,10 +126,10 @@ public class ApexEditorMain {
state = EditorState.RUNNING;
if (parameters.get().getTimeToLive() == ApexEditorParameters.INFINITY_TIME_TO_LIVE) {
- outStream.println(REST_ENDPOINT_PREFIX + this.toString() + ") started at "
- + parameters.get().getBaseUri().toString());
+ outStream.println(REST_ENDPOINT_PREFIX + this + ") started at "
+ + parameters.get().getBaseUri().toString());
} else {
- outStream.println(REST_ENDPOINT_PREFIX + this.toString() + ") started");
+ outStream.println(REST_ENDPOINT_PREFIX + this + ") started");
}
// Find out how long is left to wait
@@ -137,7 +144,7 @@ public class ApexEditorMain {
Thread.sleep(EDITOR_RNNING_CHECK_TIMEOUT);
}
} catch (final Exception e) {
- String message = REST_ENDPOINT_PREFIX + this.toString() + ") failed at with error: " + e.getMessage();
+ String message = REST_ENDPOINT_PREFIX + this + ") failed at with error: " + e.getMessage();
outStream.println(message);
LOGGER.warn(message, e);
} finally {
@@ -163,10 +170,7 @@ public class ApexEditorMain {
*/
@Override
public String toString() {
- final StringBuilder ret = new StringBuilder();
- ret.append(this.getClass().getSimpleName()).append(": Config=[").append(parameters).append("], State=")
- .append(this.getState());
- return ret.toString();
+ return this.getClass().getSimpleName() + ": Config=[" + parameters + "], State=" + this.getState();
}
/**
@@ -174,11 +178,11 @@ public class ApexEditorMain {
*/
public void shutdown() {
if (apexEditor != null) {
- outStream.println(REST_ENDPOINT_PREFIX + this.toString() + ") shutting down");
+ outStream.println(REST_ENDPOINT_PREFIX + this + ") shutting down");
apexEditor.shutdown();
}
state = EditorState.STOPPED;
- outStream.println(REST_ENDPOINT_PREFIX + this.toString() + ") shut down");
+ outStream.println(REST_ENDPOINT_PREFIX + this + ") shut down");
}
/**
@@ -212,7 +216,7 @@ public class ApexEditorMain {
*/
public static void main(final String[] args) {
try {
- final ApexEditorMain editorMain = new ApexEditorMain(args, null);
+ final ApexEditorMain editorMain = new ApexEditorMain(args, System.out);
editorMain.init();
} catch (final Exception e) {
LOGGER.error("start failed", e);