Class GenericDistributedQueue
- java.lang.Object
-
- org.apache.solr.cloud.autoscaling.sim.GenericDistributedQueue
-
- All Implemented Interfaces:
DistributedQueue
public class GenericDistributedQueue extends Object implements DistributedQueue
A distributed queue that usesDistribStateManager
as the underlying distributed store. Implementation based onZkDistributedQueue
-
-
Constructor Summary
Constructors Constructor Description GenericDistributedQueue(DistribStateManager stateManager, String dir)
GenericDistributedQueue(DistribStateManager stateManager, String dir, Stats stats)
GenericDistributedQueue(DistribStateManager stateManager, String dir, Stats stats, int maxQueueSize)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Map<String,Object>
getStats()
Stats
getZkStats()
void
offer(byte[] data)
Inserts data into queue.byte[]
peek()
Returns the data at the first element of the queue, or null if the queue is empty.byte[]
peek(boolean block)
Returns the data at the first element of the queue, or null if the queue is empty and block is false.byte[]
peek(long wait)
Returns the data at the first element of the queue, or null if the queue is empty after wait ms.Collection<Pair<String,byte[]>>
peekElements(int max, long waitMillis, Predicate<String> acceptFilter)
Return the currently-known set of elements, using child names from memory.byte[]
poll()
Attempts to remove the head of the queue and return it.byte[]
remove()
Attempts to remove the head of the queue and return it.void
remove(Collection<String> paths)
byte[]
take()
Removes the head of the queue and returns it, blocks until it succeeds.
-
-
-
Constructor Detail
-
GenericDistributedQueue
public GenericDistributedQueue(DistribStateManager stateManager, String dir)
-
GenericDistributedQueue
public GenericDistributedQueue(DistribStateManager stateManager, String dir, Stats stats)
-
GenericDistributedQueue
public GenericDistributedQueue(DistribStateManager stateManager, String dir, Stats stats, int maxQueueSize)
-
-
Method Detail
-
peek
public byte[] peek() throws Exception
Returns the data at the first element of the queue, or null if the queue is empty.- Specified by:
peek
in interfaceDistributedQueue
- Returns:
- data at the first element of the queue, or null.
- Throws:
Exception
-
peek
public byte[] peek(boolean block) throws Exception
Returns the data at the first element of the queue, or null if the queue is empty and block is false.- Specified by:
peek
in interfaceDistributedQueue
- Parameters:
block
- if true, blocks until an element enters the queue- Returns:
- data at the first element of the queue, or null.
- Throws:
Exception
-
peek
public byte[] peek(long wait) throws Exception
Returns the data at the first element of the queue, or null if the queue is empty after wait ms.- Specified by:
peek
in interfaceDistributedQueue
- Parameters:
wait
- max wait time in ms.- Returns:
- data at the first element of the queue, or null.
- Throws:
Exception
-
poll
public byte[] poll() throws Exception
Attempts to remove the head of the queue and return it. Returns null if the queue is empty.- Specified by:
poll
in interfaceDistributedQueue
- Returns:
- Head of the queue or null.
- Throws:
Exception
-
remove
public byte[] remove() throws Exception
Attempts to remove the head of the queue and return it.- Specified by:
remove
in interfaceDistributedQueue
- Returns:
- The former head of the queue
- Throws:
Exception
-
remove
public void remove(Collection<String> paths) throws Exception
- Throws:
Exception
-
take
public byte[] take() throws Exception
Removes the head of the queue and returns it, blocks until it succeeds.- Specified by:
take
in interfaceDistributedQueue
- Returns:
- The former head of the queue
- Throws:
Exception
-
offer
public void offer(byte[] data) throws Exception
Inserts data into queue. If there are no other queue consumers, the offered element will be immediately visible when this method returns.- Specified by:
offer
in interfaceDistributedQueue
- Throws:
Exception
-
getZkStats
public Stats getZkStats()
-
getStats
public Map<String,Object> getStats()
- Specified by:
getStats
in interfaceDistributedQueue
-
peekElements
public Collection<Pair<String,byte[]>> peekElements(int max, long waitMillis, Predicate<String> acceptFilter) throws Exception
Return the currently-known set of elements, using child names from memory. If no children are found, or no children passacceptFilter
, waits up towaitMillis
for at least one child to become available.Package-private to support
OverseerTaskQueue
specifically.- Specified by:
peekElements
in interfaceDistributedQueue
- Throws:
Exception
-
-