KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.util.HashSet JavaDoc;
27 import java.util.Set JavaDoc;
28 import java.util.logging.Level JavaDoc;
29 import java.util.logging.Logger JavaDoc;
30
31 import javax.resource.ResourceException JavaDoc;
32 import javax.resource.spi.ConnectionRequestInfo JavaDoc;
33 import javax.resource.spi.ManagedConnection JavaDoc;
34 import javax.resource.spi.ManagedConnectionFactory JavaDoc;
35 import javax.resource.spi.ValidatingManagedConnectionFactory JavaDoc;
36 import javax.security.auth.Subject JavaDoc;
37
38 import com.sun.enterprise.PoolManager;
39 import com.sun.enterprise.deployment.ConnectorDescriptor;
40 import com.sun.logging.LogDomains;
41
42
43 /**
44  * An abstract implementation of the <code>ResourceAllocator</code> interface
45  * that houses all the common implementation(s) of the various connector allocators.
46  * All resource allocators except <code>BasicResourceAllocator</code> extend this
47  * abstract implementation
48  * @author Sivakumar Thyagarajan
49  */

50 public abstract class AbstractConnectorAllocator
51                             implements ResourceAllocator {
52
53     protected PoolManager poolMgr;
54     protected ResourceSpec spec;
55     protected ConnectionRequestInfo JavaDoc reqInfo;
56     protected Subject JavaDoc subject;
57     protected ManagedConnectionFactory JavaDoc mcf;
58     protected ConnectorDescriptor desc;
59     protected ClientSecurityInfo info;
60     
61     protected static Logger JavaDoc _logger = LogDomains.getLogger(LogDomains.RSR_LOGGER);
62
63     public AbstractConnectorAllocator() {
64     }
65
66     public AbstractConnectorAllocator(PoolManager poolMgr,
67                     ManagedConnectionFactory JavaDoc mcf,
68                     ResourceSpec spec,
69                     Subject JavaDoc subject,
70                     ConnectionRequestInfo JavaDoc reqInfo,
71                     ClientSecurityInfo info,
72                     ConnectorDescriptor desc) {
73         this.poolMgr = poolMgr;
74         this.mcf = mcf;
75         this.spec = spec;
76         this.subject = subject;
77         this.reqInfo = reqInfo;
78         this.info = info;
79         this.desc = desc;
80         
81     }
82
83     public Set JavaDoc getInvalidConnections(Set JavaDoc connectionSet)
84                                 throws ResourceException JavaDoc {
85         if(mcf instanceof ValidatingManagedConnectionFactory JavaDoc){
86             return ((ValidatingManagedConnectionFactory JavaDoc)this.mcf).
87                                     getInvalidConnections(connectionSet);
88         }
89         return null;
90     }
91
92     public boolean isConnectionValid( ResourceHandle h )
93     {
94          HashSet JavaDoc conn = new HashSet JavaDoc();
95          conn.add( h.getResource() );
96          Set JavaDoc invalids = null;
97          try {
98              invalids = getInvalidConnections( conn );
99          } catch( ResourceException JavaDoc re ) {
100              //ignore and continue??
101
}
102          
103      if ( (invalids != null && invalids.size() > 0) ||
104              h.hasConnectionErrorOccurred() ) {
105          return false;
106      }
107
108      return true;
109     }
110
111     public void destroyResource(ResourceHandle resourceHandle)
112         throws PoolingException {
113         throw new UnsupportedOperationException JavaDoc();
114     }
115
116     public void fillInResourceObjects(ResourceHandle resourceHandle)
117         throws PoolingException {
118         throw new UnsupportedOperationException JavaDoc();
119     }
120
121
122
123     public boolean supportsReauthentication() {
124         return this.desc.supportsReauthentication();
125     }
126
127     public boolean isTransactional() {
128         return true;
129     }
130
131     public void cleanup(ResourceHandle h) throws PoolingException {
132         try {
133             ManagedConnection JavaDoc mc = (ManagedConnection JavaDoc) h.getResource();
134             mc.cleanup();
135         } catch (Exception JavaDoc ex) {
136             _logger.log(Level.WARNING, "managed_con.cleanup-failed", ex);
137             throw new PoolingException(ex.toString(), ex);
138         }
139     }
140
141     public boolean matchConnection(ResourceHandle h) {
142         Set JavaDoc set = new HashSet JavaDoc();
143         set.add(h.getResource());
144         try {
145             ManagedConnection JavaDoc mc =
146                 mcf.matchManagedConnections(set, subject, reqInfo);
147             return (mc != null);
148         } catch (ResourceException JavaDoc ex) {
149             return false;
150         }
151     }
152
153     public void closeUserConnection(ResourceHandle resource) throws PoolingException {
154     
155         try {
156             ManagedConnection JavaDoc mc = (ManagedConnection JavaDoc) resource.getResource();
157             mc.cleanup();
158         } catch (ResourceException JavaDoc ex) {
159             throw new PoolingException(ex);
160         }
161     }
162
163     public boolean shareableWithinComponent() {
164         return false;
165     }
166
167     public Object JavaDoc getSharedConnection(ResourceHandle h)
168                                     throws PoolingException {
169         throw new UnsupportedOperationException JavaDoc();
170     }
171
172 }
173
Popular Tags