public void attach(ContainerLifeCycle container) { for (LifeCycle object : managedObjects) { container.addBean(object); } container.addLifeCycleListener(new AbstractLifeCycle.AbstractLifeCycleListener() { @Override public void lifeCycleStarting(LifeCycle event) { LOGGER.debug("managed objects = {}", managedObjects); } }); for (LifeCycle.Listener listener : lifecycleListeners) { container.addLifeCycleListener(listener); } }
@Override public void destroy() throws Exception { try { if (this.executor instanceof LifeCycle) { ((LifeCycle)this.executor).stop(); } } catch (Throwable ex) { // ignore } try { if (this.scheduler != null) { this.scheduler.stop(); } } catch (Throwable ex) { // ignore } }
private List<Connector> buildAdminConnectors(MetricRegistry metricRegistry, Server server) { // threadpool is shared between all the connectors, so it should be managed by the server instead of the // individual connectors final QueuedThreadPool threadPool = new InstrumentedQueuedThreadPool(metricRegistry, adminMaxThreads, adminMinThreads); threadPool.setName("dw-admin"); server.addBean(threadPool); final List<Connector> connectors = new ArrayList<>(); for (ConnectorFactory factory : adminConnectors) { final Connector connector = factory.build(server, metricRegistry, "admin", threadPool); if (connector instanceof ContainerLifeCycle) { ((ContainerLifeCycle) connector).unmanage(threadPool); } connectors.add(connector); } return connectors; }
@Override public void afterPropertiesSet() throws Exception { String name = this.threadPrefix + "@" + Integer.toHexString(hashCode()); if (this.executor == null) { QueuedThreadPool threadPool = new QueuedThreadPool(); threadPool.setName(name); this.executor = threadPool; } if (this.byteBufferPool == null) { this.byteBufferPool = new MappedByteBufferPool(2048, this.executor instanceof ThreadPool.SizedThreadPool ? ((ThreadPool.SizedThreadPool) executor).getMaxThreads() / 2 : ProcessorUtils.availableProcessors() * 2); } if (this.scheduler == null) { this.scheduler = new ScheduledExecutorScheduler(name + "-scheduler", false); } if (this.executor instanceof LifeCycle) { ((LifeCycle)this.executor).start(); } this.scheduler.start(); }
@Override public String dump() { return Dumpable.dump(this); }
/** * Dump this object to an Appendable with no indent. * @param out The appendable to dump to. * @throws IOException May be thrown by the Appendable */ public void dump(Appendable out) throws IOException { dump(out, ""); }
public void updateBean(Object oldBean, final Object newBean) { if (newBean!=oldBean) { if (oldBean!=null) removeBean(oldBean); if (newBean!=null) addBean(newBean); } }
@Override public void setStopTimeout(long stopTimeout) { super.setStopTimeout(stopTimeout); for (Bean bean : _beans) { if (bean.isManaged() && bean._bean instanceof AbstractLifeCycle) ((AbstractLifeCycle)bean._bean).setStopTimeout(stopTimeout); } }
public boolean isManageable() { switch(_managed) { case MANAGED: return true; case AUTO: return _bean instanceof LifeCycle && ((LifeCycle)_bean).isStopped(); default: return false; } }
/** Dump this object, it's contained beans and additional items to an Appendable * @param out The appendable to dump to * @param indent The indent to apply after any new lines * @param items Additional items to be dumped as contained. * @throws IOException May be thrown by the Appendable */ protected void dumpObjects(Appendable out, String indent, Object... items) throws IOException { Dumpable.dumpObjects(out,indent,this, items); }
@Override public void dump(Appendable out, String indent) throws IOException { List<String> system_classes=null; if (_systemClasses!=null) { system_classes=new ArrayList<>(_systemClasses); Collections.sort(system_classes); } List<String> server_classes=null; if (_serverClasses!=null) { server_classes=new ArrayList<>(_serverClasses); Collections.sort(server_classes); } dumpObjects(out,indent, new ClassLoaderDump(getClassLoader()), new DumpableCollection("Systemclasses "+this,system_classes), new DumpableCollection("Serverclasses "+this,server_classes), new DumpableCollection("Configurations "+this,_configurations), new DumpableCollection("Handler attributes "+this,((AttributesMap)getAttributes()).getAttributeEntrySet()), new DumpableCollection("Context attributes "+this,((Context)getServletContext()).getAttributeEntrySet()), new DumpableCollection("Initparams "+this,getInitParams().entrySet()) ); }
/** * @param bean the bean to test * @return whether this aggregate contains and manages the bean */ @Override public boolean isManaged(Object bean) { for (Bean b : _beans) if (b._bean == bean) return b.isManaged(); return false; }
public StopLifeCycle(LifeCycle lifecycle) { _lifecycle = lifecycle; addLifeCycleListener(this); }
@Override public void dump(Appendable out, String indent) throws IOException { dumpObjects(out,indent); }
@Override public void destroy() throws Exception { try { if (this.executor instanceof LifeCycle) { ((LifeCycle)this.executor).stop(); } } catch (Throwable ex) { // ignore } try { if (this.scheduler != null) { this.scheduler.stop(); } } catch (Throwable ex) { // ignore } }
/** * Starts the given lifecycle. * * @param l the lifecycle to start * @throws Exception if unable to start lifecycle */ protected void start(LifeCycle l) throws Exception { l.start(); }
@Override public String dump() { return Dumpable.dump(SslSelectionDump.CaptionedList.this); }
@Override public void dump(Appendable out, String indent) throws IOException { Dumpable.dumpObjects(out, indent, this, enabled, disabled); }
@Override public void afterPropertiesSet() throws Exception { String name = this.threadPrefix + "@" + Integer.toHexString(hashCode()); if (this.executor == null) { QueuedThreadPool threadPool = new QueuedThreadPool(); threadPool.setName(name); this.executor = threadPool; } if (this.byteBufferPool == null) { this.byteBufferPool = new MappedByteBufferPool(2048, this.executor instanceof ThreadPool.SizedThreadPool ? ((ThreadPool.SizedThreadPool) executor).getMaxThreads() / 2 : ProcessorUtils.availableProcessors() * 2); } if (this.scheduler == null) { this.scheduler = new ScheduledExecutorScheduler(name + "-scheduler", false); } if (this.executor instanceof LifeCycle) { ((LifeCycle)this.executor).start(); } this.scheduler.start(); }
@Override public String dump() { return Dumpable.dump(this); }