From 1f049a441ac4efc63fb9671107649d6106f02f7c Mon Sep 17 00:00:00 2001 From: Jim Hahn Date: Fri, 10 Jan 2020 11:30:21 -0500 Subject: Address items deprecated by move to java 11 Addressed the following deprecated items: - "new Integer(xxx)" - Observable/Observer - Mockito.anyObject() Added assertion to a junit test to address a sonar issue. Did not address deprecated Nashorn javascript interpreter; that will be done in a separate review. Updated licenses. Issue-ID: POLICY-1406 Signed-off-by: Jim Hahn Change-Id: I81fd158f831e01d5410d79898ced658285787d47 --- .../org/onap/policy/common/im/StateManagement.java | 27 ++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) (limited to 'integrity-monitor/src/main/java/org/onap/policy/common/im/StateManagement.java') diff --git a/integrity-monitor/src/main/java/org/onap/policy/common/im/StateManagement.java b/integrity-monitor/src/main/java/org/onap/policy/common/im/StateManagement.java index 68ad3bc6..7a018ef9 100644 --- a/integrity-monitor/src/main/java/org/onap/policy/common/im/StateManagement.java +++ b/integrity-monitor/src/main/java/org/onap/policy/common/im/StateManagement.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * Integrity Monitor * ================================================================================ - * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2020 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,8 +20,9 @@ package org.onap.policy.common.im; +import java.util.Collection; import java.util.List; -import java.util.Observable; +import java.util.concurrent.ConcurrentLinkedQueue; import java.util.concurrent.atomic.AtomicReference; import java.util.function.Consumer; import javax.persistence.EntityManager; @@ -43,7 +44,7 @@ import org.slf4j.LoggerFactory; * notified. * */ -public class StateManagement extends Observable { +public class StateManagement { private static final String RESOURCE_NAME = "resource"; private static final String GET_STATE_MANAGEMENT_ENTITY_QUERY = "Select p from StateManagementEntity p where p.resourceName=:" + RESOURCE_NAME; @@ -96,6 +97,11 @@ public class StateManagement extends Observable { private static final Object SYNCLOCK = new Object(); private static final Object FLUSHLOCK = new Object(); + /** + * Observers to be notified when this object changes state. + */ + private final Collection observers = new ConcurrentLinkedQueue<>(); + /** * StateManagement constructor. * @@ -162,7 +168,6 @@ public class StateManagement extends Observable { et.commit(); if (changed != null) { - setChanged(); notifyObservers(changed); } @@ -175,6 +180,20 @@ public class StateManagement extends Observable { } } + /** + * Adds an observer to list of those to be notified when this changes. + * @param observer observer to be added + */ + public void addObserver(StateChangeNotifier observer) { + observers.add(observer); + } + + private void notifyObservers(String changed) { + for (StateChangeNotifier obs : observers) { + obs.update(this, changed); + } + } + private void setStateUsingTable(String actionName, String resourceName, String changeName) throws StateManagementException { -- cgit 1.2.3-korg