1 22 package org.jboss.system.deployers; 23 24 import javax.management.ObjectName ; 25 26 import org.jboss.deployers.plugins.deployers.helpers.AbstractSimpleRealDeployer; 27 import org.jboss.deployers.spi.DeploymentException; 28 import org.jboss.deployers.spi.deployer.DeploymentUnit; 29 import org.jboss.mx.loading.RepositoryClassLoader; 30 import org.jboss.system.ServiceContext; 31 import org.jboss.system.ServiceController; 32 import org.jboss.system.metadata.ServiceDeployment; 33 import org.jboss.system.metadata.ServiceMetaData; 34 35 44 public class ServiceDeployer extends AbstractSimpleRealDeployer<ServiceMetaData> 45 { 46 47 private final ServiceController controller; 48 49 55 public ServiceDeployer(ServiceController controller) 56 { 57 super(ServiceMetaData.class); 58 if (controller == null) 59 throw new IllegalArgumentException ("Null controller"); 60 this.controller = controller; 61 } 62 63 public void deploy(DeploymentUnit unit, ServiceMetaData deployment) throws DeploymentException 64 { 65 ObjectName name = deployment.getObjectName(); 66 try 67 { 68 ObjectName loaderName = deployment.getClassLoaderName(); 69 if (loaderName == null) 70 { 71 ClassLoader cl = unit.getClassLoader(); 72 if (cl != null && cl instanceof RepositoryClassLoader) 73 loaderName = ((RepositoryClassLoader) cl).getObjectName(); 74 } 75 76 controller.install(deployment, loaderName); 77 ServiceContext context = controller.getServiceContext(name); 78 if (context == null) 79 throw new IllegalStateException ("No context for " + name); 80 try 81 { 82 create(context); 83 try 84 { 85 start(context); 86 } 87 catch (Throwable t) 88 { 89 destroy(name); 90 throw t; 91 } 92 } 93 catch (Throwable t) 94 { 95 remove(name); 96 throw t; 97 } 98 } 99 catch (Throwable t) 100 { 101 throw DeploymentException.rethrowAsDeploymentException("Error deploying: " + name, t); 102 } 103 } 104 105 public void undeploy(DeploymentUnit unit, ServiceMetaData deployment) 106 { 107 ObjectName name = deployment.getObjectName(); 108 ServiceContext context = controller.getServiceContext(name); 109 if (context != null) 110 { 111 stop(name); 112 destroy(name); 113 remove(name); 114 } 115 } 116 117 protected void create(ServiceContext context) throws Throwable 118 { 119 controller.create(context.objectName); 120 } 121 122 protected void start(ServiceContext context) throws Throwable 123 { 124 controller.start(context.objectName); 125 } 126 127 protected void stop(ObjectName name) 128 { 129 try 130 { 131 controller.stop(name); 132 } 133 catch (Throwable t) 134 { 135 log.warn("Error during stop for " + name, t); 136 } 137 } 138 139 protected void destroy(ObjectName name) 140 { 141 try 142 { 143 controller.destroy(name); 144 } 145 catch (Throwable t) 146 { 147 log.warn("Error during destroy for " + name, t); 148 } 149 } 150 151 protected void remove(ObjectName name) 152 { 153 try 154 { 155 controller.remove(name); 156 } 157 catch (Throwable t) 158 { 159 log.warn("Error during destroy for " + name, t); 160 } 161 } 162 } 163 | Popular Tags |