405631 Plugin gives error when its started twice
This commit is contained in:
parent
04bcde9b14
commit
28d4f41572
|
@ -284,7 +284,7 @@ public abstract class AbstractJettyMojo extends AbstractMojo
|
||||||
/**
|
/**
|
||||||
* A wrapper for the Server object
|
* A wrapper for the Server object
|
||||||
*/
|
*/
|
||||||
protected JettyServer server = JettyServer.getInstance();
|
protected JettyServer server = new JettyServer();
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -494,6 +494,8 @@ public abstract class AbstractJettyMojo extends AbstractMojo
|
||||||
String tmp = System.getProperty(PORT_SYSPROPERTY, MavenServerConnector.DEFAULT_PORT_STR);
|
String tmp = System.getProperty(PORT_SYSPROPERTY, MavenServerConnector.DEFAULT_PORT_STR);
|
||||||
httpConnector.setPort(Integer.parseInt(tmp.trim()));
|
httpConnector.setPort(Integer.parseInt(tmp.trim()));
|
||||||
}
|
}
|
||||||
|
if (httpConnector.getServer() == null)
|
||||||
|
httpConnector.setServer(this.server);
|
||||||
this.server.addConnector(httpConnector);
|
this.server.addConnector(httpConnector);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -509,7 +511,8 @@ public abstract class AbstractJettyMojo extends AbstractMojo
|
||||||
String tmp = System.getProperty(PORT_SYSPROPERTY, MavenServerConnector.DEFAULT_PORT_STR);
|
String tmp = System.getProperty(PORT_SYSPROPERTY, MavenServerConnector.DEFAULT_PORT_STR);
|
||||||
httpConnector.setPort(Integer.parseInt(tmp.trim()));
|
httpConnector.setPort(Integer.parseInt(tmp.trim()));
|
||||||
}
|
}
|
||||||
|
if (httpConnector.getServer() == null)
|
||||||
|
httpConnector.setServer(this.server);
|
||||||
this.server.setConnectors(new Connector[] {httpConnector});
|
this.server.setConnectors(new Connector[] {httpConnector});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -38,16 +38,6 @@ public class JettyServer extends org.eclipse.jetty.server.Server
|
||||||
{
|
{
|
||||||
public static final JettyServer __instance = new JettyServer();
|
public static final JettyServer __instance = new JettyServer();
|
||||||
|
|
||||||
/**
|
|
||||||
* Singleton instance
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public static JettyServer getInstance()
|
|
||||||
{
|
|
||||||
return __instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private RequestLog requestLog;
|
private RequestLog requestLog;
|
||||||
private ContextHandlerCollection contexts;
|
private ContextHandlerCollection contexts;
|
||||||
|
|
||||||
|
@ -56,7 +46,7 @@ public class JettyServer extends org.eclipse.jetty.server.Server
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
private JettyServer()
|
public JettyServer()
|
||||||
{
|
{
|
||||||
super();
|
super();
|
||||||
setStopAtShutdown(true);
|
setStopAtShutdown(true);
|
||||||
|
|
|
@ -19,21 +19,259 @@
|
||||||
|
|
||||||
package org.eclipse.jetty.maven.plugin;
|
package org.eclipse.jetty.maven.plugin;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.concurrent.Executor;
|
||||||
|
import java.util.concurrent.Future;
|
||||||
|
|
||||||
|
import org.eclipse.jetty.io.ByteBufferPool;
|
||||||
|
import org.eclipse.jetty.io.EndPoint;
|
||||||
|
import org.eclipse.jetty.server.ConnectionFactory;
|
||||||
|
import org.eclipse.jetty.server.Connector;
|
||||||
|
import org.eclipse.jetty.server.Server;
|
||||||
import org.eclipse.jetty.server.ServerConnector;
|
import org.eclipse.jetty.server.ServerConnector;
|
||||||
|
import org.eclipse.jetty.util.annotation.ManagedAttribute;
|
||||||
|
import org.eclipse.jetty.util.component.AbstractLifeCycle;
|
||||||
|
import org.eclipse.jetty.util.thread.Scheduler;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* MavenServerConnector
|
* MavenServerConnector
|
||||||
*
|
*
|
||||||
*
|
* As the ServerConnector class does not have a no-arg constructor, and moreover requires
|
||||||
|
* the server instance passed in to all its constructors, it cannot
|
||||||
|
* be referenced in the pom.xml. This class wraps a ServerConnector, delaying setting the
|
||||||
|
* server instance. Only a few of the setters from the ServerConnector class are supported.
|
||||||
*/
|
*/
|
||||||
public class MavenServerConnector extends ServerConnector
|
public class MavenServerConnector extends AbstractLifeCycle implements Connector
|
||||||
{
|
{
|
||||||
public static int DEFAULT_PORT = 8080;
|
public static int DEFAULT_PORT = 8080;
|
||||||
public static String DEFAULT_PORT_STR = String.valueOf(DEFAULT_PORT);
|
public static String DEFAULT_PORT_STR = String.valueOf(DEFAULT_PORT);
|
||||||
public static int DEFAULT_MAX_IDLE_TIME = 30000;
|
public static int DEFAULT_MAX_IDLE_TIME = 30000;
|
||||||
|
|
||||||
|
private Server server;
|
||||||
|
private ServerConnector delegate;
|
||||||
|
private String host;
|
||||||
|
private String name;
|
||||||
|
private int port;
|
||||||
|
private long idleTimeout;
|
||||||
|
private int lingerTime;
|
||||||
|
|
||||||
|
|
||||||
public MavenServerConnector()
|
public MavenServerConnector()
|
||||||
{
|
{
|
||||||
super(JettyServer.getInstance());
|
}
|
||||||
|
|
||||||
|
public void setServer(Server server)
|
||||||
|
{
|
||||||
|
this.server = server;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setHost(String host)
|
||||||
|
{
|
||||||
|
this.host = host;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getHost()
|
||||||
|
{
|
||||||
|
return this.host;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPort(int port)
|
||||||
|
{
|
||||||
|
this.port = port;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getPort ()
|
||||||
|
{
|
||||||
|
return this.port;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName (String name)
|
||||||
|
{
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIdleTimeout(long idleTimeout)
|
||||||
|
{
|
||||||
|
this.idleTimeout = idleTimeout;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSoLingerTime(int lingerTime)
|
||||||
|
{
|
||||||
|
this.lingerTime = lingerTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void doStart() throws Exception
|
||||||
|
{
|
||||||
|
|
||||||
|
if (this.server == null)
|
||||||
|
throw new IllegalStateException("Server not set for MavenServerConnector");
|
||||||
|
|
||||||
|
this.delegate = new ServerConnector(this.server);
|
||||||
|
this.delegate.setName(this.name);
|
||||||
|
this.delegate.setPort(this.port);
|
||||||
|
this.delegate.setHost(this.host);
|
||||||
|
this.delegate.setIdleTimeout(idleTimeout);
|
||||||
|
this.delegate.setSoLingerTime(lingerTime);
|
||||||
|
this.delegate.start();
|
||||||
|
|
||||||
|
super.doStart();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void doStop() throws Exception
|
||||||
|
{
|
||||||
|
this.delegate.stop();
|
||||||
|
super.doStop();
|
||||||
|
this.delegate = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.eclipse.jetty.util.component.Graceful#shutdown()
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Future<Void> shutdown()
|
||||||
|
{
|
||||||
|
checkDelegate();
|
||||||
|
return this.delegate.shutdown();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.eclipse.jetty.server.Connector#getServer()
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Server getServer()
|
||||||
|
{
|
||||||
|
return this.server;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.eclipse.jetty.server.Connector#getExecutor()
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Executor getExecutor()
|
||||||
|
{
|
||||||
|
checkDelegate();
|
||||||
|
return this.delegate.getExecutor();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.eclipse.jetty.server.Connector#getScheduler()
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Scheduler getScheduler()
|
||||||
|
{
|
||||||
|
checkDelegate();
|
||||||
|
return this.delegate.getScheduler();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.eclipse.jetty.server.Connector#getByteBufferPool()
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public ByteBufferPool getByteBufferPool()
|
||||||
|
{
|
||||||
|
checkDelegate();
|
||||||
|
return this.delegate.getByteBufferPool();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.eclipse.jetty.server.Connector#getConnectionFactory(java.lang.String)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public ConnectionFactory getConnectionFactory(String nextProtocol)
|
||||||
|
{
|
||||||
|
checkDelegate();
|
||||||
|
return this.delegate.getConnectionFactory(nextProtocol);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.eclipse.jetty.server.Connector#getConnectionFactory(java.lang.Class)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public <T> T getConnectionFactory(Class<T> factoryType)
|
||||||
|
{
|
||||||
|
checkDelegate();
|
||||||
|
return this.delegate.getConnectionFactory(factoryType);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.eclipse.jetty.server.Connector#getDefaultConnectionFactory()
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public ConnectionFactory getDefaultConnectionFactory()
|
||||||
|
{
|
||||||
|
checkDelegate();
|
||||||
|
return getDefaultConnectionFactory();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.eclipse.jetty.server.Connector#getConnectionFactories()
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Collection<ConnectionFactory> getConnectionFactories()
|
||||||
|
{
|
||||||
|
checkDelegate();
|
||||||
|
return this.delegate.getConnectionFactories();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.eclipse.jetty.server.Connector#getProtocols()
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public List<String> getProtocols()
|
||||||
|
{
|
||||||
|
checkDelegate();
|
||||||
|
return this.delegate.getProtocols();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.eclipse.jetty.server.Connector#getIdleTimeout()
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
@ManagedAttribute("maximum time a connection can be idle before being closed (in ms)")
|
||||||
|
public long getIdleTimeout()
|
||||||
|
{
|
||||||
|
checkDelegate();
|
||||||
|
return this.delegate.getIdleTimeout();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.eclipse.jetty.server.Connector#getTransport()
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Object getTransport()
|
||||||
|
{
|
||||||
|
checkDelegate();
|
||||||
|
return this.delegate.getTransport();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.eclipse.jetty.server.Connector#getConnectedEndPoints()
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Collection<EndPoint> getConnectedEndPoints()
|
||||||
|
{
|
||||||
|
checkDelegate();
|
||||||
|
return this.delegate.getConnectedEndPoints();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.eclipse.jetty.server.Connector#getName()
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String getName()
|
||||||
|
{
|
||||||
|
return this.name;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void checkDelegate() throws IllegalStateException
|
||||||
|
{
|
||||||
|
if (this.delegate == null)
|
||||||
|
throw new IllegalStateException ("MavenServerConnector delegate not ready");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,7 +55,7 @@ public class Starter
|
||||||
private List<File> jettyXmls; // list of jetty.xml config files to apply - Mandatory
|
private List<File> jettyXmls; // list of jetty.xml config files to apply - Mandatory
|
||||||
private File contextXml; //name of context xml file to configure the webapp - Mandatory
|
private File contextXml; //name of context xml file to configure the webapp - Mandatory
|
||||||
|
|
||||||
private JettyServer server;
|
private JettyServer server = new JettyServer();
|
||||||
private JettyWebAppContext webApp;
|
private JettyWebAppContext webApp;
|
||||||
|
|
||||||
|
|
||||||
|
@ -120,8 +120,6 @@ public class Starter
|
||||||
{
|
{
|
||||||
LOG.debug("Starting Jetty Server ...");
|
LOG.debug("Starting Jetty Server ...");
|
||||||
|
|
||||||
this.server = JettyServer.getInstance();
|
|
||||||
|
|
||||||
//apply any configs from jetty.xml files first
|
//apply any configs from jetty.xml files first
|
||||||
applyJettyXml ();
|
applyJettyXml ();
|
||||||
|
|
||||||
|
@ -132,6 +130,7 @@ public class Starter
|
||||||
{
|
{
|
||||||
//if a SystemProperty -Djetty.port=<portnum> has been supplied, use that as the default port
|
//if a SystemProperty -Djetty.port=<portnum> has been supplied, use that as the default port
|
||||||
MavenServerConnector httpConnector = new MavenServerConnector();
|
MavenServerConnector httpConnector = new MavenServerConnector();
|
||||||
|
httpConnector.setServer(this.server);
|
||||||
String tmp = System.getProperty(PORT_SYSPROPERTY, MavenServerConnector.DEFAULT_PORT_STR);
|
String tmp = System.getProperty(PORT_SYSPROPERTY, MavenServerConnector.DEFAULT_PORT_STR);
|
||||||
httpConnector.setPort(Integer.parseInt(tmp.trim()));
|
httpConnector.setPort(Integer.parseInt(tmp.trim()));
|
||||||
connectors = new Connector[] {httpConnector};
|
connectors = new Connector[] {httpConnector};
|
||||||
|
|
Loading…
Reference in New Issue