KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > ejb > base > sfsb > initialization > FileStrategyBuilder


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 package com.sun.ejb.base.sfsb.initialization;
25
26 import java.io.File JavaDoc;
27
28 import java.util.logging.Level JavaDoc;
29 import java.util.logging.Logger JavaDoc;
30
31 import java.util.HashMap JavaDoc;
32 import java.util.Map JavaDoc;
33
34 import com.sun.ejb.spi.sfsb.initialization.SFSBContainerInitialization;
35
36 import com.sun.ejb.spi.sfsb.store.SFSBStoreManager;
37 import com.sun.ejb.spi.sfsb.store.SFSBStoreManagerException;
38
39 import com.sun.enterprise.deployment.Application;
40 import com.sun.enterprise.deployment.EjbDescriptor;
41
42 import com.sun.ejb.base.sfsb.store.FileStoreManager;
43 import com.sun.ejb.base.sfsb.store.FileStoreManagerConstants;
44
45 import com.sun.enterprise.server.ServerContext;
46 import com.sun.enterprise.server.ApplicationServer;
47 import com.sun.enterprise.instance.InstanceEnvironment;
48
49 import com.sun.enterprise.config.ConfigException;
50 import com.sun.enterprise.config.serverbeans.*;
51 import com.sun.enterprise.instance.*;
52 import com.sun.enterprise.server.*;
53 import com.sun.enterprise.server.ServerContext;
54 import com.sun.enterprise.server.ApplicationServer;
55 import com.sun.enterprise.util.io.FileUtils;
56
57 import com.sun.ejb.base.container.util.CacheProperties;
58
59 /**
60  * Class to initialize Container with File based persistence
61  *
62  * @author Mahesh Kannan
63  */

64 public class FileStrategyBuilder
65     extends AbstractPersistenceStrategyBuilder
66 {
67     /** Creates a new instance of FileStrategyBuilder */
68     public FileStrategyBuilder() {
69     }
70
71     public void initializePersistenceStrategy(
72     SFSBContainerInitialization container, EjbDescriptor descriptor)
73     {
74     try {
75         super.initializePersistenceStrategy(container, descriptor);
76
77         SFSBStoreManager storeManager = createStoreManager(
78             container, descriptor);
79         container.setSFSBStoreManager(storeManager);
80
81     } catch (Throwable JavaDoc th) {
82         _logger.log(Level.SEVERE, "Could not initialize container "
83             + "using FilestrategyBuilder", th);
84     }
85     }
86
87     private SFSBStoreManager createStoreManager(
88     SFSBContainerInitialization container, EjbDescriptor descriptor)
89     {
90     //Step 1. Create the StoreManager
91
FileStoreManager manager = new FileStoreManager();
92
93     //Step 2. Create a Map that contains store specific paramteters
94
Map JavaDoc map = new HashMap JavaDoc();
95     map.put(FileStoreManagerConstants.STORE_MANAGER_NAME,
96         descriptor.getName());
97
98     map.put(FileStoreManagerConstants.CONTAINER_ID,
99         new Long JavaDoc(descriptor.getUniqueId()));
100
101     CacheProperties cacheProps = new CacheProperties(descriptor);
102     map.put(FileStoreManagerConstants.SESSION_TIMEOUT_IN_SECONDS,
103         new Integer JavaDoc(cacheProps.getRemovalTimeoutInSeconds()));
104
105     map.put(FileStoreManagerConstants.GRACE_SESSION_TIMEOUT_IN_SECONDS,
106         new Integer JavaDoc(super.getRemovalGracePeriodInSeconds()));
107
108     map.put(FileStoreManagerConstants.PASSIVATION_DIRECTORY_NAME,
109         getPassivationDirectoryName(descriptor));
110
111     //Step 3. Initialize the store with the Map
112
_logger.log(Level.FINE, "Initialzing FileStoreManager with: " + map);
113     manager.initSessionStore(map);
114
115     _logger.log(Level.FINE, "INITIALZED FileStoreManager: " + manager);
116     return manager;
117     }
118
119     private String JavaDoc getPassivationDirectoryName(EjbDescriptor desc) {
120         
121         String JavaDoc passivationDirName = null;
122
123         try {
124         
125             // runtime server context
126
ServerContext ctx = ApplicationServer.getServerContext();
127          
128             // environment object for this server instance
129
InstanceEnvironment env = ctx.getInstanceEnvironment();
130          
131             // application object associated with this ejb
132
Application application = desc.getApplication();
133             String JavaDoc dirName = null;
134             String JavaDoc componentSeparator = "_";
135             if (application.isVirtual()) {
136                 // ejb is part of a stand alone ejb module
137
String JavaDoc archURI = desc.getEjbBundleDescriptor().
138             getModuleDescriptor().getArchiveUri();
139                 passivationDirName = env.getModulePassivatedEjbPath()
140             + File.separator + FileUtils.makeFriendlyFilename(archURI)
141             + componentSeparator + desc.getName();
142             } else {
143                 // ejb is part of an application
144
passivationDirName = env.getApplicationPassivatedEjbPath()
145             + File.separator + application.getRegistrationName()
146             + componentSeparator + desc.getName()
147             + componentSeparator + desc.getUniqueId();
148             }
149          
150         } catch (Throwable JavaDoc th) {
151             _logger.log(Level.SEVERE,
152             "ejb.sfsb_helper_get_passivation_dir_failed", th);
153         }
154
155         return passivationDirName;
156     }
157
158 }
159     
160
Popular Tags