1 23 24 37 package com.sun.enterprise.server; 38 39 import java.io.File ; 40 import java.util.ArrayList ; 41 import java.util.Iterator ; 42 43 import java.util.logging.Level ; 44 import java.util.logging.Logger ; 45 import com.sun.logging.LogDomains; 46 import com.sun.enterprise.admin.server.core.channel.ReconfigHelper; 47 48 55 class ReloadMonitor extends AbstractMonitor { 56 57 58 static final String RELOAD_FILE = ".reload"; 59 60 static Logger _logger = LogDomains.getLogger(LogDomains.CORE_LOGGER); 61 62 63 private static ReloadMonitor _instance = null; 64 65 70 private ReloadMonitor(long pollInterval) { 71 super(pollInterval); 72 } 73 74 80 static ReloadMonitor getInstance(long pollInterval) { 81 if (_instance == null) { 82 _instance = new ReloadMonitor(pollInterval); 83 } 84 return _instance; 85 } 86 87 95 boolean removeMonitoredEntry(String id) { 96 97 boolean removed = false; 98 99 if (id == null) { 101 return removed; 102 } 103 104 synchronized (this._monitoredEntries) { 105 Iterator iter = this._monitoredEntries.iterator(); 106 while (iter.hasNext()) { 107 MonitorableEntry entry = (MonitorableEntry) iter.next(); 108 if ( id.equals(entry.getId()) ) { 109 this._monitoredEntries.remove(entry); 110 removed = true; 111 break; 112 } 113 } 114 } 115 116 return removed; 117 } 118 119 129 public void run() { 130 131 try { 132 ArrayList reloadList = new ArrayList (); 133 134 synchronized (_monitoredEntries) { 135 Iterator iter = _monitoredEntries.iterator(); 136 MonitorableEntry entry = null; 137 138 while (iter.hasNext()) { 139 entry = (MonitorableEntry) iter.next(); 140 File file = entry.getMonitoredFile(); 141 long lastModified = file.lastModified(); 142 long lastReloadedAt = entry.getLastReloadedTimeStamp(); 143 144 if (lastModified > lastReloadedAt) { 146 entry.setLastReloadedTimeStamp(lastModified); 148 149 reloadList.add(entry); 150 } 151 } 152 } 153 154 if (reloadList.size() > 0) { 156 157 _logger.log(Level.FINEST, 158 "[ReloadMonitor] Monitor detected reloadable entry!"); 159 160 int size = reloadList.size(); 161 MonitorableEntry entry = null; 162 163 for (int i=0; i<size; i++) { 164 entry = (MonitorableEntry) reloadList.get(i); 165 166 MonitorListener l = entry.getListener(); 167 168 boolean success = l.reload(entry); 170 171 if (success) { 173 _logger.log(Level.INFO, 174 "core.application_reload_successful", 175 entry.getDisplayName()); 176 } else { 177 _logger.log(Level.INFO, 178 "core.application_reload_failed", 179 entry.getDisplayName()); 180 } 181 } 182 183 189 ReconfigHelper.sendReconfigMessage(""); 190 191 reloadList.clear(); 193 } 194 195 } catch (Throwable t) { 196 _logger.log(Level.WARNING, "core.exception", t); 198 } 199 } 200 } 201 | Popular Tags |