regionQueue
Class ClientQueue

java.lang.Object
  extended by java.util.AbstractCollection
      extended by com.gemstone.bp.edu.emory.mathcs.backport.java.util.AbstractCollection
          extended by com.gemstone.bp.edu.emory.mathcs.backport.java.util.AbstractQueue
              extended by regionQueue.ClientQueue
All Implemented Interfaces:
com.gemstone.bp.edu.emory.mathcs.backport.java.util.concurrent.BlockingQueue, com.gemstone.bp.edu.emory.mathcs.backport.java.util.Queue, Iterable, Collection

public class ClientQueue
extends com.gemstone.bp.edu.emory.mathcs.backport.java.util.AbstractQueue
implements com.gemstone.bp.edu.emory.mathcs.backport.java.util.concurrent.BlockingQueue

The client side of a distributed queue. A ClientQueue implements the BlockingQueue interface and delegates its work to a RegionQueue that is hosted by a ServerQueue.

Since:
4.1
Author:
GemStone Systems, Inc.

Field Summary
protected  String id
          The id of this VM
(package private) static String INSERT_PREFIX
          This is the key of the region element used for adding elements to the queue.
(package private) static Object IS_EMPTY
          An argument to a Region get() that denotes that it is an "is empty" operation.
protected static long nextRequestId
          The next request id to use when getting an element from the server queue.
(package private) static Object PEEK
          An argument to a Region get() that denotes that it is a peek operation.
(package private) static Object PUT
          An argument to a Region put() that denotes that it is a (queue) put operation.
(package private) static Object REMAINING_CAPACITY
          An argument to a Region get() that denotes that it is a "remaining capacity" operation.
(package private) static Object SIZE
          An argument to a Region get() that denotes that it is a size operation.
(package private) static Object TAKE
          An argument to a Region get() that denotes that it is a take operation.
(package private) static Object TO_ARRAY
          An argument to a Region get() that denotes that it is a "to array" operation.
 
Constructor Summary
ClientQueue(String name, String[] hosts, int[] ports)
          Creates a new ClientQueue that will access queues hosted by the given servers.
 
Method Summary
 void close()
          Closes this ClientQueue and releases all resources associated with it including the communication Region
 int drainTo(Collection c)
          Throws an UnsupportedOperationException
 int drainTo(Collection c, int maxElements)
          Throws an UnsupportedOperationException
 String getName()
           
 boolean isEmpty()
           
 Iterator iterator()
          Throws an UnsupportedOperationException
static void main(String[] args)
          Main program that creates a ClientQueue and allows the user to interact with it via the console.
 boolean offer(Object o)
           
 boolean offer(Object o, long timeout, com.gemstone.bp.edu.emory.mathcs.backport.java.util.concurrent.TimeUnit unit)
           
 Object peek()
           
 Object poll()
           
 Object poll(long timeout, com.gemstone.bp.edu.emory.mathcs.backport.java.util.concurrent.TimeUnit unit)
           
 void put(Object o)
           
 int remainingCapacity()
           
 int size()
           
 Object take()
           
 Object[] toArray()
           
 Object[] toArray(Object[] array)
           
 String toString()
           
 
Methods inherited from class com.gemstone.bp.edu.emory.mathcs.backport.java.util.AbstractQueue
add, addAll, clear, element, remove
 
Methods inherited from class java.util.AbstractCollection
contains, containsAll, remove, removeAll, retainAll
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface com.gemstone.bp.edu.emory.mathcs.backport.java.util.concurrent.BlockingQueue
add, contains, remove
 
Methods inherited from interface com.gemstone.bp.edu.emory.mathcs.backport.java.util.Queue
element, remove
 
Methods inherited from interface java.util.Collection
addAll, clear, containsAll, equals, hashCode, removeAll, retainAll
 

Field Detail

PEEK

static Object PEEK
An argument to a Region get() that denotes that it is a peek operation.


TAKE

static Object TAKE
An argument to a Region get() that denotes that it is a take operation.


PUT

static Object PUT
An argument to a Region put() that denotes that it is a (queue) put operation.


IS_EMPTY

static Object IS_EMPTY
An argument to a Region get() that denotes that it is an "is empty" operation.


SIZE

static Object SIZE
An argument to a Region get() that denotes that it is a size operation.


REMAINING_CAPACITY

static Object REMAINING_CAPACITY
An argument to a Region get() that denotes that it is a "remaining capacity" operation.


TO_ARRAY

static Object TO_ARRAY
An argument to a Region get() that denotes that it is a "to array" operation.


nextRequestId

protected static long nextRequestId
The next request id to use when getting an element from the server queue.


id

protected String id
The id of this VM


INSERT_PREFIX

static String INSERT_PREFIX
This is the key of the region element used for adding elements to the queue. Its uniqueness is required to prevent deadlock on the Cache server.

Constructor Detail

ClientQueue

public ClientQueue(String name,
                   String[] hosts,
                   int[] ports)
            throws TimeoutException
Creates a new ClientQueue that will access queues hosted by the given servers.

Parameters:
name - The name of the distributed queue
hosts - The host(s) on which the server queue(s) reside
ports - The port(s) through which the server queue(s) are accessed.
Throws:
TimeoutException - If a cache access times out which creating the client queue
IllegalStateException - If the state of the cache prevents the client queue from being created
Method Detail

close

public void close()
Closes this ClientQueue and releases all resources associated with it including the communication Region


put

public void put(Object o)
         throws InterruptedException
Specified by:
put in interface com.gemstone.bp.edu.emory.mathcs.backport.java.util.concurrent.BlockingQueue
Throws:
InterruptedException

take

public Object take()
            throws InterruptedException
Specified by:
take in interface com.gemstone.bp.edu.emory.mathcs.backport.java.util.concurrent.BlockingQueue
Throws:
InterruptedException

peek

public Object peek()
Specified by:
peek in interface com.gemstone.bp.edu.emory.mathcs.backport.java.util.Queue

isEmpty

public boolean isEmpty()
Specified by:
isEmpty in interface Collection
Overrides:
isEmpty in class AbstractCollection

poll

public Object poll()
Specified by:
poll in interface com.gemstone.bp.edu.emory.mathcs.backport.java.util.Queue

size

public int size()
Specified by:
size in interface Collection
Specified by:
size in class AbstractCollection

toArray

public Object[] toArray(Object[] array)
Specified by:
toArray in interface Collection
Overrides:
toArray in class com.gemstone.bp.edu.emory.mathcs.backport.java.util.AbstractCollection

toArray

public Object[] toArray()
Specified by:
toArray in interface Collection
Overrides:
toArray in class com.gemstone.bp.edu.emory.mathcs.backport.java.util.AbstractCollection

poll

public Object poll(long timeout,
                   com.gemstone.bp.edu.emory.mathcs.backport.java.util.concurrent.TimeUnit unit)
            throws InterruptedException
Specified by:
poll in interface com.gemstone.bp.edu.emory.mathcs.backport.java.util.concurrent.BlockingQueue
Throws:
InterruptedException

offer

public boolean offer(Object o)
Specified by:
offer in interface com.gemstone.bp.edu.emory.mathcs.backport.java.util.concurrent.BlockingQueue
Specified by:
offer in interface com.gemstone.bp.edu.emory.mathcs.backport.java.util.Queue

offer

public boolean offer(Object o,
                     long timeout,
                     com.gemstone.bp.edu.emory.mathcs.backport.java.util.concurrent.TimeUnit unit)
              throws InterruptedException
Specified by:
offer in interface com.gemstone.bp.edu.emory.mathcs.backport.java.util.concurrent.BlockingQueue
Throws:
InterruptedException

remainingCapacity

public int remainingCapacity()
Specified by:
remainingCapacity in interface com.gemstone.bp.edu.emory.mathcs.backport.java.util.concurrent.BlockingQueue

iterator

public Iterator iterator()
Throws an UnsupportedOperationException

Specified by:
iterator in interface Iterable
Specified by:
iterator in interface Collection
Specified by:
iterator in class AbstractCollection

drainTo

public int drainTo(Collection c)
Throws an UnsupportedOperationException

Specified by:
drainTo in interface com.gemstone.bp.edu.emory.mathcs.backport.java.util.concurrent.BlockingQueue

drainTo

public int drainTo(Collection c,
                   int maxElements)
Throws an UnsupportedOperationException

Specified by:
drainTo in interface com.gemstone.bp.edu.emory.mathcs.backport.java.util.concurrent.BlockingQueue

getName

public String getName()

toString

public String toString()
Overrides:
toString in class AbstractCollection

main

public static void main(String[] args)
                 throws Throwable
Main program that creates a ClientQueue and allows the user to interact with it via the console.

Throws:
Throwable


Copyright © 2002-2008 GemStone Systems, Inc. All Rights Reserved.