1 23 24 25 package com.sun.enterprise.resource; 26 27 import com.sun.enterprise.server.ResourceDeployer; 28 import com.sun.enterprise.server.ResourcesUtil; 29 30 import com.sun.enterprise.config.serverbeans.Resources; 31 import com.sun.enterprise.config.serverbeans.ConnectorResource; 32 import com.sun.enterprise.connectors.ConnectorAdminServiceUtils; 33 import com.sun.enterprise.connectors.ConnectorRuntime; 34 import com.sun.enterprise.connectors.ConnectorConnectionPool; 35 import com.sun.enterprise.deployment.ConnectionDefDescriptor; 36 import com.sun.logging.LogDomains; 37 import com.sun.enterprise.config.serverbeans.Domain; 38 import com.sun.enterprise.connectors.ConnectorConstants; 39 import javax.naming.InitialContext ; 40 import com.sun.enterprise.config.ConfigBean; 41 import com.sun.enterprise.config.ConfigException; 42 import com.sun.enterprise.connectors.util.ConnectionPoolObjectsUtils; 43 44 import java.util.logging.*; 45 import java.util.regex.Matcher ; 46 import java.util.regex.Pattern ; 47 48 53 54 public class ConnectorResourceDeployer implements ResourceDeployer { 55 56 static Logger _logger = LogDomains.getLogger(LogDomains.CORE_LOGGER); 57 public synchronized void deployResource(Object resource) throws Exception { 58 59 ConnectorResource domainResource = 60 (com.sun.enterprise.config.serverbeans.ConnectorResource)resource; 61 String jndiName = domainResource.getJndiName(); 62 String poolName = domainResource.getPoolName(); 63 ConnectorRuntime crt = ConnectorRuntime.getRuntime(); 64 _logger.log(Level.FINE, 65 "Calling backend to add connector resource",jndiName); 66 67 loadPool(domainResource); 69 70 crt.createConnectorResource(jndiName,poolName,null); 71 _logger.log(Level.FINE, 72 "Added connector resource in backend",jndiName); 73 } 74 75 public synchronized void undeployResource(Object resource) 76 throws Exception { 77 ConnectorResource domainResource = 78 (com.sun.enterprise.config.serverbeans.ConnectorResource)resource; 79 String jndiName = domainResource.getJndiName(); 80 ConnectorRuntime crt = ConnectorRuntime.getRuntime(); 81 crt.deleteConnectorResource(jndiName); 82 83 checkAndDeletePool(domainResource); 87 88 } 89 90 91 public synchronized void redeployResource(Object resource) 92 throws Exception { 93 } 94 95 public synchronized void disableResource(Object resource) 96 throws Exception { 97 undeployResource(resource); 98 } 99 100 public synchronized void enableResource(Object resource) throws Exception { 101 deployResource(resource); 102 } 103 104 public Object getResource(String name, Resources rbeans) throws Exception { 105 106 Object res = rbeans.getConnectorResourceByJndiName(name); 107 if (res == null) { 108 Exception ex = new Exception ("No such resource"); 109 _logger.log(Level.SEVERE,"no_resource",name); 110 _logger.log(Level.SEVERE,"",ex); 111 throw ex; 112 } 113 return res; 114 115 } 116 117 private void loadPool(ConnectorResource cr) throws Exception { 118 119 String poolName = cr.getPoolName(); 120 Resources resources = (Resources) cr.parent(); 121 ConfigBean cb = resources.getConnectorConnectionPoolByName(poolName); 122 com.sun.enterprise.config.serverbeans.ConnectorConnectionPool cp = 123 (com.sun.enterprise.config.serverbeans.ConnectorConnectionPool)cb; 124 if (cb != null) { 125 if (ConnectionPoolObjectsUtils.isPoolSystemPool(poolName)){ 126 createPool(cp); 127 } else { 128 try { 129 InitialContext ic = new InitialContext (); 130 ic.lookup(ConnectorAdminServiceUtils.getReservePrefixedJNDINameForPool(poolName)); 131 } catch (Exception e) { 132 createPool(cp); 134 } 135 } 136 } 137 } 138 139 146 private void checkAndDeletePool(ConnectorResource cr) throws Exception { 147 try { 148 String poolName = cr.getPoolName(); 149 Resources res = (Resources) cr.parent(); 150 151 boolean poolReferred = 152 ResourcesUtil.getInstance().isPoolReferredInServerInstance(poolName); 153 if (!poolReferred) { 154 _logger.fine("Deleting pool " + poolName + "as there is no more " + 155 "resource-refs to the pool in this server instance"); 156 com.sun.enterprise.config.serverbeans.ConnectorConnectionPool ccp 157 = res.getConnectorConnectionPoolByName(poolName); 158 ConnectorConnectionPoolDeployer deployer = 160 new ConnectorConnectionPoolDeployer(); 161 deployer.undeployResource(ccp); 162 } 163 164 } catch (ConfigException ce) { 165 _logger.warning(ce.getMessage()); 166 _logger.fine("Exception while deleting pool : " + ce ); 167 throw ce; 168 } 169 } 170 171 private void createPool(com.sun.enterprise.config.serverbeans.ConnectorConnectionPool cp) 172 throws Exception { 173 ConnectorConnectionPoolDeployer deployer = 174 new ConnectorConnectionPoolDeployer(); 175 176 deployer.deployResource(cp); 177 } 178 } 179 | Popular Tags |