QJCC homepage

biz.chitec.quarterback.util
Class LimitedThreadInterface

java.lang.Object
  extended bybiz.chitec.quarterback.util.ThreadInterface
      extended bybiz.chitec.quarterback.util.LimitedThreadInterface

public class LimitedThreadInterface
extends ThreadInterface

Implements a @see biz.chitec.quarterback.util.ThreadInterface which allows you to dynamically control the internal queue size. If the internal queue would grow beyond its maximum size the producer thread is stopped and waits for the consumer to clean up the queue.

Version:
$Id: 7ea8bcfac87d00c774118b494f652e267eb4064a $
Author:
chitec/Sebastian Cramer 2000 Distributed under the terms of the GNU LGPL.

Nested Class Summary
 
Nested classes inherited from class biz.chitec.quarterback.util.ThreadInterface
ThreadInterface.ChainElem
 
Field Summary
private  ThreadKicker gc
           
private  int maxGems
           
private  ThreadKicker tk
           
 
Fields inherited from class biz.chitec.quarterback.util.ThreadInterface
closing, consumersleeping, first, worked
 
Constructor Summary
LimitedThreadInterface()
          Constructor which sets the maximum queue size to the default of ten entries.
LimitedThreadInterface(int maxItems)
          Constructor which also sets the max internal queue size
 
Method Summary
 void close()
          Does exactly what it is expected to be doing.
 java.lang.Object consume()
          Get an object from the internal queue.
 void produce(java.lang.Object o)
          Puts an object on the internal queue.
 void setThreadQueueSize(int maxItems)
          Dynamically adjusts internal queue size.
 
Methods inherited from class biz.chitec.quarterback.util.ThreadInterface
consume, consumerSleeping, consumerWouldIdle, isClosing
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

tk

private ThreadKicker tk

gc

private ThreadKicker gc

maxGems

private int maxGems
Constructor Detail

LimitedThreadInterface

public LimitedThreadInterface(int maxItems)
Constructor which also sets the max internal queue size

Parameters:
maxItems - The maximum number of entries to the queue table

LimitedThreadInterface

public LimitedThreadInterface()
Constructor which sets the maximum queue size to the default of ten entries.

Method Detail

consume

public java.lang.Object consume()
                         throws java.io.IOException
Get an object from the internal queue.

Overrides:
consume in class ThreadInterface
Returns:
The object that has been removed from the queue.
Throws:
Throws - an IOException if object is already closed.
java.io.IOException - If the ThreadInterface is closed in the meantime.

produce

public void produce(java.lang.Object o)
             throws java.io.IOException
Puts an object on the internal queue. Blocks the calling process if there are too many objects in queue.

Overrides:
produce in class ThreadInterface
Parameters:
o - The object to be put in queue.
Throws:
Throws - an IOException if object is already closed.
java.io.IOException

close

public void close()
Does exactly what it is expected to be doing.

Overrides:
close in class ThreadInterface

setThreadQueueSize

public void setThreadQueueSize(int maxItems)
                        throws java.io.IOException
Dynamically adjusts internal queue size.

Parameters:
maxItems - The new maximum number of queue items.
Throws:
Throws - an IOException if object is already closed.
java.io.IOException

QJCC homepage