KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > oddjob > logging > LocalConsoleArchiver


1 /*
2  * (c) Rob Gordon 2005
3  */

4 package org.oddjob.logging;
5
6 import org.oddjob.Oddjob;
7
8 /**
9  * An implementation of a ConsoleArchiver for the local JVM. An Explorer or Server
10  * job will attach this archiver to a job node to capture console output from that
11  * node and it's children down to a node which is a different console archiver (
12  * because it's a sparate process or is getting console output from a remote node).
13  * <p>
14  *
15  * @author Rob Gordon.
16  */

17 public class LocalConsoleArchiver implements ConsoleArchiver {
18     
19     /** The cache we delegate most of the work to. */
20     private ConsoleArchiverCache cache;
21     
22     /** The resolver is past to archive so that it can resolve consoleIds and
23      * archives.
24      */

25     private ConsoleArchiverCache.Resolver resolver = new ConsoleArchiverCache.Resolver() {
26         public LogArchive archiveFor(Object JavaDoc component) {
27             if (component instanceof ConsoleArchive) {
28                 return ((ConsoleArchive) component).consoleLog();
29             }
30             else {
31                 return Oddjob.CONSOLE.consoleLog();
32             }
33         }
34         public String JavaDoc idFor(Object JavaDoc component) {
35             if (component instanceof ConsoleArchive) {
36                 return ((ConsoleArchive) component).consoleLog().getArchive();
37             }
38             else {
39                 return Oddjob.CONSOLE.consoleLog().getArchive();
40             }
41         }
42     };
43     
44     /**
45      * Constructor.
46      *
47      * @param root The root of the archivers.
48      */

49     public LocalConsoleArchiver(Object JavaDoc root) {
50         this(root, LogArchiver.MAX_HISTORY);
51     }
52     
53     /**
54      * Constructor with max history specified.
55      *
56      * @param root The root.
57      * @param maxHistory The number of history lines.
58      */

59     public LocalConsoleArchiver(Object JavaDoc root, int maxHistory) {
60         cache = new ConsoleArchiverCache(root, maxHistory, resolver);
61     }
62     
63     /*
64      * (non-Javadoc)
65      * @see org.oddjob.logging.ConsoleArchiver#addConsoleListener(org.oddjob.logging.LogListener, java.lang.Object, long, int)
66      */

67     public void addConsoleListener(LogListener l, Object JavaDoc component,
68             long last, int history) {
69         cache.addLogListener(l,
70                 resolver.idFor(component), LogLevel.DEBUG, last, history);
71     }
72     
73     /*
74      * (non-Javadoc)
75      * @see org.oddjob.logging.ConsoleArchiver#removeConsoleListener(org.oddjob.logging.LogListener, java.lang.Object)
76      */

77     public void removeConsoleListener(LogListener l, Object JavaDoc component) {
78         cache.removeLogListener(l,
79                 resolver.idFor(component));
80     }
81     
82     /* (non-Javadoc)
83      * @see org.oddjob.logging.ConsoleArchiver#consoleIdFor(java.lang.Object)
84      */

85     public String JavaDoc consoleIdFor(Object JavaDoc component) {
86         return resolver.idFor(component);
87     }
88     
89     /**
90      * Destroy the cache.
91      *
92      */

93     public void destroy() {
94         cache.destroy();
95     }
96         
97
98 }
99
Popular Tags