public void terminate() throws InterruptedException { if( thread == null ) throw new IllegalStateException( "Kernel not initialized." ); try { thread.close(); thread = null; // Need to let any caller waiting for a read() wakeup wakeupReader(); } catch( IOException e ) { throw new KernelException( "Error closing host connection:" + address, e ); } }
public void run() { log.log( Level.FINE, "Kernel started for connection:{0}.", address ); // An atomic is safest and costs almost nothing while( go.get() ) { // Setup any queued option changes setupSelectorOptions(); // Check for available keys and process them try { select(); } catch( ClosedSelectorException e ) { if( !go.get() ) return; // it's because we're shutting down throw new KernelException( "Premature selector closing", e ); } catch( CancelledKeyException e ) { if( !go.get() ) return; // it's because we're shutting down throw new KernelException( "Invalid key state", e ); } catch( IOException e ) { if( !go.get() ) return; // error likely due to shutting down reportError( e ); } } } }
protected void read( SelectionKey key ) throws IOException { NioEndpoint p = (NioEndpoint)key.attachment(); SocketChannel c = (SocketChannel)key.channel(); working.clear(); int size; try { size = c.read(working); } catch( IOException e ) { // The remove end forcibly closed the connection... // close out our end and cancel the key cancel( key, c ); return; } if( size == -1 ) { // The remote end shut down cleanly... // close out our end and cancel the key cancel( key, c ); return; } newData( p, c, working, size ); }
public void run() { log.log( Level.INFO, "Kernel started for connection:{0}.", address ); // An atomic is safest and costs almost nothing while( go.get() ) { // Setup any queued option changes setupSelectorOptions(); // Check for available keys and process them try { select(); } catch( ClosedSelectorException e ) { if( !go.get() ) return; // it's because we're shutting down throw new KernelException( "Premature selector closing", e ); } catch( IOException e ) { if( !go.get() ) return; // error likely due to shutting down reportError( e ); } } } }
protected void read( SelectionKey key ) throws IOException { NioEndpoint p = (NioEndpoint)key.attachment(); SocketChannel c = (SocketChannel)key.channel(); working.clear(); int size; try { size = c.read(working); } catch( IOException e ) { // The remove end forcibly closed the connection... // close out our end and cancel the key cancel( key, c ); return; } if( size == -1 ) { // The remote end shut down cleanly... // close out our end and cancel the key cancel( key, c ); return; } newData( p, c, working, size ); }
public void terminate() throws InterruptedException { if( thread == null ) throw new IllegalStateException( "Kernel not initialized." ); try { thread.close(); thread = null; // Need to let any caller waiting for a read() wakeup wakeupReader(); } catch( IOException e ) { throw new KernelException( "Error closing host connection:" + address, e ); } }
protected SelectorThread createSelectorThread() { return new SelectorThread(); }
protected SelectorThread createSelectorThread() { return new SelectorThread(); }
/** * Called by the endpoints when they need to be closed. */ protected void closeEndpoint( NioEndpoint p ) throws IOException { //log.log( Level.FINE, "Closing endpoint:{0}.", p ); thread.cancel(p); }
public void terminate() throws InterruptedException { if( thread == null ) throw new IllegalStateException( "Kernel not initialized." ); try { thread.close(); thread = null; } catch( IOException e ) { throw new KernelException( "Error closing host connection:" + address, e ); } }
public void close() throws IOException, InterruptedException { // Set the thread to stop go.set(false); // Make sure the channel is closed serverChannel.close(); // Force the selector to stop blocking wakeupSelector(); // And wait for it join(); }
/** * Called by the endpoints when they need to be closed. */ protected void closeEndpoint( NioEndpoint p ) throws IOException { log.log( Level.INFO, "Closing endpoint:{0}.", p ); thread.cancel(p); }
public void close() throws IOException, InterruptedException { // Set the thread to stop go.set(false); // Make sure the channel is closed serverChannel.close(); // And wait for it join(); }