{"action":"created","issue":{"url":"https://api.github.com/repos/dekellum/rjack/issues/9","labels_url":"https://api.github.com/repos/dekellum/rjack/issues/9/labels{/name}","comments_url":"https://api.github.com/repos/dekellum/rjack/issues/9/comments","events_url":"https://api.github.com/repos/dekellum/rjack/issues/9/events","html_url":"https://github.com/dekellum/rjack/pull/9","id":121869492,"number":9,"title":"add inherit_channel attribute for rjack-jetty","user":{"login":"uchida","id":578500,"avatar_url":"https://avatars.githubusercontent.com/u/578500?v=3","gravatar_id":"","url":"https://api.github.com/users/uchida","html_url":"https://github.com/uchida","followers_url":"https://api.github.com/users/uchida/followers","following_url":"https://api.github.com/users/uchida/following{/other_user}","gists_url":"https://api.github.com/users/uchida/gists{/gist_id}","starred_url":"https://api.github.com/users/uchida/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/uchida/subscriptions","organizations_url":"https://api.github.com/users/uchida/orgs","repos_url":"https://api.github.com/users/uchida/repos","events_url":"https://api.github.com/users/uchida/events{/privacy}","received_events_url":"https://api.github.com/users/uchida/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-12-12T18:03:22Z","updated_at":"2015-12-14T17:29:07Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/dekellum/rjack/pulls/9","html_url":"https://github.com/dekellum/rjack/pull/9","diff_url":"https://github.com/dekellum/rjack/pull/9.diff","patch_url":"https://github.com/dekellum/rjack/pull/9.patch"},"body":"This pull request add `inherit_channel` attribute to enable hot deploy, shutdown old process after new process is listening, with [`start_server`](https://metacpan.org/pod/start_server).\r\n\r\nOriginally [`setInheritChannel`](http://download.eclipse.org/jetty/9.3.6.v20151106/apidocs/org/eclipse/jetty/server/ServerConnector.html#setInheritChannel-boolean-) for `org.eclipse.jetty.server.Connector` is for `inetd` support, but this can use for hot deploy with `server_starter` >= 0.28\r\n\r\n[Server::Starter meets Java](http://www.slideshare.net/tokuhirom/serverstarter-meets-java) describes `start_server` and how it works with Java web application.\r\n\r\nA hot deploy sample is following:\r\n\r\n1. start rjack-jetty sample code with `start_server`\r\n  ```console\r\n$ start_server --port=8080=0 --kill-old-delay=20 -- jruby server.rb\r\n  ```\r\n with `--port=8080=0` `start_server` use port `8080` and file descriptor `0` for `inherit_channel`, and with `--kill-old-delay=20`, `start_server` wait 20 seconds to kill old process.\r\n  `server.rb` code, borrowed from `rjack-jetty` sample, is following:\r\n  ```ruby\r\nrequire 'rjack-jetty'\r\nrequire 'rjack-jetty/test-servlets'\r\n\r\ninclude RJack\r\n\r\nfactory = Jetty::ServerFactory.new\r\nfactory.inherit_channel = true\r\nfactory.port = 8080\r\nfactory.set_context_servlets('/', '/*' => Jetty::TestServlets::SnoopServlet.new)\r\n\r\nserver = factory.create\r\nserver.start\r\nserver.join\r\n  ```\r\n  \r\n2. hot deploy with `kill -HUP`. `start_server` launch new process and kill old process.\r\n  ```console \r\n$ kill -HUP {start_server pid}\r\n  ```\r\n\r\nI also confirmed [fishwife](https://github.com/dekellum/fishwife/), rack server using `rjack-jetty`, work with this pull request by giving `-O inherited_channel` option."},"comment":{"url":"https://api.github.com/repos/dekellum/rjack/issues/comments/164502710","html_url":"https://github.com/dekellum/rjack/pull/9#issuecomment-164502710","issue_url":"https://api.github.com/repos/dekellum/rjack/issues/9","id":164502710,"user":{"login":"uchida","id":578500,"avatar_url":"https://avatars.githubusercontent.com/u/578500?v=3","gravatar_id":"","url":"https://api.github.com/users/uchida","html_url":"https://github.com/uchida","followers_url":"https://api.github.com/users/uchida/followers","following_url":"https://api.github.com/users/uchida/following{/other_user}","gists_url":"https://api.github.com/users/uchida/gists{/gist_id}","starred_url":"https://api.github.com/users/uchida/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/uchida/subscriptions","organizations_url":"https://api.github.com/users/uchida/orgs","repos_url":"https://api.github.com/users/uchida/repos","events_url":"https://api.github.com/users/uchida/events{/privacy}","received_events_url":"https://api.github.com/users/uchida/received_events","type":"User","site_admin":false},"created_at":"2015-12-14T17:29:07Z","updated_at":"2015-12-14T17:29:07Z","body":"> 1. What version(s) of Jetty support the connector.inherit_channel property?\r\n\r\nFrom [jetty >= 9.0.0](https://github.com/eclipse/jetty.project/blob/jetty-9.0.0.M0/jetty-server/src/main/java/org/eclipse/jetty/server/ServerConnector.java#L167-L170), ServerConnector support has `setInheritedChannel` method.\r\n\r\nFor [jetty 8](http://download.eclipse.org/jetty/8.1.17.v20150415/apidocs/org/eclipse/jetty/server/nio/InheritedChannelConnector.html) and [jetty 7](http://download.eclipse.org/jetty/7.6.17.v20150415/apidocs/), there are no `setInheritedChannel` method, but `InheritedChannelConnector` is available, so using this instead of `SelectChannelConnector` will work.\r\n\r\n> 2. Is this only usable for at most one channel and thus one connector, or will it work with multiple? If only the former, then the top-level ServerFactory property should probably not be included.\r\n\r\nThis will work multiple connector.\r\n\r\nDive into the detail, [jetty](https://github.com/eclipse/jetty.project/blob/jetty-9.3.6.v20151106/jetty-server/src/main/java/org/eclipse/jetty/server/ServerConnector.java#L311-L318) uses [System.inheritedChannel](http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/6-b14/java/lang/System.java#System.inheritedChannel%28%29) and tracking this method in OpenJDK source codes, finally get [createChannel in sun.nio.ch.InheritedChannel](http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/6-b14/sun/nio/ch/InheritedChannel.java#InheritedChannel.createChannel%28%29).\r\nIn this method, duplicating fd 0 with `dup(0)` and use when it is a socket.\r\nAnd `start_server` with `--port=8080=0` option duplicate socket to fd 0 and pass fd0 to jetty.\r\n\r\nMultiple `dup(0)` in [createChannel in sun.nio.ch.InheritedChannel](http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/6-b14/sun/nio/ch/InheritedChannel.java#InheritedChannel.createChannel%28%29) will work for multiple connectors, so it will work for multiple connector.\r\n"}}