Hi again, Thanks an interesting issue :-) After investigation, the Container does close the connectors as intended. This is actually done by the Component super class. In the Jetty 6 case, it does invoke the stop() method on the Jetty server, which apparently invokes the close() / stop() methods on the internal connectors...
That was weird to see that. Looking at the JDK's docs on ServerSocket, I've realized that a call to "setReuseAddress(true)" must be done before binding if you want to reuse the socket. Jetty 6 doesn't seem to set this property so I guess that the core of the problem. I'll send an email to Jetty's list for confirmation. Any other thoughts? Best regards, Jerome > -----Message d'origine----- > De : Piyush Purang [mailto:[EMAIL PROTECTED] > Envoyé : dimanche 22 octobre 2006 14:54 > À : discuss@restlet.tigris.org > Objet : starting, stopping and starting a container throws an > exception > > 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(ServerSocketChannelImp > l.java:119) > at > sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:59) > at > org.mortbay.jetty.nio.SelectChannelConnector.open(SelectChanne > lConnector.java:152) > at > org.mortbay.jetty.AbstractConnector.doStart(AbstractConnector. > java:313) > at > org.mortbay.jetty.nio.SelectChannelConnector.doStart(SelectCha > nnelConnector.java:124) > at > org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycl > e.java:38) > at org.mortbay.jetty.Server.doStart(Server.java:217) > at > org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycl > e.java:38) > at > com.noelios.restlet.ext.jetty.JettyServerHelper.start(JettySer > verHelper.java:152) > at > com.noelios.restlet.ext.jetty.HttpServerHelper.start(HttpServe > rHelper.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(); > >