hc-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Asankha C. Perera (JIRA)" <j...@apache.org>
Subject [jira] Commented: (HTTPCORE-127) Expose improved API for lifecycle management
Date Tue, 27 Nov 2007 19:51:43 GMT

    [ https://issues.apache.org/jira/browse/HTTPCORE-127?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12545991

Asankha C. Perera commented on HTTPCORE-127:

Hi Oleg

Thanks for your reply, and upgrading my JDK solved the initial problem. Now I get the above
code to work. However, as soon as I introduce a select call into the scenario, I am unable
to re-register the new ServerSocketChannel with the (already open) Selector I had before (i.e.
the call blocks). As I explicitly cancel the SelectionKey, I am assuming that the Selector
I was using before can be reused again. Can you try this class on your end when you get some
free time

many thanks

package org.apache.http.examples.nio;

import java.nio.channels.SelectionKey;
import java.nio.channels.ServerSocketChannel;
import java.nio.channels.Selector;
import java.net.InetSocketAddress;
import java.io.IOException;

public class OlegTest {

    private Selector selector = null;

    public static void main(String[] args) throws Exception {
        OlegTest t = new OlegTest();

    private void execute() throws Exception {
        SelectionKey key = null;
        selector = Selector.open();

        ServerSocketChannel serverChannel = ServerSocketChannel.open();
        serverChannel.socket().bind(new InetSocketAddress(8080));
        key = serverChannel.register(selector, SelectionKey.OP_ACCEPT);
        System.out.println("Started... sleeping 5s");

        new Thread(new Worker()).start();

        // This will cause the server to stop accepting connections on port 8080
        System.out.println("Stopped... sleeping 10s");

        // This will cause the server to resume accepting connections on port 8080
        serverChannel = ServerSocketChannel.open();
        serverChannel.socket().bind(new InetSocketAddress(8080));
        System.out.println("Getting stuck here");
        key = serverChannel.register(selector, SelectionKey.OP_ACCEPT);
        System.out.println("Re-Started... sleeping 10s");

    private class Worker implements Runnable {
        public void run() {
            try {
                while (true) {
                    int ret = selector.select(5000);
                    System.out.println("Selector returned : " + ret);
            } catch (IOException e) {


> Expose improved API for lifecycle management
> --------------------------------------------
>                 Key: HTTPCORE-127
>                 URL: https://issues.apache.org/jira/browse/HTTPCORE-127
>             Project: HttpComponents Core
>          Issue Type: Improvement
>          Components: HttpCore NIO
>    Affects Versions: 4.0-alpha6
>            Reporter: Asankha C. Perera
>             Fix For: 4.0-beta1
> Apache Synapse uses HttpCore and we would like to stop accepting new connections to put
our servers into a "maintenance" mode. In this mode any in-flight requests already being served
will continue as normal (i.e. reading, writing etc) but new connections should be rejected,
so that a load balancer could direct new connections to another instance in the cluster. The
requirement is to then update configuration, apply patches or cleanly shutdown etc. for maintenance
without effecting any in-flight requests.
> Implementation wise I think this would be fairly straightforward as we can remove OP_ACCEPT
from the interested ops.
> On the mailing list Odi suggested that we tackle this at a broader level by exposing
lifecycle management APIs
> "I suggest create, start, stop, destroy methods in some classes/APIs (semantics of JBoss
Service MBeans)"

This message is automatically generated by JIRA.
You can reply to this email to add a comment to the issue online.

To unsubscribe, e-mail: httpcomponents-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpcomponents-dev-help@jakarta.apache.org

View raw message