Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #2103 open connectors before starting #2104

Merged
merged 2 commits into from
Jan 23, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
130 changes: 81 additions & 49 deletions jetty-server/src/main/java/org/eclipse/jetty/server/Server.java
Original file line number Diff line number Diff line change
Expand Up @@ -346,68 +346,100 @@ public HttpField getDateField()
@Override
protected void doStart() throws Exception
{
// Create an error handler if there is none
if (_errorHandler==null)
_errorHandler=getBean(ErrorHandler.class);
if (_errorHandler==null)
setErrorHandler(new ErrorHandler());
if (_errorHandler instanceof ErrorHandler.ErrorPageMapper)
LOG.warn("ErrorPageMapper not supported for Server level Error Handling");
_errorHandler.setServer(this);

//If the Server should be stopped when the jvm exits, register
//with the shutdown handler thread.
if (getStopAtShutdown())
ShutdownThread.register(this);
try
{
// Create an error handler if there is none
if (_errorHandler==null)
_errorHandler=getBean(ErrorHandler.class);
if (_errorHandler==null)
setErrorHandler(new ErrorHandler());
if (_errorHandler instanceof ErrorHandler.ErrorPageMapper)
LOG.warn("ErrorPageMapper not supported for Server level Error Handling");
_errorHandler.setServer(this);

//If the Server should be stopped when the jvm exits, register
//with the shutdown handler thread.
if (getStopAtShutdown())
ShutdownThread.register(this);

//Register the Server with the handler thread for receiving
//remote stop commands
ShutdownMonitor.register(this);

//Start a thread waiting to receive "stop" commands.
ShutdownMonitor.getInstance().start(); // initialize

String gitHash = Jetty.GIT_HASH;
String timestamp = Jetty.BUILD_TIMESTAMP;

LOG.info("jetty-{}, build timestamp: {}, git hash: {}", getVersion(), timestamp, gitHash);
if (!Jetty.STABLE)
{
LOG.warn("THIS IS NOT A STABLE RELEASE! DO NOT USE IN PRODUCTION!");
LOG.warn("Download a stable release from http://download.eclipse.org/jetty/");
}

//Register the Server with the handler thread for receiving
//remote stop commands
ShutdownMonitor.register(this);
HttpGenerator.setJettyVersion(HttpConfiguration.SERVER_VERSION);

//Start a thread waiting to receive "stop" commands.
ShutdownMonitor.getInstance().start(); // initialize
MultiException mex=new MultiException();

// Open network connector to ensure ports are available
_connectors.stream().filter(NetworkConnector.class::isInstance).map(NetworkConnector.class::cast).forEach(connector->
{
try
{
connector.open();
}
catch(Throwable th)
{
mex.add(th);
}
});

// Throw now if verified start sequence and there was an open exception
mex.ifExceptionThrow();

String gitHash = Jetty.GIT_HASH;
String timestamp = Jetty.BUILD_TIMESTAMP;
// Start the server and components, but not connectors!
// #start(LifeCycle) is overridden so that connectors are not started
super.doStart();

// start connectors
for (Connector connector : _connectors)
{
try
{
connector.start();
}
catch(Throwable e)
{
mex.add(e);
}
}

LOG.info("jetty-{}, build timestamp: {}, git hash: {}", getVersion(), timestamp, gitHash);
if (!Jetty.STABLE)
{
LOG.warn("THIS IS NOT A STABLE RELEASE! DO NOT USE IN PRODUCTION!");
LOG.warn("Download a stable release from http://download.eclipse.org/jetty/");
}

HttpGenerator.setJettyVersion(HttpConfiguration.SERVER_VERSION);
if (isDumpAfterStart())
dumpStdErr();

MultiException mex=new MultiException();
try
{
super.doStart();
mex.ifExceptionThrow();
LOG.info(String.format("Started @%dms",Uptime.getUptime()));
}
catch(Throwable e)
{
mex.add(e);
}

// start connectors last
for (Connector connector : _connectors)
catch(Throwable e1)
{
try
{
connector.start();
// Stop any components already started!
super.doStop();
}
catch(Throwable e)
catch(Exception e2)
{
mex.add(e);
e1.addSuppressed(e2);
}
finally
{
// Close any connectors that were opened
_connectors.stream().filter(NetworkConnector.class::isInstance).map(NetworkConnector.class::cast).forEach(NetworkConnector::close);
}
throw e1;
}

if (isDumpAfterStart())
dumpStdErr();

mex.ifExceptionThrow();

LOG.info(String.format("Started @%dms",Uptime.getUptime()));
}

@Override
Expand Down