Queue

exception Empty

Bases: exceptions.Exception

exception Full

Bases: exceptions.Exception

class Queue(client, service_name, name)

Bases: hazelcast.proxy.base.PartitionSpecificProxy

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)

Adds the specified item to this queue if there is available space.

Parameters:item – (object), the specified item.
Returns:(bool), true if element is successfully added, false otherwise.
add_all(items)

Adds the elements in the specified collection to this queue.

Parameters:items – (Collection), collection which includes the items to be added.
Returns:(bool), true if this queue is changed after call, false otherwise.
add_listener(include_value=False, item_added_func=None, item_removed_func=None)

Adds an item listener for this queue. Listener will be notified for all queue add/remove events.

Parameters:
  • include_value – (bool), whether received events include the updated item or not (optional).
  • item_added_func – Function to be called when an item is added to this set (optional).
  • item_removed_func – Function to be called when an item is deleted from this set (optional).
Returns:

(str), a registration id which is used as a key to remove the listener.

clear()

Clears this queue. Queue will be empty after this call.

contains(item)

Determines whether this queue contains the specified item or not.

Parameters:item – (object), the specified item to be searched.
Returns:(bool), true if the specified item exists in this queue, false otherwise.
contains_all(items)

Determines whether this queue contains all of the items in the specified collection or not.

Parameters:items – (Collection), the specified collection which includes the items to be searched.
Returns:(bool), true if all of the items in the specified collection exist in this queue, false otherwise.
drain_to(list, max_size=-1)

Transfers all available items to the given 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:
  • list – (list), the list where the items in this queue will be transferred.
  • max_size – (int), the maximum number items to transfer (optional).
Returns:

(int), number of transferred items.

iterator()

Returns all of the items in this queue.

Returns:(Sequence), collection of items in this queue.
is_empty()

Determines whether this set is empty or not.

Returns:(bool), true if this queue is empty, false otherwise.
offer(item, timeout=0)

Inserts the specified element into this queue if it is possible to do so immediately without violating capacity restrictions. Returns true upon success. If there is no space currently available:

  • If a timeout is provided, it waits until this timeout elapses and returns the result.
  • If a timeout is not provided, returns false immediately.
Parameters:
  • item – (object), the item to be added.
  • timeout – (long), maximum time in seconds to wait for addition (optional).
Returns:

(bool), true if the element was added to this queue, false otherwise.

peek()

Retrieves the head of queue without removing it from the queue. If the queue is empty, returns None.

Returns:(object), the head of this queue, or None if this queue is empty.
poll(timeout=0)
Retrieves and removes the head of this queue, if this queue is empty:
  • If a timeout is provided, it waits until this timeout elapses and returns the result.
  • If a timeout is not provided, returns None.
Parameters:timeout – (long), maximum time in seconds to wait for addition (optional).
Returns:(object), the head of this queue, or None if this queue is empty or specified timeout elapses before an

item is added to the queue.

put(item)

Adds the specified element into this queue. If there is no space, it waits until necessary space becomes available.

Parameters:item – (object), the specified item.
remaining_capacity()

Returns the remaining capacity of this queue.

Returns:(int), remaining capacity of this queue.
remove(item)

Removes the specified element from the queue if it exists.

Parameters:item – (object), the specified element to be removed.
Returns:(bool), true if the specified element exists in this queue.
remove_all(items)

Removes all of the elements of the specified collection from this queue.

Parameters:items – (Collection), the specified collection.
Returns:(bool), true if the call changed this queue, false otherwise.
remove_listener(registration_id)

Removes the specified item listener. Returns silently if the specified listener was not added before.

Parameters:registration_id – (str), id of the listener to be deleted.
Returns:(bool), true if the item listener is removed, false otherwise.
retain_all(items)

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), collection which includes the elements to be retained in this set.
Returns:(bool), true if this queue changed as a result of the call.
size()

Returns the number of elements in this collection. If the size is greater than sys.maxint, it returns sys.maxint.

Returns:(int), size of the queue.
take()

Retrieves and removes the head of this queue, if necessary, waits until an item becomes available.

Returns:(object), the head of this queue.