|
JThreadKitTM v1.1.0 ( public members only)
|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Object | +--com.jthreadkit.AbstractSizeMonitored
An abstract class that partially implements SizeMonitored.
In many cases, this is a useful class to extend instead of directly
implementing all of the methods on SizeMonitored directly.
Unless otherwise noted, all methods use synchronized blocks
internally on lock which can be retrieved via
getLockObject(),
to allow external code to prevent interleaving between method calls.
| Method Summary | |
void |
addSizeChangeListener(SizeChangeListener listener)
See addSizeChangeListener
on SizeMonitored for the full spec. |
int |
getCapacity()
Returns the maximum size possible. |
Object |
getLockObject()
Returns the reference to the object that is synchronized on by other methods in the implementing class. |
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 |
isUseTimedOutExceptionSet()
Used to determine whether or not TimedOutException
will be thrown by methods when timout periods expire. |
boolean |
removeSizeChangeListener(SizeChangeListener listener)
See addSizeChangeListener
on SizeMonitored for the full spec. |
int |
setCapacity(int requestedCapacity)
See SizeMonitored.setCapacity(int) for full spec. |
void |
setUseTimedOutException(boolean useException)
Used to change the timeout behavior of methods on the implementing classes. |
void |
shutdown()
A full shutdown is immediately initiated resulting in a ShutdownException being thrown by any methods
that modify the object or wait for it to be modified. |
boolean |
shutdownWhenEmpty(long msTimeout)
Waits until isEmpty() is true and then proceeds
to automatically invoke 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 class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Method Detail |
public Object getLockObject()
AccessibleLock
This reference can be used in synchronized blocks
to keep other threads from sneaking in between methods calls
like this:
|
obj = //...
synchronized ( obj.getLockObject() ) {
obj.methodA();
obj.methodB();
}
|
getLockObject in interface AccessibleLockcom.jthreadkit.AccessibleLock
public void setUseTimedOutException(boolean useException)
throws ShutdownException
TimedOutExceptionOptiontrue
methods will throw a TimedOutException when the
specified timeout period expires. If this option
is not set, methods usually signal a timeout through a
return value. Use
isUseTimedOutExceptionSet()
to check the current setting.setUseTimedOutException in interface TimedOutExceptionOptioncom.jthreadkit.TimedOutExceptionOptionuseException - if true is passed then
TimedOutException will be thrown after timeouts,
if false is passed, timeouts do not result
in exceptions.ShutdownException - if this object has already
been shutdown.public boolean isUseTimedOutExceptionSet()
TimedOutExceptionOptionTimedOutException
will be thrown by methods when timout periods expire.
The setUseTimedOutException()
method is used to change this setting.isUseTimedOutExceptionSet in interface TimedOutExceptionOptioncom.jthreadkit.TimedOutExceptionOptiontrue if timeouts will result in exceptions
being thrown, false otherwise.
public int setCapacity(int requestedCapacity)
throws ShutdownException
SizeMonitored.setCapacity(int) for full spec.
Internally, this implementation silently increases
requestedCapacity if necessary
(see spec) and sets the
internal value returned by getCapacity(). The new
capacity is returned. If the new capacity is different than
the old capacity, a notifyAll() is issued on
the lock object.
Subclasses may choose to override this method
if they need to do more--this should be done something like this:
|
public int setCapacity(int requestedCapacity) {
synchronized ( lock ) {
int oldCap = getCapacity();
int newCap = super.setCapacity(requestedCapacity);
if ( newCap != oldCap ) {
// do the additional stuff
// ...
}
}
}
|
|
public int setCapacity(int requestedCapacity) {
return getCapacity();
}
|
setCapacity in interface SizeMonitoredcom.jthreadkit.SizeMonitoredrequestedCapacity - the desired new capacity.
This number is silently increased to minimum of 1
and/or the value returned from SizeMonitored.getSize() if necessary.ShutdownException - see explanation.public int getCapacity()
SizeMonitoredInteger.MAX_VALUE if there is no maximum.getCapacity in interface SizeMonitoredcom.jthreadkit.SizeMonitoredSizeMonitored.setCapacity(int),
SizeMonitored.getSize()public int getSize()
SizeMonitoredgetSize in interface SizeMonitoredcom.jthreadkit.SizeMonitoredpublic boolean isEmpty()
SizeMonitoredtrue if the size is currently zero.isEmpty in interface SizeMonitoredpublic boolean isFull()
SizeMonitoredtrue if the size is equal to the value
returned from SizeMonitored.getCapacity().isFull in interface SizeMonitored
public boolean waitUntilEmpty(long msTimeout)
throws InterruptedException,
TimedOutException,
ShutdownException
SizeMonitoredwaitUntilEmpty in interface SizeMonitoredcom.jthreadkit.SizeMonitoredmsTimeout - 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
SizeMonitoredwaitUntilEmpty in interface SizeMonitoredcom.jthreadkit.SizeMonitoredInterruptedException - see explanation.ShutdownException - see explanation.
public boolean waitWhileEmpty(long msTimeout)
throws InterruptedException,
TimedOutException,
ShutdownException
SizeMonitoredwaitWhileEmpty in interface SizeMonitoredcom.jthreadkit.SizeMonitoredmsTimeout - 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
SizeMonitoredwaitWhileEmpty in interface SizeMonitoredcom.jthreadkit.SizeMonitoredInterruptedException - see explanation.ShutdownException - see explanation.
public boolean waitUntilFull(long msTimeout)
throws InterruptedException,
TimedOutException,
ShutdownException
SizeMonitoredwaitUntilFull in interface SizeMonitoredcom.jthreadkit.SizeMonitoredmsTimeout - 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
SizeMonitoredwaitUntilFull in interface SizeMonitoredcom.jthreadkit.SizeMonitoredInterruptedException - see explanation.ShutdownException - see explanation.
public boolean waitWhileFull(long msTimeout)
throws InterruptedException,
TimedOutException,
ShutdownException
SizeMonitoredwaitWhileFull in interface SizeMonitoredcom.jthreadkit.SizeMonitoredmsTimeout - 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
SizeMonitoredwaitWhileFull in interface SizeMonitoredcom.jthreadkit.SizeMonitoredInterruptedException - see explanation.ShutdownException - see explanation.
public boolean waitForSizeToClimbTo(int atLeast,
long msTimeout)
throws InterruptedException,
TimedOutException,
ShutdownException
SizeMonitoredwaitForSizeToClimbTo in interface SizeMonitoredcom.jthreadkit.SizeMonitoredmsTimeout - 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
SizeMonitoredwaitForSizeToClimbTo in interface SizeMonitoredcom.jthreadkit.SizeMonitoredInterruptedException - see explanation.ShutdownException - see explanation.
public boolean waitForSizeToFallTo(int atMost,
long msTimeout)
throws InterruptedException,
TimedOutException,
ShutdownException
SizeMonitoredwaitForSizeToFallTo in interface SizeMonitoredcom.jthreadkit.SizeMonitoredmsTimeout - 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
SizeMonitoredwaitForSizeToFallTo in interface SizeMonitoredcom.jthreadkit.SizeMonitoredInterruptedException - see explanation.ShutdownException - see explanation.
public boolean waitForSizeToChange(long msTimeout)
throws InterruptedException,
TimedOutException,
ShutdownException
SizeMonitoredwaitForSizeToChange in interface SizeMonitoredcom.jthreadkit.SizeMonitoredmsTimeout - 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
SizeMonitoredwaitForSizeToChange in interface SizeMonitoredcom.jthreadkit.SizeMonitoredInterruptedException - see explanation.ShutdownException - see explanation.
public boolean waitWhileSizeInRange(int min,
int max,
long msTimeout)
throws InterruptedException,
TimedOutException,
ShutdownException
SizeMonitoredwaitWhileSizeInRange in interface SizeMonitoredcom.jthreadkit.SizeMonitoredmsTimeout - 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
SizeMonitoredwaitWhileSizeInRange in interface SizeMonitoredcom.jthreadkit.SizeMonitoredInterruptedException - see explanation.ShutdownException - see explanation.
public boolean waitUntilSizeInRange(int min,
int max,
long msTimeout)
throws InterruptedException,
TimedOutException,
ShutdownException
SizeMonitoredwaitUntilSizeInRange in interface SizeMonitoredcom.jthreadkit.SizeMonitoredmsTimeout - 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
SizeMonitoredwaitUntilSizeInRange in interface SizeMonitoredcom.jthreadkit.SizeMonitoredInterruptedException - see explanation.ShutdownException - see explanation.
public boolean waitWhileSizeIs(int target,
long msTimeout)
throws InterruptedException,
TimedOutException,
ShutdownException
SizeMonitoredwaitWhileSizeIs in interface SizeMonitoredcom.jthreadkit.SizeMonitoredmsTimeout - 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
SizeMonitoredwaitWhileSizeIs in interface SizeMonitoredcom.jthreadkit.SizeMonitoredInterruptedException - see explanation.ShutdownException - see explanation.
public boolean waitUntilSizeIs(int target,
long msTimeout)
throws InterruptedException,
TimedOutException,
ShutdownException
SizeMonitoredwaitUntilSizeIs in interface SizeMonitoredcom.jthreadkit.SizeMonitoredmsTimeout - 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
SizeMonitoredwaitUntilSizeIs in interface SizeMonitoredcom.jthreadkit.SizeMonitoredInterruptedException - see explanation.ShutdownException - see explanation.
public boolean shutdownWhenEmpty(long msTimeout)
throws InterruptedException,
TimedOutException,
ShutdownException
SizeMonitoredSizeMonitored.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.shutdownWhenEmpty in interface SizeMonitoredcom.jthreadkit.SizeMonitoredmsTimeout - 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 shutdown()
SimpleShutdownShutdownException being thrown by any methods
that modify the object or wait for it to be modified.
See this explanation for more.shutdown in interface SimpleShutdownpublic void addSizeChangeListener(SizeChangeListener listener)
addSizeChangeListener
on SizeMonitored for the full spec. This implementation
fully supports this option and does not throw UnsupportedOperationException.addSizeChangeListener in interface SizeMonitoredcom.jthreadkit.SizeMonitoredUnsupportedOperationException - if the implementation does
not support size listeners.public boolean removeSizeChangeListener(SizeChangeListener listener)
addSizeChangeListener
on SizeMonitored for the full spec. This implementation
fully supports this option and does not throw UnsupportedOperationException.removeSizeChangeListener in interface SizeMonitoredcom.jthreadkit.SizeMonitoredUnsupportedOperationException - 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 | ||||||||