JThreadKitTM
v1.1.0
(public members only)

com.jthreadkit.fifo
Class AbstractObjectFIFO

java.lang.Object
  |
  +--com.jthreadkit.AbstractSizeMonitored
        |
        +--com.jthreadkit.fifo.AbstractFIFO
              |
              +--com.jthreadkit.fifo.AbstractObjectFIFO
All Implemented Interfaces:
AccessibleLock, BasicFIFO, ObjectFIFO, SimpleShutdown, SizeMonitored, TimedOutExceptionOption
Direct Known Subclasses:
ArrayObjectFIFO, MultiArrayObjectFIFO

public abstract class AbstractObjectFIFO
extends AbstractFIFO
implements ObjectFIFO

Partial implementation of ObjectFIFO.


Method Summary
 void add(Object obj)
          Adds the specified object to the FIFO.
 boolean add(Object obj, long msTimeout)
          Adds the specified object to the FIFO.
 void addEach(Object[] list)
          Adds each of the objects in the array to the FIFO as individual elements.
 void addEach(Object[] list, int offset, int length)
          Adds some of the objects in the array to the FIFO as individual elements starting at the specifed offset and continuing for length elements.
 int addEach(Object[] list, int offset, int length, long msTimeout)
          Adds some of the objects in the array to the FIFO as individual elements starting at the specifed offset and continuing for length elements.
 int addEach(Object[] list, long msTimeout)
          Adds each of the objects in the array to the FIFO as individual elements.
 Class getElementType()
          Returns the type of items that can be stored in this FIFO.
 Object peek()
          Returns the next item that will be removed--without removing it from the FIFO.
 Object[] peek(int atLeast, int atMost)
          The same as remove(int, int) except that the items are not removed from the FIFO.
 Object[] peek(int atLeast, int atMost, long msTimeout)
          The same as remove(int, int, long) except that the items are not removed from the FIFO.
 Object peek(long msTimeout)
          Returns the next item that will be removed--without removing it from the FIFO.
 int peek(Object[] dest, int offset, int atLeast, int atMost)
          The same as remove(Object[], int, int, int) except that the items are not removed from the FIFO.
 int peek(Object[] dest, int offset, int atLeast, int atMost, long msTimeout)
          The same as remove(Object[], int, int, int, long) except that the items are not removed from the FIFO.
 Object[] peekAll()
          Returns a copy of everything currently in the FIFO (without removing the items).
 Object[] peekAtLeastOne()
          Waits until at least one item is in the FIFO and then returns all of the items (without removing them).
 Object[] peekAtLeastOne(long msTimeout)
          Waits until at least one item is in the FIFO and then returns all of the items (without removing them).
 Object remove()
          Removes one item from the FIFO.
 Object[] remove(int atLeast, int atMost)
          Wait until atLeast items are available and then remove up to atMost items from the FIFO.
 Object[] remove(int atLeast, int atMost, long msTimeout)
          Wait until atLeast items are available and then remove up to atMost items from the FIFO.
 Object remove(long msTimeout)
          Removes one item from the FIFO.
 int remove(Object[] dest, int offset, int atLeast, int atMost)
          Wait until atLeast items are available and then remove up to atMost items from the FIFO.
 int remove(Object[] dest, int offset, int atLeast, int atMost, long msTimeout)
          Wait until atLeast items are available and then remove up to atMost items from the FIFO.
 Object[] removeAll()
          Removes all the the items currently in the FIFO without blocking.
 Object[] removeAtLeastOne()
          Waits until at least one item is in the FIFO and then removes and returns all of the items.
 Object[] removeAtLeastOne(long msTimeout)
          Waits until at least one item is in the FIFO and then removes and returns all of the items.
 int setCapacity(int requestedCapacity)
          Requests that the capacity be grown or reduced.
 void setElementType(Class newType)
          Specifies a restriction on the type of objects than can be stored in this FIFO.
 
Methods inherited from class com.jthreadkit.fifo.AbstractFIFO
skip, skip, skipExactly, skipExactly
 
Methods inherited from class com.jthreadkit.AbstractSizeMonitored
addSizeChangeListener, getCapacity, getLockObject, getSize, isEmpty, isFull, isUseTimedOutExceptionSet, removeSizeChangeListener, setUseTimedOutException, shutdown, shutdownWhenEmpty, waitForSizeToChange, waitForSizeToChange, waitForSizeToClimbTo, waitForSizeToClimbTo, waitForSizeToFallTo, waitForSizeToFallTo, waitUntilEmpty, waitUntilEmpty, waitUntilFull, waitUntilFull, waitUntilSizeInRange, waitUntilSizeInRange, waitUntilSizeIs, waitUntilSizeIs, waitWhileEmpty, waitWhileEmpty, waitWhileFull, waitWhileFull, waitWhileSizeInRange, waitWhileSizeInRange, waitWhileSizeIs, waitWhileSizeIs
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.jthreadkit.fifo.BasicFIFO
skip, skip, skipExactly, skipExactly
 
Methods inherited from interface com.jthreadkit.SizeMonitored
addSizeChangeListener, getCapacity, getSize, isEmpty, isFull, removeSizeChangeListener, shutdownWhenEmpty, waitForSizeToChange, waitForSizeToChange, waitForSizeToClimbTo, waitForSizeToClimbTo, waitForSizeToFallTo, waitForSizeToFallTo, waitUntilEmpty, waitUntilEmpty, waitUntilFull, waitUntilFull, waitUntilSizeInRange, waitUntilSizeInRange, waitUntilSizeIs, waitUntilSizeIs, waitWhileEmpty, waitWhileEmpty, waitWhileFull, waitWhileFull, waitWhileSizeInRange, waitWhileSizeInRange, waitWhileSizeIs, waitWhileSizeIs
 
Methods inherited from interface com.jthreadkit.AccessibleLock
getLockObject
 
Methods inherited from interface com.jthreadkit.SimpleShutdown
shutdown
 
Methods inherited from interface com.jthreadkit.TimedOutExceptionOption
isUseTimedOutExceptionSet, setUseTimedOutException
 

Method Detail

setElementType

public void setElementType(Class newType)
                    throws ClassCastException,
                           ShutdownException
Description copied from interface: ObjectFIFO
Specifies a restriction on the type of objects than can be stored in this FIFO. By default this is Object.class and any reference can be stored, but sometimes you might want to restrict what can be put in.

Note: This is a somewhat expensive operation in most implementations and should be used sparingly.

Specified by:
setElementType in interface ObjectFIFO
Following copied from interface: com.jthreadkit.fifo.ObjectFIFO
Parameters:
newType - the class to restrict entries to.
Throws:
ClassCastException - if any of the elements already in the FIFO can't be cast into the specified type. This exception won't be thrown on empty queues. If this exception is thrown, the element type reverts back to what it was before and the FIFO is in the same (non-corrupted) state that it was before the request.
ShutdownException - see explanation.

getElementType

public Class getElementType()
Description copied from interface: ObjectFIFO
Returns the type of items that can be stored in this FIFO. See ObjectFIFO.setElementType(java.lang.Class).
Specified by:
getElementType in interface ObjectFIFO

setCapacity

public int setCapacity(int requestedCapacity)
                throws ShutdownException
Description copied from interface: SizeMonitored
Requests that the capacity be grown or reduced. If the requested new capacity is less than 1, it is silently increased to 1. If the requested new capacity is less than the current value returned from SizeMonitored.getSize(), it is silently increased to match the current size. The actual new capacity is returned. If the implementing class has (virtually) infinite capacity, then all calls made to this method are effectively ignored and Integer.MAX_VALUE is returned for the "new" capacity. The implementation of this method will typically be an expensive operation, so calls to setCapacity should be used sparingly.

To trim the capacity down to the current size--but only down to a minimum of 1, use:
  
int newCapacity = x.setCapacity(0);

Specified by:
setCapacity in interface SizeMonitored
Overrides:
setCapacity in class AbstractSizeMonitored
Following copied from interface: com.jthreadkit.SizeMonitored
Parameters:
requestedCapacity - the desired new capacity. This number is silently increased to minimum of 1 and/or the value returned from SizeMonitored.getSize() if necessary.
Returns:
the actual new capacity--may be larger than the requested capacity.
Throws:
ShutdownException - see explanation.

add

public boolean add(Object obj,
                   long msTimeout)
            throws InterruptedException,
                   TimedOutException,
                   ShutdownException,
                   ClassCastException
Description copied from interface: ObjectFIFO
Adds the specified object to the FIFO. If any exception is thrown, the item will not be added and the FIFO will remain coherent (will not be corrupted).
Specified by:
add in interface ObjectFIFO
Following copied from interface: com.jthreadkit.fifo.ObjectFIFO
Parameters:
msTimeout - maximum number of milliseconds to wait. Use ThreadTools.NO_TIMEOUT (or 0) to indicate that the waiting should never timeout.
Returns:
true if successful, false if a timeout occurs (and the timeout option is not set to throw exceptions [see explanation]).
Throws:
ClassCastException - if the passed object can't be cast into the type specified. See ObjectFIFO.getElementType().
InterruptedException - see explanation.
TimedOutException - see explanation.
ShutdownException - see explanation.

add

public void add(Object obj)
         throws InterruptedException,
                ShutdownException,
                ClassCastException
Description copied from interface: ObjectFIFO
Adds the specified object to the FIFO. If any exception is thrown, the item will not be added and the FIFO will remain coherent (will not be corrupted).
Specified by:
add in interface ObjectFIFO
Following copied from interface: com.jthreadkit.fifo.ObjectFIFO
Throws:
ClassCastException - if the passed object can't be cast into the type specified. See ObjectFIFO.getElementType().
InterruptedException - see explanation.
ShutdownException - see explanation.

addEach

public int addEach(Object[] list,
                   long msTimeout)
            throws InterruptedException,
                   TimedOutException,
                   ShutdownException,
                   ClassCastException
Description copied from interface: ObjectFIFO
Adds each of the objects in the array to the FIFO as individual elements.

WARNING: If any exception is thrown, an indeterminate number of elements may have been added. The FIFO will remain coherent (will not be corrupted), but you have to examine it to find out exactly what portion (if any) of the list was successfully added before the exception.

Specified by:
addEach in interface ObjectFIFO
Following copied from interface: com.jthreadkit.fifo.ObjectFIFO
Parameters:
msTimeout - maximum number of milliseconds to wait. Use ThreadTools.NO_TIMEOUT (or 0) to indicate that the waiting should never timeout.
Returns:
the number of elements from the list that were actually added (this might be less than the total if a timeout occurred).
Throws:
ClassCastException - if the one of the objects can't be cast into the type specified. See ObjectFIFO.getElementType().
InterruptedException - see explanation.
TimedOutException - see explanation.
ShutdownException - see explanation.

addEach

public void addEach(Object[] list)
             throws InterruptedException,
                    ShutdownException,
                    ClassCastException
Description copied from interface: ObjectFIFO
Adds each of the objects in the array to the FIFO as individual elements.

WARNING: If any exception is thrown, an indeterminate number of elements may have been added. The FIFO will remain coherent (will not be corrupted), but you have to examine it to find out exactly what portion (if any) of the list was successfully added before the exception.

Specified by:
addEach in interface ObjectFIFO
Following copied from interface: com.jthreadkit.fifo.ObjectFIFO
Throws:
ClassCastException - if the one of the objects can't be cast into the type specified. See ObjectFIFO.getElementType().
InterruptedException - see explanation.
ShutdownException - see explanation.

addEach

public int addEach(Object[] list,
                   int offset,
                   int length,
                   long msTimeout)
            throws InterruptedException,
                   TimedOutException,
                   ShutdownException,
                   ClassCastException
Description copied from interface: ObjectFIFO
Adds some of the objects in the array to the FIFO as individual elements starting at the specifed offset and continuing for length elements.

WARNING: If any exception is thrown, an indeterminate number of elements may have been added. The FIFO will remain coherent (will not be corrupted), but you have to examine it to find out exactly what portion (if any) of the list was successfully added before the exception.

Specified by:
addEach in interface ObjectFIFO
Following copied from interface: com.jthreadkit.fifo.ObjectFIFO
Parameters:
msTimeout - maximum number of milliseconds to wait. Use ThreadTools.NO_TIMEOUT (or 0) to indicate that the waiting should never timeout.
Returns:
the number of elements from the list that were actually added (this might be less than length if a timeout occurred).
Throws:
ClassCastException - if the one of the objects can't be cast into the type specified. See ObjectFIFO.getElementType().
InterruptedException - see explanation.
TimedOutException - see explanation.
ShutdownException - see explanation.

addEach

public void addEach(Object[] list,
                    int offset,
                    int length)
             throws InterruptedException,
                    ShutdownException,
                    ClassCastException
Description copied from interface: ObjectFIFO
Adds some of the objects in the array to the FIFO as individual elements starting at the specifed offset and continuing for length elements.

WARNING: If any exception is thrown, an indeterminate number of elements may have been added. The FIFO will remain coherent (will not be corrupted), but you have to examine it to find out exactly what portion (if any) of the list was successfully added before the exception.

Specified by:
addEach in interface ObjectFIFO
Following copied from interface: com.jthreadkit.fifo.ObjectFIFO
Throws:
ClassCastException - if the one of the objects can't be cast into the type specified. See ObjectFIFO.getElementType().
InterruptedException - see explanation.
ShutdownException - see explanation.

remove

public Object remove(long msTimeout)
              throws InterruptedException,
                     ShutdownException,
                     TimedOutException
Description copied from interface: ObjectFIFO
Removes one item from the FIFO.

If any exception is thrown, the contents of the FIFO are not altered and the FIFO remains coherent (not corrupted).

Specified by:
remove in interface ObjectFIFO
Following copied from interface: com.jthreadkit.fifo.ObjectFIFO
Parameters:
msTimeout - maximum number of milliseconds to wait. Use ThreadTools.NO_TIMEOUT (or 0) to indicate that the waiting should never timeout.
Returns:
the object removed, or null if there was a timeout. Caution: null can be validly entered into the FIFO, so in that case, we can't tell if a timeout occurred or if the null returned was actually removed from the queue!
Throws:
InterruptedException - see explanation.
TimedOutException - see explanation.
ShutdownException - see explanation.

remove

public Object remove()
              throws InterruptedException,
                     ShutdownException
Description copied from interface: ObjectFIFO
Removes one item from the FIFO.

If any exception is thrown, the contents of the FIFO are not altered and the FIFO remains coherent (not corrupted).

Specified by:
remove in interface ObjectFIFO
Following copied from interface: com.jthreadkit.fifo.ObjectFIFO
Returns:
the object removed.
Throws:
InterruptedException - see explanation.
ShutdownException - see explanation.

peek

public Object peek(long msTimeout)
            throws InterruptedException,
                   ShutdownException,
                   TimedOutException
Description copied from interface: ObjectFIFO
Returns the next item that will be removed--without removing it from the FIFO.
Specified by:
peek in interface ObjectFIFO
Following copied from interface: com.jthreadkit.fifo.ObjectFIFO
Parameters:
msTimeout - maximum number of milliseconds to wait. Use ThreadTools.NO_TIMEOUT (or 0) to indicate that the waiting should never timeout.
Returns:
the next object, or null if there was a timeout. Caution: null can be validly entered into the FIFO, so in that case, we can't tell if a timeout occurred or if the null returned was actually from the queue!
Throws:
InterruptedException - see explanation.
TimedOutException - see explanation.
ShutdownException - see explanation.

peek

public Object peek()
            throws InterruptedException,
                   ShutdownException
Description copied from interface: ObjectFIFO
Returns the next item that will be removed--without removing it from the FIFO.
Specified by:
peek in interface ObjectFIFO
Following copied from interface: com.jthreadkit.fifo.ObjectFIFO
Returns:
the next object.
Throws:
InterruptedException - see explanation.
ShutdownException - see explanation.

remove

public int remove(Object[] dest,
                  int offset,
                  int atLeast,
                  int atMost,
                  long msTimeout)
           throws InterruptedException,
                  ShutdownException,
                  TimedOutException,
                  ClassCastException
Description copied from interface: ObjectFIFO
Wait until atLeast items are available and then remove up to atMost items from the FIFO. Load these items into the specified array dest starting at the specified offset.

The values for atLeast and atMost may be silently coerced into this range:
  
0 <= atLeast <= atMost <= getCapacity()
See this explanation for more details.

If any exception is thrown, the contents of the FIFO are not altered and the FIFO remains coherent (not corrupted). It is possible that a portion of the destination array is overwritten, but this partial information should be ignored.

Specified by:
remove in interface ObjectFIFO
Following copied from interface: com.jthreadkit.fifo.ObjectFIFO
Parameters:
msTimeout - maximum number of milliseconds to wait. Use ThreadTools.NO_TIMEOUT (or 0) to indicate that the waiting should never timeout.
Returns:
the number of items actually removed. This will be zero on a timeout. Under some circumstances, it can be less than atLeast see explanation
Throws:
ClassCastException - if the one of the stored objects can't be cast into the type of the dest array.
InterruptedException - see explanation.
TimedOutException - see explanation.
ShutdownException - see explanation.

remove

public int remove(Object[] dest,
                  int offset,
                  int atLeast,
                  int atMost)
           throws InterruptedException,
                  ShutdownException,
                  ClassCastException
Description copied from interface: ObjectFIFO
Wait until atLeast items are available and then remove up to atMost items from the FIFO. Load these items into the specified array dest starting at the specified offset.

The values for atLeast and atMost may be silently coerced into this range:
  
0 <= atLeast <= atMost <= getCapacity()
See this explanation for more details.

If any exception is thrown, the contents of the FIFO are not altered and the FIFO remains coherent (not corrupted). It is possible that a portion of the destination array is overwritten, but this partial information should be ignored.

Specified by:
remove in interface ObjectFIFO
Following copied from interface: com.jthreadkit.fifo.ObjectFIFO
Returns:
the number of items actually removed. Under some circumstances, it can be less than atLeast see explanation
Throws:
ClassCastException - if the one of the stored objects can't be cast into the type of the dest array.
InterruptedException - see explanation.
ShutdownException - see explanation.

peek

public int peek(Object[] dest,
                int offset,
                int atLeast,
                int atMost,
                long msTimeout)
         throws InterruptedException,
                ShutdownException,
                TimedOutException,
                ClassCastException
Description copied from interface: ObjectFIFO
The same as remove(Object[], int, int, int, long) except that the items are not removed from the FIFO.
Specified by:
peek in interface ObjectFIFO

peek

public int peek(Object[] dest,
                int offset,
                int atLeast,
                int atMost)
         throws InterruptedException,
                ShutdownException,
                ClassCastException
Description copied from interface: ObjectFIFO
The same as remove(Object[], int, int, int) except that the items are not removed from the FIFO.
Specified by:
peek in interface ObjectFIFO

remove

public Object[] remove(int atLeast,
                       int atMost,
                       long msTimeout)
                throws InterruptedException,
                       ShutdownException,
                       TimedOutException
Description copied from interface: ObjectFIFO
Wait until atLeast items are available and then remove up to atMost items from the FIFO.

The values for atLeast and atMost may be silently coerced into this range:
  
0 <= atLeast <= atMost <= getCapacity()
See this explanation for more details.

If any exception is thrown, the contents of the FIFO are not altered and the FIFO remains coherent (not corrupted).

Specified by:
remove in interface ObjectFIFO
Following copied from interface: com.jthreadkit.fifo.ObjectFIFO
Parameters:
msTimeout - maximum number of milliseconds to wait. Use ThreadTools.NO_TIMEOUT (or 0) to indicate that the waiting should never timeout.
Returns:
the items removed, or a zero-length array if a timeout occurred. Under some circumstances, it can be less than atLeast see explanation
Throws:
InterruptedException - see explanation.
TimedOutException - see explanation.
ShutdownException - see explanation.

remove

public Object[] remove(int atLeast,
                       int atMost)
                throws InterruptedException,
                       ShutdownException
Description copied from interface: ObjectFIFO
Wait until atLeast items are available and then remove up to atMost items from the FIFO.

The values for atLeast and atMost may be silently coerced into this range:
  
0 <= atLeast <= atMost <= getCapacity()
See this explanation for more details.

If any exception is thrown, the contents of the FIFO are not altered and the FIFO remains coherent (not corrupted).

Specified by:
remove in interface ObjectFIFO
Following copied from interface: com.jthreadkit.fifo.ObjectFIFO
Returns:
the items removed. Under some circumstances, it can be less than atLeast see explanation
Throws:
InterruptedException - see explanation.
ShutdownException - see explanation.

peek

public Object[] peek(int atLeast,
                     int atMost,
                     long msTimeout)
              throws InterruptedException,
                     ShutdownException,
                     TimedOutException
Description copied from interface: ObjectFIFO
The same as remove(int, int, long) except that the items are not removed from the FIFO.
Specified by:
peek in interface ObjectFIFO

peek

public Object[] peek(int atLeast,
                     int atMost)
              throws InterruptedException,
                     ShutdownException
Description copied from interface: ObjectFIFO
The same as remove(int, int) except that the items are not removed from the FIFO.
Specified by:
peek in interface ObjectFIFO

removeAll

public Object[] removeAll()
                   throws ShutdownException
Description copied from interface: ObjectFIFO
Removes all the the items currently in the FIFO without blocking. If the FIFO is empty, a zero-length array is returned.
Specified by:
removeAll in interface ObjectFIFO
Following copied from interface: com.jthreadkit.fifo.ObjectFIFO
Throws:
ShutdownException - see explanation.

peekAll

public Object[] peekAll()
Description copied from interface: ObjectFIFO
Returns a copy of everything currently in the FIFO (without removing the items). If the FIFO is empty, a zero-length array is immediately returned (no blocking).
Specified by:
peekAll in interface ObjectFIFO

removeAtLeastOne

public Object[] removeAtLeastOne(long msTimeout)
                          throws InterruptedException,
                                 ShutdownException,
                                 TimedOutException
Description copied from interface: ObjectFIFO
Waits until at least one item is in the FIFO and then removes and returns all of the items.

If any exception is thrown, the contents of the FIFO are not altered and the FIFO remains coherent (not corrupted).

Specified by:
removeAtLeastOne in interface ObjectFIFO
Following copied from interface: com.jthreadkit.fifo.ObjectFIFO
Parameters:
msTimeout - maximum number of milliseconds to wait. Use ThreadTools.NO_TIMEOUT (or 0) to indicate that the waiting should never timeout.
Returns:
the items removed, or a zero-length array if a timeout occurred.
Throws:
InterruptedException - see explanation.
TimedOutException - see explanation.
ShutdownException - see explanation.

removeAtLeastOne

public Object[] removeAtLeastOne()
                          throws InterruptedException,
                                 ShutdownException
Description copied from interface: ObjectFIFO
Waits until at least one item is in the FIFO and then removes and returns all of the items.

If any exception is thrown, the contents of the FIFO are not altered and the FIFO remains coherent (not corrupted).

Specified by:
removeAtLeastOne in interface ObjectFIFO
Following copied from interface: com.jthreadkit.fifo.ObjectFIFO
Returns:
the items removed.
Throws:
InterruptedException - see explanation.
ShutdownException - see explanation.

peekAtLeastOne

public Object[] peekAtLeastOne(long msTimeout)
                        throws InterruptedException,
                               ShutdownException,
                               TimedOutException
Description copied from interface: ObjectFIFO
Waits until at least one item is in the FIFO and then returns all of the items (without removing them).
Specified by:
peekAtLeastOne in interface ObjectFIFO
Following copied from interface: com.jthreadkit.fifo.ObjectFIFO
Parameters:
msTimeout - maximum number of milliseconds to wait. Use ThreadTools.NO_TIMEOUT (or 0) to indicate that the waiting should never timeout.
Returns:
the items removed, or a zero-length array if a timeout occurred.
Throws:
InterruptedException - see explanation.
TimedOutException - see explanation.
ShutdownException - see explanation.

peekAtLeastOne

public Object[] peekAtLeastOne()
                        throws InterruptedException,
                               ShutdownException
Description copied from interface: ObjectFIFO
Waits until at least one item is in the FIFO and then returns all of the items (without removing them).
Specified by:
peekAtLeastOne in interface ObjectFIFO
Following copied from interface: com.jthreadkit.fifo.ObjectFIFO
Returns:
the items removed.
Throws:
InterruptedException - see explanation.
ShutdownException - see explanation.

JThreadKitTM
v1.1.0
(public members only)

© Copyright 2000-2001 Programix Incorporated. All rights reserved. JThreadKit home