1 23 24 package com.sun.enterprise.server; 25 26 import java.io.*; 27 import java.util.*; 28 import java.util.logging.*; 29 30 import com.sun.enterprise.config.serverbeans.WebModule; 31 import com.sun.enterprise.config.serverbeans.ApplicationHelper; 32 import com.sun.enterprise.config.ConfigContext; 33 import com.sun.enterprise.config.ConfigBean; 34 import com.sun.enterprise.config.ConfigException; 35 import com.sun.enterprise.config.serverbeans.ApplicationRef; 36 import com.sun.enterprise.config.serverbeans.Server; 37 import com.sun.enterprise.config.serverbeans.ServerBeansFactory; 38 import com.sun.enterprise.admin.server.core.AdminService; 39 40 import com.sun.enterprise.deployment.backend.DeploymentRequest; 41 import com.sun.enterprise.deployment.backend.DeploymentCommand; 42 import com.sun.enterprise.deployment.backend.DeployableObjectType; 43 import com.sun.enterprise.instance.BaseManager; 44 import com.sun.enterprise.instance.InstanceEnvironment; 45 import com.sun.enterprise.deployment.autodeploy.AutoDirReDeployer; 46 import com.sun.enterprise.deployment.backend.IASDeploymentException; 47 import com.sun.enterprise.util.i18n.StringManager; 48 import com.sun.logging.LogDomains; 49 import com.sun.enterprise.instance.WebModulesManager; 50 import com.sun.enterprise.instance.InstanceFactory; 51 52 63 public final class StandaloneWebModulesManager implements MonitorListener { 64 65 66 ReloadMonitor reloadMonitor; 67 68 69 71 79 public StandaloneWebModulesManager(String id, String modulesRoot, 80 long pollInterval) { 81 _id = id; 82 _modulesRoot = modulesRoot; 83 start(pollInterval); 84 } 85 86 87 89 93 private String _id = null; 94 95 99 private String _modulesRoot = null; 100 101 104 private ArrayList _reloadables = new ArrayList(); 105 106 107 109 116 public void start(long pollInterval) { 117 118 reloadMonitor = ReloadMonitor.getInstance(pollInterval * 1000); 119 } 120 121 128 public void stop() { 129 ReloadMonitor reloadMonitor = ReloadMonitor.getInstance(1); 130 for (int i = 0; i < _reloadables.size(); i++) { 131 String id = (String ) _reloadables.get(i); 132 reloadMonitor.removeMonitoredEntry(id); 133 } 134 _reloadables.clear(); 135 _reloadables = null; 136 } 137 138 140 150 public boolean reload(MonitorableEntry entry) { 151 155 InstanceEnvironment ienv = ApplicationServer.getServerContext().getInstanceEnvironment(); 156 157 String moduleName = entry.getDisplayName(); 161 boolean status = false; 162 163 try { 164 DeploymentRequest req = new DeploymentRequest(ienv, DeployableObjectType.WEB, DeploymentCommand.DEPLOY); 165 166 req.setFileSource(entry.getMonitoredFile().getParentFile()); 168 169 req.setName(moduleName); 171 172 req.setForced(true); 174 175 AutoDirReDeployer deployer = new AutoDirReDeployer(req); 176 status = deployer.redeploy(); 177 178 } catch (IASDeploymentException de) { 179 _logger.log(Level.WARNING,"core.error_in_reload_war_module",de); 180 return false; 181 } 182 return status; 183 } 184 185 193 public boolean deploy(MonitorableEntry entry, File archive) { 194 return false; 196 } 197 198 205 public void addWebModule(WebModule wm) { 206 if (wm != null && isEnabled(wm.getConfigContext(), wm.getName())) { 207 String name = wm.getName(); 208 String id = name + "[" + _id + "]"; 209 String fileName = getReloadFilename(wm); 210 MonitorableEntry entry = new MonitorableEntry(id, name, 211 new File(fileName), 212 this); 213 _reloadables.add(id); 214 reloadMonitor.addMonitorableEntry(entry); 215 } 216 } 217 218 227 protected boolean isEnabled (ConfigContext config, String moduleName) { 228 try { 229 if (config == null) { 230 config = AdminService.getAdminService().getAdminContext().getAdminConfigContext(); 231 } 232 ConfigBean app = ApplicationHelper.findApplication(config, 233 moduleName); 234 Server server = ServerBeansFactory.getServerBean(config); 235 ApplicationRef appRef = server.getApplicationRefByRef(moduleName); 236 237 return ((app != null && app.isEnabled()) && 238 (appRef != null && appRef.isEnabled())); 239 } catch (ConfigException e) { 240 _logger.log(Level.FINE, "Error in finding " + moduleName, e); 241 242 return false; 244 } 245 } 246 247 248 255 public void addWebModules(WebModule[] modules) { 256 if (modules != null && modules.length > 0) { 257 for (int i = 0; i < modules.length; i++) { 258 addWebModule(modules[i]); 259 } 260 } 261 } 262 263 267 private String getReloadFilename(WebModule wm) { 268 String path = wm.getLocation(); 269 File dir = new File(path); 270 if (!dir.isAbsolute()) 271 path = _modulesRoot + "/" + path; 272 return path + "/" + ReloadMonitor.RELOAD_FILE; 273 } 274 275 276 static Logger _logger = LogDomains.getLogger(LogDomains.CORE_LOGGER); 277 278 279 private static StringManager localStrings = 280 StringManager.getManager(StandAloneEJBModulesManager.class); 281 282 } 283 | Popular Tags |