Madan Jampani | 63c659f | 2015-06-11 00:52:58 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 Open Networking Laboratory |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | package org.onosproject.store.service; |
| 17 | |
| 18 | import java.util.concurrent.CompletableFuture; |
| 19 | |
| 20 | /** |
| 21 | * A distributed collection designed for holding elements prior to processing. |
| 22 | * A queue provides insertion, extraction and inspection operations. The extraction operation |
| 23 | * is designed to be non-blocking. |
| 24 | * |
| 25 | * @param <E> queue entry type |
| 26 | */ |
| 27 | public interface DistributedQueue<E> { |
| 28 | |
| 29 | /** |
| 30 | * Returns total number of entries in the queue. |
| 31 | * @return queue size |
| 32 | */ |
| 33 | long size(); |
| 34 | |
| 35 | /** |
| 36 | * Returns true if queue has elements in it. |
| 37 | * @return true is queue has elements, false otherwise |
| 38 | */ |
| 39 | default boolean isEmpty() { |
| 40 | return size() == 0; |
| 41 | } |
| 42 | |
| 43 | /** |
| 44 | * Inserts an entry into the queue. |
| 45 | * @param entry entry to insert |
| 46 | */ |
| 47 | void push(E entry); |
| 48 | |
| 49 | /** |
| 50 | * If the queue is non-empty, an entry will be removed from the queue and the returned future |
| 51 | * will be immediately completed with it. If queue is empty when this call is made, the returned |
| 52 | * future will be eventually completed when an entry is added to the queue. |
| 53 | * @return queue entry |
| 54 | */ |
| 55 | CompletableFuture<E> pop(); |
| 56 | |
| 57 | /** |
| 58 | * Returns an entry from the queue without removing it. If the queue is empty returns null. |
| 59 | * @return queue entry or null if queue is empty |
| 60 | */ |
| 61 | E peek(); |
| 62 | } |