public void resume() { suspendChanges.incrementAndGet(); if( suspendCount.decrementAndGet() == 0 && this.transport!=null ) { this.transport.resumeRead(); if(this.heartBeatMonitor!=null){ this.heartBeatMonitor.resumeRead(); } } }
pingedAt = 0; if(mqtt.getKeepAlive()>0) { heartBeatMonitor = new HeartBeatMonitor(); heartBeatMonitor.setWriteInterval((mqtt.getKeepAlive() * 1000) / 2); heartBeatMonitor.setTransport(this.transport); heartBeatMonitor.suspendRead(); // to match the suspended state of the transport. heartBeatMonitor.setOnKeepAlive(new Task() { @Override public void run() { heartBeatMonitor.start();
public void run() { if(!executed) { executed = true; requests.remove(requestId); if(heartBeatMonitor!=null) { heartBeatMonitor.stop(); heartBeatMonitor = null; } transport.stop(new Task() { @Override public void run() { listener.onDisconnected(); if (onComplete != null) { onComplete.onSuccess(null); } } }); } } };
heart_beat_monitor.setReadInterval(((long) (keep_alive * 1.5)) * 1000); heart_beat_monitor.setOnDead(new Task() { @Override public void run() { heart_beat_monitor.suspendRead(); heart_beat_monitor.setTransport(connection().transport()); heart_beat_monitor.start();
public void suspend() { suspendChanges.incrementAndGet(); if( suspendCount.incrementAndGet() == 1 && this.transport!=null ) { this.transport.suspendRead(); if(this.heartBeatMonitor!=null){ this.heartBeatMonitor.suspendRead(); } } }
public void start() { session++; readSuspendedInterval = false; if (writeInterval != 0) { if (initialWriteCheckDelay != 0) { transport.getDispatchQueue().executeAfter(initialWriteCheckDelay, TimeUnit.MILLISECONDS, new Task() { public void run() { scheduleCheckWrites(session); } }); } else { scheduleCheckWrites(session); } } if (readInterval != 0) { if (initialReadCheckDelay != 0) { transport.getDispatchQueue().executeAfter(initialReadCheckDelay, TimeUnit.MILLISECONDS, new Task() { public void run() { scheduleCheckReads(session); } }); } else { scheduleCheckReads(session); } } }
private void scheduleCheckWrites(final short session) { final ProtocolCodec codec = transport.getProtocolCodec(); Task func; if (codec == null) { func = new Task() { public void run() { scheduleCheckWrites(session); } }; } else { final long lastWriteCounter = codec.getWriteCounter(); func = new Task() { public void run() { if (lastWriteCounter == codec.getWriteCounter()) { onKeepAlive.run(); } scheduleCheckWrites(session); } }; } schedule(session, writeInterval, func); }
public void suspend() { suspendChanges.incrementAndGet(); if( suspendCount.incrementAndGet() == 1 && this.transport!=null ) { this.transport.suspendRead(); if(this.heartBeatMonitor!=null){ this.heartBeatMonitor.suspendRead(); } } }
private void scheduleCheckReads(final short session) { final ProtocolCodec codec = transport.getProtocolCodec(); Task func; if (codec == null) { func = new Task() { public void run() { scheduleCheckReads(session); } }; } else { final long lastReadCounter = codec.getReadCounter(); func = new Task() { public void run() { if (lastReadCounter == codec.getReadCounter() && !readSuspendedInterval && readSuspendCount == 0) { onDead.run(); } readSuspendedInterval = false; scheduleCheckReads(session); } }; } schedule(session, readInterval, func); }
pingedAt = 0; if(mqtt.getKeepAlive()>0) { heartBeatMonitor = new HeartBeatMonitor(); heartBeatMonitor.setWriteInterval((mqtt.getKeepAlive() * 1000) / 2); heartBeatMonitor.setTransport(this.transport); heartBeatMonitor.suspendRead(); // to match the suspended state of the transport. heartBeatMonitor.setOnKeepAlive(new Task() { @Override public void run() { heartBeatMonitor.start();
/** * Kills the connection without a graceful disconnect. * @param onComplete */ public void kill(final Callback<Void> onComplete) { if( disconnected ) { if(onComplete!=null){ onComplete.onSuccess(null); } return; } disconnected = true; if(heartBeatMonitor!=null) { heartBeatMonitor.stop(); heartBeatMonitor = null; } transport.stop(new Task() { @Override public void run() { listener.onDisconnected(); if (onComplete != null) { onComplete.onSuccess(null); } } }); }
public void suspend_read(Fn0<String> reason) { status = reason; connection().transport().suspendRead(); heart_beat_monitor.suspendRead(); }
public void resume() { suspendChanges.incrementAndGet(); if( suspendCount.decrementAndGet() == 0 && this.transport!=null ) { this.transport.resumeRead(); if(this.heartBeatMonitor!=null){ this.heartBeatMonitor.resumeRead(); } } }
void handleSessionFailure(Throwable error) { // Socket failure, should we try to reconnect? if( !disconnected && (mqtt.reconnectAttemptsMax<0 || reconnects < mqtt.reconnectAttemptsMax ) ) { mqtt.tracer.debug("Reconnecting transport"); // Cleanup the previous transport. if(heartBeatMonitor!=null) { heartBeatMonitor.stop(); heartBeatMonitor = null; } final Transport t = transport; transport = null; if(t!=null) { t.stop(new Task() { @Override public void run() { listener.onDisconnected(); reconnect(); } }); } else { reconnect(); } } else { // nope. handleFatalFailure(error); } }
public void resume_read() { status = WAITING_ON_CLIENT_REQUEST; connection().transport().resumeRead(); heart_beat_monitor.resumeRead(); }
public void run() { if(!executed) { executed = true; requests.remove(requestId); if(heartBeatMonitor!=null) { heartBeatMonitor.stop(); heartBeatMonitor = null; } transport.stop(new Task() { @Override public void run() { listener.onDisconnected(); if (onComplete != null) { onComplete.onSuccess(null); } } }); } } };
/** * Kills the connection without a graceful disconnect. * @param onComplete */ public void kill(final Callback<Void> onComplete) { if( disconnected ) { if(onComplete!=null){ onComplete.onSuccess(null); } return; } disconnected = true; if(heartBeatMonitor!=null) { heartBeatMonitor.stop(); heartBeatMonitor = null; } transport.stop(new Task() { @Override public void run() { listener.onDisconnected(); if (onComplete != null) { onComplete.onSuccess(null); } } }); }
void handleSessionFailure(Throwable error) { // Socket failure, should we try to reconnect? if( !disconnected && (mqtt.reconnectAttemptsMax<0 || reconnects < mqtt.reconnectAttemptsMax ) ) { mqtt.tracer.debug("Reconnecting transport"); // Cleanup the previous transport. if(heartBeatMonitor!=null) { heartBeatMonitor.stop(); heartBeatMonitor = null; } final Transport t = transport; transport = null; if(t!=null) { t.stop(new Task() { @Override public void run() { listener.onDisconnected(); reconnect(); } }); } else { reconnect(); } } else { // nope. handleFatalFailure(error); } }
public void on_transport_disconnected() { if (!closed) { closed = true; dead = true; command_handler = dead_handler; security_context.logout(toScala(new UnitFn1<Throwable>() { @Override public void call(Throwable e) { if (e != null) { connection_log.info(e, "MQTT connection '%s' log out error: %s", security_context.remote_address(), e.toString()); } } })); heart_beat_monitor.stop(); if (!connection().stopped()) { connection().stop(NOOP); } log.trace("mqtt protocol resources released"); } }