From 0e23f7634e1e1fb31454c516974613335fcea1a4 Mon Sep 17 00:00:00 2001 From: liamfallon Date: Wed, 12 Sep 2018 23:29:25 +0100 Subject: Sonar/Checkstyle in model/context/core Checkstyle and sonar changes in the model, contexot and core modules. Issue-ID: POLICY-1034 Change-Id: I2d40bc877f3a548844470fc290fc89d63fa465ae Signed-off-by: liamfallon --- .../infrastructure/java/JavaHandlingException.java | 12 +- .../infrastructure/java/classes/ClassUtils.java | 41 +++--- .../compile/singleclass/SingleClassBuilder.java | 24 ++-- .../singleclass/SingleClassByteCodeFileObject.java | 2 +- .../compile/singleclass/SingleFileManager.java | 2 +- .../infrastructure/messaging/MessageHolder.java | 15 +- .../infrastructure/messaging/MessageListener.java | 6 +- .../infrastructure/messaging/MessagingService.java | 10 +- .../messaging/MessagingServiceFactory.java | 8 +- .../messaging/impl/ws/RawMessageHandler.java | 67 ++++----- .../impl/ws/WebSocketMessageListener.java | 8 +- .../impl/ws/client/InternalMessageBusClient.java | 16 +-- .../messaging/impl/ws/client/MessagingClient.java | 12 +- .../impl/ws/messageblock/MessageBlock.java | 10 +- .../impl/ws/messageblock/MessageBlockHandler.java | 12 +- .../impl/ws/server/InternalMessageBusServer.java | 36 ++--- .../impl/ws/server/MessageServerImpl.java | 31 ++--- .../stringmessaging/WSStringMessageClient.java | 147 -------------------- .../stringmessaging/WSStringMessageListener.java | 36 ----- .../stringmessaging/WSStringMessageServer.java | 150 -------------------- .../stringmessaging/WSStringMessager.java | 51 ------- .../stringmessaging/WsStringMessageClient.java | 153 +++++++++++++++++++++ .../stringmessaging/WsStringMessageListener.java | 36 +++++ .../stringmessaging/WsStringMessageServer.java | 150 ++++++++++++++++++++ .../stringmessaging/WsStringMessager.java | 51 +++++++ .../messaging/util/MessagingUtils.java | 11 +- .../messaging/EndToEndStringMessagingTest.java | 22 +-- .../infrastructure/messaging/StringTestServer.java | 45 +++++- 28 files changed, 597 insertions(+), 567 deletions(-) delete mode 100644 core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/messaging/stringmessaging/WSStringMessageClient.java delete mode 100644 core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/messaging/stringmessaging/WSStringMessageListener.java delete mode 100644 core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/messaging/stringmessaging/WSStringMessageServer.java delete mode 100644 core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/messaging/stringmessaging/WSStringMessager.java create mode 100644 core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/messaging/stringmessaging/WsStringMessageClient.java create mode 100644 core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/messaging/stringmessaging/WsStringMessageListener.java create mode 100644 core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/messaging/stringmessaging/WsStringMessageServer.java create mode 100644 core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/messaging/stringmessaging/WsStringMessager.java (limited to 'core/core-infrastructure/src') diff --git a/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/java/JavaHandlingException.java b/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/java/JavaHandlingException.java index f6ef68105..63bd1c477 100644 --- a/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/java/JavaHandlingException.java +++ b/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/java/JavaHandlingException.java @@ -40,19 +40,19 @@ public class JavaHandlingException extends Exception { /** * Instantiates a new Java handling exception. * - * @param e the exception to wrap + * @param exception the exception to wrap */ - public JavaHandlingException(final Exception e) { - super(e); + public JavaHandlingException(final Exception exception) { + super(exception); } /** * Instantiates a new Java handling exception. * * @param message the message - * @param e the exception to wrap + * @param exception the exception to wrap */ - public JavaHandlingException(final String message, final Exception e) { - super(message, e); + public JavaHandlingException(final String message, final Exception exception) { + super(message, exception); } } diff --git a/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/java/classes/ClassUtils.java b/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/java/classes/ClassUtils.java index 919d1b122..16a3369fb 100644 --- a/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/java/classes/ClassUtils.java +++ b/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/java/classes/ClassUtils.java @@ -22,6 +22,7 @@ package org.onap.policy.apex.core.infrastructure.java.classes; import java.io.File; import java.io.FileInputStream; +import java.io.IOException; import java.io.InputStream; import java.lang.reflect.Method; import java.net.URL; @@ -44,6 +45,9 @@ public abstract class ClassUtils { // Get a reference to the logger private static final XLogger LOGGER = XLoggerFactory.getXLogger(ClassUtils.class); + // Repeated string constants + private static final String CLASS_PATTERN = "\\.class$"; + // The boot directory in Java for predefined JARs private static final String SUN_BOOT_LIBRARY_PATH = "sun.boot.library.path"; @@ -89,16 +93,13 @@ public abstract class ClassUtils { try { final Class nullclassloader = Class.forName("sun.misc.Launcher"); if (nullclassloader != null) { - // There a long way and a short way, Short way: causes a warning that cannot be suppressed - // URL[] moreurls = sun.misc.Launcher.getBootstrapClassPath().getURLs(); - // long way: - Method m = nullclassloader.getMethod("getBootstrapClassPath"); - if (m != null) { - final Object cp = m.invoke(null, (Object[]) null); + Method mmethod = nullclassloader.getMethod("getBootstrapClassPath"); + if (mmethod != null) { + final Object cp = mmethod.invoke(null, (Object[]) null); if (cp != null) { - m = cp.getClass().getMethod("getURLs"); - if (m != null) { - final URL[] moreurls = (URL[]) (m.invoke(cp, (Object[]) null)); + mmethod = cp.getClass().getMethod("getURLs"); + if (mmethod != null) { + final URL[] moreurls = (URL[]) (mmethod.invoke(cp, (Object[]) null)); if (moreurls != null && moreurls.length > 0) { if (urls.length == 0) { urls = moreurls; @@ -130,10 +131,8 @@ public abstract class ClassUtils { // JARs are processed as well else if (url.getFile().endsWith(".jar")) { classNameSet.addAll(processJar(urlFile)); - } else { - // It's a resource or some other non-executable thing - continue; } + // It's a resource or some other non-executable thing } } catch (final Exception e) { LOGGER.warn("could not get the names of Java classes", e); @@ -168,9 +167,7 @@ public abstract class ClassUtils { } else if (child.getName().endsWith(".class") && !child.getName().contains("$")) { // Process the ".class" file classNameSet.add( - child.getAbsolutePath().replace(rootDir, "").replaceFirst("\\.class$", "").replace('/', '.')); - } else { - continue; + child.getAbsolutePath().replace(rootDir, "").replaceFirst(CLASS_PATTERN, "").replace('/', '.')); } } return classNameSet; @@ -194,7 +191,7 @@ public abstract class ClassUtils { fileName = fileName.substring(classesPos + CLASSES_TOKEN.length()); } - return fileName.replaceFirst("\\.class$", "").replace('/', '.'); + return fileName.replaceFirst(CLASS_PATTERN, "").replace('/', '.'); } /** @@ -202,9 +199,9 @@ public abstract class ClassUtils { * * @param jarFile the JAR file * @return a set of class names - * @throws Exception on errors processing JARs + * @throws IOException on errors processing JARs */ - public static Set processJar(final File jarFile) throws Exception { + public static Set processJar(final File jarFile) throws IOException { // Pass the file as an input stream return processJar(new FileInputStream(jarFile.getAbsolutePath())); } @@ -214,9 +211,9 @@ public abstract class ClassUtils { * * @param jarInputStream the JAR input stream * @return a set of class names - * @throws Exception on errors processing JARs + * @throws IOException on errors processing JARs */ - public static Set processJar(final InputStream jarInputStream) throws Exception { + public static Set processJar(final InputStream jarInputStream) throws IOException { // The return set final TreeSet classPathSet = new TreeSet<>(); @@ -229,7 +226,7 @@ public abstract class ClassUtils { // Iterate over each entry in the JAR for (ZipEntry entry = zip.getNextEntry(); entry != null; entry = zip.getNextEntry()) { if (!entry.isDirectory() && entry.getName().endsWith(".class") && !entry.getName().contains("$")) { - classPathSet.add(entry.getName().replaceFirst("\\.class$", "").replace('/', '.')); + classPathSet.add(entry.getName().replaceFirst(CLASS_PATTERN, "").replace('/', '.')); } } zip.close(); @@ -243,7 +240,7 @@ public abstract class ClassUtils { */ public static void main(final String[] args) { for (final String clz : getClassNames()) { - System.out.println("Found class: " + clz); + LOGGER.info("Found class: {}", clz); } } } diff --git a/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/java/compile/singleclass/SingleClassBuilder.java b/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/java/compile/singleclass/SingleClassBuilder.java index 7a0b6048e..464a601e1 100644 --- a/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/java/compile/singleclass/SingleClassBuilder.java +++ b/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/java/compile/singleclass/SingleClassBuilder.java @@ -69,8 +69,8 @@ public class SingleClassBuilder { */ public void compile() throws JavaHandlingException { // Get the list of compilation units, there is only one here - final List compilationUnits = - Arrays.asList(new SingleClassCompilationUnit(className, sourceCode)); + final List compilationUnits = Arrays + .asList(new SingleClassCompilationUnit(className, sourceCode)); // Allows us to get diagnostics from the compilation final DiagnosticCollector diagnosticListener = new DiagnosticCollector<>(); @@ -80,8 +80,8 @@ public class SingleClassBuilder { // Set up the target file manager and call the compiler singleFileManager = new SingleFileManager(compiler, new SingleClassByteCodeFileObject(className)); - final JavaCompiler.CompilationTask task = - compiler.getTask(null, singleFileManager, diagnosticListener, null, null, compilationUnits); + final JavaCompiler.CompilationTask task = compiler.getTask(null, singleFileManager, diagnosticListener, null, + null, compilationUnits); // Check if the compilation worked if (!task.call()) { @@ -104,9 +104,9 @@ public class SingleClassBuilder { builder.append("\n"); } - LOGGER.warn("error compiling Java code for class \"" + className + "\": " + builder.toString()); - throw new JavaHandlingException( - "error compiling Java code for class \"" + className + "\": " + builder.toString()); + String message = "error compiling Java code for class \"" + className + "\": " + builder.toString(); + LOGGER.warn(message); + throw new JavaHandlingException(message); } } @@ -120,12 +120,12 @@ public class SingleClassBuilder { * @throws ClassNotFoundException the byte code for the class is not found in the class loader * @throws JavaHandlingException the java handling exception if the Java class source code is not compiled */ - public Object createObject() - throws InstantiationException, IllegalAccessException, ClassNotFoundException, JavaHandlingException { + public Object createObject() throws InstantiationException, IllegalAccessException, ClassNotFoundException, + JavaHandlingException { if (singleFileManager == null) { - LOGGER.warn("error instantiating instance for class \"" + className + "\": code may not be compiled"); - throw new JavaHandlingException( - "error instantiating instance for class \"" + className + "\": code may not be compiled"); + String message = "error instantiating instance for class \"" + className + "\": code may not be compiled"; + LOGGER.warn(message); + throw new JavaHandlingException(message); } return singleFileManager.getClassLoader(null).findClass(className).newInstance(); diff --git a/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/java/compile/singleclass/SingleClassByteCodeFileObject.java b/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/java/compile/singleclass/SingleClassByteCodeFileObject.java index 4b7225267..043657854 100644 --- a/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/java/compile/singleclass/SingleClassByteCodeFileObject.java +++ b/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/java/compile/singleclass/SingleClassByteCodeFileObject.java @@ -35,7 +35,7 @@ import javax.tools.SimpleJavaFileObject; * basis for {@code JavaFileObject} implementations. Subclasses can override the implementation and specification of any * method of this class as long as the general contract of {@code JavaFileObject} is obeyed. * - * This class holds the byte code for a single class in memory. + *

This class holds the byte code for a single class in memory. * * @author Liam Fallon (liam.fallon@ericsson.com) */ diff --git a/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/java/compile/singleclass/SingleFileManager.java b/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/java/compile/singleclass/SingleFileManager.java index cd14b1a06..066765504 100644 --- a/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/java/compile/singleclass/SingleFileManager.java +++ b/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/java/compile/singleclass/SingleFileManager.java @@ -34,7 +34,7 @@ import javax.tools.StandardJavaFileManager; * is an implementation of {@code JavaFileManager} that forwards the {@code JavaFileManager} methods to a given file * manager. * - * This class instantiates and forwards those requests to a {@link StandardJavaFileManager} instance to act as a + *

This class instantiates and forwards those requests to a {@link StandardJavaFileManager} instance to act as a * {@code JavaFileManager} for a Java single file, managing class loading for the class. * * @author Liam Fallon (liam.fallon@ericsson.com) diff --git a/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/messaging/MessageHolder.java b/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/messaging/MessageHolder.java index f74ffa0b3..243e057be 100644 --- a/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/messaging/MessageHolder.java +++ b/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/messaging/MessageHolder.java @@ -33,9 +33,9 @@ import org.slf4j.ext.XLoggerFactory; * implementation. * * @author Sajeevan Achuthan (sajeevan.achuthan@ericsson.com) - * @param the generic type of message being handled by a message holder instance + * @param the generic type of message being handled by a message holder instance */ -public class MessageHolder implements Serializable { +public class MessageHolder implements Serializable { private static final int HASH_PRIME = 31; private static final int FOUR_BYTES = 32; @@ -50,7 +50,7 @@ public class MessageHolder implements Serializable { private final InetAddress senderHostAddress; // Sequence of message in the message holder - private final List messages; + private final List messages; /** * Constructor, create the message holder. @@ -69,7 +69,7 @@ public class MessageHolder implements Serializable { * * @return the messages */ - public List getMessages() { + public List getMessages() { return messages; } @@ -78,7 +78,7 @@ public class MessageHolder implements Serializable { * * @param message the message to add */ - public void addMessage(final MESSAGE message) { + public void addMessage(final M message) { if (!messages.contains(message)) { messages.add(message); } else { @@ -160,9 +160,6 @@ public class MessageHolder implements Serializable { } else if (!messages.equals(other.messages)) { return false; } - if (creationTime != other.creationTime) { - return false; - } - return true; + return creationTime == other.creationTime; } } diff --git a/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/messaging/MessageListener.java b/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/messaging/MessageListener.java index c8b132423..0aab650d3 100644 --- a/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/messaging/MessageListener.java +++ b/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/messaging/MessageListener.java @@ -27,16 +27,16 @@ import org.onap.policy.apex.core.infrastructure.messaging.impl.ws.messageblock.M * implements this interface. * * @author Sajeevan Achuthan (sajeevan.achuthan@ericsson.com) - * @param of message of any given type that is being listened for and handled + * @param of message of any given type that is being listened for and handled */ -public interface MessageListener { +public interface MessageListener { /** * This method is called when a message block is received on a web socket and is to be forwarded to a listener. * * @param data the message data containing a message */ - void onMessage(MessageBlock data); + void onMessage(MessageBlock data); /** * This method is called when a string message is received on a web socket and is to be forwarded to a listener. diff --git a/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/messaging/MessagingService.java b/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/messaging/MessagingService.java index 7e91b95ea..352e70806 100644 --- a/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/messaging/MessagingService.java +++ b/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/messaging/MessagingService.java @@ -25,9 +25,9 @@ package org.onap.policy.apex.core.infrastructure.messaging; * messaging. * * @author Sajeevan Achuthan (sajeevan.achuthan@ericsson.com) - * @param the type of message being passed by an implementation of Apex messaging + * @param the type of message being passed by an implementation of Apex messaging */ -public interface MessagingService { +public interface MessagingService { /** * Start the messaging connection. @@ -51,7 +51,7 @@ public interface MessagingService { * * @param messageHolder The message holder holding the messages to be sent */ - void send(MessageHolder messageHolder); + void send(MessageHolder messageHolder); /** * Send a string message on the connection. @@ -65,12 +65,12 @@ public interface MessagingService { * * @param messageListener the message listener */ - void addMessageListener(MessageListener messageListener); + void addMessageListener(MessageListener messageListener); /** * Removes the message listener. * * @param messageListener the message listener */ - void removeMessageListener(MessageListener messageListener); + void removeMessageListener(MessageListener messageListener); } diff --git a/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/messaging/MessagingServiceFactory.java b/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/messaging/MessagingServiceFactory.java index 1d08fac74..b38b32f0e 100644 --- a/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/messaging/MessagingServiceFactory.java +++ b/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/messaging/MessagingServiceFactory.java @@ -30,9 +30,9 @@ import org.onap.policy.apex.core.infrastructure.messaging.impl.ws.server.Message * A factory class to create a "server" or "client" type Messaging Service. * * @author Sajeevan Achuthan (sajeevan.achuthan@ericsson.com) - * @param the generic type of message to be handled by this messaging service + * @param the generic type of message to be handled by this messaging service */ -public class MessagingServiceFactory { +public class MessagingServiceFactory { /** * Create a web socket server instance and returns to the caller. @@ -40,7 +40,7 @@ public class MessagingServiceFactory { * @param address the address of the server machine * @return the messaging service */ - public MessagingService createServer(final InetSocketAddress address) { + public MessagingService createServer(final InetSocketAddress address) { return new MessageServerImpl<>(address); } @@ -50,7 +50,7 @@ public class MessagingServiceFactory { * @param uri the URI of the server to connect to * @return an instance of {@link MessagingService} */ - public MessagingService createClient(final URI uri) { + public MessagingService createClient(final URI uri) { if (uri == null) { throw new IllegalArgumentException("URI cannot be null"); } diff --git a/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/messaging/impl/ws/RawMessageHandler.java b/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/messaging/impl/ws/RawMessageHandler.java index 7e9a31a4f..e0bf0ea6b 100644 --- a/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/messaging/impl/ws/RawMessageHandler.java +++ b/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/messaging/impl/ws/RawMessageHandler.java @@ -20,6 +20,8 @@ package org.onap.policy.apex.core.infrastructure.messaging.impl.ws; +import com.google.common.eventbus.Subscribe; + import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.ObjectInputStream; @@ -38,19 +40,20 @@ import org.onap.policy.apex.core.infrastructure.threading.ThreadUtilities; import org.slf4j.ext.XLogger; import org.slf4j.ext.XLoggerFactory; -import com.google.common.eventbus.Subscribe; - /** - * The Class RawMessageHandler handles raw messages being received on a Java web socket and forwards - * the messages to the DataHandler instance that has subscribed to the RawMessageHandler instance. + * The Class RawMessageHandler handles raw messages being received on a Java web socket and forwards the messages to the + * DataHandler instance that has subscribed to the RawMessageHandler instance. * * @author Sajeevan Achuthan (sajeevan.achuthan@ericsson.com) - * @param the generic type of message being received + * @param the generic type of message being received */ -public class RawMessageHandler implements WebSocketMessageListener, Runnable { +public class RawMessageHandler implements WebSocketMessageListener, Runnable { // The logger for this class private static final XLogger LOGGER = XLoggerFactory.getXLogger(RawMessageHandler.class); + // Repeated string constants + private static final String RAW_MESSAGE_LISTENING_INTERRUPTED = "raw message listening has been interrupted"; + // The amount of time to sleep during shutdown for the thread of this message handler to stop private static final int SHUTDOWN_WAIT_TIME = 10; @@ -58,13 +61,13 @@ public class RawMessageHandler implements WebSocketMessageListener> messageBlockQueue = new LinkedBlockingDeque<>(); + private final BlockingQueue> messageBlockQueue = new LinkedBlockingDeque<>(); // A queue that temporarily holds message blocks private final BlockingQueue stringMessageQueue = new LinkedBlockingDeque<>(); // Client applications that have subscribed for messages - private final MessageBlockHandler dataHandler = new MessageBlockHandler("data-processor"); + private final MessageBlockHandler dataHandler = new MessageBlockHandler<>("data-processor"); // The thread that the raw message handler is receiving messages on private Thread thisThread = null; @@ -90,19 +93,19 @@ public class RawMessageHandler implements WebSocketMessageListener messageHolder = (MessageHolder) ois.readObject(); + final MessageHolder messageHolder = (MessageHolder) ois.readObject(); if (LOGGER.isDebugEnabled()) { LOGGER.debug("message {} recieved from the client {} ", messageHolder, - messageHolder == null ? "Apex Engine " : messageHolder.getSenderHostAddress()); + messageHolder == null ? "Apex Engine " : messageHolder.getSenderHostAddress()); } if (messageHolder != null) { - final List messages = messageHolder.getMessages(); + final List messages = messageHolder.getMessages(); if (messages != null) { - messageBlockQueue.add(new MessageBlock(messages, incomingData.getConn())); + messageBlockQueue.add(new MessageBlock(messages, incomingData.getConn())); } } } catch (final IOException | ClassNotFoundException e) { @@ -112,8 +115,7 @@ public class RawMessageHandler implements WebSocketMessageListener implements WebSocketMessageListener data) { + throw new UnsupportedOperationException("this operation is not supported"); + } + /** * This thread monitors the message queue and processes messages as they appear on the queue. * @@ -143,14 +155,14 @@ public class RawMessageHandler implements WebSocketMessageListener messageBlock = null; + MessageBlock messageBlock = null; while ((messageBlock = messageBlockQueue.poll(1, TimeUnit.MILLISECONDS)) != null) { dataHandler.post(messageBlock); } } catch (final InterruptedException e) { // restore the interrupt status Thread.currentThread().interrupt(); - LOGGER.debug("raw message listening has been interrupted"); + LOGGER.debug(RAW_MESSAGE_LISTENING_INTERRUPTED); break; } @@ -163,7 +175,7 @@ public class RawMessageHandler implements WebSocketMessageListener implements WebSocketMessageListener implements WebSocketMessageListener data) { - throw new UnsupportedOperationException("this operation is not supported"); - } - /** * Register a data forwarder to which messages coming in on the web socket will be forwarded. * * @param listener The listener to register */ @Override - public void registerDataForwarder(final MessageListener listener) { + public void registerDataForwarder(final MessageListener listener) { stateCheck(listener); dataHandler.registerMessageHandler(listener); } @@ -226,7 +227,7 @@ public class RawMessageHandler implements WebSocketMessageListener listener) { + public void unRegisterDataForwarder(final MessageListener listener) { stateCheck(listener); dataHandler.unRegisterMessageHandler(listener); } @@ -236,7 +237,7 @@ public class RawMessageHandler implements WebSocketMessageListener listener) { + private void stateCheck(final MessageListener listener) { if (listener == null) { throw new IllegalArgumentException("The listener object cannot be null"); } diff --git a/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/messaging/impl/ws/WebSocketMessageListener.java b/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/messaging/impl/ws/WebSocketMessageListener.java index aa951b4ec..529e887e4 100644 --- a/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/messaging/impl/ws/WebSocketMessageListener.java +++ b/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/messaging/impl/ws/WebSocketMessageListener.java @@ -30,10 +30,10 @@ import org.onap.policy.apex.core.infrastructure.messaging.impl.ws.messageblock.R * object's appropriate method is invoked. * * @author Sajeevan Achuthan (sajeevan.achuthan@ericsson.com) - * @param the generic type + * @param the generic type * @see RawMessageBlock */ -public interface WebSocketMessageListener extends MessageListener, Runnable { +public interface WebSocketMessageListener extends MessageListener, Runnable { /** * This method is called by the class with which this message listener has been registered. @@ -47,12 +47,12 @@ public interface WebSocketMessageListener extends MessageListener listener); + void registerDataForwarder(MessageListener listener); /** * Unregister a data forwarder that was previously registered on the web socket listener. * * @param listener The listener to unregister */ - void unRegisterDataForwarder(MessageListener listener); + void unRegisterDataForwarder(MessageListener listener); } diff --git a/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/messaging/impl/ws/client/InternalMessageBusClient.java b/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/messaging/impl/ws/client/InternalMessageBusClient.java index 9f7f89d8c..17391fb89 100644 --- a/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/messaging/impl/ws/client/InternalMessageBusClient.java +++ b/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/messaging/impl/ws/client/InternalMessageBusClient.java @@ -36,9 +36,9 @@ import org.slf4j.ext.XLoggerFactory; * receive messages on the web socket. * * @author Sajeevan Achuthan (sajeevan.achuthan@ericsson.com) - * @param the generic type of message being handled + * @param the generic type of message being handled */ -abstract class InternalMessageBusClient extends WebSocketClientImpl { +abstract class InternalMessageBusClient extends WebSocketClientImpl { private static final int THREAD_FACTORY_STACK_SIZE = 256; // The logger for this class @@ -48,15 +48,15 @@ abstract class InternalMessageBusClient extends WebSocketClientImpl { private static final String RAW_EVENT_BUS = "Raw-Event-Bus"; // This instance handles the raw data received from the web socket - private final RawMessageHandler rawMessageHandler = new RawMessageHandler<>(); + private final RawMessageHandler rawMessageHandler = new RawMessageHandler<>(); // The message block handler to which to pass messages coming in on this client - private MessageBlockHandler messageBlockHandler = null; + private MessageBlockHandler messageBlockHandler = null; // The raw message handler uses a thread to process incoming events off a queue, this class owns and controls that // thread. These fields hold the thread and // the thread factory for creating threads. - private ApplicationThreadFactory tFactory = + private ApplicationThreadFactory threadFactory = new ApplicationThreadFactory("ws-client-thread", THREAD_FACTORY_STACK_SIZE); private Thread forwarderThread = null; @@ -75,7 +75,7 @@ abstract class InternalMessageBusClient extends WebSocketClientImpl { messageBlockHandler.registerMessageHandler(rawMessageHandler); // Create the thread that manages the queue in the data handler - forwarderThread = tFactory.newThread(rawMessageHandler); + forwarderThread = threadFactory.newThread(rawMessageHandler); forwarderThread.start(); LOGGER.exit(); @@ -109,7 +109,7 @@ abstract class InternalMessageBusClient extends WebSocketClientImpl { * * @param listener a simple class, that listens for the events from Event */ - public void addMessageListener(final MessageListener listener) { + public void addMessageListener(final MessageListener listener) { rawMessageHandler.registerDataForwarder(listener); } @@ -118,7 +118,7 @@ abstract class InternalMessageBusClient extends WebSocketClientImpl { * * @param listener the listener */ - public void removeMessageListener(final MessageListener listener) { + public void removeMessageListener(final MessageListener listener) { rawMessageHandler.unRegisterDataForwarder(listener); } diff --git a/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/messaging/impl/ws/client/MessagingClient.java b/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/messaging/impl/ws/client/MessagingClient.java index 36ad3b163..dd9aac122 100644 --- a/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/messaging/impl/ws/client/MessagingClient.java +++ b/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/messaging/impl/ws/client/MessagingClient.java @@ -33,9 +33,9 @@ import org.onap.policy.apex.core.infrastructure.threading.ThreadUtilities; * message reception on the client side of a web socket in Apex. * * @author Sajeevan Achuthan (sajeevan.achuthan@ericsson.com) - * @param the generic type + * @param the generic type */ -public class MessagingClient extends InternalMessageBusClient implements MessagingService { +public class MessagingClient extends InternalMessageBusClient implements MessagingService { // The length of time to wait for a connection to a web socket server before aborting private static final int CONNECTION_TIMEOUT_TIME_MS = 3000; @@ -102,7 +102,7 @@ public class MessagingClient extends InternalMessageBusClient */ private boolean waitforConnection(final WebSocket connection) { // The total time we have before timeout - int timeoutMSCounter = CONNECTION_TIMEOUT_TIME_MS; + int timeoutMsCounter = CONNECTION_TIMEOUT_TIME_MS; // Check the connection state do { @@ -112,7 +112,7 @@ public class MessagingClient extends InternalMessageBusClient case CLOSING: // Not connected yet so wait for the try interval ThreadUtilities.sleep(CONNECTION_TRY_INTERVAL_MS); - timeoutMSCounter -= CONNECTION_TRY_INTERVAL_MS; + timeoutMsCounter -= CONNECTION_TRY_INTERVAL_MS; break; case OPEN: // Connection is open, happy days @@ -125,7 +125,7 @@ public class MessagingClient extends InternalMessageBusClient } } // While the timeout value has not expired - while (timeoutMSCounter > 0); + while (timeoutMsCounter > 0); // We have timed out return false; @@ -139,7 +139,7 @@ public class MessagingClient extends InternalMessageBusClient * .core. infrastructure. messaging.MessageHolder) */ @Override - public void send(final MessageHolder commands) { + public void send(final MessageHolder commands) { // Get the connection and send the message final WebSocket connection = super.getConnection(); connection.send(MessagingUtils.serializeObject(commands)); diff --git a/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/messaging/impl/ws/messageblock/MessageBlock.java b/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/messaging/impl/ws/messageblock/MessageBlock.java index 70b1d2c3a..1c6852686 100644 --- a/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/messaging/impl/ws/messageblock/MessageBlock.java +++ b/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/messaging/impl/ws/messageblock/MessageBlock.java @@ -28,12 +28,12 @@ import org.java_websocket.WebSocket; * This class encapsulate messages and the web socket on which they are handled. * * @author Sajeevan Achuthan (sajeevan.achuthan@ericsson.com) - * @param the generic type of message being handled + * @param the generic type of message being handled */ -public final class MessageBlock { +public final class MessageBlock { // List of Messages received on a web socket - private final List messages; + private final List messages; // The web socket on which the messages are handled private final WebSocket webSocket; @@ -44,7 +44,7 @@ public final class MessageBlock { * @param messages the messages in the message block * @param webSocket the web socket used to handle the message block */ - public MessageBlock(final List messages, final WebSocket webSocket) { + public MessageBlock(final List messages, final WebSocket webSocket) { this.messages = messages; this.webSocket = webSocket; } @@ -54,7 +54,7 @@ public final class MessageBlock { * * @return the messages */ - public List getMessages() { + public List getMessages() { return messages; } diff --git a/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/messaging/impl/ws/messageblock/MessageBlockHandler.java b/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/messaging/impl/ws/messageblock/MessageBlockHandler.java index 4265718db..123305b07 100644 --- a/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/messaging/impl/ws/messageblock/MessageBlockHandler.java +++ b/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/messaging/impl/ws/messageblock/MessageBlockHandler.java @@ -31,9 +31,9 @@ import org.slf4j.ext.XLoggerFactory; * event bus. * * @author Sajeevan Achuthan (sajeevan.achuthan@ericsson.com) - * @param the generic type + * @param the generic type */ -public class MessageBlockHandler { +public class MessageBlockHandler { // Logger for this class private static final XLogger LOGGER = XLoggerFactory.getXLogger(MessageBlockHandler.class); @@ -72,7 +72,7 @@ public class MessageBlockHandler { * * @param messageBlock the block containing typed messages */ - public void post(final MessageBlock messageBlock) { + public void post(final MessageBlock messageBlock) { if (messageBlock.getMessages() != null) { if (LOGGER.isDebugEnabled()) { LOGGER.debug("new data message recieved from {}", messageBlock.getConnection() == null ? "server" @@ -90,7 +90,7 @@ public class MessageBlockHandler { public void post(final String messageString) { if (messageString != null) { if (LOGGER.isDebugEnabled()) { - LOGGER.debug("new string message recieved from server: " + messageString); + LOGGER.debug("new string message recieved from server: {}", messageString); } eventBus.post(messageString); } @@ -101,7 +101,7 @@ public class MessageBlockHandler { * * @param listener is an instance of WebSocketMessageListener */ - public void registerMessageHandler(final MessageListener listener) { + public void registerMessageHandler(final MessageListener listener) { LOGGER.entry(listener); if (listener == null) { throw new IllegalArgumentException("listener object cannot be null"); @@ -116,7 +116,7 @@ public class MessageBlockHandler { * * @param listener the listener */ - public void unRegisterMessageHandler(final MessageListener listener) { + public void unRegisterMessageHandler(final MessageListener listener) { if (listener == null) { throw new IllegalArgumentException("listener object cannot be null"); } diff --git a/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/messaging/impl/ws/server/InternalMessageBusServer.java b/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/messaging/impl/ws/server/InternalMessageBusServer.java index 8e65bbf98..a436bd7e3 100644 --- a/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/messaging/impl/ws/server/InternalMessageBusServer.java +++ b/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/messaging/impl/ws/server/InternalMessageBusServer.java @@ -38,9 +38,9 @@ import org.slf4j.ext.XLoggerFactory; * receive messages on the web socket. * * @author Sajeevan Achuthan (sajeevan.achuthan@ericsson.com) - * @param the generic type + * @param the generic type */ -abstract class InternalMessageBusServer extends WebSocketServerImpl implements MessagingService { +abstract class InternalMessageBusServer extends WebSocketServerImpl implements MessagingService { // Logger for this class private static final XLogger LOGGER = XLoggerFactory.getXLogger(InternalMessageBusServer.class); @@ -50,15 +50,15 @@ abstract class InternalMessageBusServer extends WebSocketServerImpl imp private static final String RAW_EVENT_BUS = "Raw-Event-Bus"; // This instance handles the raw data received from the web socket - private final RawMessageHandler rawMessageHandler = new RawMessageHandler<>(); + private final RawMessageHandler rawMessageHandler = new RawMessageHandler<>(); // The message block handler to which to pass messages coming in on this client - private MessageBlockHandler messageBlockHandler = null; + private MessageBlockHandler messageBlockHandler = null; // The raw message handler uses a thread to process incoming events off a queue, this class owns and controls that // thread. These fields hold the thread and // the thread factory for creating threads. - private ApplicationThreadFactory tFactory = + private ApplicationThreadFactory threadFactory = new ApplicationThreadFactory("ws-server-thread", THREAD_FACTORY_STACK_SIZE); private Thread forwarderThread = null; @@ -77,7 +77,7 @@ abstract class InternalMessageBusServer extends WebSocketServerImpl imp messageBlockHandler.registerMessageHandler(rawMessageHandler); // Create the thread that manages the queue in the data handler - forwarderThread = tFactory.newThread(rawMessageHandler); + forwarderThread = threadFactory.newThread(rawMessageHandler); forwarderThread.start(); LOGGER.exit(); @@ -95,13 +95,23 @@ abstract class InternalMessageBusServer extends WebSocketServerImpl imp messageBlockHandler.post(new RawMessageBlock(rawMessage, webSocket)); } + /* + * (non-Javadoc) + * + * @see org.java_websocket.server.WebSocketServer#onMessage(org.java_websocket.WebSocket, java.lang.String) + */ + @Override + public void onMessage(final WebSocket webSocket, final String stringMessage) { + messageBlockHandler.post(stringMessage); + } + /** * Register a subscriber class to the raw message handler. * * @param subscriber the subscriber */ @Override - public void addMessageListener(final MessageListener subscriber) { + public void addMessageListener(final MessageListener subscriber) { rawMessageHandler.registerDataForwarder(subscriber); } @@ -111,20 +121,10 @@ abstract class InternalMessageBusServer extends WebSocketServerImpl imp * @param subscriber the subscriber */ @Override - public void removeMessageListener(final MessageListener subscriber) { + public void removeMessageListener(final MessageListener subscriber) { rawMessageHandler.unRegisterDataForwarder(subscriber); } - /* - * (non-Javadoc) - * - * @see org.java_websocket.server.WebSocketServer#onMessage(org.java_websocket.WebSocket, java.lang.String) - */ - @Override - public void onMessage(final WebSocket webSocket, final String stringMessage) { - messageBlockHandler.post(stringMessage); - } - /** * Stop the thread handling message forwarding. */ diff --git a/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/messaging/impl/ws/server/MessageServerImpl.java b/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/messaging/impl/ws/server/MessageServerImpl.java index 389d04dcc..d5ef40b5b 100644 --- a/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/messaging/impl/ws/server/MessageServerImpl.java +++ b/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/messaging/impl/ws/server/MessageServerImpl.java @@ -34,9 +34,9 @@ import org.slf4j.ext.XLoggerFactory; * A messaging server implementation using web socket. * * @author Sajeevan Achuthan (sajeevan.achuthan@ericsson.com) - * @param the generic type of message being passed + * @param the generic type of message being passed */ -public class MessageServerImpl extends InternalMessageBusServer { +public class MessageServerImpl extends InternalMessageBusServer { // The logger for this class private static final XLogger LOGGER = XLoggerFactory.getXLogger(MessageServerImpl.class); @@ -44,7 +44,7 @@ public class MessageServerImpl extends InternalMessageBusServer extends InternalMessageBusServer extends InternalMessageBusServer message) { + public void send(final MessageHolder message) { // Send the incoming message to all clients connected to this web socket final Collection connections = getConnections(); for (final WebSocket webSocket : connections) { @@ -137,8 +135,7 @@ public class MessageServerImpl extends InternalMessageBusServer extends InternalMessageBusServer factory = new MessagingServiceFactory<>(); - private MessagingService service = null; - - // The listener to use for reception of strings - private WSStringMessageListener wsStringMessageListener; - - // Address of the server - private final String host; - private final int port; - private String uriString; - - /** - * Constructor, define the host and port of the server to connect to. - * - * @param host the host of the server - * @param port the port of the server - */ - public WSStringMessageClient(final String host, final int port) { - this.host = host; - this.port = port; - } - - /* - * (non-Javadoc) - * - * @see - * org.onap.policy.apex.core.infrastructure.messaging.stringmessaging.WSStringMessageSender#start(org.onap.policy. - * apex. core.infrastructure.messaging. stringmessaging.WSStringMessageListener) - */ - @Override - public void start(final WSStringMessageListener newWsStringMessageListener) throws MessagingException { - this.wsStringMessageListener = newWsStringMessageListener; - - uriString = "ws://" + host + ":" + port; - LOGGER.entry("web socket event consumer client to \"" + uriString + "\" starting . . ."); - - try { - service = factory.createClient(new URI(uriString)); - service.addMessageListener(new WSStringMessageClientListener()); - service.startConnection(); - } catch (final Exception e) { - LOGGER.warn("web socket event consumer client to \"" + uriString + "\" start failed", e); - throw new MessagingException("web socket event consumer client to \"" + uriString + "\" start failed", e); - } - - LOGGER.exit("web socket event consumer client to \"" + uriString + "\" started"); - } - - /* - * (non-Javadoc) - * - * @see org.onap.policy.apex.core.infrastructure.messaging.stringmessaging.WSStringMessageSender#stop() - */ - @Override - public void stop() { - LOGGER.entry("web socket event consumer client to \"" + uriString + "\" stopping . . ."); - service.stopConnection(); - LOGGER.exit("web socket event consumer client to \"" + uriString + "\" stopped"); - } - - /* - * (non-Javadoc) - * - * @see - * org.onap.policy.apex.core.infrastructure.messaging.stringmessaging.WSStringMessageSender#sendString(java.lang. - * String) - */ - @Override - public void sendString(final String stringMessage) { - service.send(stringMessage); - - if (LOGGER.isDebugEnabled()) { - LOGGER.debug("message sent to server: " + stringMessage); - } - } - - /** - * The Class WSStringMessageClientListener. - */ - private class WSStringMessageClientListener implements MessageListener { - /* - * (non-Javadoc) - * - * @see org.onap.policy.apex.core.infrastructure.messaging.MessageListener#onMessage(org.onap.policy.apex.core. - * infrastructure.messaging.impl.ws.messageblock. MessageBlock) - */ - @Subscribe - @Override - public void onMessage(final MessageBlock messageBlock) { - throw new UnsupportedOperationException("raw messages are not supported on string message clients"); - } - - /* - * (non-Javadoc) - * - * @see org.onap.policy.apex.core.infrastructure.messaging.MessageListener#onMessage(java.lang.String) - */ - @Subscribe - @Override - public void onMessage(final String messageString) { - wsStringMessageListener.receiveString(messageString); - } - } -} diff --git a/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/messaging/stringmessaging/WSStringMessageListener.java b/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/messaging/stringmessaging/WSStringMessageListener.java deleted file mode 100644 index e524b43d7..000000000 --- a/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/messaging/stringmessaging/WSStringMessageListener.java +++ /dev/null @@ -1,36 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.apex.core.infrastructure.messaging.stringmessaging; - -/** - * This interface is used to call back the owner of a String Web socket message server or client. - * - * @author Liam Fallon (liam.fallon@ericsson.com) - */ -public interface WSStringMessageListener { - - /** - * Receive a string coming off a web socket. - * - * @param stringMessage the string message - */ - void receiveString(String stringMessage); -} diff --git a/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/messaging/stringmessaging/WSStringMessageServer.java b/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/messaging/stringmessaging/WSStringMessageServer.java deleted file mode 100644 index 4da478f6a..000000000 --- a/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/messaging/stringmessaging/WSStringMessageServer.java +++ /dev/null @@ -1,150 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.apex.core.infrastructure.messaging.stringmessaging; - -import com.google.common.eventbus.Subscribe; - -import java.net.InetAddress; -import java.net.InetSocketAddress; - -import org.onap.policy.apex.core.infrastructure.messaging.MessageListener; -import org.onap.policy.apex.core.infrastructure.messaging.MessagingException; -import org.onap.policy.apex.core.infrastructure.messaging.MessagingService; -import org.onap.policy.apex.core.infrastructure.messaging.MessagingServiceFactory; -import org.onap.policy.apex.core.infrastructure.messaging.impl.ws.messageblock.MessageBlock; -import org.onap.policy.apex.core.infrastructure.messaging.util.MessagingUtils; -import org.slf4j.ext.XLogger; -import org.slf4j.ext.XLoggerFactory; - -/** - * This class runs a web socket server for sending and receiving of strings over a web socket. - * - * @author Liam Fallon (liam.fallon@ericsson.com) - */ -public class WSStringMessageServer implements WSStringMessager { - private static final XLogger LOGGER = XLoggerFactory.getXLogger(WSStringMessageServer.class); - - // Message service factory and the message service itself - private final MessagingServiceFactory factory = new MessagingServiceFactory<>(); - private MessagingService service = null; - - // The listener to use for reception of strings - private WSStringMessageListener wsStringMessageListener; - - // Address of the server - private final int port; - - /** - * Constructor, define the port of the server. - * - * @param port the port of the server - */ - public WSStringMessageServer(final int port) { - this.port = port; - } - - /* - * (non-Javadoc) - * - * @see - * org.onap.policy.apex.core.infrastructure.messaging.stringmessaging.WSStringMessageSender#start(org.onap.policy. - * apex. core.infrastructure.messaging. stringmessaging.WSStringMessageListener) - */ - @Override - public void start(final WSStringMessageListener newWsStringMessageListener) throws MessagingException { - this.wsStringMessageListener = newWsStringMessageListener; - - LOGGER.entry("web socket event consumer server starting . . ."); - - try { - final InetAddress addrLan = MessagingUtils.getLocalHostLANAddress(); - LOGGER.debug("web socket string message server LAN address=" + addrLan.getHostAddress()); - final InetAddress addr = InetAddress.getLocalHost(); - LOGGER.debug("web socket string message server host address=" + addr.getHostAddress()); - - service = factory.createServer(new InetSocketAddress(port)); - service.addMessageListener(new WSStringMessageServerListener()); - - service.startConnection(); - } catch (final Exception e) { - LOGGER.warn("web socket string message server start failed", e); - throw new MessagingException("web socket string message start failed", e); - } - - LOGGER.exit("web socket string message server started"); - } - - /* - * (non-Javadoc) - * - * @see org.onap.policy.apex.core.infrastructure.messaging.stringmessaging.WSStringMessageSender#stop() - */ - @Override - public void stop() { - LOGGER.entry("web socket string message server stopping . . ."); - service.stopConnection(); - LOGGER.exit("web socket string message server stopped"); - } - - /* - * (non-Javadoc) - * - * @see - * org.onap.policy.apex.core.infrastructure.messaging.stringmessaging.WSStringMessageSender#sendString(java.lang. - * String) - */ - @Override - public void sendString(final String stringMessage) { - service.send(stringMessage); - if (LOGGER.isDebugEnabled()) { - LOGGER.debug("server sent message: " + stringMessage); - } - } - - /** - * The listener for strings coming into the server. - */ - private class WSStringMessageServerListener implements MessageListener { - - /* - * (non-Javadoc) - * - * @see org.onap.policy.apex.core.infrastructure.messaging.MessageListener#onMessage(org.onap.policy.apex.core. - * infrastructure.messaging.impl.ws.messageblock. MessageBlock) - */ - @Subscribe - @Override - public void onMessage(final MessageBlock messageBlock) { - throw new UnsupportedOperationException("raw messages are not supported on string message clients"); - } - - /* - * (non-Javadoc) - * - * @see org.onap.policy.apex.core.infrastructure.messaging.MessageListener#onMessage(java.lang.String) - */ - @Subscribe - @Override - public void onMessage(final String messageString) { - wsStringMessageListener.receiveString(messageString); - } - } -} diff --git a/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/messaging/stringmessaging/WSStringMessager.java b/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/messaging/stringmessaging/WSStringMessager.java deleted file mode 100644 index a2781e932..000000000 --- a/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/messaging/stringmessaging/WSStringMessager.java +++ /dev/null @@ -1,51 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.apex.core.infrastructure.messaging.stringmessaging; - -import org.onap.policy.apex.core.infrastructure.messaging.MessagingException; - -/** - * This interface is used to call a String Web socket message server or client to send a string. - * - * @author Liam Fallon (liam.fallon@ericsson.com) - */ -public interface WSStringMessager { - - /** - * Start the string message sender. - * - * @param wsStringMessageListener the listener to use for listening for string messages - * @throws MessagingException the messaging exception - */ - void start(WSStringMessageListener wsStringMessageListener) throws MessagingException; - - /** - * Stop the string messaging sender. - */ - void stop(); - - /** - * Send a string on a web socket. - * - * @param stringMessage the string message to send - */ - void sendString(String stringMessage); -} diff --git a/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/messaging/stringmessaging/WsStringMessageClient.java b/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/messaging/stringmessaging/WsStringMessageClient.java new file mode 100644 index 000000000..28afde03b --- /dev/null +++ b/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/messaging/stringmessaging/WsStringMessageClient.java @@ -0,0 +1,153 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.apex.core.infrastructure.messaging.stringmessaging; + +import com.google.common.eventbus.Subscribe; + +import java.net.URI; + +import org.onap.policy.apex.core.infrastructure.messaging.MessageListener; +import org.onap.policy.apex.core.infrastructure.messaging.MessagingException; +import org.onap.policy.apex.core.infrastructure.messaging.MessagingService; +import org.onap.policy.apex.core.infrastructure.messaging.MessagingServiceFactory; +import org.onap.policy.apex.core.infrastructure.messaging.impl.ws.messageblock.MessageBlock; +import org.slf4j.ext.XLogger; +import org.slf4j.ext.XLoggerFactory; + +/** + * This class uses a web socket client to send and receive strings over a web socket. + * + * @author Liam Fallon (liam.fallon@ericsson.com) + */ +public class WsStringMessageClient implements WsStringMessager { + private static final XLogger LOGGER = XLoggerFactory.getXLogger(WsStringMessageClient.class); + + // Repeated string constants + private static final String MESSAGE_PREAMBLE = "web socket event consumer client to \""; + + // Message service factory and the message service itself + private final MessagingServiceFactory factory = new MessagingServiceFactory<>(); + private MessagingService service = null; + + // The listener to use for reception of strings + private WsStringMessageListener wsStringMessageListener; + + // Address of the server + private final String host; + private final int port; + private String uriString; + + /** + * Constructor, define the host and port of the server to connect to. + * + * @param host the host of the server + * @param port the port of the server + */ + public WsStringMessageClient(final String host, final int port) { + this.host = host; + this.port = port; + } + + /* + * (non-Javadoc) + * + * @see + * org.onap.policy.apex.core.infrastructure.messaging.stringmessaging.WSStringMessageSender#start(org.onap.policy. + * apex. core.infrastructure.messaging. stringmessaging.WSStringMessageListener) + */ + @Override + public void start(final WsStringMessageListener newWsStringMessageListener) throws MessagingException { + this.wsStringMessageListener = newWsStringMessageListener; + + uriString = "ws://" + host + ":" + port; + String messagePreamble = MESSAGE_PREAMBLE + uriString + "\" "; + LOGGER.entry(messagePreamble + "starting . . ."); + + try { + service = factory.createClient(new URI(uriString)); + service.addMessageListener(new WsStringMessageClientListener()); + service.startConnection(); + } catch (final Exception e) { + String message = messagePreamble + "start failed"; + LOGGER.warn(message, e); + throw new MessagingException(message, e); + } + + LOGGER.exit(messagePreamble + "started"); + } + + /* + * (non-Javadoc) + * + * @see org.onap.policy.apex.core.infrastructure.messaging.stringmessaging.WSStringMessageSender#stop() + */ + @Override + public void stop() { + LOGGER.entry(MESSAGE_PREAMBLE + uriString + "\" stopping . . ."); + service.stopConnection(); + LOGGER.exit(MESSAGE_PREAMBLE + uriString + "\" stopped"); + } + + /* + * (non-Javadoc) + * + * @see + * org.onap.policy.apex.core.infrastructure.messaging.stringmessaging.WSStringMessageSender#sendString(java.lang. + * String) + */ + @Override + public void sendString(final String stringMessage) { + service.send(stringMessage); + + if (LOGGER.isDebugEnabled()) { + String message = "message sent to server: " + stringMessage; + LOGGER.debug(message); + } + } + + /** + * The Class WSStringMessageClientListener. + */ + private class WsStringMessageClientListener implements MessageListener { + /* + * (non-Javadoc) + * + * @see org.onap.policy.apex.core.infrastructure.messaging.MessageListener#onMessage(org.onap.policy.apex.core. + * infrastructure.messaging.impl.ws.messageblock. MessageBlock) + */ + @Subscribe + @Override + public void onMessage(final MessageBlock messageBlock) { + throw new UnsupportedOperationException("raw messages are not supported on string message clients"); + } + + /* + * (non-Javadoc) + * + * @see org.onap.policy.apex.core.infrastructure.messaging.MessageListener#onMessage(java.lang.String) + */ + @Subscribe + @Override + public void onMessage(final String messageString) { + wsStringMessageListener.receiveString(messageString); + } + } +} diff --git a/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/messaging/stringmessaging/WsStringMessageListener.java b/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/messaging/stringmessaging/WsStringMessageListener.java new file mode 100644 index 000000000..0a5e147cc --- /dev/null +++ b/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/messaging/stringmessaging/WsStringMessageListener.java @@ -0,0 +1,36 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.apex.core.infrastructure.messaging.stringmessaging; + +/** + * This interface is used to call back the owner of a String Web socket message server or client. + * + * @author Liam Fallon (liam.fallon@ericsson.com) + */ +public interface WsStringMessageListener { + + /** + * Receive a string coming off a web socket. + * + * @param stringMessage the string message + */ + void receiveString(String stringMessage); +} diff --git a/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/messaging/stringmessaging/WsStringMessageServer.java b/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/messaging/stringmessaging/WsStringMessageServer.java new file mode 100644 index 000000000..3e8db268c --- /dev/null +++ b/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/messaging/stringmessaging/WsStringMessageServer.java @@ -0,0 +1,150 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.apex.core.infrastructure.messaging.stringmessaging; + +import com.google.common.eventbus.Subscribe; + +import java.net.InetAddress; +import java.net.InetSocketAddress; + +import org.onap.policy.apex.core.infrastructure.messaging.MessageListener; +import org.onap.policy.apex.core.infrastructure.messaging.MessagingException; +import org.onap.policy.apex.core.infrastructure.messaging.MessagingService; +import org.onap.policy.apex.core.infrastructure.messaging.MessagingServiceFactory; +import org.onap.policy.apex.core.infrastructure.messaging.impl.ws.messageblock.MessageBlock; +import org.onap.policy.apex.core.infrastructure.messaging.util.MessagingUtils; +import org.slf4j.ext.XLogger; +import org.slf4j.ext.XLoggerFactory; + +/** + * This class runs a web socket server for sending and receiving of strings over a web socket. + * + * @author Liam Fallon (liam.fallon@ericsson.com) + */ +public class WsStringMessageServer implements WsStringMessager { + private static final XLogger LOGGER = XLoggerFactory.getXLogger(WsStringMessageServer.class); + + // Message service factory and the message service itself + private final MessagingServiceFactory factory = new MessagingServiceFactory<>(); + private MessagingService service = null; + + // The listener to use for reception of strings + private WsStringMessageListener wsStringMessageListener; + + // Address of the server + private final int port; + + /** + * Constructor, define the port of the server. + * + * @param port the port of the server + */ + public WsStringMessageServer(final int port) { + this.port = port; + } + + /* + * (non-Javadoc) + * + * @see + * org.onap.policy.apex.core.infrastructure.messaging.stringmessaging.WSStringMessageSender#start(org.onap.policy. + * apex. core.infrastructure.messaging. stringmessaging.WSStringMessageListener) + */ + @Override + public void start(final WsStringMessageListener newWsStringMessageListener) throws MessagingException { + this.wsStringMessageListener = newWsStringMessageListener; + + LOGGER.entry("web socket event consumer server starting . . ."); + + try { + final InetAddress addrLan = MessagingUtils.getLocalHostLanAddress(); + LOGGER.debug("web socket string message server LAN address=" + addrLan.getHostAddress()); + final InetAddress addr = InetAddress.getLocalHost(); + LOGGER.debug("web socket string message server host address=" + addr.getHostAddress()); + + service = factory.createServer(new InetSocketAddress(port)); + service.addMessageListener(new WsStringMessageServerListener()); + + service.startConnection(); + } catch (final Exception e) { + LOGGER.warn("web socket string message server start failed", e); + throw new MessagingException("web socket string message start failed", e); + } + + LOGGER.exit("web socket string message server started"); + } + + /* + * (non-Javadoc) + * + * @see org.onap.policy.apex.core.infrastructure.messaging.stringmessaging.WSStringMessageSender#stop() + */ + @Override + public void stop() { + LOGGER.entry("web socket string message server stopping . . ."); + service.stopConnection(); + LOGGER.exit("web socket string message server stopped"); + } + + /* + * (non-Javadoc) + * + * @see + * org.onap.policy.apex.core.infrastructure.messaging.stringmessaging.WSStringMessageSender#sendString(java.lang. + * String) + */ + @Override + public void sendString(final String stringMessage) { + service.send(stringMessage); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("server sent message: {}", stringMessage); + } + } + + /** + * The listener for strings coming into the server. + */ + private class WsStringMessageServerListener implements MessageListener { + + /* + * (non-Javadoc) + * + * @see org.onap.policy.apex.core.infrastructure.messaging.MessageListener#onMessage(org.onap.policy.apex.core. + * infrastructure.messaging.impl.ws.messageblock. MessageBlock) + */ + @Subscribe + @Override + public void onMessage(final MessageBlock messageBlock) { + throw new UnsupportedOperationException("raw messages are not supported on string message clients"); + } + + /* + * (non-Javadoc) + * + * @see org.onap.policy.apex.core.infrastructure.messaging.MessageListener#onMessage(java.lang.String) + */ + @Subscribe + @Override + public void onMessage(final String messageString) { + wsStringMessageListener.receiveString(messageString); + } + } +} diff --git a/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/messaging/stringmessaging/WsStringMessager.java b/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/messaging/stringmessaging/WsStringMessager.java new file mode 100644 index 000000000..2a731b0eb --- /dev/null +++ b/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/messaging/stringmessaging/WsStringMessager.java @@ -0,0 +1,51 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.apex.core.infrastructure.messaging.stringmessaging; + +import org.onap.policy.apex.core.infrastructure.messaging.MessagingException; + +/** + * This interface is used to call a String Web socket message server or client to send a string. + * + * @author Liam Fallon (liam.fallon@ericsson.com) + */ +public interface WsStringMessager { + + /** + * Start the string message sender. + * + * @param wsStringMessageListener the listener to use for listening for string messages + * @throws MessagingException the messaging exception + */ + void start(WsStringMessageListener wsStringMessageListener) throws MessagingException; + + /** + * Stop the string messaging sender. + */ + void stop(); + + /** + * Send a string on a web socket. + * + * @param stringMessage the string message to send + */ + void sendString(String stringMessage); +} diff --git a/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/messaging/util/MessagingUtils.java b/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/messaging/util/MessagingUtils.java index 66edd2f1d..a501a66d6 100644 --- a/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/messaging/util/MessagingUtils.java +++ b/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/messaging/util/MessagingUtils.java @@ -43,7 +43,7 @@ public final class MessagingUtils { private static final int LOWEST_USER_PORT = 1024; /** - * Port number is an unsigned 16-bit integer, so maximum port is 65535 + * Port number is an unsigned 16-bit integer, so maximum port is 65535. */ private static final int MAX_PORT_RANGE = 65535; @@ -71,7 +71,7 @@ public final class MessagingUtils { return port; } LOGGER.debug("Port {} is not available", port); - throw new RuntimeException("could not allocate requested port: " + port); + throw new IllegalArgumentException("could not allocate requested port: " + port); } /** @@ -96,7 +96,7 @@ public final class MessagingUtils { LOGGER.debug("Port {} is not available", availablePort); availablePort++; } - throw new RuntimeException("could not find free available"); + throw new IllegalArgumentException("could not find free available"); } /** @@ -149,7 +149,7 @@ public final class MessagingUtils { * @return an Internet address * @throws UnknownHostException if the address of the local host cannot be found */ - public static InetAddress getLocalHostLANAddress() throws UnknownHostException { + public static InetAddress getLocalHostLanAddress() throws UnknownHostException { try { InetAddress candidateAddress = null; // Iterate all NICs (network interface cards)... @@ -225,8 +225,7 @@ public final class MessagingUtils { } finally { flushAndClose(oos, bytesOut); } - final byte[] bytes = bytesOut.toByteArray(); - return bytes; + return bytesOut.toByteArray(); } /** diff --git a/core/core-infrastructure/src/test/java/org/onap/policy/apex/core/infrastructure/messaging/EndToEndStringMessagingTest.java b/core/core-infrastructure/src/test/java/org/onap/policy/apex/core/infrastructure/messaging/EndToEndStringMessagingTest.java index 21c5ee984..c9d56ef2c 100644 --- a/core/core-infrastructure/src/test/java/org/onap/policy/apex/core/infrastructure/messaging/EndToEndStringMessagingTest.java +++ b/core/core-infrastructure/src/test/java/org/onap/policy/apex/core/infrastructure/messaging/EndToEndStringMessagingTest.java @@ -24,9 +24,9 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import org.junit.Test; -import org.onap.policy.apex.core.infrastructure.messaging.stringmessaging.WSStringMessageClient; -import org.onap.policy.apex.core.infrastructure.messaging.stringmessaging.WSStringMessageListener; -import org.onap.policy.apex.core.infrastructure.messaging.stringmessaging.WSStringMessageServer; +import org.onap.policy.apex.core.infrastructure.messaging.stringmessaging.WsStringMessageClient; +import org.onap.policy.apex.core.infrastructure.messaging.stringmessaging.WsStringMessageListener; +import org.onap.policy.apex.core.infrastructure.messaging.stringmessaging.WsStringMessageServer; import org.onap.policy.apex.core.infrastructure.threading.ThreadUtilities; import org.slf4j.ext.XLogger; import org.slf4j.ext.XLoggerFactory; @@ -40,22 +40,22 @@ public class EndToEndStringMessagingTest { // Logger for this class private static final XLogger logger = XLoggerFactory.getXLogger(EndToEndStringMessagingTest.class); - private WSStringMessageServer server; - private WSStringMessageClient client; + private WsStringMessageServer server; + private WsStringMessageClient client; private boolean finished = false; @Test public void testEndToEndMessaging() throws MessagingException { logger.debug("end to end messaging test starting . . ."); - server = new WSStringMessageServer(44441); + server = new WsStringMessageServer(44441); assertNotNull(server); - server.start(new WSStringServerMessageListener()); + server.start(new WsStringServerMessageListener()); try { - client = new WSStringMessageClient("localhost", 44441); + client = new WsStringMessageClient("localhost", 44441); assertNotNull(client); - client.start(new WSStringClientMessageListener()); + client.start(new WsStringClientMessageListener()); client.sendString("Hello, client here"); @@ -74,7 +74,7 @@ public class EndToEndStringMessagingTest { logger.debug("end to end messaging test finished"); } - private class WSStringServerMessageListener implements WSStringMessageListener { + private class WsStringServerMessageListener implements WsStringMessageListener { @Override public void receiveString(final String stringMessage) { logger.debug(stringMessage); @@ -83,7 +83,7 @@ public class EndToEndStringMessagingTest { } } - private class WSStringClientMessageListener implements WSStringMessageListener { + private class WsStringClientMessageListener implements WsStringMessageListener { @Override public void receiveString(final String stringMessage) { logger.debug(stringMessage); diff --git a/core/core-infrastructure/src/test/java/org/onap/policy/apex/core/infrastructure/messaging/StringTestServer.java b/core/core-infrastructure/src/test/java/org/onap/policy/apex/core/infrastructure/messaging/StringTestServer.java index 09fa62d59..30590c0c0 100644 --- a/core/core-infrastructure/src/test/java/org/onap/policy/apex/core/infrastructure/messaging/StringTestServer.java +++ b/core/core-infrastructure/src/test/java/org/onap/policy/apex/core/infrastructure/messaging/StringTestServer.java @@ -22,18 +22,29 @@ package org.onap.policy.apex.core.infrastructure.messaging; import static org.junit.Assert.assertNotNull; -import org.onap.policy.apex.core.infrastructure.messaging.stringmessaging.WSStringMessageListener; -import org.onap.policy.apex.core.infrastructure.messaging.stringmessaging.WSStringMessageServer; +import org.onap.policy.apex.core.infrastructure.messaging.stringmessaging.WsStringMessageListener; +import org.onap.policy.apex.core.infrastructure.messaging.stringmessaging.WsStringMessageServer; import org.onap.policy.apex.core.infrastructure.threading.ThreadUtilities; +// TODO: Auto-generated Javadoc +/** + * The Class StringTestServer. + */ public class StringTestServer { - private WSStringMessageServer server; + private WsStringMessageServer server; + /** + * Create a string test server. + * + * @param port port to use + * @param timeToLive time to live + * @throws MessagingException exceptions on messages + */ public StringTestServer(final int port, long timeToLive) throws MessagingException { System.out.println("StringTestServer starting on port " + port + " for " + timeToLive + " seconds . . ."); - server = new WSStringMessageServer(port); + server = new WsStringMessageServer(port); assertNotNull(server); - server.start(new WSStringServerMessageListener()); + server.start(new WsStringServerMessageListener()); System.out.println("StringTestServer started on port " + port + " for " + timeToLive + " seconds"); @@ -45,7 +56,23 @@ public class StringTestServer { System.out.println("StringTestServer completed"); } - private class WSStringServerMessageListener implements WSStringMessageListener { + /** + * The listener interface for receiving WSStringServerMessage events. The class that is interested in processing a + * WSStringServerMessage event implements this interface, and the object created with that class is registered with + * a component using the component's addWSStringServerMessageListener method. When the + * WSStringServerMessage event occurs, that object's appropriate method is invoked. + * + * @see WSStringServerMessageEvent + */ + private class WsStringServerMessageListener implements WsStringMessageListener { + + /* + * (non-Javadoc) + * + * @see + * org.onap.policy.apex.core.infrastructure.messaging.stringmessaging.WsStringMessageListener#receiveString(java + * .lang.String) + */ @Override public void receiveString(final String stringMessage) { System.out.println("Server received string \"" + stringMessage + "\""); @@ -53,6 +80,12 @@ public class StringTestServer { } } + /** + * The main method. + * + * @param args the arguments + * @throws MessagingException the messaging exception + */ public static void main(final String[] args) throws MessagingException { if (args.length != 2) { System.err.println("Usage: StringTestServer port timeToLive"); -- cgit 1.2.3-korg