2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.openecomp.policy.admin;
24 import java.io.Serializable;
25 import java.util.LinkedList;
26 import java.util.concurrent.ExecutorService;
27 import java.util.concurrent.Executors;
30 import org.openecomp.policy.common.logging.flexlogger.FlexLogger;
31 import org.openecomp.policy.common.logging.flexlogger.Logger;
34 * Handle Notifications from the PAP that the PDP Groups have been changed.
35 * We need a Server Push Broadcaster because there may be multiple Vaadin instances (i.e. Users) that need to be told when a change occurs.
37 * Initially we only update the entire set of PDPGroups in one shot.
39 * (Code copied from Book of Vaadin chapter on Server Push
42 public class PAPNotificationBroadcaster implements Serializable {
46 private static final long serialVersionUID = -2539940306348821754L;
49 private static Logger logger = FlexLogger.getLogger(PAPNotificationBroadcaster.class);
52 static ExecutorService executorService = Executors.newSingleThreadExecutor();
55 * Interface used by all classes that need to be notified when PAP sends an update message.
59 public interface PAPNotificationBroadcastListener {
60 void updateAllGroups();
66 * list of registered listeners
68 private static LinkedList<PAPNotificationBroadcastListener> listeners =
69 new LinkedList<PAPNotificationBroadcastListener>();
72 * Listener registers to hear about updates.
75 public static synchronized void register(
76 PAPNotificationBroadcastListener listener) {
77 listeners.add(listener);
82 * Listener is going away.
86 public static synchronized void unregister(
87 PAPNotificationBroadcastListener listener) {
88 listeners.remove(listener);
94 * Tell all listeners about an update.
98 public static synchronized void updateAllGroups() {
99 for (final PAPNotificationBroadcastListener listener: listeners) {
100 // Original code copied from example:
101 // executorService.execute(new Runnable() {
103 // public void run() {
104 // The problem with this is that the execute starts a new Thread, but the thing we are calling (the listener.updateAllGroups)
105 // happens in this case to ALSO create a new thread, and it locks up because the shared threadpool queue is already locked by this method.
106 // On application shutdown that left us with a blocked thread, so the process never goes away.
107 // Since the listener.updateAllGroups does ALL of its work inside a new Runnable thread, there should be no need for this method to also create a thread.
111 * All listeners MUST either execute with no possibility of blocking
112 * OR must start their own threads to handle blocking and concurrent operations.
114 if (logger.isDebugEnabled()) {
115 logger.debug("updateAllGroups");
117 listener.updateAllGroups();