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)
This commit is contained in:
parent
e290ce2a8c
commit
0437cc7b92
195
src/com/silverwrist/util/cache/ObjectCache.java
vendored
Normal file
195
src/com/silverwrist/util/cache/ObjectCache.java
vendored
Normal file
|
@ -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 <http://www.mozilla.org/MPL/>.
|
||||||
|
*
|
||||||
|
* 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 <erbo@silcom.com>,
|
||||||
|
* 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
|
||||||
|
* <CODE>ObjectFactory</CODE> to do the creating. The cache uses <CODE>SoftReferences</CODE> 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 <CODE>ObjectCache</CODE>.
|
||||||
|
*
|
||||||
|
* @param factory The factory object used to create new objects when <CODE>getOrCreate</CODE> is called.
|
||||||
|
* @exception java.lang.NullPointerException The object factory passed in is <CODE>null</CODE>.
|
||||||
|
*/
|
||||||
|
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 <CODE>null</CODE> 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
|
|
@ -15,23 +15,37 @@
|
||||||
*
|
*
|
||||||
* Contributor(s):
|
* Contributor(s):
|
||||||
*/
|
*/
|
||||||
package com.silverwrist.util.rcache;
|
package com.silverwrist.util.cache;
|
||||||
|
|
||||||
public class ReferenceCacheException extends RuntimeException
|
/**
|
||||||
|
* An exception thrown by the <CODE>ObjectCache</CODE> 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
|
* Attributes
|
||||||
*--------------------------------------------------------------------------------
|
*--------------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
|
|
||||||
private Object keyval;
|
private Object keyval; // key value
|
||||||
|
|
||||||
/*--------------------------------------------------------------------------------
|
/*--------------------------------------------------------------------------------
|
||||||
* Constructor
|
* Constructor
|
||||||
*--------------------------------------------------------------------------------
|
*--------------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public ReferenceCacheException(String msg, Object keyval)
|
/**
|
||||||
|
* Constructs a new <CODE>ObjectCacheException</CODE>.
|
||||||
|
*
|
||||||
|
* @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);
|
super("[keyval " + keyval.toString() + "]: " + msg);
|
||||||
this.keyval = keyval;
|
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()
|
public Object getKeyVal()
|
||||||
{
|
{
|
||||||
return keyval;
|
return keyval;
|
||||||
|
|
||||||
} // end getKeyVal
|
} // end getKeyVal
|
||||||
|
|
||||||
} // end class ReferenceCacheException
|
} // end class ObjectClassException
|
41
src/com/silverwrist/util/cache/ObjectFactory.java
vendored
Normal file
41
src/com/silverwrist/util/cache/ObjectFactory.java
vendored
Normal file
|
@ -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 <http://www.mozilla.org/MPL/>.
|
||||||
|
*
|
||||||
|
* 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 <erbo@silcom.com>,
|
||||||
|
* 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 <CODE>ObjectCache</CODE> to create new objects which match a specified
|
||||||
|
* key. An instance of an object implementing this interface must be specified to the constructor
|
||||||
|
* of <CODE>ObjectFactory</CODE>.
|
||||||
|
*
|
||||||
|
* @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 <CODE>newObject</CODE>; it is wrapped in this exception.
|
||||||
|
* @see ObjectCache#getOrCreate(java.lang.Object)
|
||||||
|
*/
|
||||||
|
public abstract Object newObject(Object key) throws ObjectFactoryException;
|
||||||
|
|
||||||
|
} // end interface ObjectFactory
|
126
src/com/silverwrist/util/cache/ObjectFactoryException.java
vendored
Normal file
126
src/com/silverwrist/util/cache/ObjectFactoryException.java
vendored
Normal file
|
@ -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 <http://www.mozilla.org/MPL/>.
|
||||||
|
*
|
||||||
|
* 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 <erbo@silcom.com>,
|
||||||
|
* 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 <CODE>ObjectFactory.newObject</CODE>, 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 <CODE>ObjectFactoryException</CODE>.
|
||||||
|
*
|
||||||
|
* @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 <CODE>PrintStream</CODE>. Also prints the
|
||||||
|
* backtrace of any "wrapped" exception.
|
||||||
|
*
|
||||||
|
* @param s <CODE>PrintStream</CODE> 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 <CODE>PrintWriter</CODE>. Also prints the
|
||||||
|
* backtrace of any "wrapped" exception.
|
||||||
|
*
|
||||||
|
* @param s <CODE>PrintWriter</CODE> 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 <CODE>null</CODE> if there is none.
|
||||||
|
*
|
||||||
|
* @return See above.
|
||||||
|
*/
|
||||||
|
public Throwable getException()
|
||||||
|
{
|
||||||
|
return inner;
|
||||||
|
|
||||||
|
} // end getException
|
||||||
|
|
||||||
|
} // end class ObjectFactoryException
|
|
@ -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 <http://www.mozilla.org/MPL/>.
|
|
||||||
*
|
|
||||||
* 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 <erbo@silcom.com>,
|
|
||||||
* 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; i<count; i++)
|
|
||||||
the_data.remove(keyzap[i]);
|
|
||||||
|
|
||||||
} // end synchronized block
|
|
||||||
|
|
||||||
} // end sweep
|
|
||||||
|
|
||||||
public List sweepReturn()
|
|
||||||
{
|
|
||||||
ArrayList rc = new ArrayList();
|
|
||||||
int count = 0;
|
|
||||||
|
|
||||||
synchronized (this)
|
|
||||||
{ // bail out early if possible
|
|
||||||
if (the_data.size()>0)
|
|
||||||
{ // 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<count; i++)
|
|
||||||
the_data.remove(keyzap[i]);
|
|
||||||
|
|
||||||
} // end if
|
|
||||||
|
|
||||||
} // end synchronized block
|
|
||||||
|
|
||||||
return Collections.unmodifiableList(rc);
|
|
||||||
|
|
||||||
} // end sweepReturn
|
|
||||||
|
|
||||||
} // end ReferenceCache
|
|
|
@ -1,30 +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 <http://www.mozilla.org/MPL/>.
|
|
||||||
*
|
|
||||||
* 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 <erbo@silcom.com>,
|
|
||||||
* 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
|
|
|
@ -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 <http://www.mozilla.org/MPL/>.
|
|
||||||
*
|
|
||||||
* 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 <erbo@silcom.com>,
|
|
||||||
* 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
|
|
|
@ -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 <http://www.mozilla.org/MPL/>.
|
|
||||||
*
|
|
||||||
* 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 <erbo@silcom.com>,
|
|
||||||
* 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
|
|
|
@ -17,47 +17,134 @@
|
||||||
*/
|
*/
|
||||||
package com.silverwrist.venice.core;
|
package com.silverwrist.venice.core;
|
||||||
|
|
||||||
|
import java.io.PrintStream;
|
||||||
|
import java.io.PrintWriter;
|
||||||
|
|
||||||
public class InternalStateError extends RuntimeException
|
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 <CODE>InternalStateError</CODE>.
|
||||||
|
*/
|
||||||
public InternalStateError()
|
public InternalStateError()
|
||||||
{
|
{
|
||||||
super();
|
super();
|
||||||
|
|
||||||
} // end constructor
|
} // end constructor
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs a new <CODE>InternalStateError</CODE> with a text message.
|
||||||
|
*
|
||||||
|
* @param msg The message to set in this exception.
|
||||||
|
*/
|
||||||
public InternalStateError(String msg)
|
public InternalStateError(String msg)
|
||||||
{
|
{
|
||||||
super(msg);
|
super(msg);
|
||||||
|
|
||||||
} // end constructor
|
} // end constructor
|
||||||
|
|
||||||
public InternalStateError(Exception e)
|
/**
|
||||||
|
* Constructs a new <CODE>InternalStateError</CODE> wrapping another exception.
|
||||||
|
*
|
||||||
|
* @param inner The exception wrapped by this one.
|
||||||
|
*/
|
||||||
|
public InternalStateError(Throwable inner)
|
||||||
{
|
{
|
||||||
super(e.getMessage());
|
super(inner.getMessage());
|
||||||
this.e = e;
|
this.inner = inner;
|
||||||
|
|
||||||
} // end constructor
|
} // end constructor
|
||||||
|
|
||||||
public InternalStateError(String msg, Exception e)
|
/**
|
||||||
|
* Constructs a new <CODE>InternalStateError</CODE> 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);
|
super(msg);
|
||||||
this.e = e;
|
this.inner = inner;
|
||||||
|
|
||||||
} // end constructor
|
} // end constructor
|
||||||
|
|
||||||
protected void finalize() throws Throwable
|
/*--------------------------------------------------------------------------------
|
||||||
{
|
* Overrides from class Throwable
|
||||||
e = null;
|
*--------------------------------------------------------------------------------
|
||||||
super.finalize();
|
*/
|
||||||
|
|
||||||
} // end finalize
|
/**
|
||||||
|
* Prints this exception and its backtrace to the standard error stream. Also prints the backtrace
|
||||||
public Exception getException()
|
* 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 <CODE>PrintStream</CODE>. Also prints the
|
||||||
|
* backtrace of any "wrapped" exception.
|
||||||
|
*
|
||||||
|
* @param s <CODE>PrintStream</CODE> 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 <CODE>PrintWriter</CODE>. Also prints the
|
||||||
|
* backtrace of any "wrapped" exception.
|
||||||
|
*
|
||||||
|
* @param s <CODE>PrintWriter</CODE> 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 <CODE>null</CODE> if there is none.
|
||||||
|
*
|
||||||
|
* @return See above.
|
||||||
|
*/
|
||||||
|
public Throwable getException()
|
||||||
|
{
|
||||||
|
return inner;
|
||||||
|
|
||||||
} // end getException
|
} // end getException
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,7 @@ import java.sql.*;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import org.apache.log4j.*;
|
import org.apache.log4j.*;
|
||||||
import com.silverwrist.util.ParallelRunQueue;
|
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.db.*;
|
||||||
import com.silverwrist.venice.core.DataException;
|
import com.silverwrist.venice.core.DataException;
|
||||||
import com.silverwrist.venice.core.InternalStateError;
|
import com.silverwrist.venice.core.InternalStateError;
|
||||||
|
@ -46,7 +46,7 @@ class BackgroundCommunityPurge implements Runnable
|
||||||
private int cid;
|
private int cid;
|
||||||
private int num_confs;
|
private int num_confs;
|
||||||
private int max_confid;
|
private int max_confid;
|
||||||
private ReferenceCache conf_refcache;
|
private ObjectCache conf_objcache;
|
||||||
|
|
||||||
/*--------------------------------------------------------------------------------
|
/*--------------------------------------------------------------------------------
|
||||||
* Constructor
|
* Constructor
|
||||||
|
@ -54,7 +54,7 @@ class BackgroundCommunityPurge implements Runnable
|
||||||
*/
|
*/
|
||||||
|
|
||||||
BackgroundCommunityPurge(EngineBackend engine, DataPool datapool, UserBackend user, int cid, int num_confs,
|
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.engine = engine;
|
||||||
this.datapool = datapool;
|
this.datapool = datapool;
|
||||||
|
@ -62,7 +62,7 @@ class BackgroundCommunityPurge implements Runnable
|
||||||
this.cid = cid;
|
this.cid = cid;
|
||||||
this.num_confs = num_confs;
|
this.num_confs = num_confs;
|
||||||
this.max_confid = max_confid;
|
this.max_confid = max_confid;
|
||||||
this.conf_refcache = conf_refcache;
|
this.conf_objcache = conf_objcache;
|
||||||
|
|
||||||
} // end constructor
|
} // end constructor
|
||||||
|
|
||||||
|
@ -102,12 +102,11 @@ class BackgroundCommunityPurge implements Runnable
|
||||||
for (int i=0; i<conferences; i++)
|
for (int i=0; i<conferences; i++)
|
||||||
{ // look to see if there's a conference community object first
|
{ // look to see if there's a conference community object first
|
||||||
Integer key = new Integer(conf_ids[i]);
|
Integer key = new Integer(conf_ids[i]);
|
||||||
ConferenceCommunityContext confobj = (ConferenceCommunityContext)(conf_refcache.get(key));
|
ConferenceCommunityContext confobj = (ConferenceCommunityContext)(conf_objcache.get(key));
|
||||||
if (confobj!=null)
|
if (confobj!=null)
|
||||||
{ // OK, there's an object - do the delete internally and release the object
|
{ // OK, there's an object - do the delete internally and release the object
|
||||||
conf_refcache.detach(key);
|
conf_objcache.detach(key);
|
||||||
confobj.delete(user);
|
confobj.delete(user);
|
||||||
confobj.rd_release();
|
|
||||||
|
|
||||||
} // end if
|
} // end if
|
||||||
else
|
else
|
||||||
|
|
|
@ -22,7 +22,7 @@ import java.util.*;
|
||||||
import org.apache.log4j.*;
|
import org.apache.log4j.*;
|
||||||
import com.silverwrist.util.OptionSet;
|
import com.silverwrist.util.OptionSet;
|
||||||
import com.silverwrist.util.StringUtil;
|
import com.silverwrist.util.StringUtil;
|
||||||
import com.silverwrist.util.rcache.*;
|
import com.silverwrist.util.cache.*;
|
||||||
import com.silverwrist.venice.db.*;
|
import com.silverwrist.venice.db.*;
|
||||||
import com.silverwrist.venice.core.*;
|
import com.silverwrist.venice.core.*;
|
||||||
import com.silverwrist.venice.security.AuditRecord;
|
import com.silverwrist.venice.security.AuditRecord;
|
||||||
|
@ -36,13 +36,13 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend
|
||||||
*--------------------------------------------------------------------------------
|
*--------------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
|
|
||||||
protected class ConferenceCommunityContextImplCreator implements ReferencedDataBuilder
|
protected class ConferenceCommunityContextImplCreator implements ObjectFactory
|
||||||
{
|
{
|
||||||
protected ConferenceCommunityContextImplCreator()
|
protected ConferenceCommunityContextImplCreator()
|
||||||
{ // do nothing
|
{ // do nothing
|
||||||
} // end constructor
|
} // end constructor
|
||||||
|
|
||||||
public ReferencedData build(Object key) throws ReferencedDataBuilderException
|
public Object newObject(Object key) throws ObjectFactoryException
|
||||||
{
|
{
|
||||||
Integer xconf = (Integer)key;
|
Integer xconf = (Integer)key;
|
||||||
try
|
try
|
||||||
|
@ -52,7 +52,7 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend
|
||||||
} // end try
|
} // end try
|
||||||
catch (DataException e)
|
catch (DataException e)
|
||||||
{ // rethrow as a "wrapped" exception
|
{ // rethrow as a "wrapped" exception
|
||||||
throw new ReferencedDataBuilderException(e);
|
throw new ObjectFactoryException(e);
|
||||||
|
|
||||||
} // end catch
|
} // end catch
|
||||||
|
|
||||||
|
@ -77,7 +77,6 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend
|
||||||
*--------------------------------------------------------------------------------
|
*--------------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
|
|
||||||
private int refcount = 1; // object reference count
|
|
||||||
private EngineBackend engine; // pointer to engine back end
|
private EngineBackend engine; // pointer to engine back end
|
||||||
private DataPool datapool; // pointer to data pool
|
private DataPool datapool; // pointer to data pool
|
||||||
private int cid; // ID of this community
|
private int cid; // ID of this community
|
||||||
|
@ -104,8 +103,7 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend
|
||||||
private String alias; // the community alias value
|
private String alias; // the community alias value
|
||||||
private boolean public_comm; // is this a public community?
|
private boolean public_comm; // is this a public community?
|
||||||
private BitSet features; // set of available features
|
private BitSet features; // set of available features
|
||||||
private ReferenceCache conf_refcache = new ReferenceCache();
|
private ObjectCache conf_objcache = new ObjectCache(new ConferenceCommunityContextImplCreator());
|
||||||
private ConferenceCommunityContextImplCreator conf_creator = new ConferenceCommunityContextImplCreator();
|
|
||||||
private boolean deleted = false; // has this community been deleted?
|
private boolean deleted = false; // has this community been deleted?
|
||||||
private OptionSet flags; // property flags
|
private OptionSet flags; // property flags
|
||||||
|
|
||||||
|
@ -369,35 +367,6 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend
|
||||||
|
|
||||||
} // end storeProperties
|
} // end storeProperties
|
||||||
|
|
||||||
/*--------------------------------------------------------------------------------
|
|
||||||
* Implementations from interface ReferencedData
|
|
||||||
*--------------------------------------------------------------------------------
|
|
||||||
*/
|
|
||||||
|
|
||||||
public int rd_addRef()
|
|
||||||
{
|
|
||||||
return ++refcount;
|
|
||||||
|
|
||||||
} // end rd_addRef()
|
|
||||||
|
|
||||||
public int rd_release()
|
|
||||||
{
|
|
||||||
return --refcount;
|
|
||||||
|
|
||||||
} // end rd_release
|
|
||||||
|
|
||||||
public boolean rd_unreferenced()
|
|
||||||
{
|
|
||||||
return (refcount<=0);
|
|
||||||
|
|
||||||
} // end rd_unreferenced
|
|
||||||
|
|
||||||
public Object rd_getKey()
|
|
||||||
{
|
|
||||||
return new Integer(cid);
|
|
||||||
|
|
||||||
} // end rd_getKey
|
|
||||||
|
|
||||||
/*--------------------------------------------------------------------------------
|
/*--------------------------------------------------------------------------------
|
||||||
* Implementations from interface CommunityData
|
* Implementations from interface CommunityData
|
||||||
*--------------------------------------------------------------------------------
|
*--------------------------------------------------------------------------------
|
||||||
|
@ -1535,13 +1504,13 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend
|
||||||
logger.debug("getConferenceDataObject(" + confid + ")...");
|
logger.debug("getConferenceDataObject(" + confid + ")...");
|
||||||
|
|
||||||
try
|
try
|
||||||
{ // delegate to the conf_refcache and conf_creator objects
|
{ // delegate to the conf_objcache object
|
||||||
return (ConferenceCommunityContext)(conf_refcache.getOrCreate(new Integer(confid),conf_creator));
|
return (ConferenceCommunityContext)(conf_objcache.getOrCreate(new Integer(confid)));
|
||||||
|
|
||||||
} // end try
|
} // end try
|
||||||
catch (ReferencedDataBuilderException e)
|
catch (ObjectFactoryException e)
|
||||||
{ // this may be a DataException, or it may not
|
{ // this may be a DataException, or it may not
|
||||||
Exception e2 = e.getTarget();
|
Throwable e2 = e.getException();
|
||||||
if (e2 instanceof DataException)
|
if (e2 instanceof DataException)
|
||||||
throw (DataException)e2;
|
throw (DataException)e2;
|
||||||
else
|
else
|
||||||
|
@ -1557,7 +1526,7 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend
|
||||||
if (logger.isDebugEnabled())
|
if (logger.isDebugEnabled())
|
||||||
logger.debug("detachConferenceDataObject(" + confid + ")...");
|
logger.debug("detachConferenceDataObject(" + confid + ")...");
|
||||||
|
|
||||||
conf_refcache.detach(new Integer(confid));
|
conf_objcache.detach(new Integer(confid));
|
||||||
|
|
||||||
} // end detachConferenceDataObject
|
} // end detachConferenceDataObject
|
||||||
|
|
||||||
|
@ -1578,10 +1547,9 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend
|
||||||
// extra reference on it.
|
// extra reference on it.
|
||||||
ConferenceCommunityContextImpl conf =
|
ConferenceCommunityContextImpl conf =
|
||||||
new ConferenceCommunityContextImpl(engine,this,datapool,rcs.getSequence(),hide_list,cdata);
|
new ConferenceCommunityContextImpl(engine,this,datapool,rcs.getSequence(),hide_list,cdata);
|
||||||
cdata.rd_release();
|
|
||||||
rcs = null;
|
rcs = null;
|
||||||
|
|
||||||
conf_refcache.register(conf); // register this object with our local cache
|
conf_objcache.register(new Integer(conf.getConfID()),conf); // register this object with our local cache
|
||||||
|
|
||||||
return conf; // pass it up to the next level
|
return conf; // pass it up to the next level
|
||||||
|
|
||||||
|
@ -1976,19 +1944,13 @@ class CommunityCoreData implements CommunityData, CommunityDataBackend
|
||||||
|
|
||||||
// Delete the rest of the gunk in the background; use another thread to do it.
|
// Delete the rest of the gunk in the background; use another thread to do it.
|
||||||
BackgroundCommunityPurge purger = new BackgroundCommunityPurge(engine,datapool,user,cid,conf_count,
|
BackgroundCommunityPurge purger = new BackgroundCommunityPurge(engine,datapool,user,cid,conf_count,
|
||||||
conf_max,conf_refcache);
|
conf_max,conf_objcache);
|
||||||
Thread thrd = new Thread(purger);
|
Thread thrd = new Thread(purger);
|
||||||
thrd.setPriority(Thread.NORM_PRIORITY-1);
|
thrd.setPriority(Thread.NORM_PRIORITY-1);
|
||||||
thrd.start();
|
thrd.start();
|
||||||
|
|
||||||
} // end delete
|
} // end delete
|
||||||
|
|
||||||
public void sweepCache()
|
|
||||||
{
|
|
||||||
conf_refcache.sweep();
|
|
||||||
|
|
||||||
} // end sweepCache
|
|
||||||
|
|
||||||
public CommunityProperties getProperties()
|
public CommunityProperties getProperties()
|
||||||
{
|
{
|
||||||
return createProperties();
|
return createProperties();
|
||||||
|
|
|
@ -20,13 +20,12 @@ package com.silverwrist.venice.core.impl;
|
||||||
import java.util.BitSet;
|
import java.util.BitSet;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import com.silverwrist.util.rcache.ReferencedData;
|
|
||||||
import com.silverwrist.venice.core.AccessError;
|
import com.silverwrist.venice.core.AccessError;
|
||||||
import com.silverwrist.venice.core.CommunityProperties;
|
import com.silverwrist.venice.core.CommunityProperties;
|
||||||
import com.silverwrist.venice.core.ContactInfo;
|
import com.silverwrist.venice.core.ContactInfo;
|
||||||
import com.silverwrist.venice.core.DataException;
|
import com.silverwrist.venice.core.DataException;
|
||||||
|
|
||||||
public interface CommunityData extends ReferencedData
|
public interface CommunityData
|
||||||
{
|
{
|
||||||
public abstract int getID();
|
public abstract int getID();
|
||||||
|
|
||||||
|
@ -153,8 +152,6 @@ public interface CommunityData extends ReferencedData
|
||||||
|
|
||||||
public abstract void delete(UserBackend user) throws DataException;
|
public abstract void delete(UserBackend user) throws DataException;
|
||||||
|
|
||||||
public abstract void sweepCache();
|
|
||||||
|
|
||||||
public abstract CommunityProperties getProperties();
|
public abstract CommunityProperties getProperties();
|
||||||
|
|
||||||
public abstract void setProperties(CommunityProperties props) throws DataException;
|
public abstract void setProperties(CommunityProperties props) throws DataException;
|
||||||
|
|
|
@ -21,7 +21,6 @@ import java.sql.*;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import org.apache.log4j.*;
|
import org.apache.log4j.*;
|
||||||
import com.silverwrist.util.StringUtil;
|
import com.silverwrist.util.StringUtil;
|
||||||
import com.silverwrist.util.rcache.ReferencedData;
|
|
||||||
import com.silverwrist.venice.db.*;
|
import com.silverwrist.venice.db.*;
|
||||||
import com.silverwrist.venice.security.AuditRecord;
|
import com.silverwrist.venice.security.AuditRecord;
|
||||||
import com.silverwrist.venice.security.Capability;
|
import com.silverwrist.venice.security.Capability;
|
||||||
|
@ -130,29 +129,11 @@ class CommunityUserContextImpl implements CommunityContext, CommunityBackend
|
||||||
this.datapool = datapool;
|
this.datapool = datapool;
|
||||||
this.cid = data.getID();
|
this.cid = data.getID();
|
||||||
this.cache = null; // no cache required - we have the CommunityData
|
this.cache = null; // no cache required - we have the CommunityData
|
||||||
data.rd_addRef();
|
|
||||||
this.data = data;
|
this.data = data;
|
||||||
setMemberValues(DefaultLevels.creatorCommunity(),true,true);
|
setMemberValues(DefaultLevels.creatorCommunity(),true,true);
|
||||||
|
|
||||||
} // end constructor
|
} // end constructor
|
||||||
|
|
||||||
/*--------------------------------------------------------------------------------
|
|
||||||
* finalize() function
|
|
||||||
*--------------------------------------------------------------------------------
|
|
||||||
*/
|
|
||||||
|
|
||||||
protected void finalize()
|
|
||||||
{
|
|
||||||
if (data!=null)
|
|
||||||
data.rd_release();
|
|
||||||
engine = null;
|
|
||||||
user = null;
|
|
||||||
datapool = null;
|
|
||||||
cache = null;
|
|
||||||
data = null;
|
|
||||||
|
|
||||||
} // end finalize
|
|
||||||
|
|
||||||
/*--------------------------------------------------------------------------------
|
/*--------------------------------------------------------------------------------
|
||||||
* Internal functions
|
* Internal functions
|
||||||
*--------------------------------------------------------------------------------
|
*--------------------------------------------------------------------------------
|
||||||
|
@ -1102,19 +1083,7 @@ class CommunityUserContextImpl implements CommunityContext, CommunityBackend
|
||||||
ConferenceCommunityContext cdata = getData().createConference(this,name,alias,description,pvt,hide_list);
|
ConferenceCommunityContext cdata = getData().createConference(this,name,alias,description,pvt,hide_list);
|
||||||
|
|
||||||
// wrap the returned object in a conference user context object and release the extra reference
|
// wrap the returned object in a conference user context object and release the extra reference
|
||||||
ConferenceUserContextImpl rc;
|
return new ConferenceUserContextImpl(engine,this,datapool,cdata);
|
||||||
try
|
|
||||||
{ // need to wrap this 'cos it can throw DataException
|
|
||||||
rc = new ConferenceUserContextImpl(engine,this,datapool,cdata);
|
|
||||||
|
|
||||||
} // end try
|
|
||||||
finally
|
|
||||||
{ // make sure to release that extra reference before we go
|
|
||||||
cdata.rd_release();
|
|
||||||
|
|
||||||
} // end finally
|
|
||||||
|
|
||||||
return rc;
|
|
||||||
|
|
||||||
} // end createConference
|
} // end createConference
|
||||||
|
|
||||||
|
@ -1226,7 +1195,6 @@ class CommunityUserContextImpl implements CommunityContext, CommunityBackend
|
||||||
|
|
||||||
// detach our references from the lower-level object
|
// detach our references from the lower-level object
|
||||||
data = null;
|
data = null;
|
||||||
my_comm.rd_release();
|
|
||||||
|
|
||||||
} // end delete
|
} // end delete
|
||||||
|
|
||||||
|
@ -1444,7 +1412,7 @@ class CommunityUserContextImpl implements CommunityContext, CommunityBackend
|
||||||
|
|
||||||
} // end realFullName
|
} // end realFullName
|
||||||
|
|
||||||
public void saveMRU(String tag, ReferencedData data)
|
public void saveMRU(String tag, Object data)
|
||||||
{
|
{
|
||||||
user.saveMRU(tag,data);
|
user.saveMRU(tag,data);
|
||||||
|
|
||||||
|
|
|
@ -20,11 +20,10 @@ package com.silverwrist.venice.core.impl;
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import com.silverwrist.util.rcache.ReferencedData;
|
|
||||||
import com.silverwrist.venice.core.ConferenceProperties;
|
import com.silverwrist.venice.core.ConferenceProperties;
|
||||||
import com.silverwrist.venice.core.DataException;
|
import com.silverwrist.venice.core.DataException;
|
||||||
|
|
||||||
public interface ConferenceCommunityContext extends ReferencedData
|
public interface ConferenceCommunityContext
|
||||||
{
|
{
|
||||||
public abstract int getConfID();
|
public abstract int getConfID();
|
||||||
|
|
||||||
|
|
|
@ -78,7 +78,6 @@ class ConferenceCommunityContextImpl implements ConferenceCommunityContext
|
||||||
*--------------------------------------------------------------------------------
|
*--------------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
|
|
||||||
private int refcount = 1; // reference count (within the CommunityData)
|
|
||||||
private EngineBackend engine; // engine object reference
|
private EngineBackend engine; // engine object reference
|
||||||
private CommunityDataBackend comm; // community object reference
|
private CommunityDataBackend comm; // community object reference
|
||||||
private DataPool datapool; // data pool object
|
private DataPool datapool; // data pool object
|
||||||
|
@ -166,28 +165,10 @@ class ConferenceCommunityContextImpl implements ConferenceCommunityContext
|
||||||
this.sequence = sequence;
|
this.sequence = sequence;
|
||||||
this.hide_list = hide_list;
|
this.hide_list = hide_list;
|
||||||
this.cache = null;
|
this.cache = null;
|
||||||
cdata.rd_addRef();
|
|
||||||
this.confdata = cdata;
|
this.confdata = cdata;
|
||||||
|
|
||||||
} // end constructor
|
} // end constructor
|
||||||
|
|
||||||
/*--------------------------------------------------------------------------------
|
|
||||||
* finalize() function
|
|
||||||
*--------------------------------------------------------------------------------
|
|
||||||
*/
|
|
||||||
|
|
||||||
protected void finalize()
|
|
||||||
{
|
|
||||||
if (confdata!=null)
|
|
||||||
confdata.rd_release();
|
|
||||||
confdata = null;
|
|
||||||
engine = null;
|
|
||||||
comm = null;
|
|
||||||
datapool = null;
|
|
||||||
cache = null;
|
|
||||||
|
|
||||||
} // end finalize
|
|
||||||
|
|
||||||
/*--------------------------------------------------------------------------------
|
/*--------------------------------------------------------------------------------
|
||||||
* Internal functions
|
* Internal functions
|
||||||
*--------------------------------------------------------------------------------
|
*--------------------------------------------------------------------------------
|
||||||
|
@ -238,35 +219,6 @@ class ConferenceCommunityContextImpl implements ConferenceCommunityContext
|
||||||
|
|
||||||
} // end getConferenceDataNE
|
} // end getConferenceDataNE
|
||||||
|
|
||||||
/*--------------------------------------------------------------------------------
|
|
||||||
* Implementations from interface ReferencedData
|
|
||||||
*--------------------------------------------------------------------------------
|
|
||||||
*/
|
|
||||||
|
|
||||||
public int rd_addRef()
|
|
||||||
{
|
|
||||||
return ++refcount;
|
|
||||||
|
|
||||||
} // end rd_addRef
|
|
||||||
|
|
||||||
public int rd_release()
|
|
||||||
{
|
|
||||||
return --refcount;
|
|
||||||
|
|
||||||
} // end rd_release
|
|
||||||
|
|
||||||
public boolean rd_unreferenced()
|
|
||||||
{
|
|
||||||
return (refcount<=0);
|
|
||||||
|
|
||||||
} // end rd_unreferences
|
|
||||||
|
|
||||||
public Object rd_getKey()
|
|
||||||
{
|
|
||||||
return new Integer(confid);
|
|
||||||
|
|
||||||
} // end rd_getKey
|
|
||||||
|
|
||||||
/*--------------------------------------------------------------------------------
|
/*--------------------------------------------------------------------------------
|
||||||
* Implementations from interface ConferenceCommunityContext
|
* Implementations from interface ConferenceCommunityContext
|
||||||
*--------------------------------------------------------------------------------
|
*--------------------------------------------------------------------------------
|
||||||
|
@ -829,7 +781,6 @@ class ConferenceCommunityContextImpl implements ConferenceCommunityContext
|
||||||
|
|
||||||
// detach our own reference from the lower-level object
|
// detach our own reference from the lower-level object
|
||||||
confdata = null;
|
confdata = null;
|
||||||
c.rd_release();
|
|
||||||
|
|
||||||
} // end delete
|
} // end delete
|
||||||
|
|
||||||
|
|
|
@ -48,7 +48,6 @@ class ConferenceCoreData implements ConferenceData
|
||||||
*--------------------------------------------------------------------------------
|
*--------------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
|
|
||||||
private int refcount = 1; // object reference count
|
|
||||||
private EngineBackend engine; // pointer to engine back end
|
private EngineBackend engine; // pointer to engine back end
|
||||||
private DataPool datapool; // pointer to data pool
|
private DataPool datapool; // pointer to data pool
|
||||||
private int confid; // ID of this conference
|
private int confid; // ID of this conference
|
||||||
|
@ -274,35 +273,6 @@ class ConferenceCoreData implements ConferenceData
|
||||||
|
|
||||||
} // end storeProperties
|
} // end storeProperties
|
||||||
|
|
||||||
/*--------------------------------------------------------------------------------
|
|
||||||
* Implementations from interface ReferencedData
|
|
||||||
*--------------------------------------------------------------------------------
|
|
||||||
*/
|
|
||||||
|
|
||||||
public int rd_addRef()
|
|
||||||
{
|
|
||||||
return ++refcount;
|
|
||||||
|
|
||||||
} // end rd_addRef()
|
|
||||||
|
|
||||||
public int rd_release()
|
|
||||||
{
|
|
||||||
return --refcount;
|
|
||||||
|
|
||||||
} // end rd_release
|
|
||||||
|
|
||||||
public boolean rd_unreferenced()
|
|
||||||
{
|
|
||||||
return (refcount<=0);
|
|
||||||
|
|
||||||
} // end rd_unreferenced
|
|
||||||
|
|
||||||
public Object rd_getKey()
|
|
||||||
{
|
|
||||||
return new Integer(confid);
|
|
||||||
|
|
||||||
} // end rd_getKey
|
|
||||||
|
|
||||||
/*--------------------------------------------------------------------------------
|
/*--------------------------------------------------------------------------------
|
||||||
* Implementations from interface ConferenceData
|
* Implementations from interface ConferenceData
|
||||||
*--------------------------------------------------------------------------------
|
*--------------------------------------------------------------------------------
|
||||||
|
|
|
@ -20,11 +20,10 @@ package com.silverwrist.venice.core.impl;
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import com.silverwrist.util.rcache.ReferencedData;
|
|
||||||
import com.silverwrist.venice.core.ConferenceProperties;
|
import com.silverwrist.venice.core.ConferenceProperties;
|
||||||
import com.silverwrist.venice.core.DataException;
|
import com.silverwrist.venice.core.DataException;
|
||||||
|
|
||||||
public interface ConferenceData extends ReferencedData
|
public interface ConferenceData
|
||||||
{
|
{
|
||||||
public abstract int getID();
|
public abstract int getID();
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,6 @@ package com.silverwrist.venice.core.impl;
|
||||||
import java.sql.*;
|
import java.sql.*;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import org.apache.log4j.*;
|
import org.apache.log4j.*;
|
||||||
import com.silverwrist.util.rcache.ReferencedData;
|
|
||||||
import com.silverwrist.venice.db.*;
|
import com.silverwrist.venice.db.*;
|
||||||
import com.silverwrist.venice.htmlcheck.*;
|
import com.silverwrist.venice.htmlcheck.*;
|
||||||
import com.silverwrist.venice.security.DefaultLevels;
|
import com.silverwrist.venice.security.DefaultLevels;
|
||||||
|
@ -202,7 +201,6 @@ class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend
|
||||||
this.datapool = datapool;
|
this.datapool = datapool;
|
||||||
this.confid = cdata.getConfID();
|
this.confid = cdata.getConfID();
|
||||||
this.cache = null;
|
this.cache = null;
|
||||||
cdata.rd_addRef();
|
|
||||||
this.confdata = cdata;
|
this.confdata = cdata;
|
||||||
recalcLevel(DefaultLevels.hostConference());
|
recalcLevel(DefaultLevels.hostConference());
|
||||||
this.pseud = comm.userDefaultPseud();
|
this.pseud = comm.userDefaultPseud();
|
||||||
|
@ -211,23 +209,6 @@ class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend
|
||||||
|
|
||||||
} // end constructor
|
} // end constructor
|
||||||
|
|
||||||
/*--------------------------------------------------------------------------------
|
|
||||||
* finalize() function
|
|
||||||
*--------------------------------------------------------------------------------
|
|
||||||
*/
|
|
||||||
|
|
||||||
protected void finalize()
|
|
||||||
{
|
|
||||||
if (confdata!=null)
|
|
||||||
confdata.rd_release();
|
|
||||||
engine = null;
|
|
||||||
comm = null;
|
|
||||||
datapool = null;
|
|
||||||
cache = null;
|
|
||||||
confdata = null;
|
|
||||||
|
|
||||||
} // end finalize
|
|
||||||
|
|
||||||
/*--------------------------------------------------------------------------------
|
/*--------------------------------------------------------------------------------
|
||||||
* Internal functions
|
* Internal functions
|
||||||
*--------------------------------------------------------------------------------
|
*--------------------------------------------------------------------------------
|
||||||
|
@ -1261,7 +1242,6 @@ class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend
|
||||||
|
|
||||||
// detach our references from the lower-level object
|
// detach our references from the lower-level object
|
||||||
confdata = null;
|
confdata = null;
|
||||||
ctxt.rd_release();
|
|
||||||
|
|
||||||
} // end delete
|
} // end delete
|
||||||
|
|
||||||
|
@ -1532,7 +1512,7 @@ class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend
|
||||||
|
|
||||||
} // end realFullName
|
} // end realFullName
|
||||||
|
|
||||||
public void saveMRU(String tag, ReferencedData data)
|
public void saveMRU(String tag, Object data)
|
||||||
{
|
{
|
||||||
comm.saveMRU(tag,data);
|
comm.saveMRU(tag,data);
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,6 @@
|
||||||
*/
|
*/
|
||||||
package com.silverwrist.venice.core.impl;
|
package com.silverwrist.venice.core.impl;
|
||||||
|
|
||||||
import com.silverwrist.util.rcache.ReferencedData;
|
|
||||||
import com.silverwrist.venice.core.DataException;
|
import com.silverwrist.venice.core.DataException;
|
||||||
|
|
||||||
public interface UserBackend
|
public interface UserBackend
|
||||||
|
@ -38,6 +37,6 @@ public interface UserBackend
|
||||||
|
|
||||||
public abstract String realFullName() throws DataException;
|
public abstract String realFullName() throws DataException;
|
||||||
|
|
||||||
public abstract void saveMRU(String tag, ReferencedData data);
|
public abstract void saveMRU(String tag, Object data);
|
||||||
|
|
||||||
} // end interface UserBackend
|
} // end interface UserBackend
|
||||||
|
|
|
@ -23,7 +23,6 @@ import org.apache.log4j.*;
|
||||||
import com.silverwrist.util.LocaleFactory;
|
import com.silverwrist.util.LocaleFactory;
|
||||||
import com.silverwrist.util.OptionSet;
|
import com.silverwrist.util.OptionSet;
|
||||||
import com.silverwrist.util.StringUtil;
|
import com.silverwrist.util.StringUtil;
|
||||||
import com.silverwrist.util.rcache.ReferencedData;
|
|
||||||
import com.silverwrist.venice.*;
|
import com.silverwrist.venice.*;
|
||||||
import com.silverwrist.venice.core.*;
|
import com.silverwrist.venice.core.*;
|
||||||
import com.silverwrist.venice.db.*;
|
import com.silverwrist.venice.db.*;
|
||||||
|
@ -75,7 +74,7 @@ class UserContextImpl implements UserContext, UserBackend
|
||||||
private String full_name = null; // my full name (cached)
|
private String full_name = null; // my full name (cached)
|
||||||
private Locale my_locale = null; // my default locale (cached)
|
private Locale my_locale = null; // my default locale (cached)
|
||||||
private TimeZone my_tz = null; // my default timezone (cached)
|
private TimeZone my_tz = null; // my default timezone (cached)
|
||||||
private HashMap mru_cache = new HashMap(); // MRU cache for ReferencedData objects
|
private HashMap mru_cache = new HashMap(); // MRU cache for data objects
|
||||||
private OptionSet flags = null; // option flags
|
private OptionSet flags = null; // option flags
|
||||||
|
|
||||||
/*--------------------------------------------------------------------------------
|
/*--------------------------------------------------------------------------------
|
||||||
|
@ -90,35 +89,6 @@ class UserContextImpl implements UserContext, UserBackend
|
||||||
|
|
||||||
} // end constructor
|
} // end constructor
|
||||||
|
|
||||||
/*--------------------------------------------------------------------------------
|
|
||||||
* finalize() method
|
|
||||||
*--------------------------------------------------------------------------------
|
|
||||||
*/
|
|
||||||
|
|
||||||
protected void finalize()
|
|
||||||
{
|
|
||||||
Iterator it = mru_cache.values().iterator();
|
|
||||||
while (it.hasNext())
|
|
||||||
{ // release all our ReferencedData objects
|
|
||||||
ReferencedData rd = (ReferencedData)(it.next());
|
|
||||||
rd.rd_release();
|
|
||||||
|
|
||||||
} // end while
|
|
||||||
|
|
||||||
engine = null;
|
|
||||||
datapool = null;
|
|
||||||
username = null;
|
|
||||||
created = null;
|
|
||||||
last_access = null;
|
|
||||||
description = null;
|
|
||||||
my_email = null;
|
|
||||||
my_pseud = null;
|
|
||||||
full_name = null;
|
|
||||||
my_locale = null;
|
|
||||||
my_tz = null;
|
|
||||||
|
|
||||||
} // end finalize
|
|
||||||
|
|
||||||
/*--------------------------------------------------------------------------------
|
/*--------------------------------------------------------------------------------
|
||||||
* Internal functions
|
* Internal functions
|
||||||
*--------------------------------------------------------------------------------
|
*--------------------------------------------------------------------------------
|
||||||
|
@ -1039,8 +1009,6 @@ class UserContextImpl implements UserContext, UserBackend
|
||||||
// Create the community context we return to the user.
|
// Create the community context we return to the user.
|
||||||
CommunityContext rc = new CommunityUserContextImpl(engine,this,datapool,new_comm);
|
CommunityContext rc = new CommunityUserContextImpl(engine,this,datapool,new_comm);
|
||||||
|
|
||||||
new_comm.rd_release(); // release the extra reference we have on CommunityData
|
|
||||||
|
|
||||||
// And that's it! You expected lightning bolts maybe? :-)
|
// And that's it! You expected lightning bolts maybe? :-)
|
||||||
|
|
||||||
return rc;
|
return rc;
|
||||||
|
@ -1604,13 +1572,9 @@ class UserContextImpl implements UserContext, UserBackend
|
||||||
|
|
||||||
} // end realFullName
|
} // end realFullName
|
||||||
|
|
||||||
public void saveMRU(String tag, ReferencedData data)
|
public void saveMRU(String tag, Object data)
|
||||||
{
|
{
|
||||||
ReferencedData old = (ReferencedData)(mru_cache.get(tag));
|
|
||||||
data.rd_addRef();
|
|
||||||
mru_cache.put(tag,data);
|
mru_cache.put(tag,data);
|
||||||
if (old!=null)
|
|
||||||
old.rd_release();
|
|
||||||
|
|
||||||
} // end saveMRU
|
} // end saveMRU
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,7 @@ import org.w3c.dom.*;
|
||||||
import com.silverwrist.util.OptionSet;
|
import com.silverwrist.util.OptionSet;
|
||||||
import com.silverwrist.util.StringUtil;
|
import com.silverwrist.util.StringUtil;
|
||||||
import com.silverwrist.util.DOMElementHelper;
|
import com.silverwrist.util.DOMElementHelper;
|
||||||
import com.silverwrist.util.rcache.*;
|
import com.silverwrist.util.cache.*;
|
||||||
import com.silverwrist.venice.core.*;
|
import com.silverwrist.venice.core.*;
|
||||||
import com.silverwrist.venice.db.*;
|
import com.silverwrist.venice.db.*;
|
||||||
import com.silverwrist.venice.htmlcheck.*;
|
import com.silverwrist.venice.htmlcheck.*;
|
||||||
|
@ -312,58 +312,18 @@ public class VeniceEngineImpl implements VeniceEngine, EngineBackend
|
||||||
|
|
||||||
} // end class MasterSideBoxList
|
} // end class MasterSideBoxList
|
||||||
|
|
||||||
/*--------------------------------------------------------------------------------
|
|
||||||
* Internal cache sweeper class information.
|
|
||||||
*--------------------------------------------------------------------------------
|
|
||||||
*/
|
|
||||||
|
|
||||||
protected class CacheSweeper implements Runnable
|
|
||||||
{
|
|
||||||
public void run()
|
|
||||||
{
|
|
||||||
for (;;)
|
|
||||||
{ // this is a background thread that runs always
|
|
||||||
try
|
|
||||||
{ // wait for a little while
|
|
||||||
Thread.sleep(10000);
|
|
||||||
|
|
||||||
} // end try
|
|
||||||
catch (InterruptedException e)
|
|
||||||
{ // if we're interrupted, just schedule the next run a little early
|
|
||||||
} // end catch
|
|
||||||
|
|
||||||
// sweep the community cache first
|
|
||||||
List comms = comm_refcache.sweepReturn();
|
|
||||||
Iterator it = comms.iterator();
|
|
||||||
while (it.hasNext())
|
|
||||||
{ // perform subsweeps on the community data
|
|
||||||
CommunityData comm = (CommunityData)(it.next());
|
|
||||||
comm.sweepCache();
|
|
||||||
comm.rd_release();
|
|
||||||
|
|
||||||
} // end while
|
|
||||||
|
|
||||||
// now sweep other caches
|
|
||||||
conf_refcache.sweep();
|
|
||||||
|
|
||||||
} // end for (ever)
|
|
||||||
|
|
||||||
} // end run
|
|
||||||
|
|
||||||
} // end class CacheSweeper
|
|
||||||
|
|
||||||
/*--------------------------------------------------------------------------------
|
/*--------------------------------------------------------------------------------
|
||||||
* Internal class for creating new CommunityCoreData objects.
|
* Internal class for creating new CommunityCoreData objects.
|
||||||
*--------------------------------------------------------------------------------
|
*--------------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
|
|
||||||
protected class CommunityCoreDataCreator implements ReferencedDataBuilder
|
protected class CommunityCoreDataCreator implements ObjectFactory
|
||||||
{
|
{
|
||||||
protected CommunityCoreDataCreator()
|
protected CommunityCoreDataCreator()
|
||||||
{ // do nothing
|
{ // do nothing
|
||||||
} // end constructor
|
} // end constructor
|
||||||
|
|
||||||
public ReferencedData build(Object key) throws ReferencedDataBuilderException
|
public Object newObject(Object key) throws ObjectFactoryException
|
||||||
{
|
{
|
||||||
Integer xcid = (Integer)key;
|
Integer xcid = (Integer)key;
|
||||||
try
|
try
|
||||||
|
@ -373,7 +333,7 @@ public class VeniceEngineImpl implements VeniceEngine, EngineBackend
|
||||||
} // end try
|
} // end try
|
||||||
catch (DataException e)
|
catch (DataException e)
|
||||||
{ // rethrow as a "wrapped" exception
|
{ // rethrow as a "wrapped" exception
|
||||||
throw new ReferencedDataBuilderException(e);
|
throw new ObjectFactoryException(e);
|
||||||
|
|
||||||
} // end catch
|
} // end catch
|
||||||
|
|
||||||
|
@ -386,13 +346,13 @@ public class VeniceEngineImpl implements VeniceEngine, EngineBackend
|
||||||
*--------------------------------------------------------------------------------
|
*--------------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
|
|
||||||
protected class ConferenceCoreDataCreator implements ReferencedDataBuilder
|
protected class ConferenceCoreDataCreator implements ObjectFactory
|
||||||
{
|
{
|
||||||
protected ConferenceCoreDataCreator()
|
protected ConferenceCoreDataCreator()
|
||||||
{ // do nothing
|
{ // do nothing
|
||||||
} // end constructor
|
} // end constructor
|
||||||
|
|
||||||
public ReferencedData build(Object key) throws ReferencedDataBuilderException
|
public Object newObject(Object key) throws ObjectFactoryException
|
||||||
{
|
{
|
||||||
Integer xconf = (Integer)key;
|
Integer xconf = (Integer)key;
|
||||||
try
|
try
|
||||||
|
@ -402,7 +362,7 @@ public class VeniceEngineImpl implements VeniceEngine, EngineBackend
|
||||||
} // end try
|
} // end try
|
||||||
catch (DataException e)
|
catch (DataException e)
|
||||||
{ // rethrow as a "wrapped" exception
|
{ // rethrow as a "wrapped" exception
|
||||||
throw new ReferencedDataBuilderException(e);
|
throw new ObjectFactoryException(e);
|
||||||
|
|
||||||
} // end catch
|
} // end catch
|
||||||
|
|
||||||
|
@ -501,12 +461,10 @@ public class VeniceEngineImpl implements VeniceEngine, EngineBackend
|
||||||
private Properties email_props = null; // email properties
|
private Properties email_props = null; // email properties
|
||||||
private javax.mail.Session mailsession = null; // email session object
|
private javax.mail.Session mailsession = null; // email session object
|
||||||
private Hashtable stock_messages = null; // stock messages holder
|
private Hashtable stock_messages = null; // stock messages holder
|
||||||
private ReferenceCache comm_refcache = new ReferenceCache();
|
private ObjectCache comm_objcache = new ObjectCache(new CommunityCoreDataCreator());
|
||||||
private CommunityCoreDataCreator comm_creator = new CommunityCoreDataCreator();
|
|
||||||
private VeniceFeatureDef[] features; // master feature table
|
private VeniceFeatureDef[] features; // master feature table
|
||||||
private Hashtable feature_syms = new Hashtable(); // hashtable mapping symbols to features
|
private Hashtable feature_syms = new Hashtable(); // hashtable mapping symbols to features
|
||||||
private ReferenceCache conf_refcache = new ReferenceCache();
|
private ObjectCache conf_objcache = new ObjectCache(new ConferenceCoreDataCreator());
|
||||||
private ConferenceCoreDataCreator conf_creator = new ConferenceCoreDataCreator();
|
|
||||||
private HTMLCheckerConfig[] html_configs; // holder for HTML checker configurations
|
private HTMLCheckerConfig[] html_configs; // holder for HTML checker configurations
|
||||||
private int[] gp_ints; // global integer parameters
|
private int[] gp_ints; // global integer parameters
|
||||||
private MasterSideBox[] sideboxes; // master sidebox table
|
private MasterSideBox[] sideboxes; // master sidebox table
|
||||||
|
@ -1084,12 +1042,6 @@ public class VeniceEngineImpl implements VeniceEngine, EngineBackend
|
||||||
cfg.addOutputFilter(html_filter);
|
cfg.addOutputFilter(html_filter);
|
||||||
html_configs[HTMLC_ESCAPE_BODY_PSEUD] = cfg;
|
html_configs[HTMLC_ESCAPE_BODY_PSEUD] = cfg;
|
||||||
|
|
||||||
// Start the cache sweeper.
|
|
||||||
Thread thrd = new Thread(new CacheSweeper());
|
|
||||||
thrd.setPriority(Thread.currentThread().getPriority()-2);
|
|
||||||
thrd.setDaemon(true);
|
|
||||||
thrd.start();
|
|
||||||
|
|
||||||
if (logger.isDebugEnabled())
|
if (logger.isDebugEnabled())
|
||||||
logger.debug("initialize() complete :-)");
|
logger.debug("initialize() complete :-)");
|
||||||
|
|
||||||
|
@ -2144,13 +2096,13 @@ public class VeniceEngineImpl implements VeniceEngine, EngineBackend
|
||||||
logger.debug("getCommunityDataObject(" + cid + ")...");
|
logger.debug("getCommunityDataObject(" + cid + ")...");
|
||||||
|
|
||||||
try
|
try
|
||||||
{ // delegate to the comm_refcache and comm_creator objects
|
{ // delegate to the comm_objcache object
|
||||||
return (CommunityData)(comm_refcache.getOrCreate(new Integer(cid),comm_creator));
|
return (CommunityData)(comm_objcache.getOrCreate(new Integer(cid)));
|
||||||
|
|
||||||
} // end try
|
} // end try
|
||||||
catch (ReferencedDataBuilderException e)
|
catch (ObjectFactoryException e)
|
||||||
{ // this may be a DataException, or it may not
|
{ // this may be a DataException, or it may not
|
||||||
Exception e2 = e.getTarget();
|
Throwable e2 = e.getException();
|
||||||
if (e2 instanceof DataException)
|
if (e2 instanceof DataException)
|
||||||
throw (DataException)e2;
|
throw (DataException)e2;
|
||||||
else
|
else
|
||||||
|
@ -2167,7 +2119,7 @@ public class VeniceEngineImpl implements VeniceEngine, EngineBackend
|
||||||
if (logger.isDebugEnabled())
|
if (logger.isDebugEnabled())
|
||||||
logger.debug("detachCommunityDataObject(" + cid + ")...");
|
logger.debug("detachCommunityDataObject(" + cid + ")...");
|
||||||
|
|
||||||
comm_refcache.detach(new Integer(cid));
|
comm_objcache.detach(new Integer(cid));
|
||||||
|
|
||||||
} // end detachCommunityDataObject
|
} // end detachCommunityDataObject
|
||||||
|
|
||||||
|
@ -2255,7 +2207,7 @@ public class VeniceEngineImpl implements VeniceEngine, EngineBackend
|
||||||
if (logger.isDebugEnabled())
|
if (logger.isDebugEnabled())
|
||||||
logger.debug("registerNewCommunity(" + comm.getID() + ")...");
|
logger.debug("registerNewCommunity(" + comm.getID() + ")...");
|
||||||
|
|
||||||
comm_refcache.register(comm);
|
comm_objcache.register(new Integer(comm.getID()),comm);
|
||||||
|
|
||||||
} // end registerNewCommunity
|
} // end registerNewCommunity
|
||||||
|
|
||||||
|
@ -2286,13 +2238,13 @@ public class VeniceEngineImpl implements VeniceEngine, EngineBackend
|
||||||
logger.debug("getConferenceDataObject(" + confid + ")...");
|
logger.debug("getConferenceDataObject(" + confid + ")...");
|
||||||
|
|
||||||
try
|
try
|
||||||
{ // delegate to the conf_refcache and conf_creator objects
|
{ // delegate to the conf_objcache objects
|
||||||
return (ConferenceData)(conf_refcache.getOrCreate(new Integer(confid),conf_creator));
|
return (ConferenceData)(conf_objcache.getOrCreate(new Integer(confid)));
|
||||||
|
|
||||||
} // end try
|
} // end try
|
||||||
catch (ReferencedDataBuilderException e)
|
catch (ObjectFactoryException e)
|
||||||
{ // this may be a DataException, or it may not
|
{ // this may be a DataException, or it may not
|
||||||
Exception e2 = e.getTarget();
|
Throwable e2 = e.getException();
|
||||||
if (e2 instanceof DataException)
|
if (e2 instanceof DataException)
|
||||||
throw (DataException)e2;
|
throw (DataException)e2;
|
||||||
else
|
else
|
||||||
|
@ -2309,7 +2261,7 @@ public class VeniceEngineImpl implements VeniceEngine, EngineBackend
|
||||||
if (logger.isDebugEnabled())
|
if (logger.isDebugEnabled())
|
||||||
logger.debug("detachConferenceDataObject(" + confid + ")...");
|
logger.debug("detachConferenceDataObject(" + confid + ")...");
|
||||||
|
|
||||||
conf_refcache.detach(new Integer(confid));
|
conf_objcache.detach(new Integer(confid));
|
||||||
|
|
||||||
} // end detachConferenceDataObject
|
} // end detachConferenceDataObject
|
||||||
|
|
||||||
|
@ -2347,7 +2299,7 @@ public class VeniceEngineImpl implements VeniceEngine, EngineBackend
|
||||||
if (logger.isDebugEnabled())
|
if (logger.isDebugEnabled())
|
||||||
logger.debug("registerNewConference(" + conf.getID() + ")...");
|
logger.debug("registerNewConference(" + conf.getID() + ")...");
|
||||||
|
|
||||||
conf_refcache.register(conf);
|
conf_objcache.register(new Integer(conf.getID()),conf);
|
||||||
|
|
||||||
} // end registerNewConference
|
} // end registerNewConference
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user