protected void reportError( Endpoint p, Object context, Exception e ) { // Should really be queued up so the outer thread can // retrieve them. For now we'll just log it. FIXME log.log( Level.SEVERE, "Unhandled error, endpoint:" + p + ", context:" + context, e ); if( p.isConnected() ) { // In lieu of other options, at least close the endpoint p.close(); } }
@Override public String getAddress() { return channels[CH_RELIABLE] == null ? null : channels[CH_RELIABLE].getAddress(); }
@Override public void send( Message message ) { if( log.isLoggable(Level.FINER) ) { log.log(Level.FINER, "send({0})", message); } ByteBuffer buffer = MessageProtocol.messageToBuffer(message, null); if( message.isReliable() || channels[CH_UNRELIABLE] == null ) { channels[CH_RELIABLE].send( buffer ); } else { channels[CH_UNRELIABLE].send( buffer ); } }
protected void connectionClosed( Endpoint p ) if( p.isConnected() ) { log.log( Level.FINE, "Connection closed:{0}.", p ); } else {
@Override public void close( String reason ) { // Send a reason DisconnectMessage m = new DisconnectMessage(); m.setType( DisconnectMessage.KICK ); m.setReason( reason ); m.setReliable( true ); send( m ); // Just close the reliable endpoint // fast will be cleaned up as a side-effect // when closeConnection() is called by the // connectionClosed() endpoint callback. if( channels[CH_RELIABLE] != null ) { // Close with flush so we make sure our // message gets out channels[CH_RELIABLE].close(true); } }
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); } } }
@Override public void close( String reason ) { // Send a reason DisconnectMessage m = new DisconnectMessage(); m.setType( DisconnectMessage.KICK ); m.setReason( reason ); m.setReliable( true ); send( m ); // Just close the reliable endpoint // fast will be cleaned up as a side-effect // when closeConnection() is called by the // connectionClosed() endpoint callback. if( channels[CH_RELIABLE] != null ) { // Close with flush so we make sure our // message gets out channels[CH_RELIABLE].close(true); } }
protected void closeConnection() { if( closed ) return; closed = true; // Make sure all endpoints are closed. Note: reliable // should always already be closed through all paths that I // can conceive... but it doesn't hurt to be sure. for( Endpoint p : channels ) { if( p == null || !p.isConnected() ) continue; p.close(); } fireConnectionRemoved( this ); }
@Override public void send( int channel, Message message ) { if( log.isLoggable(Level.FINER) ) { log.log(Level.FINER, "send({0}, {1})", new Object[]{channel, message}); } checkChannel(channel); ByteBuffer buffer = MessageProtocol.messageToBuffer(message, null); channels[channel+CH_FIRST].send(buffer); }
protected void connectionClosed( Endpoint p ) if( p.isConnected() ) { log.log( Level.FINE, "Connection closed:{0}.", p ); } else {
@Override public String getAddress() { return channels[CH_RELIABLE] == null ? null : channels[CH_RELIABLE].getAddress(); }
public void close( String reason ) { // Send a reason DisconnectMessage m = new DisconnectMessage(); m.setType( DisconnectMessage.KICK ); m.setReason( reason ); m.setReliable( true ); send( m ); // Just close the reliable endpoint // fast will be cleaned up as a side-effect // when closeConnection() is called by the // connectionClosed() endpoint callback. if( reliable != null ) { // Close with flush so we make sure our // message gets out reliable.close(true); } }
protected void reportError( Endpoint p, Object context, Exception e ) { // Should really be queued up so the outer thread can // retrieve them. For now we'll just log it. FIXME log.log( Level.SEVERE, "Unhandled error, endpoint:" + p + ", context:" + context, e ); if( p.isConnected() ) { // In lieu of other options, at least close the endpoint p.close(); } }
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 String getAddress() { return reliable == null ? null : reliable.getAddress(); }
protected void closeConnection() { if( closed ) return; closed = true; // Make sure both endpoints are closed. Note: reliable // should always already be closed through all paths that I // can conceive... but it doesn't hurt to be sure. if( reliable != null && reliable.isConnected() ) { reliable.close(); } if( fast != null && fast.isConnected() ) { fast.close(); } fireConnectionRemoved( this ); }
@Override public void send( Message message ) { if( log.isLoggable(Level.FINER) ) { log.log(Level.FINER, "send({0})", message); } ByteBuffer buffer = MessageProtocol.messageToBuffer(message, null); if( message.isReliable() || channels[CH_UNRELIABLE] == null ) { channels[CH_RELIABLE].send( buffer ); } else { channels[CH_UNRELIABLE].send( buffer ); } }
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 closeConnection() { if( closed ) return; closed = true; // Make sure all endpoints are closed. Note: reliable // should always already be closed through all paths that I // can conceive... but it doesn't hurt to be sure. for( Endpoint p : channels ) { if( p == null || !p.isConnected() ) continue; p.close(); } fireConnectionRemoved( this ); }