public Boolean call() { return getDriver().isRunning(); } }))
protected void rebind() { // e.g. rebinding to a running instance // FIXME For rebind, what to do about things in STARTING or STOPPING state? // FIXME What if location not set? log.info("Connecting to pre-running service: {}", this); MachineLocation machine = getMachineOrNull(); if (machine != null) { initDriver(machine); driver.rebind(); if (log.isDebugEnabled()) log.debug("On rebind of {}, re-created driver {}", this, driver); } else { log.info("On rebind of {}, no MachineLocation found (with locations {}) so not generating driver", this, getLocations()); } callRebindHooks(); }
@Override protected String startProcessesAtMachine(final Supplier<MachineLocation> machineS) { entity().getDriver().start(); return "Started with driver "+entity().getDriver(); }
@Override protected String stopProcessesAtMachine() { if (entity().getDriver() != null) { entity().getDriver().stop(); return "Driver stop completed"; } return "No driver (nothing to do)"; }
@Override public void restart() { if (((SoftwareProcessImpl)entity()).getDriver() == null) { log.debug("restart of "+entity()+" has no driver - doing machine-level restart"); super.restart(); return; } if (Strings.isEmpty(entity().getAttribute(Attributes.HOSTNAME))) { log.debug("restart of "+entity()+" has no hostname - doing machine-level restart"); super.restart(); return; } log.debug("restart of "+entity()+" appears to have driver and hostname - doing driver-level restart"); ((SoftwareProcessImpl)entity()).getDriver().restart(); DynamicTasks.queue("post-restart", new Runnable() { public void run() { postStartCustom(); if (entity().getAttribute(Attributes.SERVICE_STATE) == Lifecycle.STARTING) entity().setAttribute(Attributes.SERVICE_STATE, Lifecycle.RUNNING); }}); }
public void waitForEntityStart() { if (log.isDebugEnabled()) log.debug("waiting to ensure {} doesn't abort prematurely", this); Duration startTimeout = Duration.seconds(getConfig(START_TIMEOUT)); CountdownTimer timer = startTimeout.countdownTimer(); boolean isRunningResult = false; long delay = 100; while (!isRunningResult && !timer.isExpired()) { Time.sleep(delay); try { isRunningResult = driver.isRunning(); } catch (Exception e) { setAttribute(SERVICE_STATE, Lifecycle.ON_FIRE); // provide extra context info, as we're seeing this happen in strange circumstances if (driver==null) throw new IllegalStateException(this+" concurrent start and shutdown detected"); throw new IllegalStateException("Error detecting whether "+this+" is running: "+e, e); } if (log.isDebugEnabled()) log.debug("checked {}, is running returned: {}", this, isRunningResult); // slow exponential delay -- 1.1^N means after 40 tries and 50s elapsed, it reaches the max of 5s intervals delay = Math.min(delay*11/10, 5000); } if (!isRunningResult) { String msg = "Software process entity "+this+" did not pass is-running check within "+ "the required "+startTimeout+" limit ("+timer.getDurationElapsed()+" elapsed)"; log.warn(msg+" (throwing)"); setAttribute(SERVICE_STATE, Lifecycle.ON_FIRE); throw new IllegalStateException(msg); } }