Hello.

ServletContextListener is the only part that opens/closes the stream. I even checked the usages in Netbeans to test it. The stream is opened in the init() method, closed in the shutdown() method, and written to in the notify() method. There are not any other usages of the stream. init() is called only from contextInitialized(), and shutdown() is called only from contextDestroyed(). notify() is called from various parts of the app, but it only writes to the stream. Here are the relevant parts of the code:

    /**
     * The event handler output stream.
     */
    static OutputStream out;
    /**
     * The writer to the handler.
     */
    static PrintWriter writer;
   
    /**
     * Initializes this notifier.
     *
     * @param binaryFileName            name of the binary file of the event handler
     */
    public static void init(String eventHandlerFileName) throws IOException {
        eventHandler = Runtime.getRuntime().exec(eventHandlerFileName);
        out = eventHandler.getOutputStream();
        writer = new PrintWriter(out, true);
        notify(EVENT_INIT_MONITOR, null, -1, -1); // works ok

        // snipped
    }
    /**
     * Shuts down this notifier.
     */
    public static void shutdown() {
        // snipped

        // the following two calls work OK in Tomcat,
        // but do not work any more in Winstone
        notify(EVENT_SHUTDOWN_MONITOR, null, -1, -1);
        notify(EVENT_DESTROY_HANDLER, null, -1, -1);
        try {
            writer.close();
            out.close();
        } catch(IOException e) {
            /* empty */
        }
    }

The method notify() sends data over the pipe to another process, using the PrintWriter. notify() inside init() and in any other part of the app works ok, except for the call from inside the shutdown() method. Instead, IOException: Broken pipe is thrown. It look as if the java process would close I/O with another process for some reason, before contextDestroyed() is called.

Thanks,
Artur