blob: f325b7c27fb2e53e786349c3a8288ce8473fe234 [file] [log] [blame]
/*
* Licensed to the Apache Software Foundation (ASF) under one or more contributor license
* agreements. See the NOTICE file distributed with this work for additional information regarding
* copyright ownership. The ASF licenses this file to You 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 org.apache.geode.internal.cache;
import java.util.List;
import org.apache.geode.cache.CacheException;
import org.apache.geode.cache.CacheListener;
import org.apache.geode.cache.Region;
/**
* Interface <code>RegionQueue</code> is an interface for queue implementations backed by regions.
*
*
* @since GemFire 4.2
*/
public interface RegionQueue {
/**
* A token used to signify this is a WAN queue. It is set in the callback argument.
*/
String WAN_QUEUE_TOKEN = "WAN_QUEUE_TOKEN";
/**
* Puts an object onto the tail of the queue
*
* @param object The object to put onto the queue
*
* @return boolean whether object was successfully put onto the queue
*/
boolean put(Object object) throws InterruptedException, CacheException;
/**
* Returns the underlying region that backs this queue.
*/
Region getRegion();
/**
* Takes the first object from the head of the queue. This method returns null if there are no
* objects on the queue.
*
* @return The object taken
*
*/
Object take() throws CacheException, InterruptedException;
/**
* Takes up to batchSize number of objects from the head of the queue. As soon as it gets a null
* response from a take, it stops taking.
*
* @param batchSize The number of objects to take from the queue
*
* @return the <code>List</code> of objects taken from the queue
*
*/
List take(int batchSize) throws CacheException, InterruptedException;
/**
* Removes a single object from the head of the queue without returning it. This method assumes
* that the queue contains at least one object.
*
*/
void remove() throws InterruptedException, CacheException;
/**
* Peeks the first object from the head of the queue without removing it. This method returns null
* if there are no objects on the queue.
*
* @return The object peeked
*/
Object peek() throws InterruptedException, CacheException;
/**
* Peeks up to batchSize number of objects from the head of the queue without removing them. As
* soon as it gets a null response from a peek, it stops peeking.
*
* @param batchSize The number of objects to peek from the queue
*
* @return The list of objects peeked
*/
List peek(int batchSize) throws InterruptedException, CacheException;
/**
* Peeks either a batchSize number of elements from the queue or until timeToWait milliseconds
* have elapsed (whichever comes first). If it has peeked batchSize number of elements from the
* queue before timeToWait milliseconds have elapsed, it stops peeking. If timeToWait milliseconds
* elapse before batchSize number of elements has been peeked, it stops.
*
* @param batchSize The number of objects to peek from the queue
* @param timeToWait The number of milliseconds to attempt to peek
*
* @return The list of objects peeked
*
*/
List peek(int batchSize, int timeToWait) throws InterruptedException, CacheException;
/**
* Returns the size of the queue
*
* @return the size of the queue
*/
int size();
/**
* Add a <code>CacheListener</code> to the queue
*
* @param listener The <code>CacheListener</code> to add
*/
void addCacheListener(CacheListener listener);
/**
* Remove the <code>CacheListener</code> from the queue
*/
void removeCacheListener();
// TODO:Asif: Remove this method. Added this justto make it compilable
void remove(int top) throws CacheException;
void close();
}