本文整理了Java中org.eclipse.jetty.util.component.LifeCycle
类的一些代码示例,展示了LifeCycle
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。LifeCycle
类的具体详情如下:
包路径:org.eclipse.jetty.util.component.LifeCycle
类名称:LifeCycle
[英]The lifecycle interface for generic components.
Classes implementing this interface have a defined life cycle defined by the methods of this interface.
[中]通用组件的生命周期接口。
实现该接口的类具有由该接口的方法定义的生命周期。
代码示例来源:origin: spring-projects/spring-framework
@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
}
}
代码示例来源:origin: spring-projects/spring-framework
@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();
}
代码示例来源:origin: org.eclipse.jetty/jetty-util
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;
}
代码示例来源:origin: org.eclipse.jetty/jetty-util
@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);
}
}
}
}
代码示例来源:origin: i2p/i2p.i2p
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);
}
}
代码示例来源:origin: i2p/i2p.i2p
if (!lc.isRunning()) {
try {
lc.start();
if (_context != null) {
PortMapper pm = _context.portMapper();
代码示例来源:origin: org.cometd.java/cometd-java-server
/**
* <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;
}
代码示例来源:origin: org.eclipse.jetty/jetty-util
/**
* 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);
}
代码示例来源:origin: org.eclipse.jetty.aggregate/jetty-webapp
/**
* 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()));
}
代码示例来源:origin: org.eclipse.jetty/jetty-util
public boolean isManageable()
{
switch(_managed)
{
case MANAGED:
return true;
case AUTO:
return _bean instanceof LifeCycle && ((LifeCycle)_bean).isStopped();
default:
return false;
}
}
代码示例来源:origin: Nextdoor/bender
/**
* 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);
}
}
}
代码示例来源:origin: sonatype/nexus-public
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();
}
代码示例来源:origin: org.eclipse.jetty.aggregate/jetty-all-server
/**
* 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();
}
代码示例来源:origin: org.eclipse.jetty/jetty-util
/**
* 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);
}
}
代码示例来源:origin: org.eclipse.jetty.aggregate/jetty-all-server
/**
* 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()));
}
代码示例来源:origin: jenkinsci/winstone
public boolean isManageable()
{
switch(_managed)
{
case MANAGED:
return true;
case AUTO:
return _bean instanceof LifeCycle && ((LifeCycle)_bean).isStopped();
default:
return false;
}
}
代码示例来源:origin: at.bestsolution.efxclipse.eclipse/org.eclipse.jetty.server
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);
}
}
}
}
代码示例来源:origin: org.springframework/spring-web
@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
}
}
代码示例来源:origin: org.sonatype.nexus/nexus-bootstrap
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();
}
代码示例来源:origin: org.eclipse.jetty.aggregate/jetty-webapp
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;
}
内容来源于网络,如有侵权,请联系作者删除!