public void drainInbound() { if (!getServiceState().isStarted() || readSource.isSuspended()) { return; } try { long initial = codec.getReadCounter(); // Only process upto 2 x the read buffer worth of data at a time so we can give // other connections a chance to process their requests. while( codec.getReadCounter()-initial < codec.getReadBufferSize()<<2 ) { Object command = codec.read(); if ( command!=null ) { try { listener.onTransportCommand(command); } catch (Throwable e) { e.printStackTrace(); onTransportFailure(new IOException("Transport listener failure.")); } // the transport may be suspended after processing a command. if (getServiceState() == STOPPED || readSource.isSuspended()) { return; } } else { return; } } yieldSource.merge(1); } catch (IOException e) { onTransportFailure(e); } }
public void drainInbound() { if (!getServiceState().isStarted() || readSource.isSuspended()) { return; } try { long initial = codec.getReadCounter(); // Only process upto 2 x the read buffer worth of data at a time so we can give // other connections a chance to process their requests. while( codec.getReadCounter()-initial < codec.getReadBufferSize()<<2 ) { Object command = codec.read(); if ( command!=null ) { try { listener.onTransportCommand(command); } catch (Throwable e) { e.printStackTrace(); onTransportFailure(new IOException("Transport listener failure.")); } // the transport may be suspended after processing a command. if (getServiceState() == STOPPED || readSource.isSuspended()) { return; } } else { return; } } yieldSource.merge(1); } catch (IOException e) { onTransportFailure(e); } }
private void accept() { if (getServiceState().isStarted() || getServiceState().isStarting()) { try { UdpTransport udpTransport = createTransport(); transport = udpTransport; transport.onDispose = new Task() { public void run() { queueAccept(); } }; channel = DatagramChannel.open(); channel.socket().bind(bindAddress); transport.connected(channel); listener.onAccept(transport); } catch (Exception e) { listener.onAcceptError(e); } } }