- cookie-based persistent logins - expanded activity reporting - "top" and "fixed" left menus are now dynamically generated from XML config, not hard coded - error reporting enhanced and protection increased - "About Venice" page first draft - new means of "framing" static content within the Venice "frame" - base page now includes the "footer" itself, "content" pages don't anymore - general cleanup of some heavyweight old containers, replaced with faster Collections framework containers - probably more, there's a LOT of stuff in here
162 lines
4.1 KiB
Java
162 lines
4.1 KiB
Java
/*
|
|
* 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
|