1 23 24 package com.sun.enterprise.connectors; 25 26 import com.sun.logging.LogDomains; 27 28 import java.util.Iterator ; 29 import java.util.Set ; 30 import java.util.logging.*; 31 32 import com.sun.enterprise.*; 33 import com.sun.enterprise.admin.monitor.registry.MonitoredObjectType; 34 import com.sun.enterprise.admin.monitor.registry.MonitoringRegistry; 35 import com.sun.enterprise.config.*; 36 import com.sun.enterprise.connectors.util.*; 37 import com.sun.enterprise.connectors.work.monitor.ConnectorWorkMonitoringLevelListener; 38 import com.sun.enterprise.deployment.*; 39 import com.sun.enterprise.deployment.archivist.ApplicationArchivist; 40 import com.sun.enterprise.deployment.deploy.shared.FileArchive; 41 import com.sun.enterprise.resource.*; 42 import com.sun.enterprise.server.*; 43 import com.sun.enterprise.util.*; 44 45 import java.io.IOException ; 46 import java.security.AccessController ; 47 import java.security.PrivilegedAction ; 48 49 import org.xml.sax.SAXParseException ; 50 51 52 58 59 60 public class ConnectorServiceImpl implements ConnectorConstants { 61 static Logger _logger = LogDomains.getLogger(LogDomains.RSR_LOGGER); 62 63 protected static ConnectorRegistry _registry = 64 ConnectorRegistry.getInstance(); 65 66 protected static ConnectorRuntime _runtime = ConnectorRuntime.getRuntime(); 67 68 69 private boolean debug=true; 70 protected static int environment = CLIENT; 71 72 75 76 public ConnectorServiceImpl() { 77 } 78 79 86 87 public static void initialize(int environ) { 88 environment = environ; 89 } 90 91 97 98 public static int getEnviron() { 99 return environment; 100 } 101 102 107 108 public String getDefaultPoolName(String jndiName) { 109 return jndiName; 111 } 112 113 120 121 public String getDefaultPoolName(String moduleName, 122 String connectionDefName) { 123 return moduleName+POOLNAME_APPENDER+connectionDefName; 124 } 125 126 133 public String getDefaultResourceName(String moduleName, 134 String connectionDefName) { 135 String resourceJNDIName = ConnectorAdminServiceUtils. 138 getReservePrefixedJNDINameForResource(moduleName); 139 return resourceJNDIName + RESOURCENAME_APPENDER + connectionDefName; 140 } 141 142 145 146 public void create() throws ConnectorRuntimeException { 147 148 } 149 150 public void destroy() throws ConnectorRuntimeException { 151 152 } 153 154 158 159 public static boolean isServer() { 160 if(getEnviron() == SERVER) { 161 return true; 162 } else { 163 return false; 164 } 165 } 166 167 172 public boolean checkAndLoadResource(String resname) { 173 resname = ConnectorAdminServiceUtils.getOriginalResourceName(resname); 179 _logger.fine("ConnectorServiceImpl :: checkAndLoadResource resolved to " + 180 "load " + resname); 181 182 ResourcesUtil resutil = ResourcesUtil.getInstance(); 183 DeferredResourceConfig defResConfig = resutil.getDeferredResourceConfig( 184 resname); 185 return loadResourcesAndItsRar(defResConfig); 186 } 187 188 public boolean checkAndLoadPoolResource(String poolName) { 189 190 ResourcesUtil resutil = ResourcesUtil.getInstance(); 191 DeferredResourceConfig defResConfig = resutil.getDeferredPoolConfig( 192 poolName); 193 return loadResourcesAndItsRar(defResConfig); 194 } 195 196 public boolean loadResourcesAndItsRar(DeferredResourceConfig defResConfig) { 197 if(defResConfig != null) { 198 try { 199 loadDeferredResources(defResConfig.getResourceAdapterConfig()); 200 String rarName = defResConfig.getRarName(); 201 loadDeferredResourceAdapter(rarName); 202 final ConfigBean[] resToLoad = defResConfig.getResourcesToLoad(); 203 AccessController.doPrivileged(new PrivilegedAction () { 204 public Object run() { 205 try { 206 loadDeferredResources(resToLoad); 207 } catch(Exception ex) { 208 _logger.log( Level.SEVERE, 209 "failed to load resources/ResourceAdapter"); 210 _logger.log(Level.SEVERE,"" ,ex); 211 } 212 return null; 213 } 214 }); 215 } catch(Exception ex) { 216 _logger.log( 217 Level.SEVERE,"failed to load resources/ResourceAdapter"); 218 _logger.log(Level.SEVERE,"" ,ex); 219 return false; 220 } 221 return true; 222 } 223 return false; 224 } 225 226 227 public void loadDeferredResourceAdapter(String rarName) 228 throws ConnectorRuntimeException 229 { 230 try { 231 ManagerFactory.getSAConnectorModulesManager(). 232 loadOneSystemApp(rarName, true); 233 } catch (Exception e) { 234 ConnectorRuntimeException ce = 235 new ConnectorRuntimeException(e.getMessage()); 236 ce.initCause(e); 237 throw ce; 238 } 239 } 240 241 public void loadDeferredResources(ConfigBean[] resourcesToLoad) 242 throws Exception 243 { 244 if(resourcesToLoad == null || resourcesToLoad.length == 0) { 245 return; 246 } 247 String resourceType = null; 248 ResourceDeployer deployer = null; 249 ResourcesUtil resourceUtil = ResourcesUtil.getInstance(); 250 for(int i=0;i<resourcesToLoad.length;++i) { 251 if(resourcesToLoad[i] == null) { 252 continue; 253 } else if (resourceUtil.isEnabled(resourcesToLoad[i])) { 254 resourceType = resourceUtil.getResourceType(resourcesToLoad[i]); 255 deployer = resourceUtil.getResourceDeployer(resourceType); 256 if(deployer != null) { 257 deployer.deployResource(resourcesToLoad[i]); 258 } 259 } 260 } 261 } 262 263 public void ifSystemRarLoad(String rarName) 264 throws ConnectorRuntimeException 265 { 266 ResourcesUtil resUtil = ResourcesUtil.getInstance(); 267 if(resUtil.belongToSystemRar(rarName)){ 268 loadDeferredResourceAdapter(rarName); 269 } 270 } 271 272 281 public boolean checkAccessibility(String rarName, ClassLoader loader) { 282 ActiveResourceAdapter ar = _registry.getActiveResourceAdapter(rarName); 283 if (ar != null && loader != null) { ClassLoader rarLoader = ar.getClassLoader(); 285 if (rarLoader != null && (!(rarLoader instanceof ConnectorClassLoader))) { 287 ClassLoader parent = loader; 288 while (true) { 289 if (parent.equals(rarLoader)) { 290 return true; 291 } 292 293 final ClassLoader temp = parent; 294 Object obj = AccessController.doPrivileged( new PrivilegedAction () { 295 public Object run() { 296 return temp.getParent(); 297 } 298 }); 299 300 if (obj == null) { 301 break; 302 } else { 303 parent = (ClassLoader ) obj; 304 } 305 } 306 return false; 308 } 309 } 310 return true; 311 } 312 313 321 322 public ConnectorDescriptor getConnectorDescriptor(String rarName) 323 throws ConnectorRuntimeException 324 { 325 326 if(rarName == null) { 327 return null; 328 } 329 ConnectorDescriptor desc = null; 330 desc = _registry.getDescriptor(rarName); 331 if(desc != null) { 332 return desc; 333 } 334 String moduleDir = null; 335 ResourcesUtil resUtil = ResourcesUtil.getInstance(); 336 337 if (rarName.indexOf(ConnectorConstants.EMBEDDEDRAR_NAME_DELIMITER) != -1){ 340 try { 341 desc = loadConnectorDescriptorForEmbeddedRAR(rarName); 342 if (desc != null) return desc; 343 } catch (ConnectorRuntimeException e) { 344 throw e; 345 } 346 } 347 348 if(resUtil.belongToSystemRar(rarName)){ 349 ResourceInstaller installer = 350 Switch.getSwitch().getResourceInstaller(); 351 moduleDir = installer.getSystemModuleLocation(rarName); 352 } else { 353 moduleDir = resUtil.getLocation(rarName); 354 } 355 if (moduleDir != null) { 356 desc = ConnectorDDTransformUtils.getConnectorDescriptor(moduleDir); 357 } else { 358 _logger.log(Level.SEVERE, 359 "rardeployment.no_module_deployed", rarName); 360 } 361 return desc; 362 } 363 364 private ConnectorDescriptor loadConnectorDescriptorForEmbeddedRAR(String rarName) throws ConnectorRuntimeException { 365 try { 368 String appName = rarName.substring(0, rarName.indexOf(ConnectorConstants.EMBEDDEDRAR_NAME_DELIMITER)); 369 String actualRarName = rarName.substring(rarName.indexOf(ConnectorConstants.EMBEDDEDRAR_NAME_DELIMITER) + 1); 370 String appDeployLocation = ResourcesUtil.getInstance().getApplicationDeployLocation(appName); 371 372 FileArchive in = new FileArchive(); 373 in.open(appDeployLocation); 374 ApplicationArchivist archivist = new ApplicationArchivist(); 375 Application application = (Application) archivist.open(in); 376 Set s = application.getRarDescriptors(); 378 for (Iterator iter = s.iterator(); iter.hasNext();) { 379 ConnectorDescriptor element = (ConnectorDescriptor) iter.next(); 380 String rardescname = element.getDeployName().substring( 382 0, element.getDeployName().indexOf(".rar")); 383 if(rardescname.equals(actualRarName)){ 384 return element; 385 } 386 } 387 } catch (SAXParseException e) { 388 ConnectorRuntimeException crex = new ConnectorRuntimeException("" + 389 "SAXParseException while trying to load connector descriptor for embedded RAR"); 390 crex.initCause(e); 391 throw crex; 392 } catch (IOException e) { 393 ConnectorRuntimeException crex = new ConnectorRuntimeException("" + 394 "SAXParseException while trying to load connector descriptor for embedded RAR"); 395 crex.initCause(e); 396 throw crex; 397 } 398 return null; 399 400 } 401 402 409 public void switchOnMatching(String rarName, String poolName) { 410 if (rarName.equals(ConnectorRuntime.JDBCDATASOURCE_RA_NAME) || 413 rarName.equals(ConnectorRuntime.JDBCCONNECTIONPOOLDATASOURCE_RA_NAME) || 414 rarName.equals(ConnectorRuntime.JDBCXA_RA_NAME)) { 415 416 PoolManager poolMgr = Switch.getSwitch().getPoolManager(); 417 boolean result = poolMgr.switchOnMatching(poolName); 418 if (result == false) { 419 try { 420 _runtime.switchOnMatchingInJndi(poolName); 421 } catch (ConnectorRuntimeException cre) { 422 } 424 } 425 } 426 427 } 428 429 433 public void initializeConnectorMonitoring() { 434 Switch.getSwitch().getPoolManager().initializeMonitoring(); 435 initializeWorkMgmtAndEndPointMonitoring(); 436 } 437 438 442 private void initializeWorkMgmtAndEndPointMonitoring() { 443 try { 444 final ConnectorWorkMonitoringLevelListener cwmll 445 = new ConnectorWorkMonitoringLevelListener(); 446 448 AccessController.doPrivileged(new PrivilegedAction () { 449 public Object run() { 450 ServerContext ctxt = ApplicationServer.getServerContext(); 451 if (ctxt != null) { 452 MonitoringRegistry monitoringRegistry_ 453 = ctxt.getMonitoringRegistry(); 454 monitoringRegistry_.registerMonitoringLevelListener(cwmll, 456 MonitoredObjectType.CONNECTOR_WORKMGMT); 457 458 462 } 463 return null; 464 } 465 }); 466 467 _logger.log( Level.FINE, "poolmon.init_monitoring_registry"); 468 } catch(Exception e) { 469 _logger.log( Level.INFO, "poolmon.error_registering_listener", 470 e); 471 } 472 } 473 } 474 | Popular Tags |