@Override public void postLaunch() { String rootUrl = inferRootUrl(); entity.setAttribute(WebAppService.ROOT_URL, rootUrl); }
@Override public void onUpdated() { try { entity.setAttribute(target, getAggregate()); } catch (Throwable t) { LOG.warn("Error calculating and setting aggregate for enricher "+this, t); throw Throwables.propagate(t); } }
public void update() { for (SubscriptionDetails s: subscriptions) { if (s.count==0) return; } entity.setAttribute(target, compute()); }
@Override public void onException(Exception exception) { log.error("Detected exception while retrieving Windows Performance Counters from entity " + entity.getDisplayName(), exception); for (AttributeSensor attribute : sensorMap.values()) { entity.setAttribute(attribute, null); } } }
public JavaSoftwareProcessSshDriver(EntityLocal entity, SshMachineLocation machine) { super(entity, machine); entity.setAttribute(Attributes.LOG_FILE_LOCATION, getLogFileLocation()); }
@Override public void onException(Exception exception) { log.error("Detected exception while retrieving Chef attributes from entity " + entity.getDisplayName(), exception); for (AttributeSensor attribute : chefAttributeSensors.values()) { if (!attribute.getName().startsWith(CHEF_ATTRIBUTE_PREFIX)) continue; entity.setAttribute(attribute, null); } } }
@Override public void postLaunch() { entity.setAttribute(JBoss6Server.HTTP_PORT, DEFAULT_HTTP_PORT + getPortIncrement()); super.postLaunch(); }
public void emitAllAttributes(boolean includeNullValues) { for (Sensor s: sensors) { if (s instanceof AttributeSensor) { AttributeSensor destinationSensor = (AttributeSensor<?>) getDestinationSensor(s); Object v = source.getAttribute((AttributeSensor)s); if (v != null || includeNullValues) entity.setAttribute(destinationSensor, v); } } }
public static <T> T apply(EntityLocal entity, AttributeSensorAndConfigKey<?,T> key) { T v = entity.getAttribute(key); if (v!=null) return v; v = key.getAsSensorValue(entity); if (v!=null) entity.setAttribute(key, v); return v; } }
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() {
protected void onRestartFailed(String msg) { LOG.warn("ServiceRestarter failed for "+entity+": "+msg); if (getConfig(SET_ON_FIRE_ON_FAILURE)) { entity.setAttribute(Attributes.SERVICE_STATE, Lifecycle.ON_FIRE); } entity.emit(ENTITY_RESTART_FAILED, new FailureDescriptor(entity, msg)); } }
@Override public void onEvent(SensorEvent<T> event) { values.addLast(event.getValue()); pruneValues(); entity.setAttribute((AttributeSensor<Double>)target, getAverage()); }
@Override public void onFailure(SshPollValue val) { log.error("Windows Performance Counter query did not respond as expected. exitcode={} stdout={} stderr={}", new Object[]{val.getExitStatus(), val.getStdout(), val.getStderr()}); for (AttributeSensor attribute : sensorMap.values()) { entity.setAttribute(attribute, null); } }
@Override public void postLaunch() { entity.setAttribute(Attributes.HTTP_PORT, getHttpPort()); super.postLaunch(); }
@Override public void onFailure(SshPollValue val) { log.error("Chef attribute query did not respond as expected. exitcode={} stdout={} stderr={}", new Object[]{val.getExitStatus(), val.getStdout(), val.getStderr()}); for (AttributeSensor attribute : chefAttributeSensors.values()) { if (!attribute.getName().startsWith(CHEF_ATTRIBUTE_PREFIX)) continue; entity.setAttribute(attribute, null); } }
@Override public void onEvent(SensorEvent<T> event) { Number current = elvis(event.getValue(), 0); double newVal = current.doubleValue() - last.doubleValue(); entity.setAttribute((AttributeSensor<T>)target, TypeCoercions.coerce(newVal, target.getTypeToken())); last = current; } }
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); } } }});
public JmxHelper(EntityLocal entity) { this(toJmxUrl(entity), entity, entity.getAttribute(Attributes.JMX_USER), entity.getAttribute(Attributes.JMX_PASSWORD)); if (entity.getAttribute(UsesJmx.JMX_URL) == null) { entity.setAttribute(UsesJmx.JMX_URL, url); } }
@SuppressWarnings({ "rawtypes", "unchecked" }) @Override public void onEvent(SensorEvent event) { Number value = recompute(); Number typedValue = cast(value, (Class<? extends Number>)target.getType()); if (target instanceof AttributeSensor) { entity.setAttribute((AttributeSensor)target, typedValue); } else if (typedValue!=null) entity.emit((Sensor)target, typedValue); }
@Override public void onEvent(SensorEvent event) { if (accept((T)event.getValue())) { if (target instanceof AttributeSensor) entity.setAttribute((AttributeSensor)target, compute((T)event.getValue())); else entity.emit(target, compute((T)event.getValue())); } }