1 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 27 public class DaemonThread extends Thread { 28 29 private Daemon daemon = null; 30 31 34 private static final JetspeedLogger logger = JetspeedLogFactoryService.getLogger(DaemonThread.class.getName()); 35 36 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 logger.error("Error instantiating DaemonThread", e); 48 } 49 } 50 51 52 public DaemonThread() 53 { 54 super(); 55 this.setDaemon(true); 56 } 57 58 60 public Daemon getDaemon() { 61 return this.daemon; 62 } 63 64 66 public void run() { 67 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 try { 82 83 synchronized( this ) { 84 this.wait( de.getInterval() * 1000 ); 85 } 86 87 } catch (InterruptedException e) { 88 } 92 93 this.runDaemon( this.getDaemon() ); 94 95 } 96 97 98 } 99 100 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 } 122 | Popular Tags |