@Override public void run() LOG.debug("Starting %s for '%s'", getServiceType(), name); try { while (running.get()) { try { if (!process()) { break; // while backoff(ioe); backoff(re); LOG.debug("Stopping %s for '%s'", getServiceType(), name); channelDisconnect();
protected Channel channelConnect() throws IOException { Channel channel = channelHolder.get(); if (channel == null) { final Connection connection = connectionFactory.newConnection(); connectionHolder.set(connection); channel = connection.createChannel(); channelHolder.set(channel); connectCallback(channel); } return channel; } }
protected void channelDisconnect() { final Channel channel = channelHolder.getAndSet(null); disconnectCallback(channel); AmqpUtils.closeQuietly(channel); final Connection connection = connectionHolder.getAndSet(null); AmqpUtils.closeQuietly(connection); }
private void backoff(final Throwable t) throws InterruptedException { final long backoffTime = amqpConfig.getBackoffDelay().getMillis() * backoff; LOG.warnDebug(t, "Could not connect to Broker, sleeping for %d ms...", backoffTime); Thread.sleep(backoffTime); if (backoff != 1 << amqpConfig.getMaxBackoffFactor()) { backoff <<= 1; } channelDisconnect(); }