KickJava   Java API By Example, From Geeks To Geeks.

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


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.resource;
25
26 import javax.transaction.xa.XAResource JavaDoc;
27 import javax.naming.*;
28 import com.sun.enterprise.log.Log;
29 import com.sun.enterprise.PoolManager;
30 import com.sun.enterprise.Switch;
31 import javax.resource.spi.*;
32 import javax.resource.ResourceException JavaDoc;
33 import java.util.*;
34 import java.util.logging.*;
35 import com.sun.logging.*;
36
37 /**
38  * @author Binod P.G
39  */

40 public class LocalTxConnectionEventListener implements ConnectionEventListener {
41
42     private PoolManager poolMgr;
43
44     // Create logger object per Java SDK 1.4 to log messages
45
// introduced Santanu De, Sun Microsystems, March 2002
46

47     static Logger _logger = LogDomains.getLogger(LogDomains.RSR_LOGGER);
48
49     // connectionHandle -> ResourceHandle
50
// Whenever a connection is associated with a ManagedConnection,
51
// that connection and the resourcehandle associated with its
52
// original ManagedConnection will be put in this table.
53
private IdentityHashMap associatedHandles;
54
55     private ResourceHandle resource;
56         
57     public LocalTxConnectionEventListener(ResourceHandle resource) {
58         this.resource = resource;
59         this.associatedHandles = new IdentityHashMap(10);
60         this.poolMgr = Switch.getSwitch().getPoolManager();
61     }
62
63     public void connectionClosed(ConnectionEvent evt) {
64         Object JavaDoc connectionHandle = evt.getConnectionHandle();
65         ResourceHandle handle = resource;
66         if (associatedHandles.containsKey(connectionHandle)) {
67             handle = (ResourceHandle) associatedHandles.get(connectionHandle);
68         }
69         poolMgr.resourceClosed(handle);
70     }
71         
72     public void connectionErrorOccurred(ConnectionEvent evt) {
73         resource.setConnectionErrorOccurred();
74         ManagedConnection mc = (ManagedConnection) evt.getSource();
75         mc.removeConnectionEventListener(this);
76     poolMgr.resourceErrorOccurred( resource );
77         try {
78             mc.destroy();
79         } catch (ResourceException JavaDoc ex) {
80             // ignore exception
81
}
82     }
83
84     public void localTransactionStarted(ConnectionEvent evt) {
85             // no-op
86
}
87
88     public void localTransactionCommitted(ConnectionEvent evt) {
89          // no-op
90
}
91
92     public void localTransactionRolledback(ConnectionEvent evt) {
93         // no-op
94
}
95
96     public void associateHandle(Object JavaDoc c, ResourceHandle h) {
97         associatedHandles.put(c, h);
98     }
99
100     public void removeAssociation(Object JavaDoc c) {
101         associatedHandles.remove(c);
102     }
103
104     public Map getAssociatedHandles(){
105         return associatedHandles;
106     }
107         
108 }
109
110
Popular Tags