JThreadKitTM
v1.1.0
(public members only)

com.jthreadkit.collection
Class WrappedSizeMonitoredSortedMap

java.lang.Object
  |
  +--com.jthreadkit.AbstractSizeMonitored
        |
        +--com.jthreadkit.collection.WrappedSizeMonitoredMap
              |
              +--com.jthreadkit.collection.WrappedSizeMonitoredSortedMap
All Implemented Interfaces:
AccessibleLock, Map, SimpleShutdown, SizeMonitored, SizeMonitoredMap, SizeMonitoredSortedMap, SortedMap, TimedOutExceptionOption

public class WrappedSizeMonitoredSortedMap
extends WrappedSizeMonitoredMap
implements SizeMonitoredSortedMap, SortedMap, SizeMonitored

Used to wrap an instance of SortedMap with synchronization and implementation of all the methods of SizeMonitored. This class can be used like this:
  
SizeMonitoredSortedMap smsm = 
        new WrappedSizeMonitoredSortedMap(new TreeMap());
SizeMonitored sm = smsm;  // can be viewed as a SizeMonitored
SortedMap smap = smsm;  // can be viewed as a SortedMap too
Note that when possible it's best to avoid keeping a direct reference to the underlying "raw" SortedMap (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.synchronizedSortedMap().]

To safely iterate in an multithreaded environment, use code like this:
  
SizeMonitoredSortedMap smsm = //...
Set set = smsm.keySet(); // safely gets the set of keys
//...
synchronized ( smsm.getLockObject() ) {  // note: use smm lock
    Iterator iter = set.iterator();  // note: key iterator from set
    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:
  
smsm.waitUntilEmpty();
while another thread is modifying (adding and removing elements) the object.


Inner classes inherited from class java.util.Map
Map.Entry
 
Constructor Summary
WrappedSizeMonitoredSortedMap(SortedMap sm)
           
WrappedSizeMonitoredSortedMap(SortedMap sm, Object lock, boolean useTimedOutException)
           
 
Method Summary
 Comparator comparator()
           
 Object firstKey()
           
 SortedMap headMap(Object toKey)
           
 Object lastKey()
           
 SortedMap subMap(Object fromKey, Object toKey)
           
 SortedMap tailMap(Object fromKey)
           
 
Methods inherited from class com.jthreadkit.collection.WrappedSizeMonitoredMap
clear, containsKey, containsValue, entrySet, equals, get, hashCode, keySet, put, putAll, remove, setCapacity, size, values
 
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.Map
clear, containsKey, containsValue, entrySet, equals, get, hashCode, isEmpty, keySet, put, putAll, remove, size, values
 

Constructor Detail

WrappedSizeMonitoredSortedMap

public WrappedSizeMonitoredSortedMap(SortedMap sm,
                                     Object lock,
                                     boolean useTimedOutException)

WrappedSizeMonitoredSortedMap

public WrappedSizeMonitoredSortedMap(SortedMap sm)
Method Detail

comparator

public Comparator comparator()
Specified by:
comparator in interface SortedMap

firstKey

public Object firstKey()
Specified by:
firstKey in interface SortedMap

headMap

public SortedMap headMap(Object toKey)
Specified by:
headMap in interface SortedMap

lastKey

public Object lastKey()
Specified by:
lastKey in interface SortedMap

subMap

public SortedMap subMap(Object fromKey,
                        Object toKey)
Specified by:
subMap in interface SortedMap

tailMap

public SortedMap tailMap(Object fromKey)
Specified by:
tailMap in interface SortedMap

JThreadKitTM
v1.1.0
(public members only)

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