diff options
author | RY303T <RY303T@att.com> | 2018-02-21 16:42:18 -0500 |
---|---|---|
committer | Patrick Brady <pb071s@att.com> | 2018-02-22 23:41:58 +0000 |
commit | 5a99e9824824b2fa5f22945cd58cd5e3ee0df1ef (patch) | |
tree | b9c916228c3440d70bbf9e34ab57df731934ca8d /appc-event-listener/appc-event-listener-bundle/src/main | |
parent | 7353bcd8f2b85a50720b7cc7ca04c837c7b1796a (diff) |
modify listeners to only start when props present
Change-Id: If4ba1552eb6bc78a95f1b53292752181bc29cb2d
Issue-ID: APPC-564
Signed-off-by: RY303T <RY303T@att.com>
Diffstat (limited to 'appc-event-listener/appc-event-listener-bundle/src/main')
3 files changed, 54 insertions, 26 deletions
diff --git a/appc-event-listener/appc-event-listener-bundle/src/main/java/org/onap/appc/listener/AppcEventListenerActivator.java b/appc-event-listener/appc-event-listener-bundle/src/main/java/org/onap/appc/listener/AppcEventListenerActivator.java index a65b315e4..7795825b6 100644 --- a/appc-event-listener/appc-event-listener-bundle/src/main/java/org/onap/appc/listener/AppcEventListenerActivator.java +++ b/appc-event-listener/appc-event-listener-bundle/src/main/java/org/onap/appc/listener/AppcEventListenerActivator.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP : APPC * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Copyright (C) 2017 Amdocs * ============================================================================= @@ -108,25 +108,32 @@ public class AppcEventListenerActivator implements BundleActivator { public void start(BundleContext ctx) throws Exception { LOG.info("Starting Bundle " + getName()); - configuration = ConfigurationFactory.getConfiguration(); - - Properties props = configuration.getProperties(); + Properties props = getProperties(); Set<ListenerProperties> listeners = new HashSet<>(); // Configure event listener for the demo use case ListenerProperties demoProps = new ListenerProperties("appc.demo", props); - demoProps.setListenerClass(org.onap.appc.listener.demo.impl.ListenerImpl.class); - listeners.add(demoProps); + // Only add the listener if properties are set + if (!demoProps.getProperties().isEmpty()) { + demoProps.setListenerClass(org.onap.appc.listener.demo.impl.ListenerImpl.class); + listeners.add(demoProps); + } + ListenerProperties clLCMProps = new ListenerProperties("appc.LCM", props); - clLCMProps.setListenerClass(org.onap.appc.listener.LCM.impl.ListenerImpl.class); - listeners.add(clLCMProps); + // Only add the listener if properties are set + if (!clLCMProps.getProperties().isEmpty()) { + clLCMProps.setListenerClass(org.onap.appc.listener.LCM.impl.ListenerImpl.class); + listeners.add(clLCMProps); + } + // Configure the OAM properties String oamPropKeyPrefix = "appc.OAM"; ListenerProperties oamProps = new ListenerProperties(oamPropKeyPrefix, props); - if (isAppcOamPropsListenerEnabled(oamProps)) { + // Only add the listener if properties are set and enabled is true + if (!oamProps.getProperties().isEmpty() && isAppcOamPropsListenerEnabled(oamProps)) { oamProps.setListenerClass(org.onap.appc.listener.LCM.impl.ListenerImpl.class); listeners.add(oamProps); } else { @@ -195,4 +202,13 @@ public class AppcEventListenerActivator implements BundleActivator { return result; } + + /** + * Get properties from configuration + */ + Properties getProperties() { + configuration = ConfigurationFactory.getConfiguration(); + return configuration.getProperties(); + } + } diff --git a/appc-event-listener/appc-event-listener-bundle/src/main/java/org/onap/appc/listener/impl/ControllerImpl.java b/appc-event-listener/appc-event-listener-bundle/src/main/java/org/onap/appc/listener/impl/ControllerImpl.java index cc77eb91d..0cb470a8e 100644 --- a/appc-event-listener/appc-event-listener-bundle/src/main/java/org/onap/appc/listener/impl/ControllerImpl.java +++ b/appc-event-listener/appc-event-listener-bundle/src/main/java/org/onap/appc/listener/impl/ControllerImpl.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP : APPC * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Copyright (C) 2017 Amdocs * ============================================================================= @@ -69,17 +69,21 @@ public class ControllerImpl implements Controller { } else { LOG.error(String.format( "The ListenerProperties %s has no Listener class associated with it and will not run.", props)); + properties.remove(props); } } LISTENER_COUNT = properties.size(); + // Only create executor if listeners are configured + if (LISTENER_COUNT > 0) { executor = new ThreadPoolExecutor(LISTENER_COUNT, LISTENER_COUNT, 1, TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(LISTENER_COUNT)); // Custom Named thread factory BasicThreadFactory threadFactory = new BasicThreadFactory.Builder().namingPattern("Appc-Listener-%d").build(); executor.setThreadFactory(threadFactory); + } } @Override @@ -107,28 +111,30 @@ public class ControllerImpl implements Controller { Iterator<Listener> itr = listeners.values().iterator(); while (itr.hasNext()) { Listener l = itr.next(); - if (stopNow) { + if (stopNow && l != null) { l.stopNow(); - } else { + } else if(l!=null){ l.stop(); } itr.remove(); } // disable new tasks from being submitted - executor.shutdown(); - int timeout=300; - try { - if (!executor.awaitTermination(timeout, TimeUnit.SECONDS)) { - LOG.error("Not all tasks completed execution after " + timeout + " seconds. " + - "Attempting to stop all actively executing tasks."); + if(executor != null) { + executor.shutdown(); + int timeout=300; + try { + if (!executor.awaitTermination(timeout, TimeUnit.SECONDS)) { + LOG.error("Not all tasks completed execution after " + timeout + " seconds. " + + "Attempting to stop all actively executing tasks."); + executor.shutdownNow(); + } + if (!executor.awaitTermination(timeout, TimeUnit.SECONDS)) { + LOG.error("Could not terminate all tasks after " + (timeout*2) + " seconds."); + } + } catch (InterruptedException e) { executor.shutdownNow(); + Thread.currentThread().interrupt(); } - if (!executor.awaitTermination(timeout, TimeUnit.SECONDS)) { - LOG.error("Could not terminate all tasks after " + (timeout*2) + " seconds."); - } - } catch (InterruptedException e) { - executor.shutdownNow(); - Thread.currentThread().interrupt(); } } diff --git a/appc-event-listener/appc-event-listener-bundle/src/main/java/org/onap/appc/listener/impl/EventHandlerImpl.java b/appc-event-listener/appc-event-listener-bundle/src/main/java/org/onap/appc/listener/impl/EventHandlerImpl.java index 4b4959725..e8fe15f20 100644 --- a/appc-event-listener/appc-event-listener-bundle/src/main/java/org/onap/appc/listener/impl/EventHandlerImpl.java +++ b/appc-event-listener/appc-event-listener-bundle/src/main/java/org/onap/appc/listener/impl/EventHandlerImpl.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP : APPC * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Copyright (C) 2017 Amdocs * ============================================================================= @@ -36,6 +36,7 @@ import org.onap.appc.listener.EventHandler; import org.onap.appc.listener.ListenerProperties; import org.onap.appc.listener.util.Mapper; import org.onap.appc.logging.LoggingConstants; +import org.osgi.framework.Bundle; import org.osgi.framework.BundleContext; import org.osgi.framework.FrameworkUtil; import org.osgi.framework.ServiceReference; @@ -206,7 +207,12 @@ public class EventHandlerImpl implements EventHandler { } Consumer out = null; - BundleContext ctx = FrameworkUtil.getBundle(EventHandlerImpl.class).getBundleContext(); + BundleContext ctx = null; + Bundle bundle = FrameworkUtil.getBundle(EventHandlerImpl.class); + if(bundle != null) { + ctx = bundle.getBundleContext(); + } + if (ctx != null) { ServiceReference svcRef = ctx.getServiceReference(MessageAdapterFactory.class.getName()); if (svcRef != null) { |