/* * Copyright (c) 2008-2017, Hazelcast, Inc. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.hazelcast.core; import java.util.concurrent.TimeUnit; /** * * Base interface for Hazelcast distributed queues. * * @see java.util.concurrent.BlockingQueue * @see IQueue * @see TransactionalQueue * @param <E> */ public interface BaseQueue<E> extends DistributedObject { /** * Inserts the specified element into this queue if it is possible to do * so immediately without violating capacity restrictions. Returns * <tt>true</tt> upon success and <tt>false</tt> if no space is currently * available. * * @param e the element to add * @return <tt>true</tt> if the element was added to this queue, * <tt>false</tt> otherwise */ boolean offer(E e); /** * Inserts the specified element into this queue, waiting up to the * specified wait time if necessary for space to become available. * * @param e the element to add * @param timeout how long to wait before giving up, in units of * <tt>unit</tt> * @param unit a <tt>TimeUnit</tt> determines how to interpret the * <tt>timeout</tt> parameter * @return <tt>true</tt> if successful, or <tt>false</tt> if * the specified waiting time elapses before space is available * @throws InterruptedException if interrupted while waiting */ boolean offer(E e, long timeout, TimeUnit unit) throws InterruptedException; /** * Retrieves and removes the head of this queue, waiting if necessary * until an element becomes available. * * @return the head of this queue * @throws InterruptedException if interrupted while waiting */ E take() throws InterruptedException; /** * Retrieves and removes the head of this queue, * or returns <tt>null</tt> if this queue is empty. * * @return the head of this queue, or <tt>null</tt> if this queue is empty */ E poll(); /** * Retrieves and removes the head of this queue, waiting up to the * specified wait time if necessary for an element to become available. * * @param timeout how long to wait before giving up, in units of * <tt>unit</tt> * @param unit a <tt>TimeUnit</tt> determining how to interpret the * <tt>timeout</tt> parameter * @return the head of this queue, or <tt>null</tt> if the * specified waiting time elapses before an element is available * @throws InterruptedException if interrupted while waiting */ E poll(long timeout, TimeUnit unit) throws InterruptedException; /** * Returns the number of elements in this collection. If this collection * contains more than <tt>Integer.MAX_VALUE</tt> elements, returns * <tt>Integer.MAX_VALUE</tt>. * * @return the number of elements in this collection */ int size(); }