1 23 package com.sun.enterprise.resource; 24 25 import javax.transaction.xa.XAResource ; 26 import javax.resource.spi.ConnectionEventListener ; 27 28 import com.sun.logging.LogDomains; 29 import java.util.logging.Level ; 30 import java.util.logging.Logger ; 31 32 import javax.security.auth.Subject ; 38 39 45 public class ResourceHandle { 46 47 static private long idSequence; 49 50 private long id; 51 private ClientSecurityInfo info; 52 private Object resource; private ResourceSpec spec; 54 private XAResource xares; 55 private Object usercon; private ResourceAllocator alloc; 57 private Object instance; private int shareCount; private boolean supportsXAResource=false; 60 61 private Subject subject = null; 63 private ResourceState state = null; 64 private ConnectionEventListener listener = null; 65 private boolean associated_ = false; 66 private long threadId_; 67 68 private static Logger logger = 69 LogDomains.getLogger(LogDomains.RSR_LOGGER); 70 71 private boolean supportsLazyEnlistment_ = false; 72 private boolean supportsLazyAssoc_ = false; 73 74 76 private boolean enlistmentSuspended = false; 77 public Object lock = new Object (); 78 private boolean dirty_; 79 private long lastValidated; 81 static private long getNextId() { 82 synchronized (ResourceHandle.class) { 83 idSequence++; 84 return idSequence; 85 } 86 } 87 88 public ResourceHandle(Object resource, 89 ResourceSpec spec, 90 ResourceAllocator alloc, 91 ClientSecurityInfo info) { 92 this.id = getNextId(); 93 this.spec = spec; 94 this.info = info; 95 this.resource = resource; 96 this.alloc = alloc; 97 98 if ( alloc instanceof LocalTxConnectorAllocator) 99 supportsXAResource = false; 100 else 101 supportsXAResource = true; 102 103 if ( resource instanceof 104 javax.resource.spi.LazyEnlistableManagedConnection ) { 105 supportsLazyEnlistment_ = true; 106 } 107 108 if ( resource instanceof 109 javax.resource.spi.DissociatableManagedConnection ) { 110 supportsLazyAssoc_ = true; 111 } 112 } 113 public ResourceHandle(Object resource, 115 ResourceSpec spec, 116 ResourceAllocator alloc, 117 ClientSecurityInfo info, 118 boolean supportsXA) { 119 this.id = getNextId(); 120 this.spec = spec; 121 this.info = info; 122 this.resource = resource; 123 this.alloc = alloc; 124 125 supportsXAResource = supportsXA; 126 127 dirty_ = false; 128 } 129 133 public boolean isTransactional() { 134 return alloc.isTransactional(); 135 } 136 137 public boolean supportsXA() { 138 return supportsXAResource; 139 } 140 141 public ResourceAllocator getResourceAllocator() { 142 return alloc; 143 } 144 145 public Object getResource() { 146 return resource; 147 } 148 149 public ClientSecurityInfo getClientSecurityInfo() { 150 return info; 151 } 152 153 public void setResourceSpec(ResourceSpec spec) { 154 this.spec = spec; 155 } 156 157 public ResourceSpec getResourceSpec() { 158 return spec; 159 } 160 161 public XAResource getXAResource() { 162 return xares; 163 } 164 165 public Object getUserConnection() { 166 return usercon; 167 } 168 169 public void setComponentInstance(Object instance) { 170 this.instance = instance; 171 } 172 173 public Object getComponentInstance() { 174 return instance; 175 } 176 177 public void fillInResourceObjects(Object userConnection, 178 XAResource xaRes) { 179 if (userConnection != null) usercon = userConnection; 180 if (xaRes !=null) { 181 if(logger.isLoggable(Level.FINEST)){ 182 if ((xaRes instanceof XAResourceWrapper) || 186 (xaRes instanceof ConnectorXAResource)) { 187 this.xares = xaRes; 188 } else { 189 this.xares = new XAResourceWrapper(xaRes); 190 } 191 } else { 192 this.xares = xaRes; 193 } 194 } 195 } 196 197 public void incrementCount() { 201 shareCount++; 202 } 203 204 public void decrementCount() { 205 if (shareCount == 0) { 206 throw new IllegalStateException ("shareCount cannot be negative"); 207 } else { 208 shareCount--; 209 } 210 } 211 212 public int getShareCount() { 213 return shareCount; 214 } 215 218 public void setSubject(Subject subject){ 220 this.subject = subject; 221 } 222 public Subject getSubject(){ 224 return subject; 225 } 226 227 230 public boolean equals(Object other) { 231 if (other == null) return false; 232 if (other instanceof ResourceHandle) { 233 return this.id == (((ResourceHandle) other).id); 234 } 235 return false; 236 } 237 238 public int hashCode() { 239 return (new Long (id)).hashCode(); 240 } 241 242 public String toString() { 243 return String.valueOf(id); 244 } 245 246 private boolean connectionErrorOccurred = false; 248 249 public void setConnectionErrorOccurred() { 250 connectionErrorOccurred = true; 251 } 252 253 public boolean hasConnectionErrorOccurred() { 254 return connectionErrorOccurred; 255 } 256 257 public void setResourceState(ResourceState state) { 258 this.state = state; 259 } 260 261 public ResourceState getResourceState() { 262 return state; 263 } 264 265 public void setListener(ConnectionEventListener l) { 266 this.listener = l; 267 } 268 269 public ConnectionEventListener getListener() { 270 return listener; 271 } 272 273 public boolean isShareable() { 274 return alloc.shareableWithinComponent(); 275 } 276 277 public boolean isEnlisted() { 278 if (state != null) 279 return state.isEnlisted(); 280 else 281 return false; 282 } 283 284 public boolean isAssociated() { 285 return associated_; 286 } 287 288 public void setAssociated( boolean flag ) { 289 associated_ = flag; 290 } 291 292 public long getThreadId() { 293 return threadId_; 294 } 295 296 public void setThreadId( long threadId ) { 297 threadId_ = threadId; 298 } 299 300 public boolean supportsLazyEnlistment() { 301 return supportsLazyEnlistment_; 302 } 303 304 public boolean supportsLazyAssociation() { 305 return supportsLazyAssoc_; 306 } 307 308 public boolean isDirty() { 309 return dirty_; 310 } 311 312 public void setDirty() { 313 dirty_ = true; 314 } 315 316 321 public boolean isEnlistmentSuspended() 322 { 323 return enlistmentSuspended; 324 } 325 326 public void setEnlistmentSuspended(boolean enlistmentSuspended) 327 { 328 this.enlistmentSuspended = enlistmentSuspended; 329 } 330 331 public long getLastValidated() { 332 return lastValidated; 333 } 334 335 public void setLastValidated(long lastValidated) { 336 this.lastValidated = lastValidated; 337 } 338 339 } 340 | Popular Tags |