1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 package fr.paris.lutece.portal.service.daemon;
35
36 import fr.paris.lutece.portal.service.plugin.PluginService;
37 import fr.paris.lutece.portal.service.util.AppLogService;
38
39 import java.util.Date;
40
41
42
43
44 public class DaemonThread implements Runnable
45 {
46 static final String DEAMON_THREAD_BEAN_NAME = "daemonThread";
47
48 private DaemonEntry _entry;
49 private String _strDaemonName;
50
51
52
53
54
55
56
57 public void setDaemonEntry( DaemonEntry entry )
58 {
59 _entry = entry;
60 }
61
62
63
64
65
66
67 public String getDaemonName( )
68 {
69 return _strDaemonName;
70 }
71
72
73
74
75 @Override
76 public void run( )
77 {
78 if ( _entry.isRunning( ) )
79 {
80 if ( _strDaemonName == null )
81 {
82 _strDaemonName = "Daemon " + _entry.getId( );
83 }
84
85 Thread currentThread = Thread.currentThread( );
86 String strPooledThreadName = currentThread.getName( );
87 currentThread.setName( "Lutece-Daemon-" + _entry.getId( ) );
88
89 Daemon daemon = _entry.getDaemon( );
90 AppLogService.info( "{} - starts processing.", _strDaemonName );
91
92 try
93 {
94 _entry.setLastRunDate( new Date( ) );
95
96 if ( PluginService.isPluginEnable( daemon.getPluginName( ) ) )
97 {
98 daemon.run( );
99 _entry.setLastRunLogs( daemon.getLastRunLogs( ) );
100 }
101 else
102 {
103 _entry.setLastRunLogs( "Plugin not enabled" );
104 }
105 }
106 catch( Throwable t )
107 {
108 AppLogService.error( "Could not process Daemon: {}", _entry.getId( ), t );
109 }
110
111 AppLogService.info( "{} - end of process.", _strDaemonName );
112 currentThread.setName( strPooledThreadName );
113 }
114 else
115 {
116 AppLogService.error( "Daemon's {} run not processed because it has been stopped. Will unschedule.", _entry.getId( ) );
117 AppDaemonService.cancelScheduledThread( _entry.getId( ) );
118 }
119 }
120 }