1 28 29 package com.caucho.j2ee.deployclient; 30 31 import com.caucho.hessian.client.HessianProxyFactory; 32 import com.caucho.util.L10N; 33 34 import javax.enterprise.deploy.model.DeployableObject ; 35 import javax.enterprise.deploy.shared.DConfigBeanVersionType ; 36 import javax.enterprise.deploy.shared.ModuleType ; 37 import javax.enterprise.deploy.spi.DeploymentConfiguration ; 38 import javax.enterprise.deploy.spi.DeploymentManager ; 39 import javax.enterprise.deploy.spi.Target ; 40 import javax.enterprise.deploy.spi.TargetModuleID ; 41 import javax.enterprise.deploy.spi.exceptions.DConfigBeanVersionUnsupportedException ; 42 import javax.enterprise.deploy.spi.exceptions.DeploymentManagerCreationException ; 43 import javax.enterprise.deploy.spi.exceptions.InvalidModuleException ; 44 import javax.enterprise.deploy.spi.exceptions.TargetException ; 45 import javax.enterprise.deploy.spi.status.ProgressObject ; 46 import java.io.File ; 47 import java.io.FileInputStream ; 48 import java.io.InputStream ; 49 import java.util.Locale ; 50 import java.util.logging.Level ; 51 import java.util.logging.Logger ; 52 53 56 public class DeploymentManagerImpl implements DeploymentManager { 57 private static final L10N L = new L10N(DeploymentManagerImpl.class); 58 private static final Logger log = Logger.getLogger(DeploymentManagerImpl.class.getName()); 59 60 private String _uri; 61 62 private DeploymentProxyAPI _proxy; 63 64 DeploymentManagerImpl(String uri) 65 { 66 int p = uri.indexOf("http"); 67 if (p < 0) 68 throw new IllegalArgumentException (uri); 69 70 _uri = uri.substring(p); 71 } 72 73 76 void connect(String user, String password) 77 throws DeploymentManagerCreationException 78 { 79 try { 80 HessianProxyFactory factory = new HessianProxyFactory(); 81 82 factory.setUser(user); 83 factory.setPassword(password); 84 factory.setReadTimeout(120000); 85 86 _proxy = 87 (DeploymentProxyAPI) factory.create(DeploymentProxyAPI.class, _uri); 88 } catch (Exception e) { 89 log.log(Level.FINE, e.toString(), e); 90 91 DeploymentManagerCreationException exn; 92 93 exn = new DeploymentManagerCreationException (e.getMessage()); 94 exn.initCause(e); 95 throw exn; 96 } 97 } 98 99 102 public Target []getTargets() 103 throws IllegalStateException 104 { 105 if (_proxy == null) 106 throw new IllegalStateException ("DeploymentManager is disconnected"); 107 108 Thread thread = Thread.currentThread(); 109 ClassLoader oldLoader = thread.getContextClassLoader(); 110 try { 111 thread.setContextClassLoader(getClass().getClassLoader()); 112 113 Target []targets = _proxy.getTargets(); 114 115 if (targets == null) 116 return new Target [0]; 117 118 return targets; 119 } catch (Throwable e) { 120 log.log(Level.INFO, e.toString(), e); 121 122 return new Target [0]; 123 } finally { 124 thread.setContextClassLoader(oldLoader); 125 } 126 } 127 128 131 public TargetModuleID []getRunningModules(ModuleType moduleType, 132 Target []targetList) 133 throws TargetException , IllegalStateException 134 { 135 return new TargetModuleID [0]; 136 } 137 138 141 public TargetModuleID []getNonRunningModules(ModuleType moduleType, 142 Target []targetList) 143 throws TargetException , IllegalStateException 144 { 145 return new TargetModuleID [0]; 146 } 147 148 151 public TargetModuleID []getAvailableModules(ModuleType moduleType, 152 Target []targetList) 153 throws TargetException , IllegalStateException 154 { 155 if (_proxy == null) 156 throw new IllegalStateException ("DeploymentManager is disconnected"); 157 158 Thread thread = Thread.currentThread(); 159 ClassLoader oldLoader = thread.getContextClassLoader(); 160 try { 161 thread.setContextClassLoader(getClass().getClassLoader()); 162 163 return _proxy.getAvailableModules(moduleType.toString()); 164 } finally { 165 thread.setContextClassLoader(oldLoader); 166 } 167 } 168 169 172 public DeploymentConfiguration createConfiguration(DeployableObject dObj) 173 throws InvalidModuleException 174 { 175 throw new UnsupportedOperationException (); 176 } 177 178 181 public ProgressObject distribute(Target []targetList, 182 File archive, 183 File deploymentPlan) 184 throws IllegalStateException 185 { 186 InputStream archiveIn = null; 187 InputStream ddIn = null; 188 189 try { 190 archiveIn = new FileInputStream (archive); 191 ddIn = new FileInputStream (deploymentPlan); 192 193 return distribute(targetList, archiveIn, ddIn); 194 195 } catch (Exception e) { 196 throw new RuntimeException (e); 197 } finally { 198 try { 199 if (archiveIn != null) 200 archiveIn.close(); 201 } catch (Throwable e) { 202 log.log(Level.FINE, e.toString(), e); 203 } 204 205 try { 206 if (ddIn != null) 207 ddIn.close(); 208 } catch (Throwable e) { 209 log.log(Level.FINE, e.toString(), e); 210 } 211 } 212 } 213 214 217 public ProgressObject distribute(Target []targetList, 218 InputStream archive, 219 InputStream deploymentPlan) 220 throws IllegalStateException 221 { 222 if (_proxy == null) { 223 String message = L.l("DeploymentManager is disconnected"); 224 225 log.log(Level.FINE, message); 226 227 ProgressObjectImpl progress = new ProgressObjectImpl(new TargetModuleID [] {}); 228 progress.failed(message); 229 230 return progress; 231 } 232 233 if (deploymentPlan == null) { 234 String message = L.l("{0} is required", "deployment plan"); 235 236 log.log(Level.FINE, message); 237 238 ProgressObjectImpl progress = new ProgressObjectImpl(new TargetModuleID [] {}); 239 progress.failed(message); 240 241 return progress; 242 } 243 244 Thread thread = Thread.currentThread(); 245 ClassLoader oldLoader = thread.getContextClassLoader(); 246 try { 247 thread.setContextClassLoader(getClass().getClassLoader()); 248 249 250 return _proxy.distribute(targetList, deploymentPlan, archive); 251 } finally { 252 thread.setContextClassLoader(oldLoader); 253 } 254 } 255 256 259 public ProgressObject start(TargetModuleID []moduleIDList) 260 throws IllegalStateException 261 { 262 if (_proxy == null) 263 throw new IllegalStateException ("DeploymentManager is disconnected"); 264 265 Thread thread = Thread.currentThread(); 266 ClassLoader oldLoader = thread.getContextClassLoader(); 267 try { 268 thread.setContextClassLoader(getClass().getClassLoader()); 269 270 return _proxy.start(moduleIDList); 271 } finally { 272 thread.setContextClassLoader(oldLoader); 273 } 274 } 275 276 279 public ProgressObject stop(TargetModuleID []moduleIDList) 280 throws IllegalStateException 281 { 282 if (_proxy == null) 283 throw new IllegalStateException ("DeploymentManager is disconnected"); 284 285 Thread thread = Thread.currentThread(); 286 ClassLoader oldLoader = thread.getContextClassLoader(); 287 try { 288 thread.setContextClassLoader(getClass().getClassLoader()); 289 290 return _proxy.stop(moduleIDList); 291 } finally { 292 thread.setContextClassLoader(oldLoader); 293 } 294 } 295 296 299 public ProgressObject undeploy(TargetModuleID []moduleIDList) 300 throws IllegalStateException 301 { 302 if (_proxy == null) 303 throw new IllegalStateException ("DeploymentManager is disconnected"); 304 305 Thread thread = Thread.currentThread(); 306 ClassLoader oldLoader = thread.getContextClassLoader(); 307 try { 308 thread.setContextClassLoader(getClass().getClassLoader()); 309 310 return _proxy.undeploy(moduleIDList); 311 } finally { 312 thread.setContextClassLoader(oldLoader); 313 } 314 } 315 316 319 public boolean isRedeploySupported() 320 { 321 return false; 322 } 323 324 327 public ProgressObject redeploy(TargetModuleID []targetList, 328 File archive, 329 File deploymentPlan) 330 throws IllegalStateException 331 { 332 throw new UnsupportedOperationException (); 333 } 334 335 338 public ProgressObject redeploy(TargetModuleID []targetList, 339 InputStream archive, 340 InputStream deploymentPlan) 341 throws IllegalStateException 342 { 343 throw new UnsupportedOperationException (); 344 } 345 346 349 public void release() 350 { 351 } 352 353 356 public Locale getDefaultLocale() 357 { 358 throw new UnsupportedOperationException (); 359 } 360 361 364 public Locale getCurrentLocale() 365 { 366 throw new UnsupportedOperationException (); 367 } 368 369 372 public void setLocale(Locale locale) 373 { 374 throw new UnsupportedOperationException (); 375 } 376 377 380 public Locale []getSupportedLocales() 381 { 382 throw new UnsupportedOperationException (); 383 } 384 385 388 public boolean isLocaleSupported(Locale locale) 389 { 390 return false; 391 } 392 393 396 public DConfigBeanVersionType getDConfigBeanVersion() 397 { 398 return DConfigBeanVersionType.V1_4; 399 } 400 401 404 public boolean isDConfigBeanVersionSupported(DConfigBeanVersionType version) 405 { 406 return true; 407 } 408 409 412 public void setDConfigBeanVersionSupported(DConfigBeanVersionType version) 413 throws DConfigBeanVersionUnsupportedException 414 { 415 } 416 417 420 public String toString() 421 { 422 return "DeploymentManagerImpl[" + _uri + "]"; 423 } 424 } 425 426 | Popular Tags |