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 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 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); } } }
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); } } }
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 HostThread createHostThread() { return new HostThread(); }
protected HostThread createHostThread() { return new HostThread(); }
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 ); } }
protected Endpoint getEndpoint( SocketAddress address, boolean create ) { UdpEndpoint p = socketEndpoints.get(address); if( p == null && create ) { p = new UdpEndpoint( this, nextEndpointId(), address, thread.getSocket() ); socketEndpoints.put( address, p ); // Add an event for it. addEvent( EndpointEvent.createAdd( this, p ) ); } return p; }
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 close() throws IOException, InterruptedException { // Set the thread to stop go.set(false); // Make sure the channel is closed socket.close(); // And wait for it join(); }
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." ); 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 close() throws IOException, InterruptedException { // Set the thread to stop go.set(false); // Make sure the channel is closed socket.close(); // And wait for it join(); }
protected Endpoint getEndpoint( SocketAddress address, boolean create ) { UdpEndpoint p = socketEndpoints.get(address); if( p == null && create ) { p = new UdpEndpoint( this, nextEndpointId(), address, thread.getSocket() ); socketEndpoints.put( address, p ); // Add an event for it. addEvent( EndpointEvent.createAdd( this, p ) ); } return p; }
protected HostThread createHostThread() { return new HostThread(); }
protected Endpoint getEndpoint( SocketAddress address, boolean create ) { UdpEndpoint p = socketEndpoints.get(address); if( p == null && create ) { p = new UdpEndpoint( this, nextEndpointId(), address, thread.getSocket() ); socketEndpoints.put( address, p ); // Add an event for it. addEvent( EndpointEvent.createAdd( this, p ) ); } return p; }
public void close() throws IOException, InterruptedException { // Set the thread to stop go.set(false); // Make sure the channel is closed socket.close(); // And wait for it join(); }