Hi,
stopping a running container and then starting it again throws the
following exception
2006-10-21 23:55:11.968::INFO: Logging to STDERR via org.mortbay.log.StdErrLog
2006-10-21 23:55:12.007::INFO: jetty-6.0.x
2006-10-21 23:55:12.041::INFO: Started SelectChannelConnector @ 127.0.0.1:8184
Stopping container!
Starting the container again!
2006-10-21 23:55:22.059::INFO: jetty-6.0.x
2006-10-21 23:55:22.060::INFO: Started SelectChannelConnector @ 127.0.0.1:8184
2006-10-21 23:55:22.061::WARN: failed SelectChannelConnector @ 127.0.0.1:8184
2006-10-21 23:55:22.061::WARN: failed [EMAIL PROTECTED]
Exception in thread "main" java.net.BindException: Address already in use
at sun.nio.ch.Net.bind(Native Method)
at
sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:119)
at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:59)
at
org.mortbay.jetty.nio.SelectChannelConnector.open(SelectChannelConnector.java:152)
at
org.mortbay.jetty.AbstractConnector.doStart(AbstractConnector.java:313)
at
org.mortbay.jetty.nio.SelectChannelConnector.doStart(SelectChannelConnector.java:124)
at
org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:38)
at org.mortbay.jetty.Server.doStart(Server.java:217)
at
org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:38)
at
com.noelios.restlet.ext.jetty.JettyServerHelper.start(JettyServerHelper.java:152)
at
com.noelios.restlet.ext.jetty.HttpServerHelper.start(HttpServerHelper.java:90)
at org.restlet.Server.start(Server.java:265)
at org.restlet.Component.start(Component.java:100)
at org.restlet.Container.start(Container.java:162)
at com.piy.restlet.Playground.main(Playground.java:71)
If i look at the stacktrace I think the problem lies in the fact that
container.stop() doesn't stop the server (Doesn't propogate the call
to Server(s)) and the next call to start() tries to start the
(new?)server.
Now is that a bug or does the contract of the container say that once
you have started a container stop doesn't stop the servers or that
there is latency to be expected or that starting after a stop isn't
expected?
Cheers
Piyush
-------------------------------------------------------------------------------------------
Code snippet to reproduce the problem
Container container = new Container();
ServerList servers = container.getServers();
Protocol httpProtocol = Protocol.HTTP;
String ipAddress = "127.0.0.1";
int httpPort = 8184;
servers.add(httpProtocol, ipAddress, httpPort);
VirtualHost host = VirtualHost.createLocalHost(container.getContext());
host.attach("/something", new Restlet() {
protected void handleGet(Request request, Response response) {
response.setEntity("ManagedDelegatedRestletContainerFlavTwo says Hello
World!", MediaType.TEXT_PLAIN);
}
});
container.setDefaultHost(host);
container.start();
try {
Thread.sleep(5000);
} catch (InterruptedException ex) {
Thread.currentThread().interrupt();
}
System.out.println("Stopping container!");
container.stop();
try {
Thread.sleep(5000);
} catch (InterruptedException ex) {
Thread.currentThread().interrupt();
}
System.out.println("Starting the container again!");
container.start();