FileDocCategorySizeDatePackage
EventBuilder.javaAPI DocGlassfish v2 API28395Fri May 04 22:33:34 BST 2007com.sun.enterprise.admin.event

EventBuilder

public class EventBuilder extends Object
Factory class for dynamic reconfig events.
author
Nazrul Islam
since
JDK1.4

Fields Summary
Constructors Summary
Methods Summary
public voidaddResourceDeployEvent(java.lang.String action, java.lang.String target, java.lang.String resName)
Adds a resource deploy event to the event stack.

param
action event action code
param
target event target
param
resName name of the resource
throws
ConfigException if an error while parsing configuration


        EventStack stack = EventContext.getEventStackFromThreadLocal();
        ConfigContext ctx = stack.getConfigContext();
        stack.setTarget(target);
        stack.setConfigChangeList( ctx.getConfigChangeList());

        ResourceDeployEvent event = createResourceDeployEvent(action, resName); 
        EventContext.addEvent(event);
    
protected static java.lang.StringconvertResourceType(java.lang.String type)
Converts config bean type to resource deploy event type.

param
type config bean type
return
resource deploy event type

        // XXX see if we can avoid this type conversion
        // may be do hash instead of string comparision

        if (type==null) {
            return null;
        } else {
            type = type.trim();
        }

        if ( type.equals(ServerTags.CUSTOM_RESOURCE)
                || type.equals(Resources.CUSTOM_RESOURCE) ) {
            return ResourceDeployEvent.RES_TYPE_CUSTOM;
        }
        if ( type.equals(ServerTags.EXTERNAL_JNDI_RESOURCE)
                || type.equals(Resources.EXTERNAL_JNDI_RESOURCE) ) {
            return ResourceDeployEvent.RES_TYPE_EXTERNAL_JNDI;
        }
        if ( type.equals(ServerTags.JDBC_RESOURCE)
                || type.equals(Resources.JDBC_RESOURCE) ) {
            return ResourceDeployEvent.RES_TYPE_JDBC;
        }
        if ( type.equals(ServerTags.MAIL_RESOURCE)
                || type.equals(Resources.MAIL_RESOURCE) ) {
            return ResourceDeployEvent.RES_TYPE_MAIL;
        }
        if ( type.equals(ServerTags.PERSISTENCE_MANAGER_FACTORY_RESOURCE)
            || type.equals(Resources.PERSISTENCE_MANAGER_FACTORY_RESOURCE)) {

            return ResourceDeployEvent.RES_TYPE_PMF;
        }
        if ( type.equals(ServerTags.ADMIN_OBJECT_RESOURCE)
                || type.equals(Resources.ADMIN_OBJECT_RESOURCE) ) {
            return ResourceDeployEvent.RES_TYPE_AOR;
        }
        if ( type.equals(ServerTags.CONNECTOR_RESOURCE)
                || type.equals(Resources.CONNECTOR_RESOURCE) ) {
            return ResourceDeployEvent.RES_TYPE_CR;
        }
        if ( type.equals(ServerTags.RESOURCE_ADAPTER_CONFIG)
                || type.equals(Resources.RESOURCE_ADAPTER_CONFIG) ) {
            return ResourceDeployEvent.RES_TYPE_RAC;
        }
        if ( type.equals(ServerTags.JDBC_CONNECTION_POOL)
                || type.equals(Resources.JDBC_CONNECTION_POOL) ) {
            return ResourceDeployEvent.RES_TYPE_JCP;
        }
        if ( type.equals(ServerTags.CONNECTOR_CONNECTION_POOL)
                || type.equals(Resources.CONNECTOR_CONNECTION_POOL) ) {
            return ResourceDeployEvent.RES_TYPE_CCP;
        }

        return type; // unsupported type
    
public ApplicationDeployEventcreateApplicationDeployEvent(java.lang.String action, java.lang.String appName, boolean cascade, boolean forceDeploy, int loadUnloadAction)
Returns an application deploy event. This assumes that the event stack is populated before this method is called.

param
action event action code
param
appName name of the application
param
cascade used by connector implementation to decide whether to remove resource adapter related resources
param
forceDeploy whether a deployment is enforced
param
loadUnloadAction what the load/unload action is
return
application deploy event
throws
ConfigException if an error while getting dependent config elements

        EventStack stack = EventContext.getEventStackFromThreadLocal();
        String target = stack.getTarget();
        assert(target != null);

        // name of the current server instance
        String instName =
            ApplicationServer.getServerContext().getInstanceName();

        ApplicationDeployEvent ade = new ApplicationDeployEvent(instName, 
            appName, action, cascade, forceDeploy, loadUnloadAction);

        ade.setTargetDestination(target);

        // adds all the config changes
        DependencyResolver dr = 
            new DependencyResolver(stack.getConfigContext(), target);
        ade.addDependentConfigChange(dr.resolveApplications(appName, action));

        ade.addConfigChange( (ArrayList) stack.getConfigChangeList() );

        return ade;
    
public ApplicationDeployEventcreateApplicationDeployEvent(java.lang.String action, java.lang.String appName)
Returns an application deploy event. This assumes that the event stack is populated before this method is called.

Example Usage:

ConfigContext ctx = stack.getConfigContext(); EventStack stack = EventContext.getEventStackFromThreadLocal(); stack.setTarget(targetName); stack.setConfigChangeList(ctx.getConfigChangeList()); EventBuilder builder = new EventBuilder(); ApplicationDeployEvent event = builder.createApplicationDeployEvent( BaseDeployEvent.REMOVE_REFERENCE, referenceName); AdminEventResult result = AdminEventMulticaster.multicast(event); Instead of using multicaster, you may also schedule the event to be sent out by the interceptor. This will release the lock for concurrent config users. Call the following API if you want to schedule the event: EventContext.addEvent(event);

param
action event action code
param
appName name of the application
return
application deploy event
throws
ConfigException if an error while getting dependent config elements


        return createApplicationDeployEvent(action, appName, false);
    
public ApplicationDeployEventcreateApplicationDeployEvent(java.lang.String action, java.lang.String appName, boolean cascade)
Returns an application deploy event. This assumes that the event stack is populated before this method is called.

param
action event action code
param
appName name of the application
param
cascade used by connector implementation to decide whether to remove resource adapter related resources
return
application deploy event
throws
ConfigException if an error while getting dependent config elements


        return createApplicationDeployEvent(action, appName, cascade, false);
    
public ApplicationDeployEventcreateApplicationDeployEvent(java.lang.String action, java.lang.String appName, boolean cascade, boolean forceDeploy)
Returns an application deploy event. This assumes that the event stack is populated before this method is called.

param
action event action code
param
appName name of the application
param
cascade used by connector implementation to decide whether to remove resource adapter related resources
param
forceDeploy whether a deployment is enforced
return
application deploy event
throws
ConfigException if an error while getting dependent config elements

        return createApplicationDeployEvent(action, appName, cascade, 
            forceDeploy, Constants.LOAD_UNSET);
    
public ConfigChangeEventcreateConfigChangeEvent(java.lang.String target, java.util.ArrayList configChangeList)
Creates config change event.

param
target target for the event
param
configChangeList config change list
throws
ConfigException if a configuration parsing error


        String instName =
             ApplicationServer.getServerContext().getInstanceName();

        ConfigChangeEvent cce = 
            new ConfigChangeEvent(instName, configChangeList);
        cce.setTargetDestination(target);
        return cce;
    
public LogLevelChangeEventcreateLogLevelChangeEvent(com.sun.enterprise.config.ConfigContext ctx, java.lang.String target, java.lang.String newLogLevel, java.lang.String moduleName)
Creates log level change event.

param
ctx config context
param
target event target
param
newLogLevel new log level
param
moduleName module name where log level was changed
throws
ConfigException if a configuration parsing error


        // name of the current server instance runtime
        String instName = 
            ApplicationServer.getServerContext().getInstanceName();
         
        // log level change event
        LogLevelChangeEvent lde = new LogLevelChangeEvent(instName);
        lde.setTargetDestination(target);

        // FIXME: get the change list from each thread local
        //rde.addConfigChange( ctx.getConfigChangeList() );

        // setEventKey

        // do i need to set old log level ???? 
        lde.setModuleName(moduleName);
        lde.setNewLogLevel(newLogLevel);
        return lde;
    
public BaseDeployEventcreateModAppDeployEvent(java.lang.String action, java.lang.String name, com.sun.enterprise.config.ConfigContext ctx, java.util.ArrayList configChanges, java.lang.String target)
Returns a module aor app deploy event.

param
action event action code
param
name name of the module or application
param
ctx config context
param
configChanges list of config changes
param
target target name
throws
ConfigException if an error while getting resource type


        // name of the current server instance runtime
        String instName = 
            ApplicationServer.getServerContext().getInstanceName();
         
        BaseDeployEvent event=getAppOrModuleEvent(instName, ctx, name, action);
        event.setTargetDestination(target);
        
        // adds all the config changes
        DependencyResolver dr = new DependencyResolver(ctx, target);
        event.addDependentConfigChange(dr.resolveApplications(name,action));
        event.addConfigChange( configChanges );

        return event;
    
public ModuleDeployEventcreateModuleDeployEvent(java.lang.String action, java.lang.String moduleName, java.lang.String moduleType)
Returns a module deploy event.

param
action event action code
param
moduleName name of the module
param
moduleType type of the module (ex. ModuleDeployEvent.TYPE_WEBMODULE)
return
module deploy event
throws
ConfigException if an error while getting dependent config elements


        return createModuleDeployEvent(action, moduleName, moduleType, false);
    
public ModuleDeployEventcreateModuleDeployEvent(java.lang.String action, java.lang.String moduleName, java.lang.String moduleType, boolean cascade)
Returns a module deploy event.

param
action event action code
param
moduleName name of the module
param
moduleType type of the module (ex. ModuleDeployEvent.TYPE_WEBMODULE)
param
cascade used by connector implementation to decide whether to remove resource adapter related resources
return
module deploy event
throws
ConfigException if an error while getting dependent config elements


        return createModuleDeployEvent(action, moduleName, moduleType, 
                    cascade, false);
    
public ModuleDeployEventcreateModuleDeployEvent(java.lang.String action, java.lang.String moduleName, java.lang.String moduleType, boolean cascade, boolean forceDeploy)
Returns a module deploy event.

param
action event action code
param
moduleName name of the module
param
moduleType type of the module (ex. ModuleDeployEvent.TYPE_WEBMODULE)
param
cascade used by connector implementation to decide whether to remove resource adapter related resources
param
forceDeploy whether a deployment is enforced
return
module deploy event
throws
ConfigException if an error while getting dependent config elements

        EventStack stack = EventContext.getEventStackFromThreadLocal();
        String target = stack.getTarget();
        assert(target != null);

        String instName =
             ApplicationServer.getServerContext().getInstanceName();

        ModuleDeployEvent mde = 
            new ModuleDeployEvent(instName, moduleName, moduleType, 
                                    action, cascade);
        mde.setTargetDestination(target);


        // sets the force deploy flag in the event
        mde.setForceDeploy(forceDeploy);

        // adds all the config changes
        DependencyResolver dr = 
            new DependencyResolver(stack.getConfigContext(), target);
        mde.addDependentConfigChange(dr.resolveApplications(moduleName,action));
        mde.addConfigChange( (ArrayList) stack.getConfigChangeList() );

        return mde;
    
public MonitoringEventcreateMonitoringEvent(com.sun.enterprise.config.ConfigContext ctx, java.lang.String target, java.lang.String component, java.lang.String action, java.lang.Object command)
Creates a monitoring event.

param
ctx config context
param
target target for the event
param
component name of monitoring module
param
action new action
param
command jmx command
throws
ConfigException if a configuration parsing error

        
        String instName =
             ApplicationServer.getServerContext().getInstanceName();
        MonitoringEvent me = 
            new MonitoringEvent(instName, component, action, command);
        me.setTargetDestination(target);

        return me; 
    
public MonitoringLevelChangeEventcreateMonitoringLevelChangeEvent(com.sun.enterprise.config.ConfigContext ctx, java.lang.String target, java.lang.String component, java.lang.String monitoringLevel)
Creates monitoring level change event.

param
ctx config context
param
target target for the event
param
component name of monitoring module
param
monitoringLevel new monitoring level
throws
ConfigException if a configuration parsing error


        String instName =
            ApplicationServer.getServerContext().getInstanceName();

        MonitoringLevelChangeEvent mle = 
            new MonitoringLevelChangeEvent(instName);
        mle.setTargetDestination(target);

        return mle;
    
public ResourceDeployEventcreateResourceDeployEvent(java.lang.String action, java.lang.String resName)
Returns a resource deploy event. This assumes that the event stack is populated before this is called.

param
action event action code
param
resName name of the resource
throws
ConfigException if an error while getting resource type


        EventStack stack = EventContext.getEventStackFromThreadLocal();

        return createResourceDeployEvent(action, resName, 
                    stack.getConfigContext(), 
                    (ArrayList)stack.getConfigChangeList(),
                    stack.getTarget()); 
    
public ResourceDeployEventcreateResourceDeployEvent(java.lang.String action, java.lang.String resName, com.sun.enterprise.config.ConfigContext ctx, java.util.ArrayList configChanges, java.lang.String target)
Returns a resource deploy event.

param
action event action code
param
resName name of the resource
param
ctx config context
param
configChanges list of config changes
param
target target name
throws
ConfigException if an error while getting resource type


        // name of the current server instance runtime
        String instName = 
            ApplicationServer.getServerContext().getInstanceName();
         
        // resource type from target string
        String resType = getResourceTypeByName(ctx, resName, target);

        // resource deploy event
        ResourceDeployEvent rde = new ResourceDeployEvent(instName, 
                                            resName, resType, action);
        rde.setTargetDestination(target);

        // adds all the config changes
        DependencyResolver dr = new DependencyResolver(ctx, target);
        rde.addDependentConfigChange( 
            dr.resolveResources(resName, action, resType) );

        rde.addConfigChange( configChanges );

        // setEventKey

        return rde;
    
private static BaseDeployEventgetAppOrModuleEvent(java.lang.String instName, com.sun.enterprise.config.ConfigContext ctx, java.lang.String name, java.lang.String action)
Creates application deploy event.

param
instName name of server instance where the event is created
param
ctx config context
param
name name of application
param
action event action - deploy/undeploy/redeploy
return
application deploy event
throws
ConfigException if a configuration parsing error


        String type = getAppOrModuleType(ctx, name);

        if (type!=null) {

            if (type.equals(BaseDeployEvent.APPLICATION)) {
                // application deploy event
                return (BaseDeployEvent)new ApplicationDeployEvent(instName, 
                                                            name, action);
            } else {
                // module deploy event
                return (BaseDeployEvent)new ModuleDeployEvent(instName, name,
                                                            type, action);
            }
        } else { //for deffered type set
            return new BaseDeployEvent(instName, null, name, action);
        }
    
private static java.lang.StringgetAppOrModuleType(com.sun.enterprise.config.ConfigContext ctx, java.lang.String name)
Returns application type.

param
ctx config context
param
name name of application
return
application type
throws
ConfigException if a configuration parsing error


        //first try to find 
        
        ConfigBean[] beans = ((Domain)ctx.getRootConfigBean()).
                                    getApplications().getAllChildBeans();
        ConfigBean bean = null;
        if (beans!=null) {
            for(int i=0; i<beans.length; i++) {
                if(name.equals(beans[i].getAttributeValue("name"))) {
                   bean = beans[i];
                   break;
                }
            }
        }

        if (bean==null) {
            return null;
        }

        String type = null;

        if (bean instanceof 
                com.sun.enterprise.config.serverbeans.J2eeApplication) {
            type = BaseDeployEvent.APPLICATION;
        }

        if (bean instanceof 
                com.sun.enterprise.config.serverbeans.ConnectorModule) {
            type = ModuleDeployEvent.TYPE_CONNECTOR;
        } else if (bean instanceof 
                com.sun.enterprise.config.serverbeans.EjbModule) {
            type = ModuleDeployEvent.TYPE_EJBMODULE;
        } else if (bean instanceof 
                com.sun.enterprise.config.serverbeans.WebModule) {
            type = ModuleDeployEvent.TYPE_WEBMODULE;
        } else if (bean instanceof 
                com.sun.enterprise.config.serverbeans.AppclientModule) {
            type = ModuleDeployEvent.TYPE_APPCLIENT;
        }

        return type;
    
static java.lang.StringgetResourceType(com.sun.enterprise.config.ConfigContext ctx, java.lang.String id, boolean includePool)
Returns the resource type of a given resource.

param
ctx config context
param
id resource name
param
includePool if true, includes pool in the search
throws
ConfigException if a config parsing exception


        Resources root = ((Domain)ctx.getRootConfigBean()).getResources();

        ConfigBean res = root.getJdbcResourceByJndiName(id);
        if ( res != null ) {
            return Resources.JDBC_RESOURCE;
        }

        res = root.getMailResourceByJndiName(id);
        if ( res != null ) {
            return Resources.MAIL_RESOURCE;
        }

        res = root.getCustomResourceByJndiName(id);
        if ( res != null ) {
            return Resources.CUSTOM_RESOURCE;
        }

        res = root.getExternalJndiResourceByJndiName(id);
        if ( res != null ) {
            return Resources.EXTERNAL_JNDI_RESOURCE;
        }

        res = root.getPersistenceManagerFactoryResourceByJndiName(id);
        if ( res != null) {
            return Resources.PERSISTENCE_MANAGER_FACTORY_RESOURCE;
        }

        res = root.getAdminObjectResourceByJndiName(id);
        if ( res != null ) {
            return Resources.ADMIN_OBJECT_RESOURCE;
        }

        res = root.getConnectorResourceByJndiName(id);
        if ( res != null ) {
            return Resources.CONNECTOR_RESOURCE;
        }

        res = root.getResourceAdapterConfigByResourceAdapterName(id);
        if ( res != null ) {
            return Resources.RESOURCE_ADAPTER_CONFIG;
        }

        if (includePool) {
            res = root.getJdbcConnectionPoolByName(id);
            if ( res != null ) {
                return Resources.JDBC_CONNECTION_POOL;
            }

            res = root.getConnectorConnectionPoolByName(id);
            if ( res != null ) {
                return Resources.CONNECTOR_CONNECTION_POOL;
            }
        }

        return null;
    
protected static java.lang.StringgetResourceTypeByName(com.sun.enterprise.config.ConfigContext ctx, java.lang.String resName, java.lang.String target)
Helper method to obtain ResourceDeployEvent's resource type correspondent to its name

returns
ResourceDeployEvent's resource type
throws
ConfigException if a config parsing exception


        String type = getTypeFromTarget(target);
        if (type == null) {
            type = getResourceType(ctx, resName, true);
        }

        return convertResourceType(type);
    
static java.lang.StringgetTypeFromTarget(java.lang.String target)
Returns the type (as defined in domain.xml) from a target. Target has the following three parts: ||

param
target target string


        String type = null;
        String msg = "\n NAZRUL Could not determine resource type for target " 
        + target;

        try { 
            if (target != null) {
                StringTokenizer st = new StringTokenizer(target, "|");
                int tokens = st.countTokens();
                if (tokens == 3) {
                    String prefix = st.nextToken();
                    String name = st.nextToken();
                    type = st.nextToken();
                }
            }
        } catch (Exception e) { }

        return type;
    
public static BaseDeployEventresolveModAppDeployEventType(BaseDeployEvent eventToResolve, com.sun.enterprise.config.ConfigContext ctx)
Provides deferred type resolution (usually on remote instance side).

param
eventToResolve original event without resolved module type in it
param
ctx effective config context used for type resolution
returns
DeployEvent of the proper type
throws
ConfigException if an error while getting resource type


        // name of the current server instance runtime
        String instName = eventToResolve.getInstanceName();
        String name = eventToResolve.getJ2EEComponentName();
        String action = eventToResolve.getAction();

        BaseDeployEvent event=getAppOrModuleEvent(instName, ctx, name, action);
        event.setCascade(eventToResolve.getCascade());
        event.setEventId(eventToResolve.getEventId());

        if (eventToResolve.getDependentChangeList()!=null) {
            event.addDependentConfigChange(
                eventToResolve.getDependentChangeList());
        }

        if (eventToResolve.getConfigChangeList()!=null) {
            event.addConfigChange(eventToResolve.getConfigChangeList());
        }

        if (eventToResolve.getTargetDestination()!=null) {
            event.setTargetDestination(eventToResolve.getTargetDestination());
        }

        return event;