2 * ================================================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property
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 * ================================================================================
20 package org.openecomp.portalsdk.core.onboarding.ueb;
23 import java.util.concurrent.ConcurrentHashMap;
24 import java.util.concurrent.LinkedBlockingQueue;
26 import org.apache.commons.logging.Log;
27 import org.apache.commons.logging.LogFactory;
30 * A thin wrapper around ConcurrentHashMap that stores a queue for each
31 * Requester that is waiting for a Reply. When a reply is received that has a
32 * matching msgId, that requesters queue is populated with the reply message.
34 * Primarily for the UebManager to track requests while it waits for responses.
36 public class WaitingRequestersQueueList {
37 private final Log logger = LogFactory.getLog(getClass());
39 private final Map<String, LinkedBlockingQueue<UebMsg>> map;
41 public WaitingRequestersQueueList() {
42 map = new ConcurrentHashMap<>();
45 public void addQueueToMap(String msgId, LinkedBlockingQueue<UebMsg> queue) {
46 this.map.put(msgId, queue);
49 public void addMsg(String msgId, UebMsg message) {
50 LinkedBlockingQueue<UebMsg> queue = this.map.get(msgId);
54 logger.warn("Did not find entry in WaitingRequestersQueueList for msgId " + msgId);
58 public void removeQueueFromMap(String msgId) {
59 this.map.remove(msgId);
62 public String toString() {
63 StringBuffer sb = new StringBuffer();
64 sb.append("Map contains " + this.map.size() + " Publishers.");
65 for (Map.Entry<String, LinkedBlockingQueue<UebMsg>> entry : this.map.entrySet()) {
66 String key = entry.getKey().toString();
67 LinkedBlockingQueue<UebMsg> queue = entry.getValue();
68 sb.append("Entry msgId, " + key + " queue " + queue);