Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
   *
   * Copyright (c) 1997-2012 Oracle and/or its affiliates. All rights reserved.
   *
   * The contents of this file are subject to the terms of either the GNU
   * General Public License Version 2 only ("GPL") or the Common Development
   * and Distribution License("CDDL") (collectively, the "License").  You
   * may not use this file except in compliance with the License.  You can
  * obtain a copy of the License at
  * https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html
  * or packager/legal/LICENSE.txt.  See the License for the specific
  * language governing permissions and limitations under the License.
  *
  * When distributing the software, include this License Header Notice in each
  * file and include the License file at packager/legal/LICENSE.txt.
  *
  * GPL Classpath Exception:
  * Oracle designates this particular file as subject to the "Classpath"
  * exception as provided by Oracle in the GPL Version 2 section of the License
  * file that accompanied this code.
  *
  * Modifications:
  * If applicable, add the following below the License Header, with the fields
  * enclosed by brackets [] replaced by your own identifying information:
  * "Portions Copyright [year] [name of copyright owner]"
  *
  * Contributor(s):
  * If you wish your version of this file to be governed by only the CDDL or
  * only the GPL Version 2, indicate your decision by adding "[Contributor]
  * elects to include this software in this distribution under the [CDDL or GPL
  * Version 2] license."  If you don't indicate a single choice of license, a
  * recipient has the option to distribute your version of this file under
  * either the CDDL, the GPL Version 2 or to extend the choice of license to
  * its licensees as provided above.  However, if you add GPL Version 2 code
  * and therefore, elected the GPL Version 2 license, then the option applies
  * only if the new code is made subject to such option by the copyright
  * holder.
  */
 
 package com.sun.enterprise.connectors.module;
 
 
 import java.util.List;
Represents a connector application, one per resource-adapter. GlassFish kernel will call start/stop of connector application during start/stop of server and deploy/undeploy of the resource-adapter.

Author(s):
Jagadish Ramu
 
 public class ConnectorApplication implements ApplicationContainerEventListener {
     private static Logger _logger = LogDomains.getLogger(ConnectorApplication.class.);
     private String moduleName = "";
     //indicates the "application" (ear) name if its embedded rar
     private String applicationName = null;
     private ClassLoader loader;
     private ConnectorRuntime runtime;
     private Events event;
     private ConnectorDescriptor descriptor;
     private static StringManager localStrings = StringManager.getManager(ConnectorRuntime.class);
     private ResourcesUtil resourcesUtil;
 
     public ConnectorApplication(String moduleNameString appNameorg.glassfish.resourcebase.resources.listener.ResourceManager resourceManager,
                                 ApplicationScopedResourcesManager asrManagerClassLoader loader,
                                 ConnectorRuntime runtimeEvents eventConnectorDescriptor descriptor) {
         this.setModuleName(moduleName);
         this. = resourceManager;
         this. = asrManager;
         this. = loader;
         this. = runtime;
         this. = appName;
         this. = event;
         this. = descriptor;
         this. = ResourcesUtil.createInstance();
    }

    
Returns the deployment descriptor associated with this application

Returns:
deployment descriptor if they exist or null if not
    public Object getDescriptor() {
        return ;
    }

    
Starts an application container. ContractProvider starting should not throw an exception but rather should use their prefered Logger instance to log any issue they encounter while starting. Returning false from a start mean that the container failed to start

Parameters:
startupContext the start up context
Returns:
true if the container startup was successful.
    public boolean start(ApplicationContext startupContext) {
        boolean started = false;
        deployResources();
        started = true;
        .register(this);
        logFine("Resource Adapter [ " + getModuleName() + " ] started");
        return started;
    }

    
deploy all resources/pools pertaining to this resource adapter
    public void deployResources() {
        deployGlobalResources();
        //deployApplicationScopedResources();
    }
    private void deployGlobalResources() {
        Resources allResources = .getAllResources();
        Collection<Resourceresources = .filterConnectorResources(allResourcesfalse);
        .deployResources(resources);
    }
/*
    private void deployApplicationScopedResources() {
        Resources resources = asrManager.getResources(applicationName);
        if(resources != null){
            Collection<Resource> connectorResources = filterConnectorResources(resources);
            asrManager.deployResources(connectorResources);
        }
    }
*/
    
undeploy all resources/pools pertaining to this resource adapter
    public void undeployResources() {
        undeployGlobalResources(false);
        //undeployApplicationScopedResources();
    }
/*
    public void undeployApplicationScopedResources() {
        Collection<Resource> resources = filterConnectorResources(asrManager.getResources(applicationName));
        asrManager.undeployResources(resources);    
    }
*/

    
undeploy all resources/pools pertaining to this resource adapter
    public boolean undeployGlobalResources(boolean failIfResourcesExist) {
        boolean status;
        //TODO ASR : should we undeploy app-scoped connector resources also ?
        //TODO ASR : should we stop deployment by checking app-scoped connector resources also ?
        Collection<Resourceresources =
        if (failIfResourcesExist && resources.size() > 0) {
            String message = "one or more resources of resource-adapter [ " +  + " ] exist, " +
                    "use '--cascade=true' to delete them during undeploy";
            .log(."resources.of.rar.exist");
            status = false;
            throw new RuntimeException(message);
        } else {
            .undeployResources(resources);
            status = true;
        }
        return status;
    }

    
Stop the application container

Parameters:
stopContext
Returns:
true if stopping was successful.
    public boolean stop(ApplicationContext stopContext) {
        boolean stopped = false;
        DeploymentContext dc = (DeploymentContextstopContext;
        boolean failIfResourcesExist = false;
        //"stop" may be called even during deployment/load failure.
        //Look for the undeploy flags only when it is undeploy-command
        if(dcp != null){
            if (dcp.origin == ..) {
                if(!(dcp._ignoreCascade || dcp.cascade)){
                    failIfResourcesExist = true;
                }
            }
        }
        if (!undeployGlobalResources(failIfResourcesExist)) {
            stopped = false;
        } else {
            stopped = true;
            logFine("Resource Adapter [ " + getModuleName() + " ] stopped");
            .unregister(this);
        }
        return stopped;
    }

    
Suspends this application container.

Returns:
true if suspending was successful, false otherwise.
    public boolean suspend() {
        // Not (yet) supported
        return false;
    }

    
Resumes this application container.

Returns:
true if resumption was successful, false otherwise.
    public boolean resume() {
        // Not (yet) supported
        return false;
    }

    
Returns the class loader associated with this application

Returns:
ClassLoader for this app
    public ClassLoader getClassLoader() {
        return ;
    }
    public void logFine(String message) {
        if(.isLoggable(.)) {
            .log(.message);
        }
    }

    
returns the module name

Returns:
module-name
    public String getModuleName() {
        return ;
    }

    
set the module name of the application

Parameters:
moduleName module-name
    public void setModuleName(String moduleName) {
        this. = moduleName;
    }
    public String getApplicationName() {
        return ;
    }

    
event listener to listen to resource-adapter undeploy validation and to validate the undeployment. Undeployment will fail, if resources are found and --cascade is not set.

Parameters:
event Event
    public void event(Event event) {
        if (..equals(event.type())) {
            //this is an application undeploy event
            DeploymentContext dc = (DeploymentContextevent.hook();
            if (dcp.name.equals() ||
                    //Consider the application with embedded RAR being undeployed
                    (dcp.name.equals() &&
                    .contains(.) &&
                    .startsWith(dcp.name))) {
                if (dcp.origin != ..) {
                    if (dcp.origin == ..) {
                        if (!(dcp._ignoreCascade || dcp.cascade)) {
                            if (.filterConnectorResources(.getAllResources(), true).size() > 0) {
                                String message = .getString("con.deployer.resources.exist");
                                .log(."resources.of.rar.exist");
                                ActionReport report = dc.getActionReport();
                                report.setMessage(message);
                                report.setActionExitCode(..);
                            }
                        }
                    }
                }
            }
        }
    }
New to GrepCode? Check out our FAQ X