diff options
author | Jim Hahn <jrh3@att.com> | 2021-08-03 14:08:09 -0400 |
---|---|---|
committer | Jim Hahn <jrh3@att.com> | 2021-08-06 15:14:31 -0400 |
commit | 0ed6c16727aa92c93965a7da756536b113b262c8 (patch) | |
tree | f7961bccd0db40a9f9985a5936381f183432235c /core/core-infrastructure | |
parent | 9344ec1396b7151262e9b4ac48c72020e2b03e7e (diff) |
Use lombok for apex-pdp #7
Updated thru core-protocols.
Issue-ID: POLICY-3391
Change-Id: I2226fee16b276eba5c7f3fd1921a6cef36654f07
Signed-off-by: Jim Hahn <jrh3@att.com>
Diffstat (limited to 'core/core-infrastructure')
11 files changed, 53 insertions, 217 deletions
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); @@ -59,13 +62,6 @@ public abstract class ClassUtils { 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 * * @return a set of class names for all classes in the class path 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 <M> the generic type of message being handled by a message holder instance */ +@Getter +@ToString +@EqualsAndHashCode public class MessageHolder<M> 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<M> implements Serializable { private final InetAddress senderHostAddress; // Sequence of message in the message holder + @ToString.Exclude private final List<M> messages; /** @@ -64,15 +70,6 @@ public class MessageHolder<M> implements Serializable { } /** - * Return the messages in this message holder. - * - * @return the messages - */ - public List<M> getMessages() { - return messages; - } - - /** * Adds a message to this message holder. * * @param message the message to add @@ -84,75 +81,4 @@ public class MessageHolder<M> 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<M> implements WebSocketMessageListener<M>, Runnab if (messageHolder != null) { final List<M> 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 <M> the generic type of message being handled */ +@Getter +@AllArgsConstructor public final class MessageBlock<M> { // List of Messages received on a web socket @@ -36,34 +41,4 @@ public final class MessageBlock<M> { // 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<M> messages, final WebSocket webSocket) { - this.messages = messages; - this.webSocket = webSocket; - } - - /** - * Gets the messages. - * - * @return the messages - */ - public List<M> 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<M> { 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<M> { public void post(final MessageBlock<M> 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; @@ -52,13 +55,6 @@ public final class MessagingUtils { 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; /** @@ -101,38 +107,11 @@ 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,21 +21,18 @@ 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. * * @param milliseconds the milliseconds 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<String> { 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); } |