2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * Copyright (C) 2017 Amdocs
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
20 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
23 package org.openecomp.appc.executionqueue.impl;
25 import java.util.concurrent.ExecutorService;
26 import java.util.concurrent.Executors;
27 import java.util.concurrent.LinkedBlockingQueue;
29 import org.openecomp.appc.executionqueue.MessageExpirationListener;
30 import org.openecomp.appc.executionqueue.helper.Util;
31 import org.openecomp.appc.executionqueue.impl.object.QueueMessage;
33 import com.att.eelf.configuration.EELFLogger;
34 import com.att.eelf.configuration.EELFManager;
36 public class QueueManager {
38 private LinkedBlockingQueue<QueueMessage<? extends Runnable>> queue;
40 private MessageExpirationListener listener;
42 private static int MAX_QUEUE_SIZE = Util.getExecutionQueSize();
44 private static int MAX_THREAD_SIZE = Util.getThreadPoolSize();
46 private ExecutorService messageExecutor;
48 private static final EELFLogger logger =
49 EELFManager.getInstance().getLogger(QueueManager.class);
51 private QueueManager(){
55 private static class QueueManagerHolder {
56 private static final QueueManager INSTANCE = new QueueManager();
59 public static QueueManager getInstance() {
60 return QueueManagerHolder.INSTANCE;
64 queue = new LinkedBlockingQueue<QueueMessage<? extends Runnable>>(MAX_QUEUE_SIZE);
65 messageExecutor = Executors.newFixedThreadPool(MAX_THREAD_SIZE,Util.getThreadFactory(true));
67 for(int i=0;i<MAX_THREAD_SIZE;i++){
68 messageExecutor.submit(new Runnable() {
73 QueueMessage<? extends Runnable> queueMessage = queue.take();
74 if (queueMessage.isExpired()) {
75 logger.debug("Message expired "+ queueMessage.getMessage());
77 listener.onMessageExpiration(queueMessage.getMessage());
80 logger.warn("Listener not available for expired message ");
84 queueMessage.getMessage().run();
86 } catch (Exception e) {
87 logger.error("Error in startMessagePolling method of ExecutionQueueServiceImpl" + e.getMessage());
95 public void setListener(MessageExpirationListener listener) {
96 this.listener = listener;
99 public boolean enqueueTask(QueueMessage<? extends Runnable> queueMessage) {
100 return queue.offer(queueMessage);