From 0ed6c16727aa92c93965a7da756536b113b262c8 Mon Sep 17 00:00:00 2001 From: Jim Hahn Date: Tue, 3 Aug 2021 14:08:09 -0400 Subject: Use lombok for apex-pdp #7 Updated thru core-protocols. Issue-ID: POLICY-3391 Change-Id: I2226fee16b276eba5c7f3fd1921a6cef36654f07 Signed-off-by: Jim Hahn --- .../infrastructure/java/classes/ClassUtils.java | 12 +-- .../compile/singleclass/SingleClassLoader.java | 28 ++----- .../infrastructure/messaging/MessageHolder.java | 90 ++-------------------- .../messaging/impl/ws/RawMessageHandler.java | 2 +- .../impl/ws/messageblock/MessageBlock.java | 35 ++------- .../impl/ws/messageblock/MessageBlockHandler.java | 9 ++- .../impl/ws/messageblock/RawMessageBlock.java | 34 ++------ .../messaging/util/MessagingUtils.java | 10 +-- .../threading/ApplicationThreadFactory.java | 35 ++------- .../infrastructure/threading/ThreadUtilities.java | 12 ++- .../messaging/DummyMessageListener.java | 3 +- 11 files changed, 53 insertions(+), 217 deletions(-) (limited to 'core/core-infrastructure') 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 03bedce81..e3a51f085 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 @@ -34,6 +34,8 @@ import java.util.Set; import java.util.TreeSet; import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; import org.slf4j.ext.XLogger; import org.slf4j.ext.XLoggerFactory; @@ -42,7 +44,8 @@ import org.slf4j.ext.XLoggerFactory; * * @author Liam Fallon (liam.fallon@ericsson.com) */ -public abstract class ClassUtils { +@NoArgsConstructor(access = AccessLevel.PRIVATE) +public final class ClassUtils { // Get a reference to the logger private static final XLogger LOGGER = XLoggerFactory.getXLogger(ClassUtils.class); @@ -58,13 +61,6 @@ public abstract class ClassUtils { // Token for library fragment in path private static final String LIBRARAY_PATH_TOKEN = "/lib"; - /** - * Private constructor used to prevent sub class instantiation. - */ - private ClassUtils() { - // Private constructor to block subclassing - } - /** * Get the class names of all classes on the class path. WARNING: This is a heavy call, use sparingly * diff --git a/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/java/compile/singleclass/SingleClassLoader.java b/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/java/compile/singleclass/SingleClassLoader.java index 61293f5d9..55fa498fd 100644 --- a/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/java/compile/singleclass/SingleClassLoader.java +++ b/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/java/compile/singleclass/SingleClassLoader.java @@ -1,6 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * Modifications Copyright (C) 2021 AT&T Intellectual Property. 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. @@ -20,23 +21,19 @@ package org.onap.policy.apex.core.infrastructure.java.compile.singleclass; +import lombok.AllArgsConstructor; +import lombok.Getter; + /** * The Class SingleClassLoader is responsible for class loading the single Java class being held in memory. * * @author Liam Fallon (liam.fallon@ericsson.com) */ +@Getter +@AllArgsConstructor public class SingleClassLoader extends ClassLoader { // The byte code of the class held in memory as byte code in a ByteCodeFileObject - private final SingleClassByteCodeFileObject byteCodeFileObject; - - /** - * Instantiates a new single class loader to load the byte code of the class that is being held in memory. - * - * @param byteCodeFileObject the byte code of the class - */ - public SingleClassLoader(final SingleClassByteCodeFileObject byteCodeFileObject) { - this.byteCodeFileObject = byteCodeFileObject; - } + private final SingleClassByteCodeFileObject fileObject; /** * {@inheritDoc}. @@ -45,15 +42,6 @@ public class SingleClassLoader extends ClassLoader { protected Class findClass(final String className) throws ClassNotFoundException { // Creates a java Class that can be instantiated from the class defined in the byte code in the // ByteCodeFileObejct - return defineClass(className, byteCodeFileObject.getByteCode(), 0, byteCodeFileObject.getByteCode().length); - } - - /** - * Gets the file object. - * - * @return the file object - */ - SingleClassByteCodeFileObject getFileObject() { - return byteCodeFileObject; + return defineClass(className, fileObject.getByteCode(), 0, fileObject.getByteCode().length); } } 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 e5c5aaee5..abc5c90de 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 @@ -1,6 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * Modifications Copyright (C) 2021 AT&T Intellectual Property. 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. @@ -24,6 +25,9 @@ import java.io.Serializable; import java.net.InetAddress; import java.util.ArrayList; import java.util.List; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.ToString; import org.slf4j.ext.XLogger; import org.slf4j.ext.XLoggerFactory; @@ -34,9 +38,10 @@ import org.slf4j.ext.XLoggerFactory; * @author Sajeevan Achuthan (sajeevan.achuthan@ericsson.com) * @param the generic type of message being handled by a message holder instance */ +@Getter +@ToString +@EqualsAndHashCode public class MessageHolder implements Serializable { - private static final int HASH_PRIME = 31; - private static final int FOUR_BYTES = 32; // Serial ID private static final long serialVersionUID = 1235487535388793719L; @@ -49,6 +54,7 @@ public class MessageHolder implements Serializable { private final InetAddress senderHostAddress; // Sequence of message in the message holder + @ToString.Exclude private final List messages; /** @@ -63,15 +69,6 @@ public class MessageHolder implements Serializable { creationTime = System.currentTimeMillis(); } - /** - * Return the messages in this message holder. - * - * @return the messages - */ - public List getMessages() { - return messages; - } - /** * Adds a message to this message holder. * @@ -84,75 +81,4 @@ public class MessageHolder implements Serializable { LOGGER.warn("duplicate message {} added to message holder", message); } } - - /** - * Gets the creation time. - * - * @return the creation time - */ - public long getCreationTime() { - return creationTime; - } - - /** - * Gets the sender host address. - * - * @return the sender host address - */ - public InetAddress getSenderHostAddress() { - return senderHostAddress; - } - - /** - * {@inheritDoc}. - */ - @Override - public String toString() { - return "ApexCommandProtocol [creationTime=" + creationTime + ", senderHostAddress=" + senderHostAddress + "]"; - } - - /** - * {@inheritDoc}. - */ - @Override - public int hashCode() { - final int prime = HASH_PRIME; - int result = 1; - result = prime * result + ((senderHostAddress == null) ? 0 : senderHostAddress.hashCode()); - result = prime * result + ((messages == null) ? 0 : messages.hashCode()); - result = prime * result + (int) (creationTime ^ (creationTime >>> FOUR_BYTES)); - return result; - } - - /** - * {@inheritDoc}. - */ - @Override - public boolean equals(final Object obj) { - if (this == obj) { - return true; - } - if (obj == null) { - return false; - } - if (getClass() != obj.getClass()) { - return false; - } - final MessageHolder other = (MessageHolder) obj; - if (senderHostAddress == null) { - if (other.senderHostAddress != null) { - return false; - } - } else if (!senderHostAddress.equals(other.senderHostAddress)) { - return false; - } - if (messages == null) { - if (other.messages != null) { - return false; - } - } else if (!messages.equals(other.messages)) { - return false; - } - return creationTime == other.creationTime; - } } 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 0493eafb5..1bc100084 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 @@ -105,7 +105,7 @@ public class RawMessageHandler implements WebSocketMessageListener, Runnab if (messageHolder != null) { final List messages = messageHolder.getMessages(); if (messages != null) { - messageBlockQueue.add(new MessageBlock<>(messages, incomingData.getConn())); + messageBlockQueue.add(new MessageBlock<>(messages, incomingData.getWebSocket())); } } } catch (final IOException | ClassNotFoundException e) { 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 ba98fd748..75e82a0d2 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 @@ -1,6 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * Modifications Copyright (C) 2021 AT&T Intellectual Property. 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. @@ -21,6 +22,8 @@ package org.onap.policy.apex.core.infrastructure.messaging.impl.ws.messageblock; import java.util.List; +import lombok.AllArgsConstructor; +import lombok.Getter; import org.java_websocket.WebSocket; /** @@ -29,6 +32,8 @@ import org.java_websocket.WebSocket; * @author Sajeevan Achuthan (sajeevan.achuthan@ericsson.com) * @param the generic type of message being handled */ +@Getter +@AllArgsConstructor public final class MessageBlock { // List of Messages received on a web socket @@ -36,34 +41,4 @@ public final class MessageBlock { // The web socket on which the messages are handled private final WebSocket webSocket; - - /** - * Instantiates a new message block. - * - * @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) { - this.messages = messages; - this.webSocket = webSocket; - } - - /** - * Gets the messages. - * - * @return the messages - */ - public List getMessages() { - return messages; - } - - /** - * Gets the web socket. - * - * @return the web socket - */ - public WebSocket getConnection() { - return webSocket; - } - } 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 3134c67cf..0349cb548 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 @@ -1,6 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * Modifications Copyright (C) 2021 AT&T Intellectual Property. 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. @@ -59,8 +60,8 @@ public class MessageBlockHandler { public void post(final RawMessageBlock rawMessageBlock) { if (rawMessageBlock.getMessage() != null) { if (LOGGER.isDebugEnabled()) { - LOGGER.debug("new raw message recieved from {}", rawMessageBlock.getConn() == null ? "server" - : rawMessageBlock.getConn().getRemoteSocketAddress().getHostName()); + LOGGER.debug("new raw message recieved from {}", rawMessageBlock.getWebSocket() == null ? "server" + : rawMessageBlock.getWebSocket().getRemoteSocketAddress().getHostName()); } eventBus.post(rawMessageBlock); } @@ -74,8 +75,8 @@ public class MessageBlockHandler { public void post(final MessageBlock messageBlock) { if (messageBlock.getMessages() != null) { if (LOGGER.isDebugEnabled()) { - LOGGER.debug("new data message recieved from {}", messageBlock.getConnection() == null ? "server" - : messageBlock.getConnection().getRemoteSocketAddress().getHostName()); + LOGGER.debug("new data message recieved from {}", messageBlock.getWebSocket() == null ? "server" + : messageBlock.getWebSocket().getRemoteSocketAddress().getHostName()); } eventBus.post(messageBlock); } diff --git a/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/messaging/impl/ws/messageblock/RawMessageBlock.java b/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/messaging/impl/ws/messageblock/RawMessageBlock.java index 7e8f09c5d..e9448abff 100644 --- a/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/messaging/impl/ws/messageblock/RawMessageBlock.java +++ b/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/messaging/impl/ws/messageblock/RawMessageBlock.java @@ -1,6 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * Modifications Copyright (C) 2021 AT&T Intellectual Property. 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. @@ -21,6 +22,8 @@ package org.onap.policy.apex.core.infrastructure.messaging.impl.ws.messageblock; import java.nio.ByteBuffer; +import lombok.AllArgsConstructor; +import lombok.Getter; import org.java_websocket.WebSocket; /** @@ -28,39 +31,12 @@ import org.java_websocket.WebSocket; * * @author Sajeevan Achuthan (sajeevan.achuthan@ericsson.com) */ +@Getter +@AllArgsConstructor public final class RawMessageBlock { // The raw message private final ByteBuffer message; // The web socket on which the message is handled private final WebSocket webSocket; - - /** - * Constructor, instantiate the bean. - * - * @param message {@link ByteBuffer} message from the web socket - * @param webSocket {@link WebSocket} the web socket on which the message is handled - */ - public RawMessageBlock(final ByteBuffer message, final WebSocket webSocket) { - this.message = message; - this.webSocket = webSocket; - } - - /** - * A getter method for message. - * - * @return the message - */ - public ByteBuffer getMessage() { - return message; - } - - /** - * A getter method for the web socket. - * - * @return the web socket - */ - public WebSocket getConn() { - return webSocket; - } } 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 bda1f870c..ba84ca069 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 @@ -30,6 +30,8 @@ import java.net.NetworkInterface; import java.net.Socket; import java.net.UnknownHostException; import java.util.Enumeration; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; import org.slf4j.ext.XLogger; import org.slf4j.ext.XLoggerFactory; @@ -39,6 +41,7 @@ import org.slf4j.ext.XLoggerFactory; * * @author Sajeevan Achuthan (sajeevan.achuthan@ericsson.com) */ +@NoArgsConstructor(access = AccessLevel.PRIVATE) public final class MessagingUtils { // The port number of the lowest user port, ports 0-1023 are system ports private static final int LOWEST_USER_PORT = 1024; @@ -51,13 +54,6 @@ public final class MessagingUtils { // Logger for this class private static final XLogger LOGGER = XLoggerFactory.getXLogger(MessagingUtils.class); - /** - * Private constructor used to prevent sub class instantiation. - */ - private MessagingUtils() { - // Private constructor to block subclassing - } - /** * This method searches the availability of the port, if the requested port not available, this method will throw an * exception. diff --git a/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/threading/ApplicationThreadFactory.java b/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/threading/ApplicationThreadFactory.java index dc9c13d7b..dd8b8294f 100644 --- a/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/threading/ApplicationThreadFactory.java +++ b/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/threading/ApplicationThreadFactory.java @@ -1,6 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * Modifications Copyright (C) 2021 AT&T Intellectual Property. 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. @@ -22,6 +23,7 @@ package org.onap.policy.apex.core.infrastructure.threading; import java.util.concurrent.ThreadFactory; import java.util.concurrent.atomic.AtomicInteger; +import lombok.Getter; /** * This class provides a thread factory for use by classes that require thread factories to handle concurrent operation. @@ -34,8 +36,12 @@ public class ApplicationThreadFactory implements ThreadFactory { private static final AtomicInteger NEXT_POOL_NUMBER = new AtomicInteger(); private final ThreadGroup group; private final AtomicInteger nextThreadNumber = new AtomicInteger(); + + @Getter private final String name; + @Getter private final long stackSize; + @Getter private final int threadPriority; /** @@ -100,39 +106,12 @@ public class ApplicationThreadFactory implements ThreadFactory { } - /** - * Gets the name of the thread factory. - * - * @return the name - */ - public String getName() { - return name; - } - - /** - * Gets the stack size of the threads created by this thread factory. - * - * @return the stack size - */ - public long getStackSize() { - return stackSize; - } - - /** - * Gets the thread priority of the threads created by this thread factory. - * - * @return the thread priority - */ - public int getThreadPriority() { - return threadPriority; - } - /** * {@inheritDoc}. */ @Override public String toString() { - return "ApplicationThreadFactory [nextPollNumber=" + NEXT_POOL_NUMBER + ",nextThreadNumber=" + nextThreadNumber + return "ApplicationThreadFactory [nextPoolNumber=" + NEXT_POOL_NUMBER + ",nextThreadNumber=" + nextThreadNumber + ", name=" + name + ", stackSize=" + stackSize + ", threadPriority=" + threadPriority + "]"; } } diff --git a/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/threading/ThreadUtilities.java b/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/threading/ThreadUtilities.java index eb4e0210b..58939d622 100644 --- a/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/threading/ThreadUtilities.java +++ b/core/core-infrastructure/src/main/java/org/onap/policy/apex/core/infrastructure/threading/ThreadUtilities.java @@ -1,6 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * Modifications Copyright (C) 2021 AT&T Intellectual Property. 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. @@ -20,20 +21,17 @@ package org.onap.policy.apex.core.infrastructure.threading; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; + /** * This class is a helper class for carrying out common threading tasks. * * @author Liam Fallon (liam.fallon@ericsson.com) */ +@NoArgsConstructor(access = AccessLevel.PRIVATE) public final class ThreadUtilities { - /** - * Private constructor to prevent sub-classing of this class. - */ - private ThreadUtilities() { - // Private constructor to prevent subclassing - } - /** * Sleeps for the specified number of milliseconds, hiding interrupt handling. * diff --git a/core/core-infrastructure/src/test/java/org/onap/policy/apex/core/infrastructure/messaging/DummyMessageListener.java b/core/core-infrastructure/src/test/java/org/onap/policy/apex/core/infrastructure/messaging/DummyMessageListener.java index d9bd93cd2..f81394c1c 100644 --- a/core/core-infrastructure/src/test/java/org/onap/policy/apex/core/infrastructure/messaging/DummyMessageListener.java +++ b/core/core-infrastructure/src/test/java/org/onap/policy/apex/core/infrastructure/messaging/DummyMessageListener.java @@ -1,6 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * Modifications Copyright (C) 2021 AT&T Intellectual Property. 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. @@ -53,7 +54,7 @@ public abstract class DummyMessageListener implements MessageListener { if (data != null) { if (logger.isDebugEnabled()) { logger.debug("{} command recieved from machine {} ", data.getMessages().size(), - data.getConnection().getRemoteSocketAddress().getHostString()); + data.getWebSocket().getRemoteSocketAddress().getHostString()); } onCommand(data); } -- cgit 1.2.3-korg