* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
* Modifications Copyright (C) 2019-2020 Nordix Foundation.
+ * Modifications Copyright (C) 2021 Bell Canada. 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.
Assertions.argumentOfClassNotNull(key, ContextException.class, "Parameter \"key\" may not be null");
// Get the class for the distributor using reflection
- final DistributorParameters distributorParameters =
- ParameterService.get(ContextParameterConstants.DISTRIBUTOR_GROUP_NAME);
+ final var distributorParameters =
+ (DistributorParameters) ParameterService.get(ContextParameterConstants.DISTRIBUTOR_GROUP_NAME);
final String pluginClass = distributorParameters.getPluginClass();
Object contextDistributorObject = null;
try {
}
// The context Distributor to return
- final Distributor contextDistributor = (Distributor) contextDistributorObject;
+ final var contextDistributor = (Distributor) contextDistributorObject;
// Lock and load the context distributor
contextDistributor.init(key);
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
* Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2021 Bell Canada. 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.
this.contextDistributor = contextDistributor;
// Set the period for persistence flushing
- final PersistorParameters persistorParameters = ParameterService
- .get(ContextParameterConstants.PERSISTENCE_GROUP_NAME);
+ final var persistorParameters =
+ (PersistorParameters) ParameterService.get(ContextParameterConstants.PERSISTENCE_GROUP_NAME);
flushPeriod = persistorParameters.getFlushPeriod();
// Set up the timer
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
* Modifications Copyright (C) 2020 Nordix Foundation.
+ * Modifications Copyright (C) 2021 Bell Canada. 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.
public LockManager createLockManager(final AxArtifactKey key) throws ContextException {
LOGGER.entry("Lock Manager factory, key=" + key);
- final LockManagerParameters lockManagerParameters =
- ParameterService.get(ContextParameterConstants.LOCKING_GROUP_NAME);
+ final var lockManagerParameters =
+ (LockManagerParameters) ParameterService.get(ContextParameterConstants.LOCKING_GROUP_NAME);
// Get the class for the lock manager using reflection
Object lockManagerObject = null;
}
// The context lock manager to return
- final LockManager lockManager = (LockManager) lockManagerObject;
+ final var lockManager = (LockManager) lockManagerObject;
// Lock and load (OK sorry!!!) the lock manager
lockManager.init(key);
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
* Modifications Copyright (C) 2019-2020 Nordix Foundation.
+ * Modifications Copyright (C) 2021 Bell Canada. 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.
LOGGER.entry("persistor factory, key=" + key);
Assertions.argumentOfClassNotNull(key, ContextException.class, "Parameter \"key\" may not be null");
- final PersistorParameters persistorParameters =
- ParameterService.get(ContextParameterConstants.PERSISTENCE_GROUP_NAME);
+ final var persistorParameters =
+ (PersistorParameters) ParameterService.get(ContextParameterConstants.PERSISTENCE_GROUP_NAME);
// Get the class for the persistor using reflection
Object persistorObject = null;
}
// The persistor to return
- final Persistor persistor = (Persistor) persistorObject;
+ final var persistor = (Persistor) persistorObject;
// Lock and load the persistor
persistor.init(key);
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
* Modifications Copyright (C) 2019-2020 Nordix Foundation.
+ * Modifications Copyright (C) 2021 Bell Canada. 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.
import org.onap.policy.apex.context.ContextRuntimeException;
import org.onap.policy.apex.context.SchemaHelper;
import org.onap.policy.apex.context.parameters.ContextParameterConstants;
-import org.onap.policy.apex.context.parameters.SchemaHelperParameters;
import org.onap.policy.apex.context.parameters.SchemaParameters;
import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
import org.onap.policy.apex.model.basicmodel.concepts.AxKey;
}
// Get the schema class using the parameter service
- final SchemaParameters schemaParameters = ParameterService.get(ContextParameterConstants.SCHEMA_GROUP_NAME);
+ final var schemaParameters =
+ (SchemaParameters) ParameterService.get(ContextParameterConstants.SCHEMA_GROUP_NAME);
// Get the class for the schema helper from the schema parameters
- final SchemaHelperParameters schemaHelperParameters =
+ final var schemaHelperParameters =
schemaParameters.getSchemaHelperParameters(schema.getSchemaFlavour());
if (schemaHelperParameters == null) {
final var resultString = "context schema helper parameters not found for context schema \""
}
// The context schema helper to return
- final SchemaHelper schemaHelper = (SchemaHelper) schemaHelperObject;
+ final var schemaHelper = (SchemaHelper) schemaHelperObject;
// Lock and load the schema helper
schemaHelper.init(owningEntityKey.getKey(), schema);
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
* Modifications Copyright (C) 2019-2020 Nordix Foundation.
+ * Modifications Copyright (C) 2021 Bell Canada. 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.
* @return the GSON instance
*/
private Gson getGson() {
- GsonBuilder gsonBuilder = new GsonBuilder().setPrettyPrinting();
+ var gsonBuilder = new GsonBuilder().setPrettyPrinting();
// Get the Java schema helper parameters from the parameter service
- SchemaParameters schemaParameters = ParameterService.get(ContextParameterConstants.SCHEMA_GROUP_NAME);
+ var schemaParameters = (SchemaParameters) ParameterService.get(ContextParameterConstants.SCHEMA_GROUP_NAME);
JavaSchemaHelperParameters javaSchemaHelperParmeters =
(JavaSchemaHelperParameters) schemaParameters.getSchemaHelperParameterMap().get("Java");
StateExecutor lastExecutor = null;
for (final AxState state : axPolicy.getStateMap().values()) {
// Create a state executor for this state and add its context (the state)
- final StateExecutor stateExecutor = new StateExecutor(executorFactory);
+ final var stateExecutor = new StateExecutor(executorFactory);
stateExecutor.setContext(this, state, internalContext);
// Update the next executor on the last executor
// Get the first state of the state machine and define a state output that starts state
// execution
- StateExecutor stateExecutor = firstExecutor;
- StateOutput stateOutput = new StateOutput(new AxStateOutput(firstExecutor.getSubject().getKey(),
+ var stateExecutor = firstExecutor;
+ var stateOutput = new StateOutput(new AxStateOutput(firstExecutor.getSubject().getKey(),
incomingEvent.getKey(), firstExecutor.getSubject().getKey()), incomingEvent);
while (true) {
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
* Modifications Copyright (C) 2020-2021 Nordix Foundation.
* Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2021 Bell Canada. 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.
*/
public ContextAlbum getContextAlbum(final String contextAlbumName) {
// Find the context album
- final ContextAlbum foundContextAlbum = context.get(contextAlbumName);
+ final var foundContextAlbum = context.get(contextAlbumName);
// Check if the context album exists
if (foundContextAlbum != null) {
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
* Modifications Copyright (C) 2020 Nordix Foundation.
* Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2021 Bell Canada. 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.
*/
public ContextAlbum getContextAlbum(final String contextAlbumName) {
// Find the context album
- final ContextAlbum foundContextAlbum = context.get(contextAlbumName);
+ final var foundContextAlbum = context.get(contextAlbumName);
// Check if the context album exists
if (foundContextAlbum != null) {
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
* Modifications Copyright (C) 2019-2020 Nordix Foundation.
+ * Modifications Copyright (C) 2021 Bell Canada. 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.
public TaskExecutor getTaskExecutor(final Executor<?, ?, ?, ?> parentExecutor, final AxTask task,
final ApexInternalContext context) {
// Create task executor
- final TaskExecutor taskExecutor = (TaskExecutor) createExecutor(task.getTaskLogic().getLogicFlavour(),
+ final var taskExecutor = (TaskExecutor) createExecutor(task.getTaskLogic().getLogicFlavour(),
taskExecutorPluginClassMap.get(task.getTaskLogic().getLogicFlavour()), TaskExecutor.class);
taskExecutor.setParameters(implementationParameterMap.get(task.getTaskLogic().getLogicFlavour()));
taskExecutor.setContext(parentExecutor, task, context);
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2021 Bell Canada. 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.
* @param userArtifactStack the keys of the artifacts using the event at the moment
*/
public void monitorGet(final AxField eventParameter, final Object value, final AxConcept[] userArtifactStack) {
- String monitorGetString = monitor("GET", userArtifactStack, eventParameter, value);
+ var monitorGetString = monitor("GET", userArtifactStack, eventParameter, value);
LOGGER.trace(monitorGetString);
}
* @param userArtifactStack the keys of the artifacts using the event at the moment
*/
public void monitorSet(final AxField eventParameter, final Object value, final AxConcept[] userArtifactStack) {
- String monitorSetString = monitor("SET", userArtifactStack, eventParameter, value);
+ var monitorSetString = monitor("SET", userArtifactStack, eventParameter, value);
LOGGER.trace(monitorSetString);
}
*/
public void monitorRemove(final AxField eventParameter, final Object removedValue,
final AxConcept[] userArtifactStack) {
- String monitorRemoveString = monitor("REMOVE", userArtifactStack, eventParameter, removedValue);
+ var monitorRemoveString = monitor("REMOVE", userArtifactStack, eventParameter, removedValue);
LOGGER.trace(monitorRemoveString);
}
*/
private String monitor(final String preamble, final AxConcept[] userArtifactStack, final AxField eventParameter,
final Object value) {
- final StringBuilder builder = new StringBuilder();
+ final var builder = new StringBuilder();
builder.append(preamble);
builder.append(",[");
if (userArtifactStack != null) {
- boolean first = true;
+ var first = true;
for (final AxConcept stackKey : userArtifactStack) {
if (first) {
first = false;
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
* Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2021 Bell Canada. 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.
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.Arrays;
try {
// The library path for predefined classes in Java
- String sunBootLibraryPathString = System.getProperty(SUN_BOOT_LIBRARY_PATH);
+ var sunBootLibraryPathString = System.getProperty(SUN_BOOT_LIBRARY_PATH);
// Check it exists and has a "lib" in it
if (sunBootLibraryPathString != null && sunBootLibraryPathString.contains(LIBRARAY_PATH_TOKEN)) {
sunBootLibraryPathString = sunBootLibraryPathString.substring(0,
sunBootLibraryPathString.lastIndexOf(LIBRARAY_PATH_TOKEN) + LIBRARAY_PATH_TOKEN.length());
- final File bootLibraryFile = new File(sunBootLibraryPathString);
+ final var bootLibraryFile = new File(sunBootLibraryPathString);
// The set used to hold class names is populated with predefined Java classes
classNameSet.addAll(processDir(bootLibraryFile, ""));
}
if (url == null || url.getFile() == null) {
continue;
}
- final File urlFile = new File(url.getFile());
+ final var urlFile = new File(url.getFile());
// Directories may contain ".class" files
if (urlFile.isDirectory()) {
classNameSet.addAll(processDir(urlFile, url.getFile()));
return urls;
}
- Method mmethod = nullclassloader.getMethod("getBootstrapClassPath");
+ var mmethod = nullclassloader.getMethod("getBootstrapClassPath");
if (mmethod == null) {
return urls;
}
return classPathSet;
}
// JARs are ZIP files
- final ZipInputStream zip = new ZipInputStream(jarInputStream);
+ final var zip = new ZipInputStream(jarInputStream);
// Iterate over each entry in the JAR
for (ZipEntry entry = zip.getNextEntry(); entry != null; entry = zip.getNextEntry()) {
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
* Modifications Copyright (C) 2020 Nordix Foundation.
+ * Modifications Copyright (C) 2021 Bell Canada. 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.
final DiagnosticCollector<JavaFileObject> diagnosticListener = new DiagnosticCollector<>();
// Get the Java compiler
- final JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
+ final var compiler = ToolProvider.getSystemJavaCompiler();
// Set up the target file manager and call the compiler
singleFileManager = new SingleFileManager(compiler, new SingleClassByteCodeFileObject(className));
// Check if the compilation worked
if (Boolean.FALSE.equals(task.call())) {
- final StringBuilder builder = new StringBuilder();
+ final var builder = new StringBuilder();
for (final Diagnostic<? extends JavaFileObject> diagnostic : diagnosticListener.getDiagnostics()) {
builder.append("code:");
builder.append(diagnostic.getCode());
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
* Modifications Copyright (C) 2019-2020 Nordix Foundation.
* Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2021 Bell Canada. 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.
// the queue
// processing thread
- try (final ByteArrayInputStream stream = new ByteArrayInputStream(dataByteBuffer.array());
- final ObjectInputStream ois = new ObjectInputStream(stream)) {
+ try (final var stream = new ByteArrayInputStream(dataByteBuffer.array());
+ final var ois = new ObjectInputStream(stream)) {
@SuppressWarnings("unchecked")
final MessageHolder<M> messageHolder = (MessageHolder<M>) ois.readObject();
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
* Modifications Copyright (C) 2019-2020 Nordix Foundation.
+ * Modifications Copyright (C) 2021 Bell Canada. 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.
LOGGER.entry("web socket event consumer server starting . . .");
if (LOGGER.isDebugEnabled()) {
- String lanaddress = "unknown";
+ var lanaddress = "unknown";
try {
lanaddress = MessagingUtils.getLocalHostLanAddress().getHostAddress();
} catch (final UnknownHostException ignore) {
LOGGER.debug("Failed to find name of local address name", ignore);
}
LOGGER.debug("web socket string message server LAN address=" + lanaddress);
- String hostaddress = "unknown";
+ var hostaddress = "unknown";
try {
hostaddress = InetAddress.getLocalHost().getHostAddress();
} catch (final UnknownHostException ignore) {
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
* Modifications Copyright (C) 2019 Nordix Foundation.
* Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2021 Bell Canada. 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.
* @return true if port is available
*/
public static boolean isPortAvailable(final int port) {
- try (final Socket socket = new Socket("localhost", port)) {
+ try (final var socket = new Socket("localhost", port)) {
return false;
} catch (final IOException ignoredException) {
LOGGER.trace("Port {} is available", port, ignoredException);
// At this point, we did not find a non-loopback address.
// Fall back to returning whatever InetAddress.getLocalHost()
// returns...
- final InetAddress jdkSuppliedAddress = InetAddress.getLocalHost();
+ final var jdkSuppliedAddress = InetAddress.getLocalHost();
if (jdkSuppliedAddress == null) {
throw new UnknownHostException("The JDK InetAddress.getLocalHost() method unexpectedly returned null.");
}
return jdkSuppliedAddress;
} catch (final Exception e) {
- final UnknownHostException unknownHostException =
+ final var unknownHostException =
new UnknownHostException("Failed to determine LAN address: " + e);
unknownHostException.initCause(e);
throw unknownHostException;
*/
public static byte[] serializeObject(final Object object) {
LOGGER.entry(object.getClass().getName());
- final ByteArrayOutputStream bytesOut = new ByteArrayOutputStream();
- try (ObjectOutputStream oos = new ObjectOutputStream(bytesOut)) {
+ final var bytesOut = new ByteArrayOutputStream();
+ try (var oos = new ObjectOutputStream(bytesOut)) {
oos.writeObject(object);
} catch (final IOException e) {
LOGGER.warn("error on object serialization", e);
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
* Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2021 Bell Canada. 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.
* @param threadPriority the thread priority
*/
public ApplicationThreadFactory(final String nameLocal, final long stackSize, final int threadPriority) {
- final SecurityManager s = System.getSecurityManager();
+ final var s = System.getSecurityManager();
group = (s != null) ? s.getThreadGroup() : Thread.currentThread().getThreadGroup();
name = APPLICATION_NAME + nameLocal + HYPHEN + NEXT_POOL_NUMBER.getAndIncrement();
this.stackSize = stackSize;
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
* Modifications Copyright (C) 2020 Nordix Foundation.
+ * Modifications Copyright (C) 2021 Bell Canada. 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.
import javax.xml.namespace.QName;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.xpath.XPath;
-import javax.xml.xpath.XPathExpression;
import javax.xml.xpath.XPathExpressionException;
import javax.xml.xpath.XPathFactory;
import org.slf4j.ext.XLogger;
private void init() {
try {
LOGGER.info("Initializing XPath reader");
- DocumentBuilderFactory df = DocumentBuilderFactory.newInstance();
+ var df = DocumentBuilderFactory.newInstance();
df.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
df.setAttribute(XMLConstants.ACCESS_EXTERNAL_DTD, "");
df.setAttribute(XMLConstants.ACCESS_EXTERNAL_SCHEMA, "");
*/
public Object read(final String expression, final QName returnType) {
try {
- final XPathExpression xPathExpression = xpath.compile(expression);
+ final var xPathExpression = xpath.compile(expression);
return xPathExpression.evaluate(xmlDocument, returnType);
} catch (final XPathExpressionException ex) {
LOGGER.error("Failed to read XML file for XPath processing, reason:\n" + ex.getMessage(), ex);