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( 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 ); } }
/** * Called by the endpoints when they need to be closed. */ protected void closeEndpoint( UdpEndpoint p ) throws IOException { // Just book-keeping to do here. if( socketEndpoints.remove( p.getRemoteAddress() ) == null ) return; log.log( Level.FINE, "Closing endpoint:{0}.", p ); log.log( Level.FINE, "Socket endpoints size:{0}", socketEndpoints.size() ); addEvent( EndpointEvent.createRemove( this, p ) ); wakeupReader(); }
/** * Dispatches the data to all endpoints managed by the * kernel. 'routing' is currently ignored. */ public void broadcast( Filter<? super Endpoint> filter, ByteBuffer data, boolean reliable, boolean copy ) { if( reliable ) throw new UnsupportedOperationException( "Reliable send not supported by this kernel." ); if( copy ) { // Copy the data just once byte[] temp = new byte[data.remaining()]; System.arraycopy(data.array(), data.position(), temp, 0, data.remaining()); data = ByteBuffer.wrap(temp); } // Hand it to all of the endpoints that match our routing for( UdpEndpoint p : socketEndpoints.values() ) { // Does it match the filter? if( filter != null && !filter.apply(p) ) continue; // Send the data p.send( data ); } }
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); } } }
/** * Dispatches the data to all endpoints managed by the * kernel. 'routing' is currently ignored. */ public void broadcast( Filter<? super Endpoint> filter, ByteBuffer data, boolean reliable, boolean copy ) { if( reliable ) throw new UnsupportedOperationException( "Reliable send not supported by this kernel." ); if( copy ) { // Copy the data just once byte[] temp = new byte[data.remaining()]; System.arraycopy(data.array(), data.position(), temp, 0, data.remaining()); data = ByteBuffer.wrap(temp); } // Hand it to all of the endpoints that match our routing for( UdpEndpoint p : socketEndpoints.values() ) { // Does it match the filter? if( filter != null && !filter.apply(p) ) continue; // Send the data p.send( data ); } }
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( IOException e ) { throw new KernelException( "Error sending datagram to:" + 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 ); } }
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; }
/** * Called by the endpoints when they need to be closed. */ protected void closeEndpoint( UdpEndpoint p ) throws IOException { log.log( Level.INFO, "Closing endpoint:{0}.", p ); // Just book-keeping to do here. socketEndpoints.remove( p.getRemoteAddress() ); addEvent( EndpointEvent.createRemove( this, p ) ); }
/** * Dispatches the data to all endpoints managed by the * kernel. 'routing' is currently ignored. */ public void broadcast( Filter<? super Endpoint> filter, ByteBuffer data, boolean reliable, boolean copy ) { if( reliable ) throw new UnsupportedOperationException( "Reliable send not supported by this kernel." ); if( copy ) { // Copy the data just once byte[] temp = new byte[data.remaining()]; System.arraycopy(data.array(), data.position(), temp, 0, data.remaining()); data = ByteBuffer.wrap(temp); } // Hand it to all of the endpoints that match our routing for( UdpEndpoint p : socketEndpoints.values() ) { // Does it match the filter? if( filter != null && !filter.apply(p) ) continue; // Send the data p.send( data ); } }
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 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 ); } }
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; }
/** * Called by the endpoints when they need to be closed. */ protected void closeEndpoint( UdpEndpoint p ) throws IOException { // Just book-keeping to do here. if( socketEndpoints.remove( p.getRemoteAddress() ) == null ) return; log.log( Level.FINE, "Closing endpoint:{0}.", p ); log.log( Level.FINE, "Socket endpoints size:{0}", socketEndpoints.size() ); addEvent( EndpointEvent.createRemove( this, p ) ); wakeupReader(); }