@ Override public void run ( ) { // Workaround for Issue #4 (http://code.google.com/p/jdiameter/issues/detail?id=4) // BEGIN WORKAROUND // Give some time to initialization... int sleepTime = 250 ; logger . debug ( "Sleeping for {}ms before starting transport so that listeners can all be added and ready for messages" , sleepTime ) ; try { Thread . sleep ( sleepTime ) ; } catch ( InterruptedException e ) { // ignore } logger . debug ( "Finished sleeping for {}ms. By now, MutablePeerTableImpl should have added its listener" , sleepTime ) ; logger . debug ( "Transport is started. Socket is [{}]" , socketDescription ) ; Selector selector = null ; try { selector = Selector . open ( ) ; socketChannel . register ( selector , SelectionKey . OP_READ ) ; while ( ! stop ) { selector . select ( SELECT_TIMEOUT ) ; Iterator < SelectionKey > it = selector . selectedKeys ( ) . iterator ( ) ; while ( it . hasNext ( ) ) { // Get the selection key SelectionKey selKey = it . next ( ) ; // Remove it from the list to indicate that it is being processed it . remove ( ) ; if ( selKey . isValid ( ) && selKey . isReadable ( ) ) { // Get channel with bytes to read SocketChannel sChannel = ( SocketChannel ) selKey . channel ( ) ; int dataLength = sChannel . read ( buffer ) ; logger . debug ( "Just read [{}] bytes on [{}]" , dataLength , socketDescription ) ; if ( dataLength == - 1 ) { stop = true ; break ; } buffer . flip ( ) ; byte [ ] data = new byte [ buffer . limit ( ) ] ; buffer . get ( data ) ; append ( data ) ; buffer . clear ( ) ; } } } } catch ( ClosedByInterruptException e ) { logger . error ( "Transport exception " , e ) ; } catch ( AsynchronousCloseException e ) { logger . error ( "Transport is closed" ) ; } catch ( Throwable e ) { logger . error ( "Transport exception " , e ) ; } finally { try { clearBuffer ( ) ; if ( selector != null ) { selector . close ( ) ; } if ( socketChannel != null && socketChannel . isOpen ( ) ) { socketChannel . close ( ) ; } getParent ( ) . onDisconnect ( ) ; } catch ( Exception e ) { logger . error ( "Error" , e ) ; } stop = false ; logger . info ( "Read thread is stopped for socket [{}]" , socketDescription ) ; } }
PCB added logging