|
Glassfish example source code file (ConnectorApplication.java)
The Glassfish ConnectorApplication.java source code/* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * * Copyright (c) 1997-2011 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 com.sun.appserv.connectors.internal.api.ConnectorConstants; import com.sun.enterprise.config.serverbeans.*; import com.sun.enterprise.connectors.util.ResourcesUtil; import com.sun.enterprise.deployment.ConnectorDescriptor; import com.sun.enterprise.util.i18n.StringManager; import com.sun.logging.LogDomains; import com.sun.appserv.connectors.internal.api.ConnectorsUtil; import com.sun.enterprise.connectors.ConnectorRuntime; import org.glassfish.api.deployment.*; import org.glassfish.api.event.EventListener; import org.glassfish.api.event.Events; import org.glassfish.api.ActionReport; import org.glassfish.javaee.services.ApplicationScopedResourcesManager; import org.glassfish.javaee.services.ResourceManager; import org.glassfish.internal.deployment.Deployment; import java.util.logging.Level; import java.util.logging.Logger; import java.util.Collection; import java.util.List; import java.util.ArrayList; /** * 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 Jagadish Ramu */ public class ConnectorApplication implements ApplicationContainer, EventListener { private static Logger _logger = LogDomains.getLogger(ConnectorApplication.class, LogDomains.RSR_LOGGER); private String moduleName = ""; //indicates the "application" (ear) name if its embedded rar private String applicationName = null; private ResourceManager resourceManager; private ApplicationScopedResourcesManager asrManager; 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 moduleName, String appName, ResourceManager resourceManager, ApplicationScopedResourcesManager asrManager, ClassLoader loader, ConnectorRuntime runtime, Events event, ConnectorDescriptor descriptor) { this.setModuleName(moduleName); this.resourceManager = resourceManager; this.asrManager = asrManager; this.loader = loader; this.runtime = runtime; this.applicationName = appName; this.event = event; this.descriptor = descriptor; this.resourcesUtil = ResourcesUtil.createInstance(); } /** * Returns the deployment descriptor associated with this application * * @return deployment descriptor if they exist or null if not */ public Object getDescriptor() { return descriptor; } /** * 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 * * @param startupContext the start up context * @return true if the container startup was successful. */ public boolean start(ApplicationContext startupContext) { boolean started = false; deployResources(); runtime.registerConnectorApplication(this); started = true; event.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 = resourceManager.getAllResources(); Collection<Resource> resources = resourcesUtil.filterConnectorResources(allResources, moduleName, false); resourceManager.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<Resource> resources = resourcesUtil.filterConnectorResources(resourceManager.getAllResources(), moduleName, true); if (failIfResourcesExist && resources.size() > 0) { String message = "one or more resources of resource-adapter [ " + moduleName + " ] exist, " + "use '--cascade=true' to delete them during undeploy"; _logger.log(Level.WARNING, "resources.of.rar.exist", moduleName); status = false; throw new RuntimeException(message); } else { resourceManager.undeployResources(resources); status = true; } return status; } private List<Resource> getAllConnectorResources() { Resources allResources = resourceManager.getAllResources(); Collection<ConnectorConnectionPool> connectionPools = ConnectorsUtil.getAllPoolsOfModule(moduleName, allResources); Collection<String> poolNames = ConnectorsUtil.getAllPoolNames(connectionPools); Collection<Resource> connectorResources = ConnectorsUtil.getAllResources(poolNames, allResources); Collection<AdminObjectResource> adminObjectResources = ResourcesUtil.createInstance().getEnabledAdminObjectResources(moduleName); List<Resource> resources = new ArrayList Other Glassfish examples (source code examples)Here is a short list of links related to this Glassfish ConnectorApplication.java source code file: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.