2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.openflowplugin.openflow.md.queue;
10 import java.util.Collection;
12 import org.slf4j.Logger;
13 import org.slf4j.LoggerFactory;
19 public class QueueKeeperHarvester<IN> implements Runnable, HarvesterHandle {
20 private static Logger LOG = LoggerFactory.getLogger(QueueKeeperHarvester.class);
22 private Enqueuer<QueueItem<IN>> enqueuer;
23 private Collection<QueueKeeper<IN>> messageSources;
25 private boolean finishing = false;
26 private boolean starving;
28 private Object harvestLock;
33 * @param messageSources
36 public QueueKeeperHarvester(Enqueuer<QueueItem<IN>> enqueuer,
37 Collection<QueueKeeper<IN>> messageSources) {
38 this.enqueuer = enqueuer;
39 this.messageSources = messageSources;
40 harvestLock = new Object();
45 while (! finishing ) {
47 for (QueueKeeper<IN> source : messageSources) {
48 QueueItem<IN> qItem = source.poll();
51 enqueuer.enqueueQueueItem(qItem);
56 synchronized (harvestLock) {
59 LOG.trace("messageHarvester is about to make a starve sleep");
61 LOG.trace("messageHarvester is waking up from a starve sleep");
63 } catch (InterruptedException e) {
64 LOG.warn("message harvester has been interrupted during starve sleep", e);
74 public void shutdown() {
75 this.finishing = true;
81 LOG.debug("pinging message harvester in starve status");
82 synchronized (harvestLock) {