@Override public void deconstruct(Object component) { if (component instanceof AbstractComponent) { AbstractComponent abstractComponent = (AbstractComponent) component; if (abstractComponent.isDeconstructable()) ((AbstractComponent) component).deconstruct(); } }}; }
/** Clones this. The clone will <i>not</i> be frozen */ @Override public FreezableSimpleComponent clone() { FreezableSimpleComponent clone=(FreezableSimpleComponent)super.clone(); clone.frozen = false; return clone; }
/** * Creates a new component with an id. * Only for testing and components that are not created via dependency injection. * * @throws NullPointerException if the given id is null */ protected AbstractComponent(ComponentId id) { initId(id); isDeconstructable = setIsDeconstructable(); }
private Object initId(Object component) { if (component instanceof AbstractComponent) { AbstractComponent abstractComponent = (AbstractComponent) component; if (abstractComponent.hasInitializedId() && !abstractComponent.getId().equals(componentId())) { throw new IllegalStateException( "Component with id '" + componentId() + "' is trying to set its component id explicitly: '" + abstractComponent.getId() + "'. " + "This is not allowed, so please remove any call to super() in your component's constructor."); } abstractComponent.initId(componentId()); } return component; }
@Override public void deconstruct() { shutdown(); super.deconstruct(); }
/** * DO NOT CALL, for internal use only, */ public final String getIdString() { if (hasInitializedId()) return getId().toString(); return "(anonymous)"; }
private static JSONArray renderAbstractComponents(List<? extends AbstractComponent> components) { JSONArray ret = new JSONArray(); for (AbstractComponent c : components) { JSONObject jc = renderComponent(c, c.getId()); ret.put(jc); } return ret; }
@Override public void deconstruct(Object component) { if (component instanceof AbstractComponent) { AbstractComponent abstractComponent = (AbstractComponent) component; if (abstractComponent.isDeconstructable()) { executor.schedule(new DestructComponentTask(abstractComponent), delay.getSeconds(), TimeUnit.SECONDS); } } else if (component instanceof Provider) { // TODO Providers should most likely be deconstructed similarily to AbstractComponent log.info("Starting deconstruction of provider " + component); ((Provider<?>)component).deconstruct(); log.info("Finished deconstruction of provider " + component); } else if (component instanceof SharedResource) { log.info("Releasing container reference to resource " + component); // No need to delay release, as jdisc does ref-counting ((SharedResource)component).release(); } }
@Override public String toString() { return "'" + getIdString() + "' of class '" + className + "'"; }
@Override public void run() { log.info("Starting deconstruction of component " + component); try { component.deconstruct(); log.info("Finished deconstructing of component " + component); } catch (Exception | NoClassDefFoundError e) { // May get class not found due to it being already unloaded log.log(WARNING, "Exception thrown when deconstructing component " + component, e); } catch (Error e) { try { Duration shutdownDelay = getRandomizedShutdownDelay(); log.log(LogLevel.FATAL, "Error when deconstructing component " + component + ". Will sleep for " + shutdownDelay.getSeconds() + " seconds then restart", e); Thread.sleep(shutdownDelay.toMillis()); } catch (InterruptedException exception) { log.log(WARNING, "Randomized wait before dying disrupted. Dying now."); } com.yahoo.protect.Process.logAndDie("Shutting down due to error when deconstructing component " + component); } catch (Throwable e) { log.log(WARNING, "Non-error not exception throwable thrown when deconstructing component " + component, e); } } }
@Override public void deconstruct() { logger.log(Level.INFO, "Deconstructing FS4ResourcePool with id '" + instanceId + "'."); super.deconstruct(); listeners.close(); timer.cancel(); for (Backend backend : connectionPoolMap.values()) { backend.shutdown(); backend.close(); } executor.shutdown(); scheduledExecutor.shutdown(); try { executor.awaitTermination(10, TimeUnit.SECONDS); scheduledExecutor.awaitTermination(10, TimeUnit.SECONDS); } catch (InterruptedException e) { logger.warning("Executors failed terminating within timeout of 10 seconds : " + e); } }
/** Clones this. The clone will <i>not</i> be frozen */ @Override public FreezableComponent clone() { FreezableComponent clone=(FreezableComponent)super.clone(); clone.frozen = false; return clone; }
/** * Shutdown the thread pool, give a grace period of 1 second before forcibly * shutting down all worker threads. */ @Override public void deconstruct() { boolean terminated; super.deconstruct(); threadpool.shutdown(); try { terminated = threadpool.awaitTermination(1, TimeUnit.SECONDS); } catch (InterruptedException e) { Thread.currentThread().interrupt(); return; } if (!terminated) { threadpool.shutdownNow(); } }
/** * Used to create a separate instance for each result to render. */ @SuppressWarnings("unchecked") @Override public Renderer<RESPONSE> clone() { return (Renderer<RESPONSE>) super.clone(); }