KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > connectors > BootstrapContextImpl


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.enterprise.connectors;
25
26 import com.sun.enterprise.Switch;
27 import com.sun.enterprise.connectors.work.WorkManagerFactory;
28 import com.sun.logging.LogDomains;
29 import java.util.Timer JavaDoc;
30 import java.util.logging.*;
31 import javax.resource.spi.BootstrapContext JavaDoc;
32 import javax.resource.spi.XATerminator JavaDoc;
33 import javax.resource.spi.work.WorkManager JavaDoc;
34
35
36 /**
37  * BootstrapContext implementation.
38  *
39  * @author Qingqing Ouyang, Binod P.G
40  * @see com.sun.enterprise.connectors.work.CommonWorkManager
41  * @see com.sun.enterprise.connectors.work.WorkManagerFactory
42  */

43 public class BootstrapContextImpl implements BootstrapContext JavaDoc {
44
45     //The following are not serialized with the ResourceAdapter
46
private WorkManager JavaDoc wm;
47     private XATerminator JavaDoc xa;
48     private String JavaDoc moduleName;
49     private String JavaDoc poolId;
50     private static Logger logger =
51         LogDomains.getLogger(LogDomains.RSR_LOGGER);
52
53     /**
54      * Constructs a <code>BootstrapContext</code> with default
55      * thread pool for work manager.
56      *
57      * @throws ConnectorRuntimeException If there is a failure in
58      * retrieving WorkManager.
59      */

60     public BootstrapContextImpl () throws ConnectorRuntimeException{
61         wm = WorkManagerFactory.getWorkManager(null);
62     }
63
64     /**
65      * Constructs a <code>BootstrapContext</code> with a specified
66      * thread pool for work manager.
67      *
68      * @throws ConnectorRuntimeException If there is a failure in
69      * retrieving WorkManager.
70      */

71     public BootstrapContextImpl (String JavaDoc poolId)
72                                  throws ConnectorRuntimeException{
73         this.poolId = poolId;
74         wm = WorkManagerFactory.getWorkManager(poolId);
75     }
76
77     /**
78      * Creates a <code>java.util.Timer</code> instance.
79      * This can cause a problem, since the timer threads are not actually
80      * under appserver control. We should override the timer later.
81      *
82      * @return <code>java.util.Timer</code> object.
83      */

84     public Timer JavaDoc createTimer() {
85         return new Timer JavaDoc();
86     }
87
88     /**
89      * Retrieves the work manager.
90      *
91      * @return <code>WorkManager</code> instance.
92      * @see com.sun.enterprise.connectors.work.CommonWorkManager
93      * @see com.sun.enterprise.connectors.work.WorkManagerFactory
94      */

95     public WorkManager JavaDoc getWorkManager() {
96         if (wm == null) {
97             try {
98                 wm = WorkManagerFactory.getWorkManager(poolId);
99             } catch(Exception JavaDoc e) {
100             logger.log(Level.SEVERE, "workmanager.instantiation_error", e);
101             }
102         }
103         return wm;
104     }
105
106     /**
107      * Retrieves the <code>XATerminator</code> object.
108      */

109     public XATerminator JavaDoc getXATerminator() {
110         if (xa == null) {
111             xa = Switch.getSwitch().getTransactionManager().getXATerminator();
112         }
113         return xa;
114     }
115 }
116
Popular Tags