|
Glassfish example source code file (StatefulContainerBuilder.java)
The Glassfish StatefulContainerBuilder.java source code/* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * * Copyright (c) 1997-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 com.sun.ejb.containers.builder; import java.io.File; import java.io.Serializable; import java.util.Map; import java.util.logging.Logger; import java.util.logging.Level; import com.sun.appserv.util.cache.CacheListener; import com.sun.ejb.base.container.util.CacheProperties; import com.sun.ejb.base.sfsb.util.CheckpointPolicyImpl; import com.sun.ejb.base.sfsb.util.ScrambledKeyGenerator; import com.sun.ejb.base.sfsb.util.SimpleKeyGenerator; import com.sun.ejb.base.sfsb.util.EJBServerConfigLookup; import com.sun.ejb.containers.StatefulSessionContainer; import com.sun.ejb.containers.BaseContainer; import com.sun.ejb.containers.util.cache.FIFOSessionCache; import com.sun.ejb.containers.util.cache.LruSessionCache; import com.sun.ejb.containers.util.cache.NRUSessionCache; import com.sun.ejb.containers.util.cache.UnBoundedSessionCache; import com.sun.enterprise.config.serverbeans.*; import com.sun.enterprise.deployment.EjbDescriptor; import com.sun.ejb.spi.container.SFSBContainerInitialization; import org.glassfish.api.deployment.DeployCommandParameters; import org.glassfish.api.deployment.DeploymentContext; import org.glassfish.gms.bootstrap.GMSAdapter; import org.glassfish.gms.bootstrap.GMSAdapterService; import org.glassfish.ha.store.api.BackingStore; import org.glassfish.ha.store.api.BackingStoreConfiguration; import org.glassfish.ha.store.api.BackingStoreException; import org.glassfish.ha.store.api.BackingStoreFactory; import org.glassfish.ha.store.util.KeyTransformer; import org.glassfish.ha.store.util.SimpleMetadata; import org.jvnet.hk2.annotations.Service; import org.jvnet.hk2.annotations.Scoped; import org.jvnet.hk2.annotations.Inject; import org.jvnet.hk2.component.PerLookup; import org.jvnet.hk2.component.Habitat; /** * A builder for StatefulSessionContainer. Takes care of * building / initializing the StatefulSessionContainer * with the following classes: * a) Cache (LRU / NRU / FIFO / UnBounded) * b) SFSBStoreManager (Using PersistenceStrategyBuilder) * c) Cache passivation task (if idle-timeout is greater than 0) * d) Passivated sessions removal task (if removal-timeout is greater than 0) * e) CheckpointPolicy (if ha enabled) * f) SFSBUUIDUtil * g) BeanLifecycleManager * * @author Mahesh Kannan */ @Service @Scoped(PerLookup.class) public class StatefulContainerBuilder extends BaseContainerBuilder { private static final Level TRACE_LEVEL = Level.FINE; private StatefulSessionContainer sfsbContainer; private SFSBContainerInitialization containerInitialization; @Inject private Habitat habitat; @Inject private CacheProperties cacheProps; @Inject private EJBServerConfigLookup ejbConfigLookup; @Inject(optional = true) private AvailabilityService availabilityService; @Inject(optional = true) private EjbContainerAvailability ejbAvailability; @Inject EjbContainer ejbContainerConfig; @Inject(optional = true) GMSAdapterService gmsAdapterService; private LruSessionCache sessionCache; private BackingStore<Serializable, SimpleMetadata> backingStore; private boolean HAEnabled = false; private boolean asyncReplication = true; private SimpleKeyGenerator keyGen; public StatefulContainerBuilder() { super(); } public BaseContainer createContainer( EjbDescriptor ejbDescriptor, ClassLoader loader) throws Exception { cacheProps.init(ejbDescriptor); ejbConfigLookup.initWithEjbDescriptor(ejbDescriptor); sfsbContainer = new StatefulSessionContainer(ejbDescriptor, loader); containerInitialization = (SFSBContainerInitialization) sfsbContainer; return sfsbContainer; } public void buildComponents() throws Exception { if (availabilityService != null) { this.HAEnabled = Boolean.valueOf(availabilityService.getAvailabilityEnabled()); _logger.log(Level.INFO, "TopLevel AvailabilityService.getAvailabilityEnabled => " + this.HAEnabled); if ((this.HAEnabled) && (ejbAvailability != null)) { this.HAEnabled = Boolean.valueOf(ejbAvailability.getAvailabilityEnabled()); _logger.log(Level.INFO, "TopLevel EjbAvailabilityService.getAvailabilityEnabled => " + this.HAEnabled); } boolean appLevelHAEnabled = false; try { if (HAEnabled) { DeploymentContext dc = getDynamicDeploymentContext(); if (dc != null) { DeployCommandParameters params = dc.getCommandParameters(DeployCommandParameters.class); if (params != null) { appLevelHAEnabled = params.availabilityenabled; asyncReplication = params.asyncreplication; } } _logger.log(Level.INFO, "**Global AvailabilityEnabled => " + this.HAEnabled + "; isAppHAEnabled: " + appLevelHAEnabled); } } catch (Exception ex) { _logger.log(Level.WARNING, "Exception while trying to determine availability-enabled settings for this app", ex); appLevelHAEnabled = false; } HAEnabled = HAEnabled && appLevelHAEnabled; _logger.log(Level.INFO, "StatefulContainerBuilder AvailabilityEnabled for this app => " + this.HAEnabled); } buildCheckpointPolicy(this.HAEnabled); buildSFSBUUIDUtil(); //First build BackingStore before Cache is built buildStoreManager(); buildCache(); scheduleTimerTasks(sfsbContainer); } /************************* Private Methods *************************/ /** * *************************************************************** */ private final void buildCheckpointPolicy(boolean haEnabled) { containerInitialization.setCheckpointPolicy( new CheckpointPolicyImpl(haEnabled)); } private void buildSFSBUUIDUtil() { //Just for debugging purpose, we instantiate // two different key generators keyGen = HAEnabled ? new ScrambledKeyGenerator(getIPAddress(), getPort()) : new SimpleKeyGenerator(getIPAddress(), getPort()); containerInitialization.setSFSBUUIDUtil(keyGen); } private void buildStoreManager() throws BackingStoreException { String persistenceStoreType = "file"; if (ejbAvailability != null) { persistenceStoreType = HAEnabled ? ejbAvailability.getSfsbHaPersistenceType() : ejbAvailability.getSfsbPersistenceType(); if ("ha".equals(persistenceStoreType)) { persistenceStoreType = "replicated"; } else if ("memory".equals(persistenceStoreType)) { persistenceStoreType = "file"; } } BackingStoreConfiguration<Serializable, SimpleMetadata> conf = new BackingStoreConfiguration Other Glassfish examples (source code examples)Here is a short list of links related to this Glassfish StatefulContainerBuilder.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.