|
Glassfish example source code file (EjbDeployer.java)
The Glassfish EjbDeployer.java source code/* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * * Copyright (c) 2006-2010 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 org.glassfish.ejb.startup; import java.util.*; import java.util.logging.Level; import java.util.concurrent.atomic.AtomicLong; import java.util.logging.Logger; import com.sun.enterprise.config.serverbeans.Domain; import com.sun.enterprise.deployment.Application; import com.sun.enterprise.deployment.EjbBundleDescriptor; import com.sun.enterprise.deployment.EjbDescriptor; import com.sun.enterprise.deployment.MethodDescriptor; import com.sun.enterprise.deployment.WebBundleDescriptor; import com.sun.enterprise.deployment.ScheduledTimerDescriptor; import com.sun.enterprise.security.PolicyLoader; import com.sun.enterprise.security.SecurityUtil; import com.sun.enterprise.security.util.IASSecurityException; import com.sun.enterprise.container.common.spi.util.ComponentEnvManager; import com.sun.enterprise.config.serverbeans.Cluster; import com.sun.enterprise.config.serverbeans.Server; import com.sun.ejb.codegen.StaticRmiStubGenerator; import com.sun.ejb.containers.EjbContainerUtilImpl; import com.sun.ejb.containers.EJBTimerService; import com.sun.logging.LogDomains; import com.sun.enterprise.util.LocalStringManagerImpl; import org.glassfish.api.admin.config.ReferenceContainer; import org.glassfish.api.deployment.DeploymentContext; import org.glassfish.api.deployment.MetaData; import org.glassfish.api.deployment.OpsParams; import org.glassfish.api.deployment.DeployCommandParameters; import org.glassfish.api.deployment.UndeployCommandParameters; import org.glassfish.deployment.common.DeploymentException; import org.glassfish.deployment.common.DeploymentProperties; import org.glassfish.deployment.common.DeploymentUtils; import org.glassfish.api.event.EventListener; import org.glassfish.api.event.Events; import org.glassfish.ejb.spi.CMPDeployer; import org.glassfish.ejb.spi.CMPService; import org.glassfish.javaee.core.deployment.JavaEEDeployer; import org.glassfish.internal.api.ServerContext; import org.glassfish.internal.deployment.Deployment; import org.glassfish.internal.deployment.ExtendedDeploymentContext; import org.glassfish.server.ServerEnvironmentImpl; import com.sun.enterprise.module.bootstrap.StartupContext; import org.glassfish.api.invocation.RegisteredComponentInvocationHandler; import org.glassfish.ejb.security.application.EJBSecurityManager; import org.glassfish.ejb.security.application.EjbSecurityProbeProvider; import org.glassfish.ejb.security.factory.EJBSecurityManagerFactory; import org.glassfish.internal.data.ApplicationInfo; import org.jvnet.hk2.annotations.Inject; import org.jvnet.hk2.annotations.Service; import org.jvnet.hk2.component.PostConstruct; /** * Ejb module deployer. * */ @Service public class EjbDeployer extends JavaEEDeployer<EjbContainerStarter, EjbApplication> implements PostConstruct, EventListener { @Inject protected ServerContext sc; @Inject protected Domain domain; @Inject protected ServerEnvironmentImpl env; @Inject protected PolicyLoader policyLoader; @Inject protected EJBSecurityManagerFactory ejbSecManagerFactory; @Inject private ComponentEnvManager compEnvManager; @Inject private Events events; @Inject StartupContext startupContext; private Object lock = new Object(); private volatile CMPDeployer cmpDeployer = null; private static Random random = new Random(); // Property used to persist unique id across server restart. static final String APP_UNIQUE_ID_PROP = "org.glassfish.ejb.container.application_unique_id"; static final String IS_TIMEOUT_APP_PROP = "org.glassfish.ejb.container.is_timeout_application"; private AtomicLong uniqueIdCounter; private static final Logger _logger = LogDomains.getLogger(EjbDeployer.class, LogDomains.EJB_LOGGER); private static final LocalStringManagerImpl localStrings = new LocalStringManagerImpl(EjbDeployer.class); private final EjbSecurityProbeProvider probeProvider = new EjbSecurityProbeProvider(); /** * Constructor */ public EjbDeployer() { // Seed a counter used for ejb application unique id generation. uniqueIdCounter = new AtomicLong(System.currentTimeMillis()); } @Override public void postConstruct() { Properties arguments = startupContext.getArguments(); if (arguments != null) { boolean isUpgrade = Boolean.valueOf(arguments.getProperty("-upgrade")); if (isUpgrade) { // we don't want to register this listener for the upgrade // start up return; } } events.register(this); } protected String getModuleType () { return "ejb"; } @Override public MetaData getMetaData() { return new MetaData(false, new Class[] {EjbBundleDescriptor.class}, new Class[] {Application.class}); } @Override public boolean prepare(DeploymentContext dc) { EjbBundleDescriptor ejbBundle = dc.getModuleMetaData(EjbBundleDescriptor.class); if( ejbBundle == null ) { String errMsg = localStrings.getLocalString("context.contains.no.ejb", "DeploymentContext does not contain any EJB", dc.getSourceDir()); throw new RuntimeException(errMsg); } // Get application-level properties (*not* module-level) Properties appProps = dc.getAppProps(); long uniqueAppId; if( !appProps.containsKey(APP_UNIQUE_ID_PROP)) { // This is the first time load is being called for any ejb module in an // application, so generate the unique id. uniqueAppId = getNextEjbAppUniqueId(); appProps.setProperty(APP_UNIQUE_ID_PROP, uniqueAppId + ""); } else { uniqueAppId = Long.parseLong(appProps.getProperty(APP_UNIQUE_ID_PROP)); } OpsParams params = dc.getCommandParameters(OpsParams.class); if (params.origin.isDeploy()) { // KEEP_STATE is saved to AppProps in EjbApplication.stop String keepStateVal = (String) dc.getAppProps().get(EjbApplication.KEEP_STATE); if (keepStateVal != null) { // save KEEP_STATE to Application so subsequent to make it available // to subsequent deploy-related methods. ejbBundle.getApplication().setKeepStateResolved(keepStateVal); if (_logger.isLoggable(Level.FINE)) { _logger.log(Level.FINE, "EjbDeployer.prepare set keepstate to {0} for application.", ejbBundle.getApplication().getKeepStateResolved()); } } } Application app = ejbBundle.getApplication(); if( !app.isUniqueIdSet() ) { // This will set the unique id for all EJB components in the application. // If there are multiple ejb modules in the app, we'll only call it once // for the first ejb module load(). All the old // .xml processing for unique-id in the sun-* descriptors is removed so // this is the only place where Application.setUniqueId() should be called. app.setUniqueId(uniqueAppId); } return super.prepare(dc); } @Override public EjbApplication load(EjbContainerStarter containerStarter, DeploymentContext dc) { super.load(containerStarter, dc); if (_logger.isLoggable(Level.FINE)) { _logger.log( Level.FINE, "EjbDeployer Loading app from: " + dc.getSourceDir()); } //Register the EjbSecurityComponentInvocationHandler RegisteredComponentInvocationHandler handler = habitat.getComponent(RegisteredComponentInvocationHandler.class,"ejbSecurityCIH"); handler.register(); EjbBundleDescriptor ejbBundle = dc.getModuleMetaData(EjbBundleDescriptor.class); if( ejbBundle == null ) { throw new RuntimeException("Unable to load EJB module. DeploymentContext does not contain any EJB " + " Check archive to ensure correct packaging for " + dc.getSourceDir()); } ejbBundle.setClassLoader(dc.getClassLoader()); if (ejbBundle.containsCMPEntity()) { CMPService cmpService = habitat.getByContract(CMPService.class); if (cmpService == null) { throw new RuntimeException("CMP Module is not available"); } else if (!cmpService.isReady()) { throw new RuntimeException("CMP Module is not initialized"); } } EjbApplication ejbApp = new EjbApplication(ejbBundle, dc, dc.getClassLoader(), habitat, ejbSecManagerFactory); try { compEnvManager.bindToComponentNamespace(ejbBundle); // If within .war, also bind dependencies declared by web application. There is // a single naming environment for the entire .war module. Yhis is necessary // in order for eagerly initialized ejb components to have visibility to all the // dependencies b/c the web container does not bind to the component namespace until // its start phase, which comes after the ejb start phase. Object rootDesc = ejbBundle.getModuleDescriptor().getDescriptor(); if( (rootDesc != ejbBundle) && (rootDesc instanceof WebBundleDescriptor ) ) { WebBundleDescriptor webBundle = (WebBundleDescriptor) rootDesc; compEnvManager.bindToComponentNamespace(webBundle); } } catch(Exception e) { throw new RuntimeException("Exception registering ejb bundle level resources", e); } ejbApp.loadContainers(dc); return ejbApp; } public void unload(EjbApplication ejbApplication, DeploymentContext dc) { EjbBundleDescriptor ejbBundle = ejbApplication.getEjbBundleDescriptor(); try { compEnvManager.unbindFromComponentNamespace(ejbBundle); } catch(Exception e) { _logger.log( Level.WARNING, "Error unbinding ejb bundle " + ejbBundle.getModuleName() + " dependency namespace", e); } if (ejbBundle.containsCMPEntity()) { initCMPDeployer(); if (cmpDeployer != null) { cmpDeployer.unload(ejbBundle.getClassLoader()); } } // All the other work is done in EjbApplication. } /** * Clean any files and artifacts that were created during the execution * of the prepare method. * * @param dc deployment context */ public void clean(DeploymentContext dc) { // Both undeploy and shutdown scenarios are // handled directly in EjbApplication.shutdown. // But CMP drop tables should be handled here. OpsParams params = dc.getCommandParameters(OpsParams.class); if ( (params.origin.isUndeploy() || params.origin.isDeploy()) && isDas()) { // If CMP beans are present, cmpDeployer should've been initialized in unload() if (cmpDeployer != null) { cmpDeployer.clean(dc); } Properties appProps = dc.getAppProps(); String uniqueAppId = appProps.getProperty(APP_UNIQUE_ID_PROP); try { if (getTimeoutStatusFromApplicationInfo(params.name()) && uniqueAppId != null) { String target = ((params.origin.isDeploy())? dc.getCommandParameters(DeployCommandParameters.class).target : dc.getCommandParameters(UndeployCommandParameters.class).target); if (DeploymentUtils.isDomainTarget(target)) { List<String> targets = (List Other Glassfish examples (source code examples)Here is a short list of links related to this Glassfish EjbDeployer.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.