2010-10-31 19:22:53 +01:00
|
|
|
/**
|
|
|
|
|
* Copyright (c) 2010, Sebastian Sdorra
|
|
|
|
|
* All rights reserved.
|
|
|
|
|
*
|
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
|
* modification, are permitted provided that the following conditions are met:
|
|
|
|
|
*
|
|
|
|
|
* 1. Redistributions of source code must retain the above copyright notice,
|
|
|
|
|
* this list of conditions and the following disclaimer.
|
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
|
* this list of conditions and the following disclaimer in the documentation
|
|
|
|
|
* and/or other materials provided with the distribution.
|
|
|
|
|
* 3. Neither the name of SCM-Manager; nor the names of its
|
|
|
|
|
* contributors may be used to endorse or promote products derived from this
|
|
|
|
|
* software without specific prior written permission.
|
|
|
|
|
*
|
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
|
|
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
|
* DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
|
|
|
|
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
|
|
|
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
|
|
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
|
|
|
|
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
|
|
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
*
|
|
|
|
|
* http://bitbucket.org/sdorra/scm-manager
|
|
|
|
|
*
|
2010-09-11 17:59:11 +02:00
|
|
|
*/
|
|
|
|
|
|
2011-03-02 19:26:48 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
package sonia.scm.server;
|
2010-09-11 17:59:11 +02:00
|
|
|
|
|
|
|
|
//~--- non-JDK imports --------------------------------------------------------
|
|
|
|
|
|
2011-03-02 19:26:48 +01:00
|
|
|
import org.eclipse.jetty.server.Server;
|
|
|
|
|
import org.eclipse.jetty.xml.XmlConfiguration;
|
|
|
|
|
|
|
|
|
|
//~--- JDK imports ------------------------------------------------------------
|
2010-09-11 17:59:11 +02:00
|
|
|
|
2011-03-02 19:26:48 +01:00
|
|
|
import java.net.URL;
|
2010-09-11 17:59:11 +02:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* @author Sebastian Sdorra
|
|
|
|
|
*/
|
2011-03-02 19:26:48 +01:00
|
|
|
public class ScmServer extends Thread
|
2010-09-11 17:59:11 +02:00
|
|
|
{
|
|
|
|
|
|
2011-03-02 19:26:48 +01:00
|
|
|
/** Field description */
|
|
|
|
|
public static final String CONFIGURATION = "/server-config.xml";
|
2010-09-11 17:59:11 +02:00
|
|
|
|
2011-03-02 19:26:48 +01:00
|
|
|
//~--- constructors ---------------------------------------------------------
|
2010-09-11 17:59:11 +02:00
|
|
|
|
|
|
|
|
/**
|
2011-03-02 19:26:48 +01:00
|
|
|
* Constructs ...
|
2010-09-11 17:59:11 +02:00
|
|
|
*
|
|
|
|
|
*/
|
2011-03-02 19:26:48 +01:00
|
|
|
public ScmServer()
|
2010-09-11 17:59:11 +02:00
|
|
|
{
|
2011-03-02 19:26:48 +01:00
|
|
|
URL configURL = ScmServer.class.getResource(CONFIGURATION);
|
2010-09-11 17:59:11 +02:00
|
|
|
|
2011-03-02 19:26:48 +01:00
|
|
|
if (configURL == null)
|
|
|
|
|
{
|
|
|
|
|
throw new ScmServerException("could not find server-config.xml");
|
|
|
|
|
}
|
2010-09-11 17:59:11 +02:00
|
|
|
|
2011-03-02 19:26:48 +01:00
|
|
|
server = new org.eclipse.jetty.server.Server();
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
XmlConfiguration config = new XmlConfiguration(configURL);
|
2010-09-11 17:59:11 +02:00
|
|
|
|
2011-03-02 19:26:48 +01:00
|
|
|
config.configure(server);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
throw new ScmServerException("error during server configuration", ex);
|
|
|
|
|
}
|
2010-09-11 17:59:11 +02:00
|
|
|
}
|
|
|
|
|
|
2011-03-02 19:26:48 +01:00
|
|
|
//~--- methods --------------------------------------------------------------
|
|
|
|
|
|
2010-09-11 17:59:11 +02:00
|
|
|
/**
|
|
|
|
|
* Method description
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
2011-03-02 19:26:48 +01:00
|
|
|
public void run()
|
2010-09-11 17:59:11 +02:00
|
|
|
{
|
2011-03-02 19:26:48 +01:00
|
|
|
try
|
|
|
|
|
{
|
2014-05-16 13:14:26 +02:00
|
|
|
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();
|
2011-03-02 19:26:48 +01:00
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
2014-05-16 13:14:26 +02:00
|
|
|
if (ex instanceof ScmServerException)
|
|
|
|
|
{
|
|
|
|
|
throw(ScmServerException) ex;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
throw new ScmServerException("could not start scm-server", ex);
|
|
|
|
|
}
|
2011-03-02 19:26:48 +01:00
|
|
|
}
|
2010-09-11 17:59:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Method description
|
|
|
|
|
*
|
|
|
|
|
*/
|
2011-03-02 19:26:48 +01:00
|
|
|
public void stopServer()
|
2010-09-11 17:59:11 +02:00
|
|
|
{
|
2011-03-02 19:26:48 +01:00
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
server.setStopAtShutdown(true);
|
2014-05-16 13:14:26 +02:00
|
|
|
initialized = false;
|
2011-03-02 19:26:48 +01:00
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
ex.printStackTrace(System.err);
|
|
|
|
|
}
|
2010-09-11 17:59:11 +02:00
|
|
|
}
|
|
|
|
|
|
2014-05-16 13:14:26 +02:00
|
|
|
/**
|
|
|
|
|
* Method description
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
void init()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
server.start();
|
|
|
|
|
initialized = true;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
throw new ScmServerException("could not initialize server", ex);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-09-11 17:59:11 +02:00
|
|
|
//~--- fields ---------------------------------------------------------------
|
|
|
|
|
|
2014-05-16 13:14:26 +02:00
|
|
|
/** Field description */
|
|
|
|
|
private boolean initialized = false;
|
|
|
|
|
|
2010-09-11 17:59:11 +02:00
|
|
|
/** Field description */
|
2011-03-02 19:26:48 +01:00
|
|
|
private Server server = new Server();
|
2010-09-11 17:59:11 +02:00
|
|
|
}
|