Example usage for java.io InterruptedIOException toString

List of usage examples for java.io InterruptedIOException toString

Introduction

In this page you can find the example usage for java.io InterruptedIOException toString.

Prototype

public String toString() 

Source Link

Document

Returns a short description of this throwable.

Usage

From source file:marytts.tools.perceptiontest.PerceptionTestHttpServer.java

public void run() {
    logger.info("Starting server.");
    System.out.println("Starting server....");
    //int localPort = MaryProperties.needInteger("socket.port");
    int localPort = serverPort;

    HttpParams params = new BasicHttpParams();
    params.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, 0) // 0 means no timeout, any positive value means time out in miliseconds (i.e. 50000 for 50 seconds)
            .setIntParameter(CoreConnectionPNames.SOCKET_BUFFER_SIZE, 8 * 1024)
            .setBooleanParameter(CoreConnectionPNames.STALE_CONNECTION_CHECK, false)
            .setBooleanParameter(CoreConnectionPNames.TCP_NODELAY, true)
            .setParameter(CoreProtocolPNames.ORIGIN_SERVER, "HttpComponents/1.1");

    BasicHttpProcessor httpproc = new BasicHttpProcessor();
    httpproc.addInterceptor(new ResponseDate());
    httpproc.addInterceptor(new ResponseServer());
    httpproc.addInterceptor(new ResponseContent());
    httpproc.addInterceptor(new ResponseConnControl());

    BufferingHttpServiceHandler handler = new BufferingHttpServiceHandler(httpproc,
            new DefaultHttpResponseFactory(), new DefaultConnectionReuseStrategy(), params);

    // Set up request handlers
    HttpRequestHandlerRegistry registry = new HttpRequestHandlerRegistry();
    //registry.register("/perceptionTest", new FileDataRequestHandler("perception.html"));
    //registry.register("/process", new FileDataRequestHandler("perception.html"));
    //registry.register("/perceptionTest", new UtterancePlayRequestHandler());

    DataRequestHandler infoRH = new DataRequestHandler(this.testXmlName);
    UserRatingStorer userRatingRH = new UserRatingStorer(this.userRatingsDirectory, infoRH);
    registry.register("/options", infoRH);
    registry.register("/queryStatement", infoRH);
    registry.register("/process", new UtterancePlayRequestHandler(infoRH));
    registry.register("/perceptionTest", new PerceptionRequestHandler(infoRH, userRatingRH));
    registry.register("/userRating", new StoreRatingRequestHandler(infoRH, userRatingRH));
    registry.register("*", new FileDataRequestHandler());

    handler.setHandlerResolver(registry);

    // Provide an event logger
    handler.setEventListener(new EventLogger());

    IOEventDispatch ioEventDispatch = new DefaultServerIOEventDispatch(handler, params);

    //int numParallelThreads = MaryProperties.getInteger("server.http.parallelthreads", 5);
    int numParallelThreads = 5;

    logger.info("Waiting for client to connect on port " + localPort);
    System.out.println("Waiting for client to connect on port " + localPort);

    try {/*from   www  .ja  va2  s.  c om*/
        ListeningIOReactor ioReactor = new DefaultListeningIOReactor(numParallelThreads, params);
        ioReactor.listen(new InetSocketAddress(localPort));
        ioReactor.execute(ioEventDispatch);
    } catch (InterruptedIOException ex) {
        logger.info("Interrupted", ex);
        System.out.println("Interrupted" + ex.toString());
    } catch (IOException e) {
        logger.info("Problem with HTTP connection ", e);
        System.out.println("Problem with HTTP connection " + e.toString());
    }
    logger.debug("Shutdown");
    System.out.println("Shutdown");
}

From source file:org.jzkit.z3950.util.ZEndpoint.java

public void run() {
    log.debug("Bringing assoc up........Active Z Thread counter = " + (++active_thread_counter));
    log.debug("My thread priority : " + this.getPriority());
    log.debug("My isDaemon: " + this.isDaemon());

    try {//from   w w w  .ja v a  2  s  .c o  m
        assoc_status = ASSOC_STATUS_CONNECTING;
        connect();
        assoc_status = ASSOC_STATUS_CONNECTED;
        log.debug("Connect completed OK, Listening for incoming PDUs");
    } catch (ConnectException ce) {
        log.info(ce.toString());
        assoc_status = ASSOC_STATUS_PERM_FAILURE;
        sendDummyFailInitResponse(ce.toString());
        running = false;
    } catch (IOException ioe) {
        log.warn("ZEndpoint thread encountered an exception", ioe);
        assoc_status = ASSOC_STATUS_PERM_FAILURE;
        sendDummyFailInitResponse(ioe.toString());
        running = false;
    }

    while (running) {
        try {
            log.debug("Waiting for data on input stream.....");
            BERInputStream bds = new BERInputStream(incoming_data, charset_encoding, DEFAULT_BUFF_SIZE, reg);
            PDU_type pdu = null;
            pdu = (PDU_type) codec.serialize(bds, pdu, false, "PDU");
            log.debug("Notifiy observers");

            if (pdu.which == PDU_type.close_CID) {
                log.debug("Just got a close APDU");
                close_notified = true;
            }

            decOpCount();

            notifyAPDUEvent(pdu);

            // If the target does not support concurrent operations then it's possible that
            // outbound APDU's have stacked up whilst we wait for the response handled here.
            // Therefore, here we  check the outgoing apdu queue and send any messages that
            // have been queued
            if (!close_notified)
                sendPending();

            log.debug("Yield to other threads....");
            yield();
        } catch (InterruptedIOException iioe) {
            log.debug("Processing java.io.InterruptedIOException, shut down association" + " - hostname="
                    + target_hostname);
            log.info(iioe.toString());
            running = false;
        } catch (SocketException se) {
            // Most likely socket closed.
            log.info("SocketException");
            log.info(se.toString() + " - hostname=" + target_hostname);
            running = false;
        } catch (Exception e) {
            log.warn("ZEndpoint Unknown error", e);
            log.info(e.toString() + " - hostname=" + target_hostname);
            running = false;
        } finally {
        }
    }

    synchronized (op_counter_lock) {
        op_counter_lock.notifyAll();
    }

    // We might need to notify any listening objects that the assoc has been
    // shut down if the target did not send a close before snapping the assoc
    // (Or in case there was a network problem etc)
    if (!close_notified) {
        notifyClose();
    }

    // End of association, clear out all listeners
    log.debug("End of ZEndpoint listening thread for host " + target_hostname + " active z thread counter="
            + (--active_thread_counter));
    pdu_announcer.deleteObservers();
    pdu_announcer = null;

    try {
        incoming_data = null;
        outgoing_data = null;
        if (z_assoc != null)
            z_assoc.close();
    } catch (Exception e) {
        // catches the socket close execption...
    }

    assoc_status = ASSOC_STATUS_IDLE;
    z_assoc = null;
}