@Override public void setEntity(EntityLocal entity) { super.setEntity(entity); if (isRunning()) { doStartPolling(); } }
@SuppressWarnings({"unchecked", "rawtypes"}) public <T extends Policy> T createPolicy(PolicySpec<T> spec) { if (spec.getFlags().containsKey("parent")) { throw new IllegalArgumentException( "Spec's flags must not contain parent; use spec.parent() instead for " + spec); } try { Class<? extends T> clazz = spec.getType(); T pol; if (isNewStylePolicy(clazz)) { pol = constructPolicy(clazz); } else { pol = constructOldStyle(clazz, MutableMap.copyOf(spec.getFlags())); } if (spec.getDisplayName() != null) ((AbstractPolicy) pol).setName(spec.getDisplayName()); if (isNewStylePolicy(clazz)) { ((AbstractPolicy) pol).setManagementContext(managementContext); Map<String, Object> config = ConfigBag.newInstance().putAll(spec.getFlags()).putAll(spec.getConfig()).getAllConfig(); ((AbstractPolicy) pol) .configure(MutableMap.copyOf(config)); // TODO AbstractPolicy.configure modifies the map } // TODO Can we avoid this for "new-style policies"? Should we just trust the configure() // method, // which the user may have overridden? // Also see InternalLocationFactory for same issue, which this code is based on. for (Map.Entry<ConfigKey<?>, Object> entry : spec.getConfig().entrySet()) { ((AbstractPolicy) pol).setConfig((ConfigKey) entry.getKey(), entry.getValue()); } ((AbstractPolicy) pol).init(); return pol; } catch (Exception e) { throw Exceptions.propagate(e); } }
@Override public void resume() { currentFailureStartTime = null; currentRecoveryStartTime = null; lastPublished = LastPublished.NONE; executorQueued.set(false); executorTime = 0; super.resume(); doStartPolling(); }
@Override public void suspend() { scheduledTask.cancel(true); super.suspend(); }