KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > resource > SystemResourceManagerImpl


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 package com.sun.enterprise.resource;
24
25 import java.util.*;
26 import java.util.logging.*;
27
28 import javax.transaction.Transaction JavaDoc;
29 import javax.transaction.SystemException JavaDoc;
30
31 import com.sun.logging.*;
32 import com.sun.enterprise.*;
33 import com.sun.enterprise.log.Log;
34
35 /**
36  * SystemResourceManagerImpl manages the resource requests from system
37  *
38  * @author Binod PG
39  */

40 public class SystemResourceManagerImpl implements ResourceManager {
41
42
43     static Logger _logger = null;
44     static {
45         _logger = LogDomains.getLogger(LogDomains.RSR_LOGGER);
46     }
47
48
49     /**
50      * Returns the transaction component is participating.
51      *
52      * @return Handle to the <code>Transaction</code> object.
53      * @exception <code>PoolingException<code> If exception is thrown
54      * while getting the transaction.
55      */

56     public Transaction JavaDoc getTransaction() throws PoolingException{
57         try {
58             J2EETransactionManager tm =
59                 Switch.getSwitch().getTransactionManager();
60             return tm.getTransaction();
61         } catch (Exception JavaDoc ex) {
62             _logger.log(Level.SEVERE,"poolmgr.unexpected_exception",ex);
63             throw new PoolingException(ex.toString(), ex);
64         }
65     }
66
67     /**
68      * Return null for System Resource.
69      */

70     public Object JavaDoc getComponent() {
71         return null;
72     }
73     
74     /**
75      * Register the <code>ResourceHandle</code> in the transaction
76      *
77      * @param h <code>ResourceHandle</code> object
78      * @exception <code>PoolingException</code> If there is any error while
79      * enlisting.
80      */

81     public void enlistResource(ResourceHandle handle) throws PoolingException{
82         try {
83             J2EETransactionManager tm =
84                 Switch.getSwitch().getTransactionManager();
85             Transaction JavaDoc tran = tm.getTransaction();
86         if (tran != null) {
87                 tm.enlistResource(tran, handle);
88             }
89     } catch (Exception JavaDoc ex) {
90             _logger.log(Level.SEVERE,"poolmgr.unexpected_exception",ex);
91             throw new PoolingException(ex.toString(), ex);
92         }
93     }
94
95     /**
96      * Dont do any thing for System Resource.
97      */

98     public void registerResource(ResourceHandle handle)
99          throws PoolingException {
100     }
101     
102     public void rollBackTransaction() {
103         try {
104             J2EETransactionManager tm =
105                 Switch.getSwitch().getTransactionManager();
106             Transaction JavaDoc tran = tm.getTransaction();
107         if ( tran != null ) {
108                 tran.setRollbackOnly();
109         }
110         } catch (SystemException JavaDoc ex) {
111             _logger.log(Level.WARNING,"poolmgr.system_exception",ex);
112         } catch (IllegalStateException JavaDoc ex) {
113             // ignore
114
}
115     }
116    
117     /**
118      * delist the <code>ResourceHandle</code> from the transaction
119      *
120      * @param h <code>ResourceHandle</code> object
121      * @param xaresFlag flag indicating transaction success. This can
122      * be XAResource.TMSUCCESS or XAResource.TMFAIL
123      * @exception <code>PoolingException</code>
124      */

125     public void delistResource(ResourceHandle h, int xaresFlag) {
126         try {
127             J2EETransactionManager tm =
128                 Switch.getSwitch().getTransactionManager();
129             Transaction JavaDoc tran = tm.getTransaction();
130         if (tran != null) {
131                 tm.delistResource(tran, h, xaresFlag);
132             }
133         } catch (SystemException JavaDoc ex) {
134             _logger.log(Level.WARNING,"poolmgr.system_exception",ex);
135         } catch (IllegalStateException JavaDoc ex) {
136             // ignore
137
}
138     }
139     
140     /**
141      * Dont do any thing for System Resource.
142      */

143     public void unregisterResource(ResourceHandle resource,
144                                    int xaresFlag) {
145     }
146 }
147
Popular Tags