FileDocCategorySizeDatePackage
StandaloneWebModulesManager.javaAPI DocGlassfish v2 API11504Fri May 04 22:35:42 BST 2007com.sun.enterprise.server

StandaloneWebModulesManager

public final class StandaloneWebModulesManager extends Object implements MonitorListener
Implements the reload callbacks for standalone web modules. When dynamic reloading is enabled, this object adds the list of enabled standalone web modules to the reload monitor thread, so that web module reload via 'touch .reload' works. This class lives in the com.sun.enterprise.server package and not the com.sun.enterprise.web package because of the scope of the interface/methods in - ReloadMonitor, MonitorableEntry and MonitorListener.

Fields Summary
ReloadMonitor
reloadMonitor
private String
_id
The id of this object (this is the same as that of the id of the associated web container object).
private String
_modulesRoot
Absolute path for location where all the deployed standalone modules are stored for this Server Instance.
private ArrayList
_reloadables
List of web module ids registered with the reload monitor thread.
static Logger
_logger
logger to log core messages
private static com.sun.enterprise.util.i18n.StringManager
localStrings
local string manager
Constructors Summary
public StandaloneWebModulesManager(String id, String modulesRoot, long pollInterval)
Standard constructor.

param
id The web container object identifier
param
modulesRoot The top level directory under which all standalone modules are deployed at.
param
pollInterval The interval at which dynamic reloading is performed

        _id = id;
        _modulesRoot = modulesRoot;
        start(pollInterval);
    
Methods Summary
public voidaddWebModule(com.sun.enterprise.config.serverbeans.WebModule wm)
Adds the given WebModule to the list of monitorable entries for dynamic reloading.

param
wm The WebModule to add to the list of monitorable entries for dynamic reloading

        if (wm != null && isEnabled(wm.getConfigContext(), wm.getName()))  {
            String name = wm.getName();
            String id = name + "[" + _id + "]";
            String fileName = getReloadFilename(wm);
            MonitorableEntry entry = new MonitorableEntry(id, name,
                                                          new File(fileName),
                                                          this);
            _reloadables.add(id);
            reloadMonitor.addMonitorableEntry(entry);
        }
    
public voidaddWebModules(com.sun.enterprise.config.serverbeans.WebModule[] modules)
Adds the given WebModule instances to the list of monitorable entries for dynamic reloading.

param
modules The array of WebModule instances to add to the list of monitorable entries for dynamic reloading

        if (modules != null && modules.length > 0) {
            for (int i = 0; i < modules.length; i++) {
                addWebModule(modules[i]);
            }
        }
    
public booleandeploy(MonitorableEntry entry, java.io.File archive)
Callback from the auto deploy monitor when a new archive is detected.

param
entry entry thats being monitored
param
archive newly detected archive under the auto deploy directory
return
true if archive was deployed successfully

        // auto-deploy has not been implemented in S1AS7
        return false;
    
private java.lang.StringgetReloadFilename(com.sun.enterprise.config.serverbeans.WebModule wm)
Returns the absolute pathname to the .reload file in the specified web module's directory.

        String path = wm.getLocation();
        File dir = new File(path);
        if (!dir.isAbsolute())
            path = _modulesRoot + "/" + path;
        return  path + "/" + ReloadMonitor.RELOAD_FILE;
    
protected booleanisEnabled(com.sun.enterprise.config.ConfigContext config, java.lang.String moduleName)
Whether or not a component (either an application or a module) should be enabled is defined by the "enable" attribute on both the application/module element and the application-ref element.

param
config The dynamic ConfigContext
param
moduleName The name of the component
return
boolean

        try {
            if (config == null) {
                config = AdminService.getAdminService().getAdminContext().getAdminConfigContext();
            }
            ConfigBean app = ApplicationHelper.findApplication(config,
                moduleName);
            Server server = ServerBeansFactory.getServerBean(config);
            ApplicationRef appRef = server.getApplicationRefByRef(moduleName);

            return ((app != null && app.isEnabled()) &&
                        (appRef != null && appRef.isEnabled()));
        } catch (ConfigException e) {
            _logger.log(Level.FINE, "Error in finding " + moduleName, e);

            //If there is anything wrong, do not enable the module
            return false;
        }
    
public booleanreload(MonitorableEntry entry)
Callback from the reload monitor thread for a web module. This is done when the user updates the $MODULE_ROOT/$MODULE/.reload file indicating the server runtime for a dynamic reload.

param
entry entry thats being monitored
return
true if application was reloaded successfully

        // The actual reload is done by the NSAPI reconfiguration logic which
        // the reload monitor thread invokes (at the end), so simply return
        // true here.
        
        InstanceEnvironment ienv = ApplicationServer.getServerContext().getInstanceEnvironment();
        
        //4926513 work-around --- use displayname
        // for "foo", the id will be "foo[0]"
        //String moduleName = entry.getId();
        String moduleName = entry.getDisplayName();
        boolean status = false;
        
        try {
            DeploymentRequest req = new DeploymentRequest(ienv, DeployableObjectType.WEB, DeploymentCommand.DEPLOY);
            
            // monitored file points to $APP_ROOT/.reload
            req.setFileSource(entry.getMonitoredFile().getParentFile());
            
            // application registration name
            req.setName(moduleName);
            
            // we are always trying a redeployment
            req.setForced(true);
                        
            AutoDirReDeployer deployer = new AutoDirReDeployer(req);
            status = deployer.redeploy();
            
        } catch (IASDeploymentException de) {
            _logger.log(Level.WARNING,"core.error_in_reload_war_module",de);
            return false;
        }
        return status;
    
public voidstart(long pollInterval)
Enable dynamic reloading (via the .reload file) for all the standalone web-modules that are marked as enabled This method is invoked be WebContainer.start() only when dynamic reloading has been enabled in server.xml.

    
    
    // --------------------------------------------------------- Public Methods
    
                                         
        
       
        reloadMonitor = ReloadMonitor.getInstance(pollInterval * 1000);
    
public voidstop()
Remove the modules (that were previously registered by start()) from the reload monitor thread. This method is invoked be WebContainer.stop() only when dynamic reloading has been enabled in server.xml.

        ReloadMonitor reloadMonitor = ReloadMonitor.getInstance(1);
        for (int i = 0; i < _reloadables.size(); i++) {
            String id = (String) _reloadables.get(i);
            reloadMonitor.removeMonitoredEntry(id);
        }
        _reloadables.clear();
        _reloadables = null;