我正在使用嵌入式码头。我正在尝试使用 Jetty 的服务器 lifeCycleEvents 来了解 Jetty 何时无法启动。具体来说,我尝试使用非空闲端口加载它。我看到的是该lifeCycleStarted()
方法被调用,当我期望lifeCycleFailure()
被调用时。
我应该如何确定 Jetty 无法启动?请参见下面的代码:
_server = new Server(port);
HandlerList handlers = new HandlerList();
DefaultHandler defaultHandler = new DefaultHandler();
_server.setHandler(handlers);
_server.addLifeCycleListener(new LifeCycle.Listener()
{
public void lifeCycleStarting(org.eclipse.jetty.util.component.LifeCycle lifeCycle) {}
public void lifeCycleStopping(org.eclipse.jetty.util.component.LifeCycle lifeCycle) {}
public void lifeCycleStopped(org.eclipse.jetty.util.component.LifeCycle lifeCycle) {}
public void lifeCycleStarted(org.eclipse.jetty.util.component.LifeCycle lifeCycle)
{
loadCompleted(port, true);
}
public void lifeCycleFailure(org.eclipse.jetty.util.component.LifeCycle lifeCycle, java.lang.Throwable throwable)
{
loadCompleted(port, false);
}
private void loadCompleted(int port, boolean success)
{
}
});