Gilad
Gilad

Reputation: 841

embedded jetty does not report startup failure

I'm using an embedded Jetty. I'm trying to use the Jetty's Server lifeCycleEvents to know when the Jetty failed to start. Specifically, I try to load it using a port that is not free. What I see is that the lifeCycleStarted() method is called, when I expect the lifeCycleFailure() to be called.

How should I figure out that the Jetty couldn't start? See code below:

_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)
   {
   }
});

Upvotes: 0

Views: 146

Answers (1)

Evgeniy Dorofeev
Evgeniy Dorofeev

Reputation: 135992

Server.start throws java.net.BindException if port is already in use. You could simply catch it.

Upvotes: 1

Related Questions