DynamicTasks.queue("stop (if running)", new Runnable() { public void run() { boolean previouslyRunning = isRunning(); try { getEntity().setAttribute(Attributes.SERVICE_STATE, Lifecycle.STOPPING); stop(); } catch (Exception e) { if (previouslyRunning) { log.debug(getEntity() + " restart: stop failed, when was previously running", e); } else { log.debug(getEntity() + " restart: stop failed (but was not previously running, so not a surprise)", e); } } }});
DynamicTasks.queue("launch", new Runnable() { public void run() { getEntity().setAttribute(Attributes.SERVICE_STATE, Lifecycle.STARTING); launch(); }}); DynamicTasks.queue("post-launch", new Runnable() { public void run() {
public String processTemplateContents(String templateContents, Map<String,? extends Object> extraSubstitutions) { Map<String, Object> config = getEntity().getApplication().getManagementContext().getConfig().asMapWithStringKeys(); Map<String, Object> substitutions = ImmutableMap.<String, Object>builder() .putAll(config) .put("entity", entity) .put("driver", this) .put("location", getLocation()) .putAll(extraSubstitutions) .build(); return TemplateProcessor.processTemplateContents(templateContents, substitutions); /* try { Configuration cfg = new Configuration(); StringTemplateLoader templateLoader = new StringTemplateLoader(); templateLoader.putTemplate("config", templateContents); cfg.setTemplateLoader(templateLoader); Template template = cfg.getTemplate("config"); ByteArrayOutputStream baos = new ByteArrayOutputStream(); Writer out = new OutputStreamWriter(baos); template.process(substitutions, out); out.flush(); return new String(baos.toByteArray()); } catch (Exception e) { log.warn("Error creating configuration file for "+entity, e); throw Exceptions.propagate(e); } */ }
@Override public void restart() { DynamicTasks.queue("stop (if running)", new Runnable() { public void run() { boolean previouslyRunning = isRunning(); try { getEntity().setAttribute(Attributes.SERVICE_STATE, Lifecycle.STOPPING); stop(); } catch (Exception e) { if (previouslyRunning) { log.debug(getEntity() + " restart: stop failed, when was previously running", e); } else { log.debug(getEntity() + " restart: stop failed (but was not previously running, so not a surprise)", e); } } }}); if (doFullStartOnRestart()) { DynamicTasks.waitForLast(); getEntity().setAttribute(Attributes.SERVICE_STATE, Lifecycle.STARTING); start(); } else { DynamicTasks.queue("launch", new Runnable() { public void run() { getEntity().setAttribute(Attributes.SERVICE_STATE, Lifecycle.STARTING); launch(); }}); DynamicTasks.queue("post-launch", new Runnable() { public void run() { postLaunch(); }}); } }