regionQueue
Class ServerQueue

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.ServerQueue
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 ServerQueue
extends com.gemstone.bp.edu.emory.mathcs.backport.java.util.AbstractQueue
implements com.gemstone.bp.edu.emory.mathcs.backport.java.util.concurrent.BlockingQueue

The server side of a distributed queue. The server holds the contents of a queue in a RegionQueue that may be backed up in other servers. It receives clients' requests to add and remove items from the queue via a "communication region" that has a special CacheLoader and CacheWriter that interact with the queue.

This class implements the BlockingQueue interface so it can be treated as a queue. However, it delegates all of the queue-related functionality to the underlying RegionQueue.

Since:
4.1
Author:
GemStone Systems, Inc.

Nested Class Summary
(package private)  class ServerQueue.QueueLoader
          A CacheLoader that perform some "get"-related operation on the RegionQueue.
(package private)  class ServerQueue.QueueWriter
          A CacheWriter that adds an element to the tail of the queue.
 
Field Summary
(package private) static String COMM_REGION_NAME
          The name of the subregion used for communication.
protected  String name
          The name of this queue
protected  RegionQueue regionQueue
          The region queue that stores the contents of this distributed queue.
 
Constructor Summary
ServerQueue(String name, int capacity, DistributedSystem system, int port)
          Creates a new ServerQueue whose contents is available to ClientQueue via the given port.
 
Method Summary
 void close()
          Closes this ServerQueue and releases all resources held by it including the Cache and all regions.
 int drainTo(Collection c)
           
 int drainTo(Collection c, int maxElements)
           
 String getName()
           
 boolean isEmpty()
           
 Iterator iterator()
           
static void main(String[] args)
          A main program that creates a ServerQueue.
 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

COMM_REGION_NAME

static final String COMM_REGION_NAME
The name of the subregion used for communication. It is package protected so that other classe scan share it.

See Also:
Constant Field Values

name

protected final String name
The name of this queue


regionQueue

protected final RegionQueue regionQueue
The region queue that stores the contents of this distributed queue.

Constructor Detail

ServerQueue

public ServerQueue(String name,
                   int capacity,
                   DistributedSystem system,
                   int port)
            throws TimeoutException
Creates a new ServerQueue whose contents is available to ClientQueue via the given port.

Parameters:
name - The name of the distributed queue
system - The distributed system to which the queue belongs
port - The port on which clients connect to the queue
capacity - The maximum number of elements allowed in the queue
Throws:
TimeoutException - If a cache access times out which creating the queue
IllegalStateException - If the state of the cache prevents the queue from being created
Method Detail

close

public void close()
Closes this ServerQueue and releases all resources held by it including the Cache and all regions.


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()
Specified by:
iterator in interface Iterable
Specified by:
iterator in interface Collection
Specified by:
iterator in class AbstractCollection

drainTo

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

drainTo

public int drainTo(Collection c,
                   int maxElements)
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
A main program that creates a ServerQueue.

Throws:
Throwable


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