JThreadKitTM
v1.1.0
(public members only)

com.jthreadkit.collection
Class WrappedSizeMonitoredCollection

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

public class WrappedSizeMonitoredCollection
extends AbstractSizeMonitored
implements SizeMonitoredCollection, Collection, SizeMonitored

Used to wrap an instance of Collection with synchronization and implementation of all the methods of SizeMonitored. This class can be used like this:
  
Collection rawCollection = //...
SizeMonitoredCollection smc = 
        new WrappedSizeMonitoredCollection(rawCollection);
SizeMonitored sm = smc;  // can be viewed as a SizeMonitored
Collection c = smc;  // can be viewed as a Collection too
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.synchronizedCollection().]

To safely iterate in an multithreaded environment, use code like this:
  
SizeMonitoredCollection smc = //...
//...
synchronized ( smc.getLockObject() ) {
    Iterator iter = smc.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:
  
smc.waitUntilEmpty();
while another thread is modifying (adding and removing elements) the object.


Constructor Summary
WrappedSizeMonitoredCollection(Collection coll)
           
WrappedSizeMonitoredCollection(Collection coll, Object lock, boolean useTimedOutException)
           
 
Method Summary
 boolean add(Object o)
           
 boolean addAll(Collection c)
           
 void clear()
           
 boolean contains(Object o)
           
 boolean containsAll(Collection c)
           
 boolean equals(Object o)
           
 int hashCode()
           
 Iterator iterator()
           
 boolean remove(Object o)
           
 boolean removeAll(Collection c)
           
 boolean retainAll(Collection c)
           
 int setCapacity(int requestedCapacity)
          Not supported, UnsupportedOperationException will always be thrown.
 int size()
           
 Object[] toArray()
           
 Object[] toArray(Object[] dst)
           
 
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, 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.Collection
isEmpty
 

Constructor Detail

WrappedSizeMonitoredCollection

public WrappedSizeMonitoredCollection(Collection coll,
                                      Object lock,
                                      boolean useTimedOutException)

WrappedSizeMonitoredCollection

public WrappedSizeMonitoredCollection(Collection coll)
Method Detail

setCapacity

public int setCapacity(int requestedCapacity)
                throws UnsupportedOperationException
Not supported, UnsupportedOperationException will always be thrown. Capacity is effectively Integer.MAX_VALUE and can't be lowered.
Specified by:
setCapacity in interface SizeMonitored
Overrides:
setCapacity in class AbstractSizeMonitored
Following copied from interface: com.jthreadkit.SizeMonitored
Parameters:
requestedCapacity - the desired new capacity. This number is silently increased to minimum of 1 and/or the value returned from SizeMonitored.getSize() if necessary.
Returns:
the actual new capacity--may be larger than the requested capacity.
Throws:
ShutdownException - see explanation.

add

public boolean add(Object o)
            throws ShutdownException
Specified by:
add in interface Collection

addAll

public boolean addAll(Collection c)
               throws ShutdownException
Specified by:
addAll in interface Collection

clear

public void clear()
           throws ShutdownException
Specified by:
clear in interface Collection

contains

public boolean contains(Object o)
Specified by:
contains in interface Collection

containsAll

public boolean containsAll(Collection c)
Specified by:
containsAll in interface Collection

equals

public boolean equals(Object o)
Specified by:
equals in interface Collection
Overrides:
equals in class Object

hashCode

public int hashCode()
Specified by:
hashCode in interface Collection
Overrides:
hashCode in class Object

iterator

public Iterator iterator()
Specified by:
iterator in interface Collection

remove

public boolean remove(Object o)
               throws ShutdownException
Specified by:
remove in interface Collection

removeAll

public boolean removeAll(Collection c)
                  throws ShutdownException
Specified by:
removeAll in interface Collection

retainAll

public boolean retainAll(Collection c)
                  throws ShutdownException
Specified by:
retainAll in interface Collection

size

public int size()
Specified by:
size in interface Collection

toArray

public Object[] toArray()
Specified by:
toArray in interface Collection

toArray

public Object[] toArray(Object[] dst)
Specified by:
toArray in interface Collection

JThreadKitTM
v1.1.0
(public members only)

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