deploymentservice.java
来自「RESIN 3.2 最新源码」· Java 代码 · 共 665 行 · 第 1/2 页
JAVA
665 行
String archiveName = "resin:type=EarDeploy,Host=" + host + ",*"; return loadArchiveMXBean(archiveName); } else return null; } private void createArchive(Path archivePath, DeploymentPlan plan, InputStream archiveIs) throws IOException { if (log.isLoggable(Level.FINER)) log.log(Level.FINER, L.l("jsr88 deploying archive {0}", archivePath)); Path originalPath = archivePath; String earFileName = archivePath.getTail(); if (earFileName.endsWith(".ear")) { // Uses ".__caucho_ear" to avoid premature expansion. String s = earFileName; s = s.substring(0, s.length() - 3) + "__caucho_ear"; archivePath = archivePath.getParent().lookup(s); if (log.isLoggable(Level.FINER)) log.log(Level.FINER, L.l("jsr88 creating temp archive {0}", archivePath)); } else { earFileName = null; } WriteStream archiveStream = null; ZipInputStream zipInputStream = null; ZipOutputStream zipOutputStream = null; try { archiveStream = archivePath.openWrite(); zipOutputStream = new ZipOutputStream(archiveStream); zipInputStream = new ZipInputStream(archiveIs); ZipEntry zipEntry = zipInputStream.getNextEntry(); TreeSet<String> entryNames = new TreeSet<String>(); int copyCount = 0; while (zipEntry != null) { if (log.isLoggable(Level.FINEST)) log.log(Level.FINEST, L.l("jsr88 copying entry {0}", zipEntry)); entryNames.add(zipEntry.getName()); zipOutputStream.putNextEntry(zipEntry); try { for (int ch = zipInputStream.read(); ch != -1; ch = zipInputStream.read()) zipOutputStream.write(ch); } catch (IOException e) { // XXX: unexpected end of ZLIB input stream. log.log(Level.WARNING, L.l("exception copying entry {0}", zipEntry), e); } zipEntry = zipInputStream.getNextEntry(); copyCount++; } if (log.isLoggable(Level.FINER)) log.log(Level.FINER, L.l("copied {0} entries", copyCount)); if (archiveIs.read() != -1) { if (log.isLoggable(Level.FINE)) log.log(Level.FINE, L.l("unexpected data at end of archive")); while (archiveIs.read() != -1) {} } int fileCount = 0; for (DeploymentPlan.PlanFile file : plan.getFileList()) { String zipEntryName = file.getPath(); if (zipEntryName.startsWith("/")) zipEntryName = zipEntryName.substring(1); if (log.isLoggable(Level.FINEST)) log.log(Level.FINEST, L.l("jsr88 plan file {0} output to {1}", file, zipEntryName)); if (entryNames.contains(zipEntryName)) log.log(Level.WARNING, L.l("plan file {0} overwrites existing file", zipEntryName)); entryNames.add(zipEntryName); zipEntry = new ZipEntry(zipEntryName); zipOutputStream.putNextEntry(zipEntry); file.writeToStream(zipOutputStream); fileCount++; } if (log.isLoggable(Level.FINER)) log.log(Level.FINER, L.l("created {0} entries from plan", fileCount)); zipInputStream.close(); zipInputStream = null; zipOutputStream.close(); zipOutputStream = null; archiveStream.close(); archiveStream = null; } finally { if (zipInputStream != null) { try { zipInputStream.close(); } catch (Exception ex) { log.log(Level.FINER, ex.toString(), ex); } } if (zipOutputStream != null) { try { zipOutputStream.close(); } catch (Exception ex) { log.log(Level.FINER, ex.toString(), ex); } } if (archiveStream != null) { try { archiveStream.close(); } catch (Exception ex) { log.log(Level.FINER, ex.toString(), ex); } } if (earFileName != null) { if (log.isLoggable(Level.FINER)) log.log(Level.FINER, L.l("jsr88 renaming temp archive {0} to {1}", archivePath, originalPath)); // Renames ".__caucho_ear" to ".ear" to allow expansion. archivePath.renameTo(originalPath); } } } public ProgressObject start(TargetModuleID[] ids) { ProgressObjectImpl progress = new ProgressObjectImpl(ids); boolean failed = false; StringBuilder message = new StringBuilder(); for (TargetModuleID targetModuleID : ids) { if (log.isLoggable(Level.FINE)) log.log(Level.FINE, L.l("jsr88 starting {0}", targetModuleID.getModuleID())); Throwable exception = null; DeployControllerMXBean mxbean = null; try { ObjectName objectName = new ObjectName(targetModuleID.getModuleID()); mxbean = (DeployControllerMXBean) Jmx.find(objectName); if (mxbean != null) mxbean.start(); else { log.finer("Jsr88[] " + objectName + " is an unknown module"); failed = true; } } catch (Exception t) { log.log(Level.INFO, t.toString(), t); // XXX: need to handle depending on type exception = t; } /* if (exception == null && mxbean != null) { // XXX: temp for types exception = null; } */ if (exception != null) { failed = true; describe(message, targetModuleID, false, getExceptionMessage(exception)); } else describe(message, targetModuleID, true); } if (failed) progress.failed(L.l("start {0}", message)); else progress.completed(L.l("start {0}", message)); return progress; } public ProgressObject stop(TargetModuleID[] ids) { ProgressObjectImpl progress = new ProgressObjectImpl(ids); boolean failed = false; StringBuilder message = new StringBuilder(); for (TargetModuleID targetModuleID : ids) { if (log.isLoggable(Level.FINE)) log.log(Level.FINE, L.l("jsr88 stopping {0}", targetModuleID.getModuleID())); Throwable exception = null; DeployControllerMXBean mxbean = null; try { ObjectName objectName = new ObjectName(targetModuleID.getModuleID()); mxbean = (DeployControllerMXBean) Jmx.find(objectName); if (mxbean != null) mxbean.stop(); else { log.finer("Jsr88[] " + objectName + " is an unknown module"); failed = true; } } catch (Exception t) { log.log(Level.INFO, t.toString(), t); // XXX: need to handle depending on type exception = t; } /* if (exception == null && mxbean != null) { // XXX: temp for types exception = null; } */ if (exception != null) { failed = true; describe(message, targetModuleID, false, getExceptionMessage(exception)); } else describe(message, targetModuleID, true); } if (failed) progress.failed(L.l("stop {0}", message)); else progress.completed(L.l("stop {0}", message)); return progress; } public ProgressObject undeploy(TargetModuleID []ids) throws IllegalStateException { ProgressObjectImpl progress = new ProgressObjectImpl(ids); boolean failed = false; StringBuilder message = new StringBuilder(); for (TargetModuleID targetModuleID : ids) { if (log.isLoggable(Level.FINE)) log.log(Level.FINE, L.l("undeploying {0}", targetModuleID.getModuleID())); ArchiveDeployMXBean mxbean = null; Throwable exception = null; try { ObjectName objectName = new ObjectName(targetModuleID.getModuleID()); mxbean = getMXBean(objectName); if (mxbean != null) mxbean.undeploy(objectName.getKeyProperty("name")); } catch (Throwable t) { log.log(Level.INFO, t.toString(), t); exception = t; } if (exception != null) { failed = true; describe(message, targetModuleID, false, getExceptionMessage(exception)); } else describe(message, targetModuleID, true); } if (failed) progress.failed(L.l("undeploy {0}", message)); else progress.completed(L.l("undeploy {0}", message)); return progress; } private void describe(StringBuilder builder, TargetModuleID targetModuleID, boolean success) { describe(builder, targetModuleID, success, null); } private void describe(StringBuilder builder, TargetModuleID targetModuleID, boolean success, String message) { if (builder.length() > 0) builder.append(", "); if (success) builder.append(L.l("successful for target {0} module {1}", targetModuleID.getTarget().getName(), targetModuleID.getModuleID())); else { builder.append(L.l("failed for target {0} module {1}", targetModuleID.getTarget().getName(), targetModuleID.getModuleID())); } if (message != null) { builder.append(" '"); builder.append(message); builder.append("'"); } }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?