1 23 24 37 package com.sun.enterprise.server; 38 39 import com.sun.enterprise.config.serverbeans.*; 40 import com.sun.enterprise.config.*; 41 import com.sun.enterprise.config.ConfigException; 42 import com.sun.enterprise.admin.event.ResourceDeployEvent; 43 import com.sun.enterprise.admin.event.ResourceDeployEventListener; 44 import com.sun.enterprise.admin.event.AdminEventListenerException; 45 import com.sun.enterprise.admin.event.AdminEventMulticaster; 46 import com.sun.enterprise.admin.event.AdminEventResult; 47 import com.sun.enterprise.admin.event.BaseDeployEvent; 48 import com.sun.enterprise.util.i18n.StringManager; 49 50 51 import java.util.logging.Level ; 52 import java.util.logging.Logger ; 53 import com.sun.logging.LogDomains; 54 55 56 66 class ResourceManager implements ResourceDeployEventListener { 67 68 69 static Logger _logger = LogDomains.getLogger(LogDomains.CORE_LOGGER); 70 71 72 private ServerContext serverContext_; 73 74 75 private ResourceDeployerFactory factory_ = null; 76 private static StringManager localStrings = StringManager.getManager( 77 "com.sun.enterprise.server"); 78 79 84 public ResourceManager(ServerContext sc) { 85 serverContext_ = sc; 86 factory_ = new ResourceDeployerFactory(); 87 } 88 89 91 public void resourceDeployed(ResourceDeployEvent event) 92 throws AdminEventListenerException { 93 94 assert(event.getJ2EEComponentType() == BaseDeployEvent.RESOURCE); 95 96 try { 97 Resources rbeans = getResources(event.getConfigContext()); 98 String type = event.getResourceType(); 99 100 if (type.equals(ResourceDeployEvent.RES_TYPE_JDBC)){ 101 ResourcesUtil.getInstance().setConfigContext(event.getConfigContext()); 102 ResourcesUtil.getInstance().setReinitConfigContext(false); 103 } 104 105 Object resource = 106 factory_.getResource(type, event.getResourceName(), rbeans); 107 if (ResourcesUtil.getInstance().isEnabled(event.getConfigContext(), (ConfigBean)resource)) { 108 factory_.getResourceDeployer(type).deployResource(resource); 109 } 110 111 _logger.log(Level.INFO, "core.resourcedeployed", 112 type + ":" + event.getResourceName()); 113 } catch (Exception e) { 114 _logger.log(Level.SEVERE,"core.resourcedeploy_error", e); 115 throw new AdminEventListenerException(e.getMessage()); 116 } finally { 117 ResourcesUtil.getInstance().setReinitConfigContext(true); 118 } 119 } 120 121 public void resourceUndeployed(ResourceDeployEvent event) 122 throws AdminEventListenerException { 123 124 assert(event.getJ2EEComponentType() == BaseDeployEvent.RESOURCE); 125 126 try { 127 Resources rbeans = getResources(event.getOldConfigContext()); 129 String type = event.getResourceType(); 130 Object resource = 131 factory_.getResource(type, event.getResourceName(), rbeans); 132 ResourcesUtil.getInstance().setConfigContext(event.getConfigContext()); 133 ResourcesUtil.getInstance().setReinitConfigContext(false); 134 135 factory_.getResourceDeployer(type).undeployResource(resource); 136 137 _logger.log(Level.INFO, "core.resourceundeployed", 138 type + ":" + event.getResourceName()); 139 } catch (UnsupportedOperationException nse) { 140 AdminEventMulticaster.notifyFailure(event, AdminEventResult.RESTART_NEEDED); 141 _logger.log(Level.INFO,"core.resource_undeployed_restart_needed", event.getResourceName()); 142 } catch (Exception e) { 143 _logger.log(Level.SEVERE,"core.resourceundeploy_error",e); 144 throw new AdminEventListenerException(e.getMessage()); 145 } finally { 146 ResourcesUtil.getInstance().setReinitConfigContext(true); 147 } 148 } 149 150 public void resourceRedeployed(ResourceDeployEvent event) 151 throws AdminEventListenerException { 152 153 assert(event.getJ2EEComponentType() == BaseDeployEvent.RESOURCE); 154 155 try { 156 Resources rbeans = getResources(event.getConfigContext()); 157 String type = event.getResourceType(); 158 Object resource = 159 factory_.getResource(type, event.getResourceName(), rbeans); 160 factory_.getResourceDeployer(type).redeployResource(resource); 161 162 _logger.log(Level.INFO, "core.resourceredeployed", 163 type + ":" + event.getResourceName()); 164 } catch (UnsupportedOperationException nse) { 165 AdminEventMulticaster.notifyFailure(event, AdminEventResult.RESTART_NEEDED); 166 _logger.log(Level.INFO,"core.resource_redeployed_restart_needed", event.getResourceName()); 167 } catch (Exception e) { 168 _logger.log(Level.SEVERE,"core.resourceredeploy_error",e); 169 throw new AdminEventListenerException(e.getMessage()); 170 } 171 } 172 173 public void resourceEnabled(ResourceDeployEvent event) 174 throws AdminEventListenerException { 175 176 assert(event.getJ2EEComponentType() == BaseDeployEvent.RESOURCE); 177 178 try { 179 Resources rbeans = getResources(event.getConfigContext()); 180 String type = event.getResourceType(); 181 Object resource = 182 factory_.getResource(type, event.getResourceName(), rbeans); 183 factory_.getResourceDeployer(type).enableResource(resource); 184 185 _logger.log(Level.INFO, "core.resourceenabled", 186 type + ":" + event.getResourceName()); 187 } catch (UnsupportedOperationException nse) { 188 AdminEventMulticaster.notifyFailure(event, AdminEventResult.RESTART_NEEDED); 189 _logger.log(Level.INFO,"core.resource_enabled_restart_needed", event.getResourceName()); 190 } catch (Exception e) { 191 _logger.log(Level.SEVERE,"core.resourceenabled_error",e); 192 throw new AdminEventListenerException(e.getMessage()); 193 } 194 } 195 196 public void resourceDisabled(ResourceDeployEvent event) 197 throws AdminEventListenerException { 198 199 assert(event.getJ2EEComponentType() == BaseDeployEvent.RESOURCE); 200 201 try { 202 Resources rbeans = getResources(event.getConfigContext()); 203 String type = event.getResourceType(); 204 Object resource = 205 factory_.getResource(type, event.getResourceName(), rbeans); 206 factory_.getResourceDeployer(type).disableResource(resource); 207 208 _logger.log(Level.INFO, "core.resourcedisabled", 209 type + ":" + event.getResourceName()); 210 } catch (UnsupportedOperationException nse) { 211 AdminEventMulticaster.notifyFailure(event, AdminEventResult.RESTART_NEEDED); 212 _logger.log(Level.INFO,"core.resource_disabled_restart_needed", event.getResourceName()); 213 } catch (Exception e) { 214 _logger.log(Level.SEVERE,"core.resourcedisabled_error",e); 215 throw new AdminEventListenerException(e.getMessage()); 216 } 217 } 218 219 public void resourceReferenceAdded(ResourceDeployEvent event) 220 throws AdminEventListenerException { 221 222 resourceDeployed(event); 223 } 224 225 public void resourceReferenceRemoved(ResourceDeployEvent event) 226 throws AdminEventListenerException { 227 228 resourceUndeployed(event); 229 } 230 231 233 240 private Resources getResources(ConfigContext ctx) throws ConfigException { 241 242 Resources rbeans = ServerBeansFactory.getDomainBean(ctx).getResources(); 244 245 if (rbeans == null) { 246 String msg = localStrings.getString("resourceManager.resource_not_found"); 247 throw new ConfigException(msg); } 249 return rbeans; 250 } 251 } 252 | Popular Tags |