/** * Storm has determined that the tuple emitted by this spout with the msgId identifier * has been fully processed. Typically, an implementation of this method will take that * message off the queue and prevent it from being replayed. * * @param msgId */ public void ack(Object msgId) { AckableMessage msg = this.pending.remove(msgId); this.connection.getDispatchQueue().execute(msg.ack()); }
public CallbackConnection refiller(Runnable refiller) { queue.assertExecuting(); this.refiller = refiller; return this; }
void reconnect(final Callback<Transport> onConnect) { long reconnectDelay = mqtt.reconnectDelay; if( reconnectDelay> 0 && mqtt.reconnectBackOffMultiplier > 1.0 ) { reconnectDelay = (long) Math.pow(mqtt.reconnectDelay*reconnects, mqtt.reconnectBackOffMultiplier); } reconnectDelay = Math.min(reconnectDelay, mqtt.reconnectDelayMax); reconnects += 1; queue.executeAfter(reconnectDelay, TimeUnit.MILLISECONDS, new Task() { @Override public void run() { if(disconnected) { onConnect.onFailure(createDisconnectedError()); } else { try { createTransport(onConnect); } catch (Exception e) { onConnect.onFailure(e); } } } }); }
public void setTargetQueue(DispatchQueue next) { super.setTargetQueue(next); // The target thread queue might be different. Optimize by switching the selector to it. // Do we need to switch selector threads? DispatchQueue queue = next; while( queue.getQueueType()!=THREAD_QUEUE && queue.getTargetQueue() !=null ) { queue = queue.getTargetQueue(); } if( queue.getQueueType()==THREAD_QUEUE && queue!=selectorQueue ) { DispatchQueue previous = selectorQueue; final DispatchQueue newQueue = queue; debug("Switching to " + newQueue.getLabel()); selectorQueue = queue; if( previous!=null ) { previous.execute(new Task(){ public void run() { key_cancel(); register_on(newQueue); } }); } else { register_on(newQueue); } } }
public void run() { if (manager_disconnected) { // we are not the assignment anymore.. go to the session manager // again to setup a new session. MqttSessionManager.attach(host(), client_id, next); } else { // so that we don't switch again until this current switch completes queue.suspend(); if (handler != null) { detach(); handler = null; } queue.execute(new Task() { public void run() { handler = next; attach(); } }); // switch the connection to the session queue.. next.connection()._set_dispatch_queue(queue, new Task() { public void run() { queue.resume(); } }); } } });
@Override public void stop(ILifecycleProgressMonitor monitor) throws SiteWhereException { if (queue != null) { queue.suspend(); } }
@Override public String toString() { return String.format("{ label:%s, enqueued:%d, dequeued:%d, max_wait_time:%.2f ms, max_run_time:%.2f ms, total_run_time:%.2f ms, total_wait_time:%.2f ms }", queue.getLabel(), enqueued, dequeued, maxWaitTimeNS / 1000000.0f, maxRunTimeNS / 1000000.0f, totalRunTimeNS / 1000000.0f, totalWaitTimeNS / 1000000.0f); } }
public void resume() { dispatchQueue.resume(); }
@Override public void stop(ILifecycleProgressMonitor monitor) throws SiteWhereException { if (queue != null) { queue.suspend(); } }
public static class KeyState { int readyOps; final NioAttachment attachment; public SelectionKey key() { return attachment.key(); } public KeyState(NioAttachment attachment) { this.attachment = attachment; } @Override public String toString() { return "{ready: "+opsToString(readyOps)+" }"; } }
public void setReceiveBuffer(final long receiveBuffer) throws InterruptedException { final CountDownLatch done = new CountDownLatch(1); next.getDispatchQueue().execute(new Runnable() { public void run() { try { next.setReceiveBuffer(receiveBuffer); } finally { done.countDown(); } } }); done.await(); }
public Throwable failure() { queue.assertExecuting(); return failure; }
final long suspends = suspendChanges.get(); pingedAt = now; queue.executeAfter(CallbackConnection.this.mqtt.getKeepAlive(), TimeUnit.SECONDS, new Task() { @Override public void run() {
public void suspend() { dispatchQueue.suspend(); }
private void trace(String message) { if( LOG.isTraceEnabled() ) { final String label = dispatchQueue.getLabel(); if( label !=null ) { LOG.trace(label +" | "+message); } else { LOG.trace(message); } } }
public long getReceiveBuffer() throws InterruptedException { final CountDownLatch done = new CountDownLatch(1); final AtomicLong result = new AtomicLong(); next.getDispatchQueue().execute(new Runnable() { public void run() { try { result.set(next.getReceiveBuffer()); } finally { done.countDown(); } } }); done.await(); return result.get(); }
public boolean full() { queue.assertExecuting(); return this.transport.full(); }
private void schedualRateAllowanceReset() { dispatchQueue.executeAfter(1, TimeUnit.SECONDS, new Task(){ public void run() { if( !socketState.is(CONNECTED.class) ) { return; } rateLimitingChannel.resetAllowance(); schedualRateAllowanceReset(); } }); }
@Override public void stop(ILifecycleProgressMonitor monitor) throws SiteWhereException { // Stop multicaster if configured. if (multicaster != null) { multicaster.lifecycleStop(monitor); } // Stop route builder if configured. if (routeBuilder != null) { routeBuilder.lifecycleStop(monitor); } if (connection != null) { try { connection.disconnect(); connection.kill(); } catch (Exception e) { LOGGER.error("Error shutting down MQTT device event receiver.", e); } } if (queue != null) { queue.suspend(); } super.stop(monitor); }