@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 } }
@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(); }
public static String getState(LifeCycle lc) { if (lc.isStarting()) return STARTING; if (lc.isStarted()) return STARTED; if (lc.isStopping()) return STOPPING; if (lc.isStopped()) return STOPPED; return FAILED; }
@Override public void run() { for (LifeCycle lifeCycle : _thread._lifeCycles) { try { if (lifeCycle.isStarted()) { lifeCycle.stop(); LOG.debug("Stopped {}",lifeCycle); } if (lifeCycle instanceof Destroyable) { ((Destroyable)lifeCycle).destroy(); LOG.debug("Destroyed {}",lifeCycle); } } catch (Exception ex) { LOG.debug(ex); } } } }
public void run() { for (LifeCycle lc : _jettys) { if (lc.isRunning()) { try { lc.stop(); } catch (Exception e) { changeState(STOPPING, e); } } } if (_context != null) { PortMapper pm = _context.portMapper(); if (_port > 0 && pm.getPort(PortMapper.SVC_EEPSITE) == _port) { _port = 0; pm.unregister(PortMapper.SVC_EEPSITE); } if (_sslPort > 0 && pm.getPort(PortMapper.SVC_HTTPS_EEPSITE) == _sslPort) { _sslPort = 0; pm.unregister(PortMapper.SVC_HTTPS_EEPSITE); } } changeState(STOPPED); } }
/** * <p>Sets the thread pool associated to this CometD service.</p> * <p>If the {@link ThreadPool} is a {@link LifeCycle} instance, * and it is not already started, then it will started.</p> * * @param pool The ThreadPool */ public void setThreadPool(ThreadPool pool) { try { if (pool instanceof LifeCycle) { if (!((LifeCycle)pool).isStarted()) { ((LifeCycle)pool).start(); } } } catch (Exception e) { throw new IllegalStateException(e); } _threadPool = pool; }
/** * Adds the given bean, detecting whether to manage it or not. * If the bean is a {@link LifeCycle}, then it will be managed if it is not * already started and not managed if it is already started. * The {@link #addBean(Object, boolean)} * method should be used if this is not correct, or the {@link #manage(Object)} and {@link #unmanage(Object)} * methods may be used after an add to change the status. * * @param o the bean object to add * @return true if the bean was added, false if it was already present */ @Override public boolean addBean(Object o) { if (o instanceof LifeCycle) { LifeCycle l = (LifeCycle)o; return addBean(o,l.isRunning()?Managed.UNMANAGED:Managed.AUTO); } return addBean(o,Managed.POJO); }
/** * Add an associated bean. * If the bean is a {@link LifeCycle}, then it will be managed if it is not * already started and umanaged if it is already started. The {@link #addBean(Object, boolean)} * method should be used if this is not correct, or the {@link #manage(Object)} and {@link #unmanage(Object)} * methods may be used after an add to change the status. * @param o the bean object to add * @return true if the bean was added or false if it has already been added. */ public boolean addBean(Object o) { // beans are joined unless they are started lifecycles return addBean(o,!((o instanceof LifeCycle)&&((LifeCycle)o).isStarted())); }
public boolean isManageable() { switch(_managed) { case MANAGED: return true; case AUTO: return _bean instanceof LifeCycle && ((LifeCycle)_bean).isStopped(); default: return false; } }
/** * Stop the registered lifecycles, optionally * calling destroy on them. * * @param destroy */ public void stopLifeCycles (boolean destroy) { for (LifeCycle l:_lifeCycles) { try { if (l.isStarted()) { l.stop(); } if ((l instanceof Destroyable) && destroy) ((Destroyable)l).destroy(); } catch (Exception e) { debug(e); } } }
public void stopComponents() throws Exception { Collections.reverse(components); // if Jetty thread is still waiting for a component to start, this should unblock it interrupt(); for (LifeCycle component : components) { if (component.isRunning()) { log.info("Stopping: {}", component); component.stop(); } } components.clear(); stopped.await(); }
/** * Start the managed lifecycle beans in the order they were added. * @see org.eclipse.jetty.util.component.AbstractLifeCycle#doStart() */ @Override protected void doStart() throws Exception { for (Bean b:_beans) { if (b._managed && b._bean instanceof LifeCycle) { LifeCycle l=(LifeCycle)b._bean; if (!l.isRunning()) l.start(); } } // indicate that we are started, so that addBean will start other beans added. _started=true; super.doStart(); }
/** * Adds a managed lifecycle. * <p>This is a convenience method that uses addBean(lifecycle,true) * and then ensures that the added bean is started iff this container * is running. Exception from nested calls to start are caught and * wrapped as RuntimeExceptions * @param lifecycle the managed lifecycle to add */ public void addManaged(LifeCycle lifecycle) { addBean(lifecycle,true); try { if (isRunning() && !lifecycle.isRunning()) start(lifecycle); } catch (RuntimeException | Error e) { throw e; } catch (Exception e) { throw new RuntimeException(e); } }
/** * Add an associated bean. * If the bean is a {@link LifeCycle}, then it will be managed if it is not * already started and umanaged if it is already started. The {@link #addBean(Object, boolean)} * method should be used if this is not correct, or the {@link #manage(Object)} and {@link #unmanage(Object)} * methods may be used after an add to change the status. * @param o the bean object to add * @return true if the bean was added or false if it has already been added. */ public boolean addBean(Object o) { // beans are joined unless they are started lifecycles return addBean(o,!((o instanceof LifeCycle)&&((LifeCycle)o).isStarted())); }
public boolean isManageable() { switch(_managed) { case MANAGED: return true; case AUTO: return _bean instanceof LifeCycle && ((LifeCycle)_bean).isStopped(); default: return false; } }
private void stopLifeCycles(Predicate<LifeCycle> predicate, boolean destroy) { List<LifeCycle> lifeCycles = new ArrayList<>(); synchronized (this) { lifeCycles.addAll(_lifeCycles); } for (LifeCycle l : lifeCycles) { try { if (l.isStarted() && predicate.test(l)) l.stop(); if ((l instanceof Destroyable) && destroy) ((Destroyable)l).destroy(); } catch (Throwable x) { debug(x); } } } }
@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 } }
public void stopComponents() throws Exception { Collections.reverse(components); // if Jetty thread is still waiting for a component to start, this should unblock it interrupt(); for (LifeCycle component : components) { if (component.isRunning()) { log.info("Stopping: {}", component); component.stop(); } } components.clear(); stopped.await(); }
public static String getState(LifeCycle lc) { if (lc.isStarting()) return STARTING; if (lc.isStarted()) return STARTED; if (lc.isStopping()) return STOPPING; if (lc.isStopped()) return STOPPED; return FAILED; }