protected void addEnvelope( Envelope env ) { if( !envelopes.offer( env ) ) { throw new KernelException( "Critical error, could not enqueue envelope." ); } } }
public void send( ByteBuffer data ) { if( data == null ) { throw new IllegalArgumentException( "Data cannot be null." ); } if( closing ) { throw new KernelException( "Endpoint has been closed:" + socket ); } send( data, true, true ); }
public void send( ByteBuffer data ) { if( !isConnected() ) { throw new KernelException( "Endpoint is not connected:" + this ); } try { DatagramPacket p = new DatagramPacket( data.array(), data.position(), data.remaining(), address ); // Just queue it up for the kernel threads to write // out kernel.enqueueWrite( this, p ); //socket.send(p); } catch (Exception e) { if (e instanceof SocketException) { throw new KernelException("Error sending datagram to:" + address, e); } else if (e instanceof RuntimeException) { throw (RuntimeException) e; } else { throw new RuntimeException(e); } } }
public void terminate() throws InterruptedException { if( thread == null ) throw new IllegalStateException( "Kernel not initialized." ); try { thread.close(); writer.shutdown(); 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 ); } } } }
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 close( boolean flush ) { // No real reason to flush UDP traffic yet... especially // when considering that the outbound UDP isn't even // queued. try { kernel.closeEndpoint(this); connected = false; } catch( IOException e ) { throw new KernelException( "Error closing endpoint for socket:" + socket, e ); } }
public void initialize() { if( thread != null ) throw new IllegalStateException( "Kernel already initialized." ); writer = Executors.newFixedThreadPool(2, new NamedThreadFactory(toString() + "-writer")); thread = createHostThread(); try { thread.connect(); thread.start(); } catch( IOException e ) { throw new KernelException( "Error hosting:" + address, e ); } }
public void initialize() { if( thread != null ) throw new IllegalStateException( "Kernel already initialized." ); thread = createSelectorThread(); try { thread.connect(); thread.start(); } catch( IOException e ) { throw new KernelException( "Error hosting:" + address, e ); } }
public void close( boolean flushData ) { if( flushData ) { closing = true; // Enqueue a close marker message to let the server // know we should close send( CLOSE_MARKER, false, true ); return; } try { // Note: even though we may be disconnected from the socket.isConnected() // standpoint, it's still safest to tell the kernel so that it can be sure // to stop managing us gracefully. kernel.closeEndpoint(this); } catch( IOException e ) { throw new KernelException( "Error closing endpoint for socket:" + socket, e ); } }
public void run() { // Not guaranteed to always work but an extra datagram // to a dead connection isn't so big of a deal. if( !endpoint.isConnected() ) { return; } try { thread.getSocket().send(packet); } catch( Exception e ) { KernelException exc = new KernelException( "Error sending datagram to:" + address, e ); exc.fillInStackTrace(); reportError(exc); } } }
protected void addEnvelope( Envelope env ) { if( !envelopes.offer( env ) ) { throw new KernelException( "Critical error, could not enqueue envelope." ); } } }
protected void addEnvelope( Envelope env ) { if( !envelopes.offer( env ) ) { throw new KernelException( "Critical error, could not enqueue envelope." ); } } }
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 terminate() throws InterruptedException { if( thread == null ) throw new IllegalStateException( "Kernel not initialized." ); try { thread.close(); writer.shutdown(); thread = null; } catch( IOException e ) { throw new KernelException( "Error closing host connection:" + address, e ); } }
public void send( ByteBuffer data ) { if( data == null ) { throw new IllegalArgumentException( "Data cannot be null." ); } if( closing ) { throw new KernelException( "Endpoint has been closed:" + socket ); } send( data, true, true ); }
public void send( ByteBuffer data ) { if( data == null ) { throw new IllegalArgumentException( "Data cannot be null." ); } if( closing ) { throw new KernelException( "Endpoint has been closed:" + socket ); } send( data, true, true ); }
public void close( boolean flush ) { // No real reason to flush UDP traffic yet... especially // when considering that the outbound UDP isn't even // queued. try { kernel.closeEndpoint(this); connected = false; } catch( IOException e ) { throw new KernelException( "Error closing endpoint for socket:" + socket, e ); } }
public void close( boolean flush ) { // No real reason to flush UDP traffic yet... especially // when considering that the outbound UDP isn't even // queued. try { kernel.closeEndpoint(this); connected = false; } catch( IOException e ) { throw new KernelException( "Error closing endpoint for socket:" + socket, e ); } }
public void initialize() { if( thread != null ) throw new IllegalStateException( "Kernel already initialized." ); thread = createSelectorThread(); try { thread.connect(); thread.start(); } catch( IOException e ) { throw new KernelException( "Error hosting:" + address, e ); } }