|
JThreadKitTM v1.1.0 ( public members only)
|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
The SizeMonitored interface is widely used throughout JThreadKit. It is used to keep tabs on the current "size" of something --for example the number of elements in a List or a FIFO queue. One thread can be waiting for the size to change while another thread does the changing.
Unless otherwise noted, all methods are internally
synchronized (using synchronized blocks of
code)
on the Object returned by the getLockObject() method specified by the AccessibleLock interface
to control concurrency. Implementors of this interface must
guarantee this synchronization behavior!
InterruptedException - can be thrown from many
of the methods in this class. If one thread is blocked inside
one of these methods and another thread interrupts it,
InterruptedException is thrown by the blocked thread.
TimedOutException - can be thrown from many
of the methods in this class only if the
"use TimedOutException" option is set.
If true is passed to the
setUseTimedOutException()
method, the option is set and TimedOutException will be
thrown from methods that timeout when the specified timeout period
expires. If false is passed, the option is unset and
TimedOutException will never be thrown.
The TimedOutExceptionOption.isUseTimedOutExceptionSet() method returns true
if the option is set and TimedOutException's will be thrown.
TimedOutException is a subclass of RuntimeException
so there is no need for a try-catch block if the option is not set.
This option allows you to determine whether or not a timeout is
an exceptional condition in your context (a condition that
should result in an exception being thrown). If timeouts are routine,
you probably will want to leave this option in its default unset state.
See the class description of
TimedOutException for more information.
ShutdownException - can be thrown from many
of the methods in this class. This exception is not thrown by methods
until the SimpleShutdown.shutdown() method is called. If shutdown() is
never called, this exception will never be thrown and can
be safely ignored. ShutdownException is a subclass of
RuntimeException so there is no need for a try-catch block
if shutdown() won't be called. After shutdown()
is called, any threads that are currently blocked waiting will immediately
throw this exception. In addition, any future calls to methods that would
either result in waiting or would alter the object cause
this exception to be thrown (if no waiting is needed because the condition
is already met, this exception will not be thrown).
See the class description of
ShutdownException for more information.
| Method Summary | |
void |
addSizeChangeListener(SizeChangeListener listener)
Adds a new SizeChangeListener for notification when
the size changes. |
int |
getCapacity()
Returns the maximum size possible. |
int |
getSize()
Returns the current size. |
boolean |
isEmpty()
Returns true if the size is currently zero. |
boolean |
isFull()
Returns true if the size is equal to the value
returned from getCapacity(). |
boolean |
removeSizeChangeListener(SizeChangeListener listener)
Removes the specified SizeChangeListener so that it is
no longer notified of size changes. |
int |
setCapacity(int requestedCapacity)
Requests that the capacity be grown or reduced. |
boolean |
shutdownWhenEmpty(long msTimeout)
Waits until isEmpty() is true and then proceeds
to automatically invoke SimpleShutdown.shutdown(). |
void |
waitForSizeToChange()
Waits for the size to change. |
boolean |
waitForSizeToChange(long msTimeout)
Waits (up to the specified amount of time) for the size to change. |
void |
waitForSizeToClimbTo(int atLeast)
Waits for the size to meet or exceed to the specified value. |
boolean |
waitForSizeToClimbTo(int atLeast,
long msTimeout)
Waits (up to the specified amount of time) for the size to meet or exceed to the specified value. |
void |
waitForSizeToFallTo(int atMost)
Waits for the size to match or drop below to the specified value. |
boolean |
waitForSizeToFallTo(int atMost,
long msTimeout)
Waits (up to the specified amount of time) for the size to match or drop below to the specified value. |
void |
waitUntilEmpty()
Waits for the size to drop to zero. |
boolean |
waitUntilEmpty(long msTimeout)
Waits (up to the specified amount of time) for the size to drop to zero. |
void |
waitUntilFull()
Waits for the size to climb to the capacity. |
boolean |
waitUntilFull(long msTimeout)
Waits (up to the specified amount of time) for the size to climb to the capacity. |
void |
waitUntilSizeInRange(int min,
int max)
Waits until the size is in the inclusive range specified. |
boolean |
waitUntilSizeInRange(int min,
int max,
long msTimeout)
Waits (up to the specified amount of time) until the size is in the inclusive range specified. |
void |
waitUntilSizeIs(int target)
Waits until the size matches the passed target value. |
boolean |
waitUntilSizeIs(int target,
long msTimeout)
Waits (up to the specified amount of time) until the size matches the passed target value. |
void |
waitWhileEmpty()
Waits while the size is zero. |
boolean |
waitWhileEmpty(long msTimeout)
Waits (up to the specified amount of time) while the size is zero. |
void |
waitWhileFull()
Waits while the size is equal to the capacity. |
boolean |
waitWhileFull(long msTimeout)
Waits (up to the specified amount of time) while the size is equal to the capacity. |
void |
waitWhileSizeInRange(int min,
int max)
Waits while the size is in the inclusive range specified. |
boolean |
waitWhileSizeInRange(int min,
int max,
long msTimeout)
Waits (up to the specified amount of time) while the size is in the inclusive range specified. |
void |
waitWhileSizeIs(int target)
Waits while the size matches the passed target value. |
boolean |
waitWhileSizeIs(int target,
long msTimeout)
Waits (up to the specified amount of time) while the size matches the passed target value. |
| 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 |
public int setCapacity(int requestedCapacity)
throws ShutdownException
1,
it is silently increased to 1.
If the requested new capacity is less than the current value
returned from 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); |
requestedCapacity - the desired new capacity.
This number is silently increased to minimum of 1
and/or the value returned from getSize() if necessary.ShutdownException - see explanation.public int getCapacity()
Integer.MAX_VALUE if there is no maximum.setCapacity(int),
getSize()public int getSize()
public boolean isEmpty()
true if the size is currently zero.public boolean isFull()
true if the size is equal to the value
returned from getCapacity().
public boolean waitUntilEmpty(long msTimeout)
throws InterruptedException,
TimedOutException,
ShutdownException
msTimeout - maximum number of milliseconds to wait. Use
ThreadTools.NO_TIMEOUT (or 0) to indicate that
the waiting should never timeout.true if successful, false if
a timeout occurs (and the timeout option is
not set to throw exceptions
[see explanation]).InterruptedException - see explanation.TimedOutException - see explanation.ShutdownException - see explanation.
public void waitUntilEmpty()
throws InterruptedException,
ShutdownException
InterruptedException - see explanation.ShutdownException - see explanation.
public boolean waitWhileEmpty(long msTimeout)
throws InterruptedException,
TimedOutException,
ShutdownException
msTimeout - maximum number of milliseconds to wait. Use
ThreadTools.NO_TIMEOUT (or 0) to indicate that
the waiting should never timeout.true if successful, false if
a timeout occurs (and the timeout option is
not set to throw exceptions
[see explanation]).InterruptedException - see explanation.TimedOutException - see explanation.ShutdownException - see explanation.
public void waitWhileEmpty()
throws InterruptedException,
ShutdownException
InterruptedException - see explanation.ShutdownException - see explanation.
public boolean waitUntilFull(long msTimeout)
throws InterruptedException,
TimedOutException,
ShutdownException
msTimeout - maximum number of milliseconds to wait. Use
ThreadTools.NO_TIMEOUT (or 0) to indicate that
the waiting should never timeout.true if successful, false if
a timeout occurs (and the timeout option is
not set to throw exceptions
[see explanation]).InterruptedException - see explanation.TimedOutException - see explanation.ShutdownException - see explanation.
public void waitUntilFull()
throws InterruptedException,
ShutdownException
InterruptedException - see explanation.ShutdownException - see explanation.
public boolean waitWhileFull(long msTimeout)
throws InterruptedException,
TimedOutException,
ShutdownException
msTimeout - maximum number of milliseconds to wait. Use
ThreadTools.NO_TIMEOUT (or 0) to indicate that
the waiting should never timeout.true if successful, false if
a timeout occurs (and the timeout option is
not set to throw exceptions
[see explanation]).InterruptedException - see explanation.TimedOutException - see explanation.ShutdownException - see explanation.
public void waitWhileFull()
throws InterruptedException,
ShutdownException
InterruptedException - see explanation.ShutdownException - see explanation.
public boolean waitForSizeToClimbTo(int atLeast,
long msTimeout)
throws InterruptedException,
TimedOutException,
ShutdownException
msTimeout - maximum number of milliseconds to wait. Use
ThreadTools.NO_TIMEOUT (or 0) to indicate that
the waiting should never timeout.true if successful, false if
a timeout occurs (and the timeout option is
not set to throw exceptions
[see explanation]).InterruptedException - see explanation.TimedOutException - see explanation.ShutdownException - see explanation.
public void waitForSizeToClimbTo(int atLeast)
throws InterruptedException,
ShutdownException
InterruptedException - see explanation.ShutdownException - see explanation.
public boolean waitForSizeToFallTo(int atMost,
long msTimeout)
throws InterruptedException,
TimedOutException,
ShutdownException
msTimeout - maximum number of milliseconds to wait. Use
ThreadTools.NO_TIMEOUT (or 0) to indicate that
the waiting should never timeout.true if successful, false if
a timeout occurs (and the timeout option is
not set to throw exceptions
[see explanation]).InterruptedException - see explanation.TimedOutException - see explanation.ShutdownException - see explanation.
public void waitForSizeToFallTo(int atMost)
throws InterruptedException,
ShutdownException
InterruptedException - see explanation.ShutdownException - see explanation.
public boolean waitForSizeToChange(long msTimeout)
throws InterruptedException,
TimedOutException,
ShutdownException
msTimeout - maximum number of milliseconds to wait. Use
ThreadTools.NO_TIMEOUT (or 0) to indicate that
the waiting should never timeout.true if successful, false if
a timeout occurs (and the timeout option is
not set to throw exceptions
[see explanation]).InterruptedException - see explanation.TimedOutException - see explanation.ShutdownException - see explanation.
public void waitForSizeToChange()
throws InterruptedException,
ShutdownException
InterruptedException - see explanation.ShutdownException - see explanation.
public boolean waitWhileSizeInRange(int min,
int max,
long msTimeout)
throws InterruptedException,
TimedOutException,
ShutdownException
msTimeout - maximum number of milliseconds to wait. Use
ThreadTools.NO_TIMEOUT (or 0) to indicate that
the waiting should never timeout.true if successful, false if
a timeout occurs (and the timeout option is
not set to throw exceptions
[see explanation]).InterruptedException - see explanation.TimedOutException - see explanation.ShutdownException - see explanation.
public void waitWhileSizeInRange(int min,
int max)
throws InterruptedException,
ShutdownException
InterruptedException - see explanation.ShutdownException - see explanation.
public boolean waitUntilSizeInRange(int min,
int max,
long msTimeout)
throws InterruptedException,
TimedOutException,
ShutdownException
msTimeout - maximum number of milliseconds to wait. Use
ThreadTools.NO_TIMEOUT (or 0) to indicate that
the waiting should never timeout.true if successful, false if
a timeout occurs (and the timeout option is
not set to throw exceptions
[see explanation]).InterruptedException - see explanation.TimedOutException - see explanation.ShutdownException - see explanation.
public void waitUntilSizeInRange(int min,
int max)
throws InterruptedException,
ShutdownException
InterruptedException - see explanation.ShutdownException - see explanation.
public boolean waitWhileSizeIs(int target,
long msTimeout)
throws InterruptedException,
TimedOutException,
ShutdownException
msTimeout - maximum number of milliseconds to wait. Use
ThreadTools.NO_TIMEOUT (or 0) to indicate that
the waiting should never timeout.true if successful, false if
a timeout occurs (and the timeout option is
not set to throw exceptions
[see explanation]).InterruptedException - see explanation.TimedOutException - see explanation.ShutdownException - see explanation.
public void waitWhileSizeIs(int target)
throws InterruptedException,
ShutdownException
InterruptedException - see explanation.ShutdownException - see explanation.
public boolean waitUntilSizeIs(int target,
long msTimeout)
throws InterruptedException,
TimedOutException,
ShutdownException
msTimeout - maximum number of milliseconds to wait. Use
ThreadTools.NO_TIMEOUT (or 0) to indicate that
the waiting should never timeout.true if successful, false if
a timeout occurs (and the timeout option is
not set to throw exceptions
[see explanation]).InterruptedException - see explanation.TimedOutException - see explanation.ShutdownException - see explanation.
public void waitUntilSizeIs(int target)
throws InterruptedException,
ShutdownException
InterruptedException - see explanation.ShutdownException - see explanation.
public boolean shutdownWhenEmpty(long msTimeout)
throws InterruptedException,
TimedOutException,
ShutdownException
isEmpty() is true and then proceeds
to automatically invoke SimpleShutdown.shutdown(). Calls block until empty
or only until the specified timeout elapses.
Once the size gets down to zero, a full shutdown
occurs resulting in a ShutdownException being thrown
by any methods that modify the object or wait for it to be modified.msTimeout - the maximum amount of time to wait for empty.msTimeout - maximum number of milliseconds to wait. Use
ThreadTools.NO_TIMEOUT (or 0) to indicate that
the waiting should never timeout.true if successful, false if
a timeout occurs (and the timeout option is
not set to throw exceptions
[see explanation]).InterruptedException - see explanation.TimedOutException - see explanation.ShutdownException - see explanation.
public void addSizeChangeListener(SizeChangeListener listener)
throws UnsupportedOperationException
SizeChangeListener for notification when
the size changes. Requests to add duplicate listeners are silently
ignored. See SizeChangeListener for more information.
Implementations that don't support this feature throw
UnsupportedOperationException. However, many implementations
do support it, and because this exception is a subclass of
RuntimeException, a try-catch block is not
required.
UnsupportedOperationException - if the implementation does
not support size listeners.
public boolean removeSizeChangeListener(SizeChangeListener listener)
throws UnsupportedOperationException
SizeChangeListener so that it is
no longer notified of size changes.
Implementations that don't support this feature throw
UnsupportedOperationException. However, many implementations
do support it, and because this exception is a subclass of
RuntimeException, a try-catch block is not
required.
UnsupportedOperationException - if the implementation does
not support size listeners.
|
JThreadKitTM v1.1.0 ( public members only)
|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||