blob: 7266f2954626be0d101c8783cf7a4ad30197a9e5 [file] [log] [blame]
Madan Jampani63c659f2015-06-11 00:52:58 -07001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
Madan Jampani63c659f2015-06-11 00:52:58 -07003 *
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 */
16package org.onosproject.store.service;
17
18import 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 */
Madan Jampania090a112016-01-18 16:38:17 -080027public interface DistributedQueue<E> extends DistributedPrimitive {
Madan Jampani63c659f2015-06-11 00:52:58 -070028
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}