mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-13 17:05:43 +01:00
rename scm-server-util to scm-server-api and added scm-server-jetty
This commit is contained in:
@@ -0,0 +1,155 @@
|
||||
/*
|
||||
* To change this template, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
package sonia.scm.server.jetty;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import org.eclipse.jetty.server.Connector;
|
||||
import org.eclipse.jetty.server.nio.SelectChannelConnector;
|
||||
import org.eclipse.jetty.webapp.WebAppContext;
|
||||
|
||||
import sonia.scm.server.Server;
|
||||
import sonia.scm.server.ServerAllreadyRunningException;
|
||||
import sonia.scm.server.ServerConfig;
|
||||
import sonia.scm.server.ServerException;
|
||||
import sonia.scm.server.ServerListener;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
public class JettyServer implements Server
|
||||
{
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param listener
|
||||
*/
|
||||
@Override
|
||||
public void addListener(ServerListener listener)
|
||||
{
|
||||
listeners.add(listener);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param listener
|
||||
*/
|
||||
@Override
|
||||
public void removeListener(ServerListener listener)
|
||||
{
|
||||
listeners.remove(listener);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param config
|
||||
* @param webapp
|
||||
*
|
||||
* @throws IOException
|
||||
* @throws ServerException
|
||||
*/
|
||||
@Override
|
||||
public void start(ServerConfig config, File webapp)
|
||||
throws ServerException, IOException
|
||||
{
|
||||
if (isRunning())
|
||||
{
|
||||
throw new ServerAllreadyRunningException();
|
||||
}
|
||||
|
||||
server = new org.eclipse.jetty.server.Server();
|
||||
|
||||
Connector connector = new SelectChannelConnector();
|
||||
|
||||
for (ServerListener listener : listeners)
|
||||
{
|
||||
connector.addLifeCycleListener(new JettyServerListenerAdapter(listener));
|
||||
}
|
||||
|
||||
connector.setPort(config.getPort());
|
||||
server.addConnector(connector);
|
||||
|
||||
WebAppContext wac = new WebAppContext();
|
||||
|
||||
wac.setContextPath(config.getContextPath());
|
||||
wac.setWar(webapp.getAbsolutePath());
|
||||
wac.setExtractWAR(false);
|
||||
server.setHandler(server);
|
||||
server.setStopAtShutdown(true);
|
||||
|
||||
try
|
||||
{
|
||||
server.start();
|
||||
server.join();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new ServerException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @throws IOException
|
||||
* @throws ServerException
|
||||
*/
|
||||
@Override
|
||||
public void stop() throws ServerException, IOException
|
||||
{
|
||||
if (isRunning())
|
||||
{
|
||||
try
|
||||
{
|
||||
server.stop();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new ServerException(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public boolean isRunning()
|
||||
{
|
||||
return server != null;
|
||||
}
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
/** Field description */
|
||||
private Set<ServerListener> listeners = new HashSet<ServerListener>();
|
||||
|
||||
/** Field description */
|
||||
private org.eclipse.jetty.server.Server server;
|
||||
}
|
||||
Reference in New Issue
Block a user