1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.jetspeed.daemon;
18
19 import org.apache.jetspeed.services.daemonfactory.DaemonFactory;
20 import org.apache.jetspeed.services.logging.JetspeedLogFactoryService;
21 import org.apache.jetspeed.services.logging.JetspeedLogger;
22
23 /***
24 @author <a href="mailto:burton@apache.org">Kevin A. Burton</a>
25 @version $Id: DaemonThread.java,v 1.20 2004/02/23 02:48:57 jford Exp $
26 */
27 public class DaemonThread extends Thread {
28
29 private Daemon daemon = null;
30
31 /***
32 * Static initialization of the logger for this class
33 */
34 private static final JetspeedLogger logger = JetspeedLogFactoryService.getLogger(DaemonThread.class.getName());
35
36 /***
37 */
38 public DaemonThread( DaemonEntry entry ) {
39
40 super( "DaemonThread:" + entry.getName() );
41 try {
42 this.setDaemon(true);
43 this.daemon = DaemonFactory.getDaemon( entry );
44 this.setPriority( Thread.MIN_PRIORITY );
45 } catch (DaemonException e) {
46
47 logger.error("Error instantiating DaemonThread", e);
48 }
49 }
50
51
52 public DaemonThread()
53 {
54 super();
55 this.setDaemon(true);
56 }
57
58 /***
59 */
60 public Daemon getDaemon() {
61 return this.daemon;
62 }
63
64 /***
65 */
66 public void run() {
67
68
69 DaemonEntry de = this.getDaemon().getDaemonEntry();
70
71 logger.info( "DaemonThread: started processing daemon " + de.getName() );
72
73 if ( de.onStartup() ) {
74 this.runDaemon( this.getDaemon() );
75 }
76
77
78 while( true ) {
79
80
81 try {
82
83 synchronized( this ) {
84 this.wait( de.getInterval() * 1000 );
85 }
86
87 } catch (InterruptedException e) {
88
89
90
91 }
92
93 this.runDaemon( this.getDaemon() );
94
95 }
96
97
98 }
99
100 /***
101 */
102 private void runDaemon( Daemon daemon ) {
103
104 daemon.setStatus( Daemon.STATUS_PROCESSING );
105
106 logger.info( "DaemonThread -> PROCESSING daemon -> " + daemon.getDaemonEntry().getName() );
107
108 try {
109 daemon.run();
110 } catch ( Throwable t ) {
111 logger.error( "Could not process Daemon: " + daemon.getDaemonEntry().getName(), t );
112 }
113
114 logger.info( "DaemonThread -> *DONE* PROCESSING daemon -> " + daemon.getDaemonEntry().getName() );
115
116 daemon.setStatus( Daemon.STATUS_PROCESSED );
117
118 }
119
120
121 }