logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Aston Chan" <ac...@altaworks.com>
Subject Re: Shutting down SocketServer programmatically?
Date Tue, 16 Jan 2001 14:34:03 GMT
Ceki,

I've added a shutdown() method inside my SocketServer.  All it does is
to set a static member isShutdown flag to true PLUS try to connect to
the socket.

In the serverSock.accept() code, when accept() is interrupted, it will
always check the isShutdown flag.  If true, then we're done.  Here is
the code segment:

        try
        {
            // we can create the server now
            while(!isShutdown)
            {
                Socket socket = serverSocket.accept();

                if (isShutdown)
                {
                    logServerCat.info("LogServer shutting down");
                    System.exit(0);
                }

                // start a SocketNode for every request
                new Thread(new SocketNode(socket,
Category.getDefaultHierarchy())).start();
            }
        }
        catch (Exception ee)
        {
            logServerCat.error("", ee);
        }

...

    public static void shutdown()
    {
        // someone called the shutdown method, we need to shutdown properly
so
        // the .logServer can be removed properly
        isShutdown = true;

        // this will trigger the serverSocket to get out of the accept call
        // and since isShutdown is set to true, it will terminate the run()
        // thread properly
        try
        {
            Socket socket = new Socket(host, port);
        }
        catch (IOException ioe)
        {
        }
    }

This should do it.

-Aston

----- Original Message -----
From: "Ceki Gulcu" <cgu@urbanet.ch>
To: "LOG4J Users Mailing List" <log4j-user@jakarta.apache.org>
Cc: "Aston Chan" <achan@altaworks.com>
Sent: Tuesday, January 16, 2001 8:22 AM
Subject: Re: Shutting down SocketServer programmatically?


>
>
> At 11:12 15.01.2001 -0500, you wrote:
> >Hi,
> >
> >Just wonder if there is a proper way to shutdown the SocketServer?
> >I..e. instead of doing  Ctrl-C.
>
> No there isn't I'll add this to my todo list. Ceki
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: log4j-user-help@jakarta.apache.org
>


Mime
View raw message