JThreadKitTM
v1.1.0
(public members only)

com.jthreadkit.collection
Class WrappedSizeMonitoredSet

java.lang.Object
  |
  +--com.jthreadkit.AbstractSizeMonitored
        |
        +--com.jthreadkit.collection.WrappedSizeMonitoredCollection
              |
              +--com.jthreadkit.collection.WrappedSizeMonitoredSet
All Implemented Interfaces:
AccessibleLock, Collection, Set, SimpleShutdown, SizeMonitored, SizeMonitoredCollection, SizeMonitoredSet, TimedOutExceptionOption
Direct Known Subclasses:
WrappedSizeMonitoredSortedSet

public class WrappedSizeMonitoredSet
extends WrappedSizeMonitoredCollection
implements SizeMonitoredSet, Set, SizeMonitored

Used to wrap an instance of Set with synchronization and implementation of all the methods of SizeMonitored. This class can be used like this:
  
SizeMonitoredSet sms = 
        new WrappedSizeMonitoredSet(new HashSet());
SizeMonitored sm = sms;  // can be viewed as a SizeMonitored
Set set = sms;  // can be viewed as a Set too
Note that when possible it's best to avoid keeping a direct reference to the underlying "raw" Set (like this example above). This makes accidental use of the un-synchronized one impossible.

All method calls are synchronized on the object returned by getLockObject(). The object to lock on can be specified during construction or defaults to this. [There is no need to wrap the raw or resulting wrapped object by using Collections.synchronizedSet().]

To safely iterate in an multithreaded environment, use code like this:
  
SizeMonitoredSet sms = //...
//...
synchronized ( sms.getLockObject() ) {
    Iterator iter = sms.iterator();
    while ( iter.hasNext() ) {
        Object obj = iter.next();
        //...
    }
}
The methods of SizeMonitored are nicely combined so that we can have one thread doing something like this:
  
sms.waitUntilEmpty();
while another thread is modifying (adding and removing elements) the object.


Constructor Summary
WrappedSizeMonitoredSet(Set set)
           
WrappedSizeMonitoredSet(Set set, Object lock, boolean useTimedOutException)
           
 
Methods inherited from class com.jthreadkit.collection.WrappedSizeMonitoredCollection
add, addAll, clear, contains, containsAll, equals, hashCode, iterator, remove, removeAll, retainAll, setCapacity, size, toArray, toArray
 
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
getClass, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.jthreadkit.SizeMonitored
addSizeChangeListener, getCapacity, getSize, isEmpty, isFull, removeSizeChangeListener, setCapacity, 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
 
Methods inherited from interface java.util.Set
add, addAll, clear, contains, containsAll, equals, hashCode, isEmpty, iterator, remove, removeAll, retainAll, size, toArray, toArray
 

Constructor Detail

WrappedSizeMonitoredSet

public WrappedSizeMonitoredSet(Set set,
                               Object lock,
                               boolean useTimedOutException)

WrappedSizeMonitoredSet

public WrappedSizeMonitoredSet(Set set)

JThreadKitTM
v1.1.0
(public members only)

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