Queue¶
- class Queue(service_name, name, context)[source]¶
Bases:
hazelcast.proxy.base.PartitionSpecificProxy[BlockingQueue],Generic[hazelcast.types.ItemType]Concurrent, blocking, distributed, observable queue.
Queue is not a partitioned data-structure. All of the Queue content is stored in a single machine (and in the backup). Queue will not scale by adding more members in the cluster.
- add(item: hazelcast.types.ItemType) hazelcast.future.Future[bool][source]¶
Adds the specified item to this queue if there is available space.
- Parameters
item – The specified item.
- Returns
Trueif element is successfully added,Falseotherwise.
- add_all(items: Sequence[hazelcast.types.ItemType]) hazelcast.future.Future[bool][source]¶
Adds the elements in the specified collection to this queue.
- Parameters
items – Collection which includes the items to be added.
- Returns
Trueif this queue is changed after call,Falseotherwise.
- add_listener(include_value: bool = False, item_added_func: Optional[Callable[[hazelcast.proxy.base.ItemEvent[hazelcast.types.ItemType]], None]] = None, item_removed_func: Optional[Callable[[hazelcast.proxy.base.ItemEvent[hazelcast.types.ItemType]], None]] = None) hazelcast.future.Future[str][source]¶
- Adds an item listener for this queue. Listener will be notified for
all queue add/remove events.
- Parameters
include_value – Whether received events include the updated item or not.
item_added_func – Function to be called when an item is added to this set.
item_removed_func – Function to be called when an item is deleted from this set.
- Returns
A registration id which is used as a key to remove the listener.
- clear() hazelcast.future.Future[None][source]¶
Clears this queue. Queue will be empty after this call.
- contains(item: hazelcast.types.ItemType) hazelcast.future.Future[bool][source]¶
Determines whether this queue contains the specified item or not.
- Parameters
item – The specified item to be searched.
- Returns
Trueif the specified item exists in this queue,Falseotherwise.
- contains_all(items: Sequence[hazelcast.types.ItemType]) hazelcast.future.Future[bool][source]¶
Determines whether this queue contains all of the items in the specified collection or not.
- Parameters
items – The specified collection which includes the items to be searched.
- Returns
Trueif all of the items in the specified collection exist in this queue,Falseotherwise.
- drain_to(target_list: List[hazelcast.types.ItemType], max_size: int = - 1) hazelcast.future.Future[int][source]¶
Transfers all available items to the given target_list and removes these items from this queue.
If a max_size is specified, it transfers at most the given number of items. In case of a failure, an item can exist in both collections or none of them.
This operation may be more efficient than polling elements repeatedly and putting into collection.
- Parameters
target_list – the list where the items in this queue will be transferred.
max_size – The maximum number items to transfer.
- Returns
Number of transferred items.
- iterator() hazelcast.future.Future[List[hazelcast.types.ItemType]][source]¶
Returns all the items in this queue.
- Returns
Collection of items in this queue.
- is_empty() hazelcast.future.Future[bool][source]¶
Determines whether this set is empty or not.
- Returns
Trueif this queue is empty,Falseotherwise.
- offer(item: hazelcast.types.ItemType, timeout: float = 0) hazelcast.future.Future[bool][source]¶
Inserts the specified element into this queue if it is possible to do so immediately without violating capacity restrictions.
If there is no space currently available:
If the timeout is provided, it waits until this timeout elapses and returns the result.
If the timeout is not provided, returns
Falseimmediately.
- Parameters
item – The item to be added.
timeout – Maximum time in seconds to wait for addition.
- Returns
Trueif the element was added to this queue,Falseotherwise.
- peek() hazelcast.future.Future[Optional[hazelcast.types.ItemType]][source]¶
Retrieves the head of queue without removing it from the queue.
- Returns
The head of this queue, or
Noneif this queue is empty.
- poll(timeout: float = 0) hazelcast.future.Future[Optional[hazelcast.types.ItemType]][source]¶
Retrieves and removes the head of this queue.
If this queue is empty:
If the timeout is provided, it waits until this timeout elapses and returns the result.
If the timeout is not provided, returns
None.
- Parameters
timeout – Maximum time in seconds to wait for addition.
- Returns
The head of this queue, or
Noneif this queue is empty or specified timeout elapses before an item is added to the queue.
- put(item: hazelcast.types.ItemType) hazelcast.future.Future[None][source]¶
Adds the specified element into this queue.
If there is no space, it waits until necessary space becomes available.
- Parameters
item – The specified item.
- remaining_capacity() hazelcast.future.Future[int][source]¶
Returns the remaining capacity of this queue.
- Returns
Remaining capacity of this queue.
- remove(item: hazelcast.types.ItemType) hazelcast.future.Future[bool][source]¶
Removes the specified element from the queue if it exists.
- Parameters
item – The specified element to be removed.
- Returns
Trueif the specified element exists in this queue,Falseotherwise.
- remove_all(items: Sequence[hazelcast.types.ItemType]) hazelcast.future.Future[bool][source]¶
Removes all of the elements of the specified collection from this queue.
- Parameters
items – The specified collection.
- Returns
Trueif the call changed this queue,Falseotherwise.
- remove_listener(registration_id: str) hazelcast.future.Future[bool][source]¶
Removes the specified item listener.
Returns silently if the specified listener was not added before.
- Parameters
registration_id – Id of the listener to be deleted.
- Returns
Trueif the item listener is removed,Falseotherwise.
- retain_all(items: Sequence[hazelcast.types.ItemType]) hazelcast.future.Future[bool][source]¶
Removes the items which are not contained in the specified collection.
In other words, only the items that are contained in the specified collection will be retained.
- Parameters
items – Collection which includes the elements to be retained in this set.
- Returns
Trueif this queue changed as a result of the call,Falseotherwise.
- size() hazelcast.future.Future[int][source]¶
Returns the number of elements in this collection.
If the size is greater than
2**31 - 1, it returns2**31 - 1.- Returns
Size of the queue.
- take() hazelcast.future.Future[hazelcast.types.ItemType][source]¶
Retrieves and removes the head of this queue, if necessary, waits until an item becomes available.
- Returns
The head of this queue.
- blocking() hazelcast.proxy.queue.BlockingQueue[hazelcast.types.ItemType][source]¶
Returns a version of this proxy with only blocking method calls.
- class BlockingQueue(wrapped: hazelcast.proxy.queue.Queue[hazelcast.types.ItemType])[source]¶
Bases:
hazelcast.proxy.queue.Queue[hazelcast.types.ItemType]- name¶
- service_name¶
- add(item: hazelcast.types.ItemType) bool[source]¶
Adds the specified item to this queue if there is available space.
- Parameters
item – The specified item.
- Returns
Trueif element is successfully added,Falseotherwise.
- add_all(items: Sequence[hazelcast.types.ItemType]) bool[source]¶
Adds the elements in the specified collection to this queue.
- Parameters
items – Collection which includes the items to be added.
- Returns
Trueif this queue is changed after call,Falseotherwise.
- add_listener(include_value: bool = False, item_added_func: Optional[Callable[[hazelcast.proxy.base.ItemEvent[hazelcast.types.ItemType]], None]] = None, item_removed_func: Optional[Callable[[hazelcast.proxy.base.ItemEvent[hazelcast.types.ItemType]], None]] = None) str[source]¶
- Adds an item listener for this queue. Listener will be notified for
all queue add/remove events.
- Parameters
include_value – Whether received events include the updated item or not.
item_added_func – Function to be called when an item is added to this set.
item_removed_func – Function to be called when an item is deleted from this set.
- Returns
A registration id which is used as a key to remove the listener.
- contains(item: hazelcast.types.ItemType) bool[source]¶
Determines whether this queue contains the specified item or not.
- Parameters
item – The specified item to be searched.
- Returns
Trueif the specified item exists in this queue,Falseotherwise.
- contains_all(items: Sequence[hazelcast.types.ItemType]) bool[source]¶
Determines whether this queue contains all of the items in the specified collection or not.
- Parameters
items – The specified collection which includes the items to be searched.
- Returns
Trueif all of the items in the specified collection exist in this queue,Falseotherwise.
- drain_to(target_list: List[hazelcast.types.ItemType], max_size: int = - 1) int[source]¶
Transfers all available items to the given target_list and removes these items from this queue.
If a max_size is specified, it transfers at most the given number of items. In case of a failure, an item can exist in both collections or none of them.
This operation may be more efficient than polling elements repeatedly and putting into collection.
- Parameters
target_list – the list where the items in this queue will be transferred.
max_size – The maximum number items to transfer.
- Returns
Number of transferred items.
- iterator() List[hazelcast.types.ItemType][source]¶
Returns all the items in this queue.
- Returns
Collection of items in this queue.
- is_empty() bool[source]¶
Determines whether this set is empty or not.
- Returns
Trueif this queue is empty,Falseotherwise.
- offer(item: hazelcast.types.ItemType, timeout: float = 0) bool[source]¶
Inserts the specified element into this queue if it is possible to do so immediately without violating capacity restrictions.
If there is no space currently available:
If the timeout is provided, it waits until this timeout elapses and returns the result.
If the timeout is not provided, returns
Falseimmediately.
- Parameters
item – The item to be added.
timeout – Maximum time in seconds to wait for addition.
- Returns
Trueif the element was added to this queue,Falseotherwise.
- peek() Optional[hazelcast.types.ItemType][source]¶
Retrieves the head of queue without removing it from the queue.
- Returns
The head of this queue, or
Noneif this queue is empty.
- poll(timeout: float = 0) Optional[hazelcast.types.ItemType][source]¶
Retrieves and removes the head of this queue.
If this queue is empty:
If the timeout is provided, it waits until this timeout elapses and returns the result.
If the timeout is not provided, returns
None.
- Parameters
timeout – Maximum time in seconds to wait for addition.
- Returns
The head of this queue, or
Noneif this queue is empty or specified timeout elapses before an item is added to the queue.
- put(item: hazelcast.types.ItemType) None[source]¶
Adds the specified element into this queue.
If there is no space, it waits until necessary space becomes available.
- Parameters
item – The specified item.
- remaining_capacity() int[source]¶
Returns the remaining capacity of this queue.
- Returns
Remaining capacity of this queue.
- remove(item: hazelcast.types.ItemType) bool[source]¶
Removes the specified element from the queue if it exists.
- Parameters
item – The specified element to be removed.
- Returns
Trueif the specified element exists in this queue,Falseotherwise.
- remove_all(items: Sequence[hazelcast.types.ItemType]) bool[source]¶
Removes all of the elements of the specified collection from this queue.
- Parameters
items – The specified collection.
- Returns
Trueif the call changed this queue,Falseotherwise.
- remove_listener(registration_id: str) bool[source]¶
Removes the specified item listener.
Returns silently if the specified listener was not added before.
- Parameters
registration_id – Id of the listener to be deleted.
- Returns
Trueif the item listener is removed,Falseotherwise.
- retain_all(items: Sequence[hazelcast.types.ItemType]) bool[source]¶
Removes the items which are not contained in the specified collection.
In other words, only the items that are contained in the specified collection will be retained.
- Parameters
items – Collection which includes the elements to be retained in this set.
- Returns
Trueif this queue changed as a result of the call,Falseotherwise.
- size() int[source]¶
Returns the number of elements in this collection.
If the size is greater than
2**31 - 1, it returns2**31 - 1.- Returns
Size of the queue.
- take() hazelcast.types.ItemType[source]¶
Retrieves and removes the head of this queue, if necessary, waits until an item becomes available.
- Returns
The head of this queue.
- destroy() bool[source]¶
Destroys this proxy.
- Returns
Trueif this proxy is destroyed successfully,Falseotherwise.
- blocking() hazelcast.proxy.queue.BlockingQueue[hazelcast.types.ItemType][source]¶
Returns a version of this proxy with only blocking method calls.