2 * Copyright (c) 2014 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.api.openflow.md.util;
10 import java.util.Queue;
13 * Zipper groups together a list of queues and exposes one poll method. Polling
14 * iterates through all groups and returns first not-null result of poll method
15 * on each queue. If after polling each grouped queue for one time there is
16 * still null result, poll will return null. <br>
17 * Iterating keeps last position so this polling is supposed to be fairly
20 * @param <T> common item type of zipped queues
22 public class PollableQueuesPriorityZipper<T> {
24 private Queue<T> prioritizedSource;
25 private PollableQueuesZipper<T> zipper;
27 public PollableQueuesPriorityZipper() {
28 zipper = new PollableQueuesZipper<>();
32 * Add all member queues before first invocation of {@link PollableQueuesPriorityZipper#poll()}.
33 * @param queue to be added to group
35 public void addSource(Queue<T> queue) {
36 zipper.addSource(queue);
40 * Next common product.
41 * @return next common product of polling member groups
46 item = prioritizedSource.poll();
54 public void setPrioritizedSource(Queue<T> prioritizedSource) {
55 this.prioritizedSource = prioritizedSource;