uk.org.iscream.cms.server.componentmanager
Class XMLCache

java.lang.Object
  |
  +--java.lang.Thread
        |
        +--uk.org.iscream.cms.server.componentmanager.XMLCache
All Implemented Interfaces:
Runnable

public class XMLCache
extends Thread

An XMLCache to cut down the cost of XML parsing. This class tries to ensure we only parse a String of XML into an XML packet once.

Version:
$Id: XMLCache.java,v 1.3 2003/02/05 16:43:46 tdb Exp $
Author:
$Author: tdb $

Field Summary
private  HashMap _hashA
          Our primary HashMap
private  HashMap _hashB
          Our secondary HashMap
private static XMLCache _instance
          Reference to our instance - we're a singleton.
private  Logger _logger
          This holds a reference to the system logger that is being used.
private  String _name
          This is the friendly identifier of the component this class is running in.
private  boolean _running
          We can set this to false to stop the Thread
private  XMLPacketMaker _xmlPacketMaker
          A reference to an XMLPacketMaker which we can use to generate XMLPackets from XML Strings
 int DEFAULT_CLEANUP_PERIOD
          The default period for cleaning out old XMLPackets
static String REVISION
          The current CVS revision of this class
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
private XMLCache()
          A private constructor to start this class up
 
Method Summary
static XMLCache getInstance()
          Return a reference to our singleton.
 XMLPacket getXMLPacket(String xml)
          Generates an XMLPacket from a given String of XML, checking to see if it already has the XMLPacket cached.
 void run()
          Main loop for the thread to clean out old XMLPackets.
 String toString()
          Overrides the Object.toString() method to provide clean logging (every class should have this).
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getContextClassLoader, getName, getPriority, getThreadGroup, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setName, setPriority, sleep, sleep, start, stop, stop, suspend, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

REVISION

public static final String REVISION
The current CVS revision of this class

See Also:
Constant Field Values

DEFAULT_CLEANUP_PERIOD

public final int DEFAULT_CLEANUP_PERIOD
The default period for cleaning out old XMLPackets

See Also:
Constant Field Values

_instance

private static XMLCache _instance
Reference to our instance - we're a singleton.


_hashA

private HashMap _hashA
Our primary HashMap


_hashB

private HashMap _hashB
Our secondary HashMap


_xmlPacketMaker

private XMLPacketMaker _xmlPacketMaker
A reference to an XMLPacketMaker which we can use to generate XMLPackets from XML Strings


_running

private boolean _running
We can set this to false to stop the Thread


_name

private String _name
This is the friendly identifier of the component this class is running in. eg, a Filter may be called "filter1", If this class does not have an owning component, a name from the configuration can be placed here. This name could also be changed to null for utility classes.


_logger

private Logger _logger
This holds a reference to the system logger that is being used.

Constructor Detail

XMLCache

private XMLCache()
A private constructor to start this class up

Method Detail

getInstance

public static XMLCache getInstance()
Return a reference to our singleton.


run

public void run()
Main loop for the thread to clean out old XMLPackets. This is done by swapping HashMap's around. This seemed like the most efficient approach, and is infact a documented garbage collection technique :)

Specified by:
run in interface Runnable
Overrides:
run in class Thread

toString

public String toString()
Overrides the Object.toString() method to provide clean logging (every class should have this). This uses the uk.org.iscream.cms.util.FormatName class to format the toString()

Overrides:
toString in class Thread
Returns:
the name of this class and its CVS revision

getXMLPacket

public XMLPacket getXMLPacket(String xml)
                       throws InvalidXMLException
Generates an XMLPacket from a given String of XML, checking to see if it already has the XMLPacket cached.

Parameters:
xml - A String of XML data
Returns:
An XMLPacket representing the xml parameter
Throws:
InvalidXMLException - if the XML does not parse


Copyright © 2000-2003 i-scream. All Rights Reserved.