diff options
author | Kjetil Ørbekk <kjetil.orbekk@gmail.com> | 2012-02-13 20:47:36 +0100 |
---|---|---|
committer | Kjetil Ørbekk <kjetil.orbekk@gmail.com> | 2012-02-13 20:47:36 +0100 |
commit | f466217e62e052d11095bb0992067d5becd5d502 (patch) | |
tree | 2861863684cc679108d229a237e39b88b5642329 /same/src/main/java | |
parent | 7c7a60f8af461287eaebdf4f6550b2310525f8e5 (diff) |
Reuse Jetty server socket.
– SameService used to get BindExceptions, try to avoid this by reusing
server sockets.
Diffstat (limited to 'same/src/main/java')
-rw-r--r-- | same/src/main/java/com/orbekk/same/http/ServerBuilder.java | 1 | ||||
-rw-r--r-- | same/src/main/java/com/orbekk/same/http/ServerContainer.java | 10 |
2 files changed, 11 insertions, 0 deletions
diff --git a/same/src/main/java/com/orbekk/same/http/ServerBuilder.java b/same/src/main/java/com/orbekk/same/http/ServerBuilder.java index dcb7b8a..65ee670 100644 --- a/same/src/main/java/com/orbekk/same/http/ServerBuilder.java +++ b/same/src/main/java/com/orbekk/same/http/ServerBuilder.java @@ -33,6 +33,7 @@ public class ServerBuilder { public ServerContainer build() { ServerContainer server = ServerContainer.create(port); + server.setReuseAddress(true); server.setContext(getServletContextHandler()); return server; } diff --git a/same/src/main/java/com/orbekk/same/http/ServerContainer.java b/same/src/main/java/com/orbekk/same/http/ServerContainer.java index cd4dc4d..f91cce1 100644 --- a/same/src/main/java/com/orbekk/same/http/ServerContainer.java +++ b/same/src/main/java/com/orbekk/same/http/ServerContainer.java @@ -1,5 +1,7 @@ package com.orbekk.same.http; +import org.eclipse.jetty.server.AbstractConnector; +import org.eclipse.jetty.server.Connector; import org.eclipse.jetty.server.Server; import org.eclipse.jetty.servlet.ServletContextHandler; import org.slf4j.Logger; @@ -27,6 +29,14 @@ public class ServerContainer { this.context = context; } + public void setReuseAddress(boolean on) { + Connector connector = server.getConnectors()[0]; + if (connector instanceof AbstractConnector) { + AbstractConnector connector_ = (AbstractConnector)connector; + connector_.setReuseAddress(on); + } + } + public int getPort() { if (port == 0) { return server.getConnectors()[0].getLocalPort(); |