public void stop(final Runnable onCompleted) { if( acceptSource.isCanceled() ) { onCompleted.run(); } else { acceptSource.setCancelHandler(new Runnable() { public void run() { try { channel.close(); } catch (IOException e) { } if( onCompleted!=null ) { onCompleted.run(); } } }); acceptSource.cancel(); } }
public void resume() { acceptSource.resume(); }
public void suspend() { acceptSource.suspend(); }
acceptSource.setEventHandler(new Runnable() { public void run() { try { acceptSource.setCancelHandler(new Runnable() { public void run() { try { acceptSource.resume(); if( onCompleted!=null ) { dispatchQueue.execute(onCompleted);
protected void onConnected() throws IOException { readSource = Dispatch.createSource(channel, SelectionKey.OP_READ, dispatchQueue); writeSource = Dispatch.createSource(channel, SelectionKey.OP_WRITE, dispatchQueue); readSource.setCancelHandler(CANCEL_HANDLER); writeSource.setCancelHandler(CANCEL_HANDLER); readSource.setEventHandler(new Runnable() { public void run() { drainInbound(); } }); writeSource.setEventHandler(new Runnable() { public void run() { drainOutbound(); } }); if( max_read_rate!=0 || max_write_rate!=0 ) { rateLimitingChannel = new RateLimitingChannel(); schedualRateAllowanceReset(); } remoteAddress = channel.socket().getRemoteSocketAddress().toString(); listener.onTransportConnected(this); }
public void run() { if (getServiceState() != STARTED) { return; } try { trace("connected."); channel.finishConnect(); readSource.setCancelHandler(null); readSource.cancel(); readSource=null; socketState = new CONNECTED(); onConnected(); } catch (IOException e) { onTransportFailure(e); } } });
protected void drainInbound() { if (!getServiceState().isStarted() || readSource.isSuspended()) { return; } try { long initial = codec.getReadCounter(); // Only process upto 64k worth of data at a time so we can give // other connections a chance to process their requests. while( codec.getReadCounter()-initial < 1024*64 ) { Object command = codec.read(); if ( command!=null ) { try { listener.onTransportCommand(this, command); } catch (Throwable e) { onTransportFailure(new IOException("Transport listener failure.")); } // the transport may be suspended after processing a command. if (getServiceState() == STOPPED || readSource.isSuspended()) { return; } } else { return; } } } catch (IOException e) { onTransportFailure(e); } }
public void setDispatchQueue(DispatchQueue queue) { this.dispatchQueue = queue; if(readSource!=null) readSource.setTargetQueue(queue); if(writeSource!=null) writeSource.setTargetQueue(queue); if(drainOutboundSource!=null) drainOutboundSource.setTargetQueue(queue); if(yieldSource!=null) yieldSource.setTargetQueue(queue); }
acceptSource.setEventHandler(new Runnable() { public void run() { try { acceptSource.setCancelHandler(new Runnable() { public void run() { try { acceptSource.resume(); if( onCompleted!=null ) { dispatchQueue.execute(onCompleted);
protected void onConnected() throws IOException { readSource = Dispatch.createSource(channel, SelectionKey.OP_READ, dispatchQueue); writeSource = Dispatch.createSource(channel, SelectionKey.OP_WRITE, dispatchQueue); readSource.setCancelHandler(CANCEL_HANDLER); writeSource.setCancelHandler(CANCEL_HANDLER); readSource.setEventHandler(new Runnable() { public void run() { drainInbound(); } }); writeSource.setEventHandler(new Runnable() { public void run() { drainOutbound(); } }); if( max_read_rate!=0 || max_write_rate!=0 ) { rateLimitingChannel = new RateLimitingChannel(); schedualRateAllowanceReset(); } remoteAddress = channel.socket().getRemoteSocketAddress().toString(); listener.onTransportConnected(this); }
public void run() { if (!(getServiceState().isStarted())) { return; } try { trace("connected."); channel.finishConnect(); readSource.setCancelHandler(null); readSource.cancel(); readSource=null; socketState = new CONNECTED(); onConnected(); } 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); } }
public void setDispatchQueue(DispatchQueue queue) { this.dispatchQueue = queue; if(readSource!=null) readSource.setTargetQueue(queue); if(writeSource!=null) writeSource.setTargetQueue(queue); if(drainOutboundSource!=null) drainOutboundSource.setTargetQueue(queue); if(yieldSource!=null) yieldSource.setTargetQueue(queue); }
acceptSource.setEventHandler(new Task() { public void run() { try { acceptSource.setCancelHandler(new Task() { public void run() { try { acceptSource.resume(); if( onCompleted!=null ) { dispatchQueue.execute(onCompleted);
public void stop(final Runnable onCompleted) { if( acceptSource.isCanceled() ) { onCompleted.run(); } else { acceptSource.setCancelHandler(new Runnable() { public void run() { try { channel.close(); } catch (IOException e) { } if( onCompleted!=null ) { onCompleted.run(); } } }); acceptSource.cancel(); } }
writeSource = Dispatch.createSource(channel, SelectionKey.OP_WRITE, dispatchQueue); readSource.setCancelHandler(CANCEL_HANDLER); writeSource.setCancelHandler(CANCEL_HANDLER); readSource.setEventHandler(new Task() { public void run() { drainInbound(); writeSource.setEventHandler(new Task() { public void run() { flush();
public void suspend() { acceptSource.suspend(); }
public void resume() { acceptSource.resume(); }