From: <bri...@us...> - 2003-07-16 06:45:04
|
Update of /cvsroot/webmacro/webmacro/src/org/webmacro/util In directory sc8-pr-cvs1:/tmp/cvs-serv32064/src/org/webmacro/util Modified Files: Clock.java LogSystem.java WMEval.java Removed Files: ComponentMap.java IntStack.java SharedObject.java SharedReference.java ThreadScheduler.java UPool.java Log Message: More ripping out -- eliminate reference counting of Brokers, pooling of context and fastwriter; streamline Context; eliminate Clock thread hack; eliminate ascii fastwriter hack Index: Clock.java =================================================================== RCS file: /cvsroot/webmacro/webmacro/src/org/webmacro/util/Clock.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** Clock.java 12 Jun 2003 00:47:48 -0000 1.5 --- Clock.java 16 Jul 2003 06:45:00 -0000 1.6 *************** *** 29,36 **** * This is an optimization. "System.currentTimeMillis()" is a relatively * slow method, and "new Date()" is an incredibly expensive operation. ! * This clock performs these operations at regular intervals and makes ! * the result of the calculations available. You can therefore use this ! * class to gain rapid access to the current time in situations where ! * it is good enough to have "close" to the current time. */ final public class Clock --- 29,34 ---- * This is an optimization. "System.currentTimeMillis()" is a relatively * slow method, and "new Date()" is an incredibly expensive operation. ! * Update: System.ctm is no longer all that slow; replaced with a version ! * that caches the Date but not the time. */ final public class Clock *************** *** 40,161 **** * Every tick interval the following variable is updated with the current system time */ ! static public volatile long TIME; /** * Date information */ - private static long dateTime = System.currentTimeMillis(); private static Date date = new Date(); - private static Object _lock = new Object(); - - /** - * The current date. This object is updated on the tick interval, - * but not faster than once per second. - */ - public static Date getDate () - { - synchronized (_lock) - { - if (_clock != null) - { - if ((TIME - dateTime) > 1000) - { - date = new Date(TIME); - } - } - else - { - // clock is not started yet - date = new Date(); - } - return date; - } - } - - /** - * The tick interval, how fast the clock updates the time. The default - * is once every 10 seconds. - */ - static private int tickInterval = 10000; - - /** - * The clock will tick at least this often. It may tick more often. - * Setting it to zero stops the clock. The actual tick interval used - * will be the smallest tick interval ever set. The tickInterval - * starts out as 10000 (ten seconds). - */ - static public void setTickInterval (int interval) - { - if (interval < 0) interval = 0; - - if ((tickInterval == 0) || (interval < tickInterval)) - { - tickInterval = interval; - synchronized (_clock) - { - _clock.notify(); - _clock.setName("clock:" + tickInterval); - } - } - } - /** ! * Set up the clock */ ! static private Thread _clock; ! ! static class ClockThread extends Thread ! { ! ! synchronized public void run () ! { ! while (!Thread.currentThread().interrupted()) ! { ! TIME = System.currentTimeMillis(); ! try ! { ! if (tickInterval == 0) ! wait(); ! else ! wait(tickInterval); ! } ! catch (InterruptedException e) ! { ! break; // terminate ! } ! } ! } ! } ! ! static private int _count; ! ! public static synchronized void startClient () ! { ! if (_count++ == 0) ! { ! _clock = new ClockThread(); ! _clock.setDaemon(true); ! _clock.setName("clock:" + tickInterval); ! _clock.start(); ! } ! } ! ! public static synchronized void stopClient () ! { ! if (--_count == 0) ! { ! _clock.interrupt(); ! _clock = null; ! } ! } ! ! public static void main (String arg[]) { ! setTickInterval(1000); ! while (true) ! { ! System.out.println(TIME); } } --- 38,59 ---- * Every tick interval the following variable is updated with the current system time */ ! static public long TIME = System.currentTimeMillis(); /** * Date information */ private static Date date = new Date(); /** ! * The current date. This object is updated not faster than once per second. */ ! public synchronized static Date getDate () { ! long time = System.currentTimeMillis(); ! if ((TIME - time) > 1000) { ! TIME = time; ! date = new Date(TIME); } + return date; } Index: LogSystem.java =================================================================== RCS file: /cvsroot/webmacro/webmacro/src/org/webmacro/util/LogSystem.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** LogSystem.java 12 Jun 2003 00:47:48 -0000 1.6 --- LogSystem.java 16 Jul 2003 06:45:00 -0000 1.7 *************** *** 79,83 **** } - private final static Map _instances = new HashMap(); private final static LogSystem _singleton; private final static Log _log; --- 79,82 ---- *************** *** 98,102 **** public static LogSystem getInstance () { ! return getInstance(null); } --- 97,101 ---- public static LogSystem getInstance () { ! return _singleton; } *************** *** 117,160 **** } - /** - * Return the log-system with the specified category - */ - public static LogSystem getInstance (String category) - { - synchronized (_instances) - { - if (category == null) return _singleton; - LogSystem ls = (LogSystem) _instances.get(category); - if (ls == null) - { - ls = new LogSystem(category); - _instances.put(category, ls); - } - return ls; - } - } - - /** - * Remove the specified LogSystem instance from the internal - * cache of LogSystems. - */ - public static void removeInstance (LogSystem instance) - { - synchronized (_instances) - { - if (_instances.containsValue(instance)) - { - for (Iterator itr = _instances.entrySet().iterator(); itr.hasNext();) - { - Map.Entry e = (Map.Entry) itr.next(); - if (e.getValue() == instance) - { - itr.remove(); - } - } - } - } - } - ///////////////////////////////////////////// --- 116,119 ---- *************** *** 165,169 **** final private Set _targets = new HashSet(); ! private LogSystem (String category) { _category = category; --- 124,128 ---- final private Set _targets = new HashSet(); ! public LogSystem (String category) { _category = category; *************** *** 324,341 **** } - /** - * Flush all log systems - */ - static public void flushAll () - { - _singleton.flush(); - Iterator i = _instances.values().iterator(); - while (i.hasNext()) - { - LogSystem ls = (LogSystem) i.next(); - ls.flush(); - } - } - /** --- 283,286 ---- *************** *** 363,367 **** l.error("2:testing error"); ! LogSystem.flushAll(); --- 308,312 ---- l.error("2:testing error"); ! LogSystem.getInstance().flush(); Index: WMEval.java =================================================================== RCS file: /cvsroot/webmacro/webmacro/src/org/webmacro/util/WMEval.java,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** WMEval.java 8 Jul 2003 19:48:45 -0000 1.13 --- WMEval.java 16 Jul 2003 06:45:00 -0000 1.14 *************** *** 233,237 **** { Template t = wm.getTemplate(templateName); ! String val = t.getString(context); if (out != null) { --- 233,237 ---- { Template t = wm.getTemplate(templateName); ! String val = t.evaluateAsString(context); if (out != null) { *************** *** 292,296 **** public String eval (Context context, Template rule) throws Exception { ! return rule.getString(context); } --- 292,296 ---- public String eval (Context context, Template rule) throws Exception { ! return rule.evaluateAsString(context); } *************** *** 309,313 **** { Template rule = wm.getTemplate(templateResourceFile); ! String value = rule.getString(context); // output the file if (outputFileName == null) --- 309,313 ---- { Template rule = wm.getTemplate(templateResourceFile); ! String value = rule.evaluateAsString(context); // output the file if (outputFileName == null) *************** *** 328,332 **** public void destroy () { - wm.destroy(); wm = null; rule = null; --- 328,331 ---- --- ComponentMap.java DELETED --- --- IntStack.java DELETED --- --- SharedObject.java DELETED --- --- SharedReference.java DELETED --- --- ThreadScheduler.java DELETED --- --- UPool.java DELETED --- |