Examples of ShardedJedis


Examples of redis.clients.jedis.ShardedJedis

     public void run() {
       CQSControllerServlet.valueAccumulator.initializeAllCounters();           
       //clear all existing in-memQueue and hidden set
       boolean brokenJedis = false;
       long ts1 = System.currentTimeMillis();
       ShardedJedis jedis = getResource();
       try {
         logger.info("event=cache_filler_started queue_url=" + queueUrl + " shard=" + shard);
         jedis.del(queueUrl + "-" + shard + "-Q");
         String previousReceiptHandle = null;
         List<CQSMessage> messages = persistenceStorage.peekQueue(queueUrl, shard, null, null, 1000);
         int totalCached = 0;
         while (messages.size() != 0) {
           for (CQSMessage message : messages) {
View Full Code Here

Examples of redis.clients.jedis.ShardedJedis

    public int getNumConnections() {
        return numRedisConnections.get();
    }
   
    public static ShardedJedis getResource() {
        ShardedJedis conn = pool.getResource();
        numRedisConnections.incrementAndGet();
        return conn;       
    }
View Full Code Here

Examples of redis.clients.jedis.ShardedJedis

     * @return The state of the queue or null if none exists
     */
    private QCacheState getCacheState(String queueUrl, int shard) {
       
      long ts1 = System.currentTimeMillis();
        ShardedJedis jedis = getResource();
        boolean brokenJedis = false;
       
        try {
            String st = jedis.hget(queueUrl + "-" + shard + "-" + CQSConstants.REDIS_STATE, CQSConstants.REDIS_STATE);
            if (st == null) {
              return null;
            }
            return QCacheState.valueOf(st);
        } catch (JedisException e) {
View Full Code Here

Examples of redis.clients.jedis.ShardedJedis

     */
    private void setCacheState(String queueUrl, int shard, QCacheState state, QCacheState oldState, boolean checkOldState) throws SetFailedException {
       
      long ts1 = System.currentTimeMillis();
        boolean brokenJedis = false;
        ShardedJedis jedis = getResource();
        try {
            Jedis j = jedis.getShard(queueUrl + "-" + shard + "-" + CQSConstants.REDIS_STATE);
            j.watch(queueUrl + "-" + shard + "-" + CQSConstants.REDIS_STATE);
            if (checkOldState) {
                String oldStateStr = j.hget(queueUrl + "-" + shard + "-" + CQSConstants.REDIS_STATE, CQSConstants.REDIS_STATE);
                if (oldState == null && oldStateStr != null) {
                    throw new SetFailedException();
View Full Code Here

Examples of redis.clients.jedis.ShardedJedis

     * @param visibilityOrCacheFiller
     */
    private void setCacheFillerProcessing(String queueUrl, int shard, int exp) {
        long ts1 = System.currentTimeMillis();
        boolean brokenJedis = false;
        ShardedJedis jedis = getResource();
        String suffix = "-F";
        try {
            if (exp > 0) {
                jedis.set(queueUrl  + "-" + shard + suffix, "Y");
                jedis.expire(queueUrl + "-" + shard + suffix, exp); //expire after exp seconds
            } else {
                jedis.del(queueUrl + "-" + shard + suffix);
            }
        } catch (JedisException e) {
            brokenJedis = true;
            throw e;
        } finally {
View Full Code Here

Examples of redis.clients.jedis.ShardedJedis

          throw new IllegalArgumentException("Redis expiration cannot be less than 0");
        }
        long ts1 = System.currentTimeMillis();
        boolean brokenJedis = false;
        String redisKey = queueUrl + "-" + shard + suffix;
        ShardedJedis jedis = getResource();
        try {
            if (jedis.exists(redisKey)) {
                return false;
            }
            Jedis j = jedis.getShard(redisKey);
            j.watch(redisKey);
          
            String val = j.get(redisKey);
            if (val != null) {
                j.unwatch();
View Full Code Here

Examples of redis.clients.jedis.ShardedJedis

        if (checkAndSetFlag(queueUrl, shard, "-VR", exp)) {
            //perform re-visible set processing. Get all memIds whose score (visibilityTO) is <= now
            long ts1 = System.currentTimeMillis();
            long ts2 = 0;
            boolean brokenJedis = false;
            ShardedJedis jedis = getResource();
            try {
                //jedis is lame and does not have a constant for "-inf" which Redis supports. So we have to
                //pick an arbitrary old min value.
                Set<String> revisibleSet = jedis.zrangeByScore(queueUrl + "-" + shard + "-V", System.currentTimeMillis() - (1000 * 3600 * 24 * 14), System.currentTimeMillis());
                for (String revisibleMemId : revisibleSet) {
                    jedis.rpush(queueUrl + "-" + shard + "-Q", revisibleMemId);
                    jedis.zrem(queueUrl + "-" + shard + "-V", revisibleMemId);
                }
                ts2 = System.currentTimeMillis();
                if (revisibleSet.size() > 0) {
                  logger.debug("event=redis_revisibility queue_url=" + queueUrl + " shard=" + shard + " num_made_revisible=" + revisibleSet.size() + " res_ts=" + (ts2 - ts1));
                }
View Full Code Here

Examples of redis.clients.jedis.ShardedJedis

    }
   
    private boolean getProcessingState(String queueUrl, int shard, boolean visibilityOrCacheFiller) {
        long ts1 = System.currentTimeMillis();
        boolean brokenJedis = false;
        ShardedJedis jedis = getResource();
        String suffix = visibilityOrCacheFiller ? "-R" : "-F";
        try {
            return jedis.exists(queueUrl + "-" + shard + suffix);
        } catch (JedisException e) {
            brokenJedis = true;
            throw e;
        } finally {
            returnResource(jedis, brokenJedis);
View Full Code Here

Examples of redis.clients.jedis.ShardedJedis

          throw new IllegalStateException("Could not get id from underlying storage");
        }
        boolean cacheAvailable = checkCacheConsistency(queue.getRelativeUrl(), shard, true); //set in cache even if its filling
        String memId = null;
        boolean brokenJedis = false;
        ShardedJedis jedis = null;
        long ts1 = System.currentTimeMillis();
        try {
            if (cacheAvailable) {
              int delaySeconds = 0;
              if (queue.getDelaySeconds() > 0) {
                delaySeconds = queue.getDelaySeconds();
              }
              if (message.getAttributes().containsKey(CQSConstants.DELAY_SECONDS)) {
                delaySeconds = Integer.parseInt(message.getAttributes().get(CQSConstants.DELAY_SECONDS));
              }
              memId = getMemQueueMessage(messageId);
              jedis = getResource();
              if (delaySeconds > 0) {
                    jedis.zadd(queue.getRelativeUrl() + "-" + shard + "-V", System.currentTimeMillis() + (delaySeconds * 1000), memId); //insert or update already existing                 
              } else {
                  jedis.rpush(queue.getRelativeUrl() + "-" + shard + "-Q", memId);
              }
                logger.debug("event=send_message cache_available=true msg_id= " + memId + " queue_url=" + queue.getAbsoluteUrl() + " shard=" + shard);
            } else {
                logger.debug("event=send_message cache_available=false msg_id= " + memId + " queue_url=" + queue.getAbsoluteUrl() + " shard=" + shard);
            }
View Full Code Here

Examples of redis.clients.jedis.ShardedJedis

    public Map<String, String> sendMessageBatch(CQSQueue queue, int shard, List<CQSMessage> messages) throws PersistenceException, IOException, InterruptedException, NoSuchAlgorithmException, JSONException {
       
        persistenceStorage.sendMessageBatch(queue, shard, messages);
        Map<String, String> memIds = new HashMap<String, String>();
        boolean cacheAvailable = checkCacheConsistency(queue.getRelativeUrl(), shard, true);//set in cache even if its filling
        ShardedJedis jedis = null;

        if (cacheAvailable) {
            try {
                jedis = getResource();
            } catch (JedisConnectionException e) {
                cacheAvailable = false;
                trySettingCacheState(queue.getRelativeUrl(), shard, QCacheState.Unavailable);
            }
        }
        // add messages in the same order as messages list
        boolean brokenJedis = false;
        try {
            for (CQSMessage message : messages) {
              int delaySeconds = 0;
              if (queue.getDelaySeconds() > 0) {
                delaySeconds = queue.getDelaySeconds();
              }
              if (message.getAttributes().containsKey(CQSConstants.DELAY_SECONDS)) {
                delaySeconds = Integer.parseInt(message.getAttributes().get(CQSConstants.DELAY_SECONDS));
              }
                String clientId = message.getSuppliedMessageId();
                String messageId = message.getMessageId();
                String memId = getMemQueueMessage(messageId);
                if (cacheAvailable) {     
                    try {
                      if (delaySeconds > 0) {
                            jedis.zadd(queue.getRelativeUrl() + "-" + shard + "-V", System.currentTimeMillis() + (delaySeconds * 1000), memId); //insert or update already existing                 
                      } else {
                        jedis.rpush(queue.getRelativeUrl() + "-" + shard + "-Q", memId);
                      }
                    } catch (JedisConnectionException e) {
                        trySettingCacheState(queue.getRelativeUrl(), shard, QCacheState.Unavailable);
                    }
                    logger.debug("event=send_message_batch cache_available=true msg_id= " + memId + " queue_url=" + queue.getAbsoluteUrl() + " shard=" + shard);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.