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 final Collection<QueueKeeper<IN>> messageSources;
23 private final Enqueuer<QueueItem<IN>> enqueuer;
24 private final Object harvestLock = new Object();
25 private volatile boolean finishing = false;
26 private volatile boolean wakeMe = false;
30 * @param messageSources
33 public QueueKeeperHarvester(final Enqueuer<QueueItem<IN>> enqueuer,
34 final Collection<QueueKeeper<IN>> messageSources) {
35 this.enqueuer = enqueuer;
36 this.messageSources = messageSources;
42 boolean starving = true;
43 for (QueueKeeper<IN> source : messageSources) {
44 QueueItem<IN> qItem = source.poll();
47 enqueuer.enqueueQueueItem(qItem);
52 LOG.trace("messageHarvester is about to make a starve sleep");
53 synchronized (harvestLock) {
56 this.harvestLock.wait();
57 LOG.trace("messageHarvester is waking up from a starve sleep");
58 } catch (InterruptedException e) {
59 LOG.warn("message harvester has been interrupted during starve sleep", e);
71 public void shutdown() {
72 this.finishing = true;
79 synchronized (harvestLock) {
80 // Might've raced while waiting for lock, so need to recheck
82 LOG.debug("pinging message harvester in starve status");