KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > ejb > containers > SFSBTxCheckpointCoordinator


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.containers;
25
26 import java.util.ArrayList JavaDoc;
27
28 import com.sun.ejb.spi.sfsb.store.SFSBTxStoreManager;
29
30 import com.sun.ejb.base.sfsb.initialization.SFSBTxStoreManagerFactory;
31
32 import com.sun.ejb.base.sfsb.util.EJBServerConfigLookup;
33
34 import com.sun.ejb.spi.sfsb.store.SFSBBeanState;
35 import com.sun.ejb.spi.sfsb.store.SFSBStoreManagerException;
36
37 import java.util.logging.*;
38 import com.sun.logging.*;
39
40 /**
41  * A class to checkpoint HA enabled SFSBs as a single transactional unit.
42  *
43  * @author Mahesh Kannan
44  */

45 public class SFSBTxCheckpointCoordinator {
46
47     private static Logger _logger =
48         LogDomains.getLogger(LogDomains.EJB_LOGGER);
49
50     private static String JavaDoc _haStoreType;
51     static {
52     EJBServerConfigLookup ejbConfigLookup = new EJBServerConfigLookup();
53     _haStoreType = ejbConfigLookup.getSfsbHaPersistenceTypeFromConfig();
54     }
55
56     private ArrayList JavaDoc ctxList = new ArrayList JavaDoc();
57
58     SFSBTxCheckpointCoordinator() {
59     }
60
61     void registerContext(SessionContextImpl ctx) {
62     ctxList.add(ctx);
63     }
64
65     void doTxCheckpoint() {
66     SessionContextImpl[] contexts = (SessionContextImpl[]) ctxList.toArray(
67         new SessionContextImpl[0]);
68     int size = contexts.length;
69     ArrayList JavaDoc states = new ArrayList JavaDoc(size);
70
71     for (int i=0; i<size; i++) {
72         SessionContextImpl ctx = contexts[i];
73         StatefulSessionContainer container =
74         (StatefulSessionContainer) ctx.getContainer();
75         SFSBBeanState beanState = container.getSFSBBeanState(ctx);
76         if (beanState != null) {
77         states.add(beanState);
78         }
79     }
80
81     if (states.size () > 0) {
82         SFSBBeanState[] beanStates = (SFSBBeanState[]) states.toArray(
83         new SFSBBeanState[0]);
84
85         try {
86         SFSBTxStoreManager txStoreManager = SFSBTxStoreManagerFactory.
87             createSFSBTxStoreManager(_haStoreType);
88         txStoreManager.checkpointSave(beanStates);
89         } catch (SFSBStoreManagerException sfsbEx) {
90         _logger.log(Level.WARNING, "Exception during checkpointSave",
91             sfsbEx);
92         } catch (Throwable JavaDoc th) {
93         _logger.log(Level.WARNING, "Exception during checkpointSave",
94             th);
95         }
96     }
97
98     for (int i=0; i<size; i++) {
99         SessionContextImpl ctx = contexts[i];
100         StatefulSessionContainer container =
101         (StatefulSessionContainer) ctx.getContainer();
102         container.txCheckpointCompleted(ctx);
103     }
104     }
105
106 }
107
Popular Tags