2020-03-23 15:35:58 +01:00
|
|
|
/*
|
2024-09-24 09:42:07 +02:00
|
|
|
* Copyright (c) 2020 - present Cloudogu GmbH
|
2010-10-31 19:22:53 +01:00
|
|
|
*
|
2024-09-24 09:42:07 +02:00
|
|
|
* This program is free software: you can redistribute it and/or modify it under
|
|
|
|
|
* the terms of the GNU Affero General Public License as published by the Free
|
|
|
|
|
* Software Foundation, version 3.
|
2010-10-31 19:22:53 +01:00
|
|
|
*
|
2024-09-24 09:42:07 +02:00
|
|
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
|
|
|
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
|
|
|
|
|
* details.
|
2010-10-31 19:22:53 +01:00
|
|
|
*
|
2024-09-24 09:42:07 +02:00
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
|
* along with this program. If not, see https://www.gnu.org/licenses/.
|
2010-09-11 17:59:11 +02:00
|
|
|
*/
|
|
|
|
|
|
2023-11-29 18:14:03 +01:00
|
|
|
package sonia.scm.server;
|
2010-09-11 17:59:11 +02:00
|
|
|
|
2011-03-02 19:26:48 +01:00
|
|
|
import org.eclipse.jetty.server.Server;
|
2010-09-11 17:59:11 +02:00
|
|
|
|
2023-11-29 18:14:03 +01:00
|
|
|
public class ScmServer extends Thread {
|
2014-08-28 09:03:43 +02:00
|
|
|
static final int GRACEFUL_TIMEOUT = 2000;
|
2023-11-29 18:14:03 +01:00
|
|
|
private boolean initialized = false;
|
|
|
|
|
private final Server server;
|
2014-08-28 09:03:43 +02:00
|
|
|
|
2023-11-29 18:14:03 +01:00
|
|
|
public ScmServer() {
|
2011-03-02 19:26:48 +01:00
|
|
|
server = new org.eclipse.jetty.server.Server();
|
2023-11-29 18:14:03 +01:00
|
|
|
ServerConfiguration config = new ServerConfiguration();
|
|
|
|
|
config.configureServer(server);
|
2010-09-11 17:59:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2023-11-29 18:14:03 +01:00
|
|
|
public void run() {
|
|
|
|
|
try {
|
|
|
|
|
if (!initialized) {
|
2014-05-18 10:20:54 +02:00
|
|
|
init();
|
2014-05-16 13:14:26 +02:00
|
|
|
}
|
|
|
|
|
|
2014-05-18 10:20:54 +02:00
|
|
|
server.join();
|
2023-11-29 18:14:03 +01:00
|
|
|
} catch (InterruptedException ex) {
|
|
|
|
|
System.err.println("server interrupted");
|
|
|
|
|
ex.printStackTrace();
|
|
|
|
|
Thread.currentThread().interrupt();
|
2011-03-02 19:26:48 +01:00
|
|
|
}
|
2010-09-11 17:59:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2014-08-28 09:03:43 +02:00
|
|
|
* Stop embedded webserver. Use {@link Server#stop()} to fix windows service.
|
2010-09-11 17:59:11 +02:00
|
|
|
*
|
2014-08-28 09:03:43 +02:00
|
|
|
* @see <a href="http://goo.gl/Zfy0Ev">http://goo.gl/Zfy0Ev</a>
|
2010-09-11 17:59:11 +02:00
|
|
|
*/
|
2023-11-29 18:14:03 +01:00
|
|
|
public void stopServer() {
|
|
|
|
|
try {
|
2014-12-06 15:42:10 +01:00
|
|
|
server.setStopTimeout(GRACEFUL_TIMEOUT);
|
2011-03-02 19:26:48 +01:00
|
|
|
server.setStopAtShutdown(true);
|
2014-08-28 09:03:43 +02:00
|
|
|
server.stop();
|
2014-05-16 13:14:26 +02:00
|
|
|
initialized = false;
|
2023-11-29 18:14:03 +01:00
|
|
|
} catch (Exception ex) {
|
2011-03-02 19:26:48 +01:00
|
|
|
ex.printStackTrace(System.err);
|
|
|
|
|
}
|
2010-09-11 17:59:11 +02:00
|
|
|
}
|
|
|
|
|
|
2023-11-29 18:14:03 +01:00
|
|
|
void init() {
|
|
|
|
|
try {
|
2014-05-16 13:14:26 +02:00
|
|
|
server.start();
|
|
|
|
|
initialized = true;
|
2023-11-29 18:14:03 +01:00
|
|
|
} catch (Exception ex) {
|
2014-05-16 13:14:26 +02:00
|
|
|
throw new ScmServerException("could not initialize server", ex);
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-09-11 17:59:11 +02:00
|
|
|
}
|