public void cleanIdle(long delayMs) { Stopwatch start = executionTimeStats.start(); try { apacheHttpClient.getClientHandler().getHttpClient() .getConnectionManager() .closeIdleConnections(delayMs, TimeUnit.SECONDS); } catch (Throwable e) { logger.error("Cannot clean connections", e); cleanupFailed.increment(); } finally { if (null != start) { start.stop(); } } } }
@Override public void run() { Stopwatch start = executionTimeStats.start(); try { HttpClientConnectionManager cm = (HttpClientConnectionManager) apacheHttpClient .getConfiguration() .getProperty(ApacheClientProperties.CONNECTION_MANAGER); cm.closeIdleConnections(connectionIdleTimeout, TimeUnit.SECONDS); } catch (Throwable e) { s_logger.error("Cannot clean connections", e); cleanupFailed.increment(); } finally { if (null != start) { start.stop(); } } } }
@Override public Message get(String messageId) { Stopwatch sw = monitor.get.start(); try { return execute("get", messageStoreKey, () -> { String json = quorumConn.hget(messageStoreKey, messageId); if(json == null){ if (logger.isDebugEnabled()) { logger.debug("Cannot get the message payload " + messageId); } return null; } Message msg = om.readValue(json, Message.class); return msg; }); } finally { sw.stop(); } }
@Override public List<Message> peek(final int messageCount) { Stopwatch sw = monitor.peek.start(); try { Set<String> ids = peekIds(0, messageCount); if (ids == null) { return Collections.emptyList(); } List<Message> msgs = execute("peek", messageStoreKey, () -> { List<Message> messages = new LinkedList<Message>(); for (String id : ids) { String json = nonQuorumConn.hget(messageStoreKey, id); Message message = om.readValue(json, Message.class); messages.add(message); } return messages; }); return msgs; } finally { sw.stop(); } }
@Override public Map<String, Map<String, Long>> shardSizes() { Stopwatch sw = monitor.size.start(); Map<String, Map<String, Long>> shardSizes = new HashMap<>(); RedisConnection jedis = nonQuorumPool.getResource(); try { long size = jedis.zcard(myQueueShard); long uacked = 0; for (int i = 0; i < maxHashBuckets; i++) { String unackShardKey = unackShardKeyPrefix + i; uacked += jedis.zcard(unackShardKey); } Map<String, Long> shardDetails = new HashMap<>(); shardDetails.put("size", size); shardDetails.put("uacked", uacked); shardSizes.put(shardName, shardDetails); return shardSizes; } finally { jedis.close(); sw.stop(); } }
@Override public Map<String, Map<String, Long>> shardSizes() { Stopwatch sw = monitor.size.start(); Map<String, Map<String, Long>> shardSizes = new HashMap<>(); try { return execute("shardSizes", "(a shard in) " + queueName, () -> { for (String shard : allShards) { long size = nonQuorumConn.zcard(getQueueShardKey(queueName, shard)); long uacked = nonQuorumConn.zcard(getUnackKey(queueName, shard)); Map<String, Long> shardDetails = new HashMap<>(); shardDetails.put("size", size); shardDetails.put("uacked", uacked); shardSizes.put(shard, shardDetails); } return shardSizes; }); } finally { sw.stop(); } }
@Override public Message get(String messageId) { Stopwatch sw = monitor.get.start(); RedisConnection jedis = connPool.getResource(); try { String json = jedis.hget(messageStoreKey(messageId), messageId); if (json == null) { if (logger.isDebugEnabled()) { logger.debug("Cannot get the message payload " + messageId); } return null; } Message msg = om.readValue(json, Message.class); return msg; } catch (Exception e) { throw new RuntimeException(e); } finally { jedis.close(); sw.stop(); } }
public void cleanIdle(long delayMs) { Stopwatch start = executionTimeStats.start(); try { apacheHttpClient.getClientHandler().getHttpClient() .getConnectionManager() .closeIdleConnections(delayMs, TimeUnit.SECONDS); } catch (Throwable e) { logger.error("Cannot clean connections", e); cleanupFailed.increment(); } finally { if (null != start) { start.stop(); } } } }
@Override public List<Message> peek(final int messageCount) { Stopwatch sw = monitor.peek.start(); RedisConnection jedis = connPool.getResource(); try { Set<String> ids = peekIds(0, messageCount); if (ids == null) { return Collections.emptyList(); } List<Message> messages = new LinkedList<Message>(); for (String id : ids) { String json = jedis.hget(messageStoreKey(id), id); Message message = om.readValue(json, Message.class); messages.add(message); } return messages; } catch (Exception e) { throw new RuntimeException(e); } finally { jedis.close(); sw.stop(); } }
@Override public long size() { Stopwatch sw = monitor.size.start(); RedisConnection jedis = nonQuorumPool.getResource(); try { long size = jedis.zcard(myQueueShard); return size; } finally { jedis.close(); sw.stop(); } }
@Override public long size() { Stopwatch sw = monitor.size.start(); try { return execute("size", "(a shard in) " + queueName, () -> { long size = 0; for (String shard : allShards) { size += nonQuorumConn.zcard(getQueueShardKey(queueName, shard)); } return size; }); } finally { sw.stop(); } }
@Override public boolean setUnackTimeout(String messageId, long timeout) { Stopwatch sw = monitor.ack.start(); try { return execute("setUnackTimeout", "(a shard in) " + queueName, () -> { double unackScore = Long.valueOf(clock.millis() + timeout).doubleValue(); for (String shard : allShards) { String unackShardKey = getUnackKey(queueName, shard); Double score = quorumConn.zscore(unackShardKey, messageId); if(score != null) { quorumConn.zadd(unackShardKey, unackScore, messageId); return true; } } return false; }); } finally { sw.stop(); } }
@Override public void run() { Stopwatch start = executionTimeStats.start(); try { HttpClientConnectionManager cm = (HttpClientConnectionManager) apacheHttpClient .getConfiguration() .getProperty(ApacheClientProperties.CONNECTION_MANAGER); cm.closeIdleConnections(connectionIdleTimeout, TimeUnit.SECONDS); } catch (Throwable e) { s_logger.error("Cannot clean connections", e); cleanupFailed.increment(); } finally { if (null != start) { start.stop(); } } } }
@Override public void ack(List<Message> messages) { Stopwatch sw = monitor.ack.start(); RedisConnection jedis = connPool.getResource(); Pipe pipe = jedis.pipelined(); List<Response<Long>> responses = new LinkedList<>(); try { for (Message msg : messages) { responses.add(pipe.zrem(unackShardKey(msg.getId()), msg.getId())); } pipe.sync(); pipe = jedis.pipelined(); List<Response<Long>> dels = new LinkedList<>(); for (int i = 0; i < messages.size(); i++) { Long removed = responses.get(i).get(); if (removed > 0) { dels.add(pipe.hdel(messageStoreKey(messages.get(i).getId()), messages.get(i).getId())); } } pipe.sync(); } catch (Exception e) { throw new RuntimeException(e); } finally { jedis.close(); sw.stop(); } }
@Override public boolean setUnackTimeout(String messageId, long timeout) { Stopwatch sw = monitor.ack.start(); RedisConnection jedis = connPool.getResource(); try { double unackScore = Long.valueOf(clock.millis() + timeout).doubleValue(); Double score = jedis.zscore(unackShardKey(messageId), messageId); if (score != null) { jedis.zadd(unackShardKey(messageId), unackScore, messageId); return true; } return false; } finally { jedis.close(); sw.stop(); } }
@Override public boolean ack(String messageId) { Stopwatch sw = monitor.ack.start(); try { return execute("ack", "(a shard in) " + queueName, () -> { for (String shard : allShards) { String unackShardKey = getUnackKey(queueName, shard); Long removed = quorumConn.zrem(unackShardKey, messageId); if (removed > 0) { quorumConn.hdel(messageStoreKey, messageId); return true; } } return false; }); } finally { sw.stop(); } }
@Override public boolean ack(String messageId) { Stopwatch sw = monitor.ack.start(); RedisConnection jedis = connPool.getResource(); try { Long removed = jedis.zrem(unackShardKey(messageId), messageId); if (removed > 0) { jedis.hdel(messageStoreKey(messageId), messageId); return true; } return false; } finally { jedis.close(); sw.stop(); } }
@Override public boolean remove(String messageId) { Stopwatch sw = monitor.remove.start(); try { return execute("remove", "(a shard in) " + queueName, () -> { for (String shard : allShards) { String unackShardKey = getUnackKey(queueName, shard); quorumConn.zrem(unackShardKey, messageId); String queueShardKey = getQueueShardKey(queueName, shard); Long removed = quorumConn.zrem(queueShardKey, messageId); Long msgRemoved = quorumConn.hdel(messageStoreKey, messageId); if (removed > 0 && msgRemoved > 0) { return true; } } return false; }); } finally { sw.stop(); } }
@Override public boolean remove(String messageId) { Stopwatch sw = monitor.remove.start(); RedisConnection jedis = connPool.getResource(); try { jedis.zrem(unackShardKey(messageId), messageId); Long removed = jedis.zrem(myQueueShard, messageId); Long msgRemoved = jedis.hdel(messageStoreKey(messageId), messageId); if (removed > 0 && msgRemoved > 0) { return true; } return false; } finally { jedis.close(); sw.stop(); } }