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
21 * common item type of zipped queues
23 public class PollableQueuesPriorityZipper<T> {
25 private Queue<T> prioritizedSource;
26 private PollableQueuesZipper<T> zipper;
31 public PollableQueuesPriorityZipper() {
32 zipper = new PollableQueuesZipper<>();
36 * Add all member queues before first invocation of
37 * {@link PollableQueuesPriorityZipper#poll()}
40 * to be added to group
42 public void addSource(Queue<T> queue) {
43 zipper.addSource(queue);
47 * @return next common product of polling member groups
52 item = prioritizedSource.poll();
60 public void setPrioritizedSource(Queue<T> prioritizedSource) {
61 this.prioritizedSource = prioritizedSource;