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

ResourceManager

public class ResourceManager extends Object implements com.sun.enterprise.admin.event.ResourceDeployEventListener
Handles resource deploy events. When a resource is updated/added, admin server sends a notification to the server instance. This object is the listener for all resource events. Resource deployers throws UnsupportedOperationException when an operation is not supported and requires a server restart. It catches the UnsupportedOperationException and notifies admin event multicaster with RESTART_NEEDED flag.

Fields Summary
static Logger
_logger
logger for this manager
private ServerContext
serverContext_
context of the server instance runtime
private ResourceDeployerFactory
factory_
resource deployer factory
private static com.sun.enterprise.util.i18n.StringManager
localStrings
Constructors Summary
public ResourceManager(ServerContext sc)
Constructor.

param
sc server context


                      
       
        serverContext_ = sc;
        factory_ = new ResourceDeployerFactory(); 	 
    
Methods Summary
private ResourcesgetResources(ConfigContext ctx)
Returns the config resources bean from the given config context.

param
ctx config context
throws
ConfigException if an error while getting the resources bean


        //Resources rbeans = ServerBeansFactory.getServerBean(ctx).getResources();
        Resources rbeans = ServerBeansFactory.getDomainBean(ctx).getResources();

        if (rbeans == null) {
			String msg = localStrings.getString("resourceManager.resource_not_found");
                throw new ConfigException(msg); //XXX
        }
        return rbeans;
    
public voidresourceDeployed(com.sun.enterprise.admin.event.ResourceDeployEvent event)


        assert(event.getJ2EEComponentType() == BaseDeployEvent.RESOURCE);

        try {
            Resources rbeans = getResources(event.getConfigContext());
            String type = event.getResourceType();
            
            ResourcesUtil.setEventConfigContext(event.getConfigContext());
            
            Object resource = 
                factory_.getResource(type, event.getResourceName(), rbeans);
            if (ResourcesUtil.createInstance().isEnabled((ConfigBean) resource)) {
                factory_.getResourceDeployer(type).deployResource(resource);
            }

            _logger.log(Level.INFO, "core.resourcedeployed",
                        type + ":" + event.getResourceName());
        } catch (Exception e) {
            _logger.log(Level.SEVERE,"core.resourcedeploy_error", e);
            throw new AdminEventListenerException(e.getMessage());
        } finally {
            ResourcesUtil.resetEventConfigContext();
        }
    
public voidresourceDisabled(com.sun.enterprise.admin.event.ResourceDeployEvent event)


        assert(event.getJ2EEComponentType() == BaseDeployEvent.RESOURCE);

        try {
            Resources rbeans = getResources(event.getConfigContext());
            String type = event.getResourceType();
            Object resource = 
                factory_.getResource(type, event.getResourceName(), rbeans);
            factory_.getResourceDeployer(type).disableResource(resource);

            _logger.log(Level.INFO, "core.resourcedisabled",
                        type + ":" + event.getResourceName());
        } catch (UnsupportedOperationException nse) {
              AdminEventMulticaster.notifyFailure(event, AdminEventResult.RESTART_NEEDED);
            _logger.log(Level.INFO,"core.resource_disabled_restart_needed", event.getResourceName());
        } catch (Exception e) {
            _logger.log(Level.SEVERE,"core.resourcedisabled_error",e);
            throw new AdminEventListenerException(e.getMessage());
        }
    
public voidresourceEnabled(com.sun.enterprise.admin.event.ResourceDeployEvent event)


        assert(event.getJ2EEComponentType() == BaseDeployEvent.RESOURCE);

        try {
            Resources rbeans = getResources(event.getConfigContext());
            String type = event.getResourceType();
            Object resource = 
                factory_.getResource(type, event.getResourceName(), rbeans);
            factory_.getResourceDeployer(type).enableResource(resource);

            _logger.log(Level.INFO, "core.resourceenabled",
                        type + ":" + event.getResourceName());
        } catch (UnsupportedOperationException nse) {
              AdminEventMulticaster.notifyFailure(event, AdminEventResult.RESTART_NEEDED);
            _logger.log(Level.INFO,"core.resource_enabled_restart_needed", event.getResourceName());
        } catch (Exception e) {
            _logger.log(Level.SEVERE,"core.resourceenabled_error",e);
            throw new AdminEventListenerException(e.getMessage()); 
        }
    
public voidresourceRedeployed(com.sun.enterprise.admin.event.ResourceDeployEvent event)


        assert(event.getJ2EEComponentType() == BaseDeployEvent.RESOURCE);

        try {
            Resources rbeans = getResources(event.getConfigContext());
            String type = event.getResourceType();
            Object resource = 
                factory_.getResource(type, event.getResourceName(), rbeans);
            factory_.getResourceDeployer(type).redeployResource(resource);

            _logger.log(Level.INFO, "core.resourceredeployed",
                        type + ":" + event.getResourceName());
        } catch (UnsupportedOperationException nse) {
              AdminEventMulticaster.notifyFailure(event, AdminEventResult.RESTART_NEEDED);
            _logger.log(Level.INFO,"core.resource_redeployed_restart_needed", event.getResourceName());
        } catch (Exception e) {
            _logger.log(Level.SEVERE,"core.resourceredeploy_error",e);
            throw new AdminEventListenerException(e.getMessage());
        }
    
public voidresourceReferenceAdded(com.sun.enterprise.admin.event.ResourceDeployEvent event)


        resourceDeployed(event);
    
public voidresourceReferenceRemoved(com.sun.enterprise.admin.event.ResourceDeployEvent event)


        resourceUndeployed(event);
    
public voidresourceUndeployed(com.sun.enterprise.admin.event.ResourceDeployEvent event)


        assert(event.getJ2EEComponentType() == BaseDeployEvent.RESOURCE);
        
        try {
            // use config context prior to applying any changes
            Resources rbeans = getResources(event.getOldConfigContext());
            String type = event.getResourceType();
            Object resource = 
                factory_.getResource(type, event.getResourceName(), rbeans);
            ResourcesUtil.setEventConfigContext(event.getConfigContext());
            
            factory_.getResourceDeployer(type).undeployResource(resource);

            _logger.log(Level.INFO, "core.resourceundeployed",
                        type + ":" + event.getResourceName());
        } catch (UnsupportedOperationException nse) {
              AdminEventMulticaster.notifyFailure(event, AdminEventResult.RESTART_NEEDED);
            _logger.log(Level.INFO,"core.resource_undeployed_restart_needed", event.getResourceName());
        } catch (Exception e) {
            _logger.log(Level.SEVERE,"core.resourceundeploy_error",e);
            throw new AdminEventListenerException(e.getMessage()); 
        } finally {
            ResourcesUtil.resetEventConfigContext();
        }