1 23 24 package com.sun.enterprise.connectors; 25 26 import com.sun.enterprise.config.serverbeans.*; 27 import com.sun.enterprise.deployment.ConnectorDescriptor; 28 import com.sun.logging.LogDomains; 29 import javax.resource.spi.ManagedConnectionFactory ; 30 import java.util.HashMap ; 31 import java.util.logging.*; 32 import java.util.List ; 33 import java.util.Map ; 34 import java.util.ArrayList ; 35 import com.sun.enterprise.connectors.authentication.RuntimeSecurityMap; 36 37 38 49 50 public class ConnectorRegistry { 51 52 protected static ConnectorRegistry connectorRegistryInstance; 53 54 59 protected HashMap resourceAdapters; 60 protected HashMap factories; 61 protected HashMap resourceAdapterConfig; 62 static Logger _logger = LogDomains.getLogger(LogDomains.RSR_LOGGER); 63 64 67 68 public static ConnectorRegistry getInstance() { 69 if (connectorRegistryInstance == null) { 70 connectorRegistryInstance = new ConnectorRegistry(); 71 _logger.log(Level.FINE,"creating new connector registry"); 72 } 73 logFine("returning the connector registry"); 74 return connectorRegistryInstance; 75 } 76 77 81 82 protected ConnectorRegistry() { 83 resourceAdapters = new HashMap (); 84 factories = new HashMap (); 85 resourceAdapterConfig = new HashMap (); 86 _logger.log(Level.FINE,"initialized the connector registry"); 87 } 88 89 94 95 public void addActiveResourceAdapter( String rarModuleName, 96 ActiveResourceAdapter rar) { 97 synchronized( resourceAdapters ) { 98 resourceAdapters.put(rarModuleName,rar); 99 } 100 _logger.log(Level.FINE, 101 "Added the active resource adapter to connector registry", 102 rarModuleName); 103 } 104 105 113 114 public boolean removeActiveResourceAdapter(String rarModuleName) { 115 Object o = null; 116 117 synchronized( resourceAdapters ) { 118 o = resourceAdapters.remove( rarModuleName ); 119 } 120 121 if( o == null) { 122 logFine("Failed to remove the resource adapter from connector registry" + 123 rarModuleName); 124 return false; 125 } else { 126 _logger.log(Level.FINE, 127 "removed the active resource adapter from connector registry", 128 rarModuleName); 129 return true; 130 } 131 } 132 133 138 139 public ActiveResourceAdapter getActiveResourceAdapter( 140 String rarModuleName) { 141 if(rarModuleName != null) { 142 _logger.log(Level.FINE, 143 "returning/found the resource adapter from connector registry", 144 rarModuleName); 145 return (ActiveResourceAdapter) resourceAdapters.get(rarModuleName); 146 } else { 147 _logger.log(Level.FINE, 148 "Resourceadapter not found in connector registry.Returning null", 149 rarModuleName); 150 return null; 151 } 152 } 153 154 160 161 public boolean isMCFCreated (String poolName) { 162 boolean created = factories.containsKey( poolName ); 163 logFine("isMCFCreated " + poolName + " - " + created); 164 return created; 165 } 166 167 172 173 public boolean removeManagedConnectionFactory(String poolName) { 174 if(factories.remove(poolName) == null) { 175 _logger.log(Level.FINE, 176 "Failed to remove the MCF from connector registry.", poolName); 177 return false; 178 } else { 179 logFine("removeMCF " + poolName + " - " + !factories.containsKey(poolName)); 180 return true; 181 } 182 } 183 184 188 189 public void addManagedConnectionFactory(String poolName, 190 PoolMetaData pmd ) { 191 factories.put(poolName, pmd); 192 logFine("Added MCF to connector registry for: "+ poolName); 193 } 194 195 199 200 public ManagedConnectionFactory getManagedConnectionFactory( 201 String poolName) { 202 if(poolName != null) { 203 _logger.log(Level.FINE, 204 "Returning the MCF from connector registry.", poolName); 205 206 PoolMetaData pmd = (PoolMetaData) factories.get( poolName ); 207 if (pmd != null) { 208 return pmd.getMCF(); 209 } 210 211 } 212 return null; 213 } 214 215 216 222 223 public boolean isRegistered(String rarModuleName) { 224 _logger.log(Level.FINE, 225 "Checking for MCF presence in connector registry.",rarModuleName); 226 synchronized(resourceAdapters ) { 227 return resourceAdapters.containsKey(rarModuleName); 228 } 229 } 230 231 235 236 public ConnectorDescriptor getDescriptor(String rarModuleName) { 237 ActiveResourceAdapter ar = null; 238 if(rarModuleName != null) { 239 ar = (ActiveResourceAdapter) resourceAdapters.get(rarModuleName); 240 } 241 if (ar != null) { 242 _logger.log(Level.FINE, 243 "Found/returing Connector descriptor in connector registry.", 244 rarModuleName); 245 return ar.getDescriptor(); 246 } else { 247 _logger.log(Level.FINE, 248 "Couldnot find Connector descriptor in connector registry.", 249 rarModuleName); 250 return null; 251 } 252 } 253 254 261 262 public RuntimeSecurityMap getRuntimeSecurityMap(String poolName) { 263 if(poolName != null) { 264 _logger.log(Level.FINE, 265 "Returing the security map from connector registry.", poolName); 266 PoolMetaData pmd = (PoolMetaData)factories.get(poolName); 267 return pmd.getRuntimeSecurityMap(); 268 } else { 269 return null; 270 } 271 } 272 273 278 279 public ResourceAdapterConfig getResourceAdapterConfig(String rarName) { 280 if(rarName != null) { 281 _logger.log(Level.FINE, 282 "Returing the resourceadapter Config from registry.",rarName); 283 return (ResourceAdapterConfig)resourceAdapterConfig.get(rarName); 284 } else { 285 return null; 286 } 287 } 288 289 294 295 public void addResourceAdapterConfig(String rarName, 296 ResourceAdapterConfig raConfig) { 297 if( rarName != null) { 298 _logger.log(Level.FINE, 299 "Adding the resourceAdapter Config to connector registry.", 300 rarName); 301 resourceAdapterConfig.put(rarName,raConfig); 302 } 303 } 304 305 310 311 public boolean removeResourceAdapterConfig(String rarName) { 312 if(resourceAdapterConfig.remove(rarName) == null) { 313 _logger.log(Level.FINE, 314 "failed to remove the resourceAdapter config from registry.", 315 rarName); 316 return false; 317 } else { 318 _logger.log(Level.FINE, 319 "Removed the resourceAdapter config map from registry.", 320 rarName); 321 return true; 322 } 323 } 324 325 329 public ActiveResourceAdapter[] getAllActiveResourceAdapters() { 330 return (ActiveResourceAdapter[]) 331 this.resourceAdapters.values(). 332 toArray(new ActiveResourceAdapter[]{}); 333 } 334 335 336 static private void logFine( String msg ) { 337 if ( msg != null && _logger.isLoggable(Level.FINE) ) { 338 _logger.fine( msg ); 339 } 340 } 341 342 public PoolMetaData getPoolMetaData( String poolName ) { 343 return (PoolMetaData) factories.get( poolName ); 344 } 345 } 346 | Popular Tags |