From 0437cc7b92d527ab00ce194bed9df380e45d31bc Mon Sep 17 00:00:00 2001 From: "Eric J. Bowersox" Date: Thu, 15 Nov 2001 00:30:24 +0000 Subject: [PATCH] second round of cache cleanups - got rid of that bogus pile of monkey spew that was ReferenceCache, replaced it with the much cleaner ObjectCache (it uses SoftReferences so that the "sweep" operation is pretty much automatic) --- .../silverwrist/util/cache/ObjectCache.java | 195 ++++++++++++++++++ .../ObjectCacheException.java} | 29 ++- .../silverwrist/util/cache/ObjectFactory.java | 41 ++++ .../util/cache/ObjectFactoryException.java | 126 +++++++++++ .../util/rcache/ReferenceCache.java | 161 --------------- .../util/rcache/ReferencedData.java | 30 --- .../util/rcache/ReferencedDataBuilder.java | 24 --- .../ReferencedDataBuilderException.java | 52 ----- .../venice/core/InternalStateError.java | 117 +++++++++-- .../core/impl/BackgroundCommunityPurge.java | 13 +- .../venice/core/impl/CommunityCoreData.java | 62 ++---- .../venice/core/impl/CommunityData.java | 5 +- .../core/impl/CommunityUserContextImpl.java | 36 +--- .../core/impl/ConferenceCommunityContext.java | 3 +- .../impl/ConferenceCommunityContextImpl.java | 49 ----- .../venice/core/impl/ConferenceCoreData.java | 30 --- .../venice/core/impl/ConferenceData.java | 3 +- .../core/impl/ConferenceUserContextImpl.java | 22 +- .../venice/core/impl/UserBackend.java | 3 +- .../venice/core/impl/UserContextImpl.java | 40 +--- .../venice/core/impl/VeniceEngineImpl.java | 90 ++------ 21 files changed, 536 insertions(+), 595 deletions(-) create mode 100644 src/com/silverwrist/util/cache/ObjectCache.java rename src/com/silverwrist/util/{rcache/ReferenceCacheException.java => cache/ObjectCacheException.java} (61%) create mode 100644 src/com/silverwrist/util/cache/ObjectFactory.java create mode 100644 src/com/silverwrist/util/cache/ObjectFactoryException.java delete mode 100644 src/com/silverwrist/util/rcache/ReferenceCache.java delete mode 100644 src/com/silverwrist/util/rcache/ReferencedData.java delete mode 100644 src/com/silverwrist/util/rcache/ReferencedDataBuilder.java delete mode 100644 src/com/silverwrist/util/rcache/ReferencedDataBuilderException.java diff --git a/src/com/silverwrist/util/cache/ObjectCache.java b/src/com/silverwrist/util/cache/ObjectCache.java new file mode 100644 index 0000000..27d1b36 --- /dev/null +++ b/src/com/silverwrist/util/cache/ObjectCache.java @@ -0,0 +1,195 @@ +/* + * The contents of this file are subject to the Mozilla Public License Version 1.1 + * (the "License"); you may not use this file except in compliance with the License. + * You may obtain a copy of the License at . + * + * Software distributed under the License is distributed on an "AS IS" basis, WITHOUT + * WARRANTY OF ANY KIND, either express or implied. See the License for the specific + * language governing rights and limitations under the License. + * + * The Original Code is the Venice Web Communities System. + * + * The Initial Developer of the Original Code is Eric J. Bowersox , + * for Silverwrist Design Studios. Portions created by Eric J. Bowersox are + * Copyright (C) 2001 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. + * + * Contributor(s): + */ +package com.silverwrist.util.cache; + +import java.lang.ref.*; +import java.util.*; + +/** + * A chache which stores objects by key value, and is capable of creating them given an instance of + * ObjectFactory to do the creating. The cache uses SoftReferences which can + * automatically be removed by the garbage collector if necessary. + * + * @author Eric J. Bowersox <erbo@silcom.com> + * @version X + * @see ObjectFactory + * @see java.lang.ref.SoftReference + */ +public class ObjectCache +{ + /*-------------------------------------------------------------------------------- + * Attributes + *-------------------------------------------------------------------------------- + */ + + private HashMap the_data = new HashMap(); // the actual underlying map + private ObjectFactory factory; // used to create new objects + private ReferenceQueue rq = new ReferenceQueue(); // where our references go when they die + private ArrayList sweeper = new ArrayList(); // temporary used in doing sweeps + + /*-------------------------------------------------------------------------------- + * Constructor + *-------------------------------------------------------------------------------- + */ + + /** + * Creates a new ObjectCache. + * + * @param factory The factory object used to create new objects when getOrCreate is called. + * @exception java.lang.NullPointerException The object factory passed in is null. + */ + public ObjectCache(ObjectFactory factory) + { + if (factory==null) + throw new NullPointerException("object factory cannot be null!"); + this.factory = factory; + + } // end constructor + + /*-------------------------------------------------------------------------------- + * Internal operations + *-------------------------------------------------------------------------------- + */ + + /** + * "Sweeps" the cache by taking all references that have been cleared and queued by the garbage + * collector and removing them from the map. Should be called fairly often, to minimize wasted + * hashmap slots. + */ + private synchronized void doSweep() + { + Set entries = the_data.entrySet(); // used to find entries with the specified value + Reference r = rq.poll(); // reference that's been cleared + Iterator it; + + while (r!=null) + { // look for this reference in our hash map + it = entries.iterator(); + while (it.hasNext()) + { // look for the map entry containing the reference + Map.Entry ntry = (Map.Entry)(it.next()); + if (r==(Reference)(ntry.getValue())) + { // found the entry with this reference - nuke it + sweeper.add(ntry.getKey()); + break; // don't need to take this loop any farther + + } // end if + + } // end while + + r = rq.poll(); // get the next cleared reference + + } // end while + + if (sweeper.isEmpty()) + return; // no entries to remove + + // Remove all the corresponding keys from the hashmap. + it = sweeper.iterator(); + while (it.hasNext()) + the_data.remove(it.next()); + sweeper.clear(); // reset for next time + + } // end doSweep + + /*-------------------------------------------------------------------------------- + * External operations + *-------------------------------------------------------------------------------- + */ + + /** + * Retrieves an object from the cache. + * + * @param key The key value of the object to look up. + * @return The corresponding object value, or null if that object isn't in the cache. + */ + public synchronized Object get(Object key) + { + doSweep(); + SoftReference r = (SoftReference)(the_data.get(key)); + return ((r==null) ? null : r.get()); + + } // end get + + /** + * Retrieves an object from the cache, creating it if it doesn't already exist. + * + * @param key The key value of the object to look up or create. + * @return The corresponding object value. + * @exception com.silverwrist.util.cache.ObjectFactoryException If an exception occurred while creating + * a new object. + * @see ObjectFactory#newObject(java.lang.Object) + */ + public synchronized Object getOrCreate(Object key) throws ObjectFactoryException + { + doSweep(); + SoftReference r = (SoftReference)(the_data.get(key)); + Object rc = ((r==null) ? null : r.get()); + if (rc==null) + { // attempt to create a new object + rc = factory.newObject(key); + if (rc!=null) + { // clear the old reference, throw it away, and put in a new one + if (r!=null) + r.clear(); + r = new SoftReference(rc,rq); + the_data.put(key,r); + + } // end if + + } // end if + + return rc; + + } // end getOrCreate + + /** + * Registers a newly-created object with the cache. + * + * @param key The key value to register this object with. + * @param data The object to be registered. + * @exception com.silverwrist.util.cache.ObjectCacheException If an object with that key value already + * exists in the cache. + */ + public synchronized void register(Object key, Object data) + { + doSweep(); + SoftReference old = (SoftReference)(the_data.get(key)); + if ((old!=null) && (old.get()!=null)) + throw new ObjectCacheException("object already in cache",key); + the_data.put(key,new SoftReference(data,rq)); + if (old!=null) + old.clear(); + + } // end register + + /** + * Detaches an object from the cache. + * + * @param key Key value of the object to be detached. + */ + public synchronized void detach(Object key) + { + doSweep(); + SoftReference old = (SoftReference)(the_data.remove(key)); + if (old!=null) + old.clear(); + + } // end detach + +} // end class ObjectCache diff --git a/src/com/silverwrist/util/rcache/ReferenceCacheException.java b/src/com/silverwrist/util/cache/ObjectCacheException.java similarity index 61% rename from src/com/silverwrist/util/rcache/ReferenceCacheException.java rename to src/com/silverwrist/util/cache/ObjectCacheException.java index 6c178e7..060b609 100644 --- a/src/com/silverwrist/util/rcache/ReferenceCacheException.java +++ b/src/com/silverwrist/util/cache/ObjectCacheException.java @@ -15,23 +15,37 @@ * * Contributor(s): */ -package com.silverwrist.util.rcache; +package com.silverwrist.util.cache; -public class ReferenceCacheException extends RuntimeException +/** + * An exception thrown by the ObjectCache in unusual circumstances. The main reason why this + * exception would be thrown is if some code tried to register an object that was already in the cache. + * + * @author Eric J. Bowersox <erbo@silcom.com> + * @version X + * @see ObjectCache#register(java.lang.Object,java.lang.Object) + */ +public class ObjectCacheException extends RuntimeException { /*-------------------------------------------------------------------------------- * Attributes *-------------------------------------------------------------------------------- */ - private Object keyval; + private Object keyval; // key value /*-------------------------------------------------------------------------------- * Constructor *-------------------------------------------------------------------------------- */ - public ReferenceCacheException(String msg, Object keyval) + /** + * Constructs a new ObjectCacheException. + * + * @param msg The message to include with this exception. + * @param keyval The key value of the object that caused this exception to be generated. + */ + public ObjectCacheException(String msg, Object keyval) { super("[keyval " + keyval.toString() + "]: " + msg); this.keyval = keyval; @@ -43,10 +57,15 @@ public class ReferenceCacheException extends RuntimeException *-------------------------------------------------------------------------------- */ + /** + * Returns the key value of the object that caused this exception to be generated. + * + * @return The key value of the object that caused this exception to be generated. + */ public Object getKeyVal() { return keyval; } // end getKeyVal -} // end class ReferenceCacheException +} // end class ObjectClassException diff --git a/src/com/silverwrist/util/cache/ObjectFactory.java b/src/com/silverwrist/util/cache/ObjectFactory.java new file mode 100644 index 0000000..5ec759e --- /dev/null +++ b/src/com/silverwrist/util/cache/ObjectFactory.java @@ -0,0 +1,41 @@ +/* + * The contents of this file are subject to the Mozilla Public License Version 1.1 + * (the "License"); you may not use this file except in compliance with the License. + * You may obtain a copy of the License at . + * + * Software distributed under the License is distributed on an "AS IS" basis, WITHOUT + * WARRANTY OF ANY KIND, either express or implied. See the License for the specific + * language governing rights and limitations under the License. + * + * The Original Code is the Venice Web Communities System. + * + * The Initial Developer of the Original Code is Eric J. Bowersox , + * for Silverwrist Design Studios. Portions created by Eric J. Bowersox are + * Copyright (C) 2001 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. + * + * Contributor(s): + */ +package com.silverwrist.util.cache; + +/** + * An interface which is used by ObjectCache to create new objects which match a specified + * key. An instance of an object implementing this interface must be specified to the constructor + * of ObjectFactory. + * + * @see ObjectCache#Constructor(com.silverwrist.util.cache.ObjectFactory) + * @see ObjectCache#getOrCreate(java.lang.Object) + */ +public interface ObjectFactory +{ + /** + * Creates a new instance of an object for the object cache. + * + * @param key The key value of the new object to be created. + * @return The new object instance. + * @exception com.silverwrist.util.cache.ObjectFactoryException An exception was thrown by the + * constructors and/or methods called by newObject; it is wrapped in this exception. + * @see ObjectCache#getOrCreate(java.lang.Object) + */ + public abstract Object newObject(Object key) throws ObjectFactoryException; + +} // end interface ObjectFactory diff --git a/src/com/silverwrist/util/cache/ObjectFactoryException.java b/src/com/silverwrist/util/cache/ObjectFactoryException.java new file mode 100644 index 0000000..e9900ad --- /dev/null +++ b/src/com/silverwrist/util/cache/ObjectFactoryException.java @@ -0,0 +1,126 @@ +/* + * The contents of this file are subject to the Mozilla Public License Version 1.1 + * (the "License"); you may not use this file except in compliance with the License. + * You may obtain a copy of the License at . + * + * Software distributed under the License is distributed on an "AS IS" basis, WITHOUT + * WARRANTY OF ANY KIND, either express or implied. See the License for the specific + * language governing rights and limitations under the License. + * + * The Original Code is the Venice Web Communities System. + * + * The Initial Developer of the Original Code is Eric J. Bowersox , + * for Silverwrist Design Studios. Portions created by Eric J. Bowersox are + * Copyright (C) 2001 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. + * + * Contributor(s): + */ +package com.silverwrist.util.cache; + +import java.io.PrintStream; +import java.io.PrintWriter; + +/** + * The exception which may be thrown by ObjectFactory.newObject, which wraps any exception + * that might be thrown by constructors or other method calls within the method. + * + * @author Eric J. Bowersox <erbo@silcom.com> + * @version X + * @see ObjectFactory#newObject(java.lang.Object) + */ +public class ObjectFactoryException extends Exception +{ + /*-------------------------------------------------------------------------------- + * Attributes + *-------------------------------------------------------------------------------- + */ + + private Throwable inner = null; // internal "root cause" exception + + /*-------------------------------------------------------------------------------- + * Constructor + *-------------------------------------------------------------------------------- + */ + + /** + * Creates a new ObjectFactoryException. + * + * @param t Exception being wrapped by this one. + */ + public ObjectFactoryException(Throwable t) + { + super("Error creating new object: " + t.getMessage()); + inner = t; + + } // end constructor + + /*-------------------------------------------------------------------------------- + * Overrides from class Throwable + *-------------------------------------------------------------------------------- + */ + + /** + * Prints this exception and its backtrace to the standard error stream. Also prints the backtrace + * of any "wrapped" exception. + * + * @see java.lang.System#err + */ + public void printStackTrace() + { + this.printStackTrace(System.err); + + } // end printStackTrace + + /** + * Prints this exception and its backtrace to the specified PrintStream. Also prints the + * backtrace of any "wrapped" exception. + * + * @param s PrintStream to use for output. + */ + public void printStackTrace(PrintStream s) + { + super.printStackTrace(s); + if (inner!=null) + { // print the inner stack trace + s.print("Root cause: "); + inner.printStackTrace(s); + + } // end if + + } // end printStackTrace + + /** + * Prints this exception and its backtrace to the specified PrintWriter. Also prints the + * backtrace of any "wrapped" exception. + * + * @param s PrintWriter to use for output. + */ + public void printStackTrace(PrintWriter s) + { + super.printStackTrace(s); + if (inner!=null) + { // print the inner stack trace + s.print("Root cause: "); + inner.printStackTrace(s); + + } // end if + + } // end printStackTrace + + /*-------------------------------------------------------------------------------- + * External operations + *-------------------------------------------------------------------------------- + */ + + /** + * Returns the exception wrapped by this exception, or null if there is none. + * + * @return See above. + */ + public Throwable getException() + { + return inner; + + } // end getException + +} // end class ObjectFactoryException diff --git a/src/com/silverwrist/util/rcache/ReferenceCache.java b/src/com/silverwrist/util/rcache/ReferenceCache.java deleted file mode 100644 index e310428..0000000 --- a/src/com/silverwrist/util/rcache/ReferenceCache.java +++ /dev/null @@ -1,161 +0,0 @@ -/* - * The contents of this file are subject to the Mozilla Public License Version 1.1 - * (the "License"); you may not use this file except in compliance with the License. - * You may obtain a copy of the License at . - * - * Software distributed under the License is distributed on an "AS IS" basis, WITHOUT - * WARRANTY OF ANY KIND, either express or implied. See the License for the specific - * language governing rights and limitations under the License. - * - * The Original Code is the Venice Web Communities System. - * - * The Initial Developer of the Original Code is Eric J. Bowersox , - * for Silverwrist Design Studios. Portions created by Eric J. Bowersox are - * Copyright (C) 2001 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. - * - * Contributor(s): - */ -package com.silverwrist.util.rcache; - -import java.util.*; - -public class ReferenceCache -{ - /*-------------------------------------------------------------------------------- - * Attributes - *-------------------------------------------------------------------------------- - */ - - private HashMap the_data; - - /*-------------------------------------------------------------------------------- - * Constructor - *-------------------------------------------------------------------------------- - */ - - public ReferenceCache() - { - the_data = new HashMap(); - - } // end constructor - - /*-------------------------------------------------------------------------------- - * External operations - *-------------------------------------------------------------------------------- - */ - - public synchronized ReferencedData get(Object key) - { - ReferencedData rc = (ReferencedData)(the_data.get(key)); - if (rc!=null) - rc.rd_addRef(); - return rc; - - } // end get - - public synchronized ReferencedData getOrCreate(Object key, ReferencedDataBuilder builder) - throws ReferencedDataBuilderException - { - ReferencedData rc = (ReferencedData)(the_data.get(key)); - if (rc==null) - { // use the builder to build one - rc = builder.build(key); - if (rc!=null) - the_data.put(key,rc); - - } // end if - else // just add a reference - rc.rd_addRef(); - - return rc; - - } // end getOrCreate - - public void register(ReferencedData data) - { - Object key = data.rd_getKey(); - - synchronized (this) - { // see if it's in the cache, if not, add it - if (the_data.get(key)!=null) - throw new ReferenceCacheException("object already in cache",key); - - // dump it in the object cache - the_data.put(key,data); - - } // end synchronized block - - } // end register - - public synchronized void detach(Object key) - { - the_data.remove(key); - - } // end detach - - public void sweep() - { - int count = 0; - - synchronized (this) - { // bail out early if possible - if (the_data.size()==0) - return; - - // provide a storage bin for all keys we decide to 86 - Object keyzap[] = new Object[the_data.size()]; - Iterator it = the_data.values().iterator(); - - while (it.hasNext()) - { // check each value we contain in turn - ReferencedData rd = (ReferencedData)(it.next()); - if (rd.rd_unreferenced()) - keyzap[count++] = rd.rd_getKey(); - - } // end while - - for (int i=0; i0) - { // provide a storage bin for all keys we decide to 86 - Object keyzap[] = new Object[the_data.size()]; - Iterator it = the_data.values().iterator(); - - while (it.hasNext()) - { // check each value we contain in turn - ReferencedData rd = (ReferencedData)(it.next()); - if (rd.rd_unreferenced()) - keyzap[count++] = rd.rd_getKey(); - else - { // add another reference and tack it onto the list - rd.rd_addRef(); - rc.add(rd); - - } // end else - - } // end while - - for (int i=0; i. - * - * Software distributed under the License is distributed on an "AS IS" basis, WITHOUT - * WARRANTY OF ANY KIND, either express or implied. See the License for the specific - * language governing rights and limitations under the License. - * - * The Original Code is the Venice Web Communities System. - * - * The Initial Developer of the Original Code is Eric J. Bowersox , - * for Silverwrist Design Studios. Portions created by Eric J. Bowersox are - * Copyright (C) 2001 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. - * - * Contributor(s): - */ -package com.silverwrist.util.rcache; - -public interface ReferencedData -{ - public abstract int rd_addRef(); - - public abstract int rd_release(); - - public abstract boolean rd_unreferenced(); - - public abstract Object rd_getKey(); - -} // end interface ReferencedData diff --git a/src/com/silverwrist/util/rcache/ReferencedDataBuilder.java b/src/com/silverwrist/util/rcache/ReferencedDataBuilder.java deleted file mode 100644 index 821db2f..0000000 --- a/src/com/silverwrist/util/rcache/ReferencedDataBuilder.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * The contents of this file are subject to the Mozilla Public License Version 1.1 - * (the "License"); you may not use this file except in compliance with the License. - * You may obtain a copy of the License at . - * - * Software distributed under the License is distributed on an "AS IS" basis, WITHOUT - * WARRANTY OF ANY KIND, either express or implied. See the License for the specific - * language governing rights and limitations under the License. - * - * The Original Code is the Venice Web Communities System. - * - * The Initial Developer of the Original Code is Eric J. Bowersox , - * for Silverwrist Design Studios. Portions created by Eric J. Bowersox are - * Copyright (C) 2001 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. - * - * Contributor(s): - */ -package com.silverwrist.util.rcache; - -public interface ReferencedDataBuilder -{ - public abstract ReferencedData build(Object key) throws ReferencedDataBuilderException; - -} // end interface ReferencedDataBuilder diff --git a/src/com/silverwrist/util/rcache/ReferencedDataBuilderException.java b/src/com/silverwrist/util/rcache/ReferencedDataBuilderException.java deleted file mode 100644 index 36a978e..0000000 --- a/src/com/silverwrist/util/rcache/ReferencedDataBuilderException.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * The contents of this file are subject to the Mozilla Public License Version 1.1 - * (the "License"); you may not use this file except in compliance with the License. - * You may obtain a copy of the License at . - * - * Software distributed under the License is distributed on an "AS IS" basis, WITHOUT - * WARRANTY OF ANY KIND, either express or implied. See the License for the specific - * language governing rights and limitations under the License. - * - * The Original Code is the Venice Web Communities System. - * - * The Initial Developer of the Original Code is Eric J. Bowersox , - * for Silverwrist Design Studios. Portions created by Eric J. Bowersox are - * Copyright (C) 2001 Eric J. Bowersox/Silverwrist Design Studios. All Rights Reserved. - * - * Contributor(s): - */ -package com.silverwrist.util.rcache; - -public class ReferencedDataBuilderException extends Exception -{ - /*-------------------------------------------------------------------------------- - * Attributes - *-------------------------------------------------------------------------------- - */ - - private Exception target; - - /*-------------------------------------------------------------------------------- - * Constructors - *-------------------------------------------------------------------------------- - */ - - public ReferencedDataBuilderException(Exception target) - { - super("Error building new object: " + target.getMessage()); - this.target = target; - - } // end constructor - - /*-------------------------------------------------------------------------------- - * External operations - *-------------------------------------------------------------------------------- - */ - - public Exception getTarget() - { - return target; - - } // end getTarget - -} // end class ReferencedDataBuilderException diff --git a/src/com/silverwrist/venice/core/InternalStateError.java b/src/com/silverwrist/venice/core/InternalStateError.java index 63ea1f2..8df7b6e 100644 --- a/src/com/silverwrist/venice/core/InternalStateError.java +++ b/src/com/silverwrist/venice/core/InternalStateError.java @@ -17,47 +17,134 @@ */ package com.silverwrist.venice.core; +import java.io.PrintStream; +import java.io.PrintWriter; + public class InternalStateError extends RuntimeException { - // Attributes - private Exception e = null; // internal "root cause" exception + /*-------------------------------------------------------------------------------- + * Attributes + *-------------------------------------------------------------------------------- + */ + private Throwable inner = null; // internal "root cause" exception + + /*-------------------------------------------------------------------------------- + * Constructors + *-------------------------------------------------------------------------------- + */ + + /** + * Constructs a new InternalStateError. + */ public InternalStateError() { super(); } // end constructor + /** + * Constructs a new InternalStateError with a text message. + * + * @param msg The message to set in this exception. + */ public InternalStateError(String msg) { super(msg); } // end constructor - public InternalStateError(Exception e) + /** + * Constructs a new InternalStateError wrapping another exception. + * + * @param inner The exception wrapped by this one. + */ + public InternalStateError(Throwable inner) { - super(e.getMessage()); - this.e = e; + super(inner.getMessage()); + this.inner = inner; } // end constructor - public InternalStateError(String msg, Exception e) + /** + * Constructs a new InternalStateError wrapping another exception. + * + * @param msg The message to set in this exception. + * @param inner The exception wrapped by this one. + */ + public InternalStateError(String msg, Throwable inner) { super(msg); - this.e = e; + this.inner = inner; } // end constructor - protected void finalize() throws Throwable - { - e = null; - super.finalize(); + /*-------------------------------------------------------------------------------- + * Overrides from class Throwable + *-------------------------------------------------------------------------------- + */ - } // end finalize - - public Exception getException() + /** + * Prints this exception and its backtrace to the standard error stream. Also prints the backtrace + * of any "wrapped" exception. + * + * @see java.lang.System#err + */ + public void printStackTrace() { - return e; + this.printStackTrace(System.err); + + } // end printStackTrace + + /** + * Prints this exception and its backtrace to the specified PrintStream. Also prints the + * backtrace of any "wrapped" exception. + * + * @param s PrintStream to use for output. + */ + public void printStackTrace(PrintStream s) + { + super.printStackTrace(s); + if (inner!=null) + { // print the inner stack trace + s.print("Root cause: "); + inner.printStackTrace(s); + + } // end if + + } // end printStackTrace + + /** + * Prints this exception and its backtrace to the specified PrintWriter. Also prints the + * backtrace of any "wrapped" exception. + * + * @param s PrintWriter to use for output. + */ + public void printStackTrace(PrintWriter s) + { + super.printStackTrace(s); + if (inner!=null) + { // print the inner stack trace + s.print("Root cause: "); + inner.printStackTrace(s); + + } // end if + + } // end printStackTrace + + /*-------------------------------------------------------------------------------- + * External operations + *-------------------------------------------------------------------------------- + */ + + /** + * Returns the exception wrapped by this exception, or null if there is none. + * + * @return See above. + */ + public Throwable getException() + { + return inner; } // end getException diff --git a/src/com/silverwrist/venice/core/impl/BackgroundCommunityPurge.java b/src/com/silverwrist/venice/core/impl/BackgroundCommunityPurge.java index ae8e981..1fd1fa9 100644 --- a/src/com/silverwrist/venice/core/impl/BackgroundCommunityPurge.java +++ b/src/com/silverwrist/venice/core/impl/BackgroundCommunityPurge.java @@ -21,7 +21,7 @@ import java.sql.*; import java.util.*; import org.apache.log4j.*; import com.silverwrist.util.ParallelRunQueue; -import com.silverwrist.util.rcache.ReferenceCache; +import com.silverwrist.util.cache.ObjectCache; import com.silverwrist.venice.db.*; import com.silverwrist.venice.core.DataException; import com.silverwrist.venice.core.InternalStateError; @@ -46,7 +46,7 @@ class BackgroundCommunityPurge implements Runnable private int cid; private int num_confs; private int max_confid; - private ReferenceCache conf_refcache; + private ObjectCache conf_objcache; /*-------------------------------------------------------------------------------- * Constructor @@ -54,7 +54,7 @@ class BackgroundCommunityPurge implements Runnable */ BackgroundCommunityPurge(EngineBackend engine, DataPool datapool, UserBackend user, int cid, int num_confs, - int max_confid, ReferenceCache conf_refcache) + int max_confid, ObjectCache conf_objcache) { this.engine = engine; this.datapool = datapool; @@ -62,7 +62,7 @@ class BackgroundCommunityPurge implements Runnable this.cid = cid; this.num_confs = num_confs; this.max_confid = max_confid; - this.conf_refcache = conf_refcache; + this.conf_objcache = conf_objcache; } // end constructor @@ -102,12 +102,11 @@ class BackgroundCommunityPurge implements Runnable for (int i=0; i