@Override public Set<E> range(long start, long end) { return boundZSetOps.range(start, end); }
@Override public E first() { Set<E> members = boundZSetOps.range(0, 0); checkResult(members); Iterator<E> iterator = members.iterator(); if (iterator.hasNext()) { return iterator.next(); } throw new NoSuchElementException(); }
@Override public Iterator<E> iterator() { Set<E> members = boundZSetOps.range(0, -1); checkResult(members); return new DefaultRedisSortedSetIterator(members.iterator()); }
@Override public Set<E> range(long start, long end) { return boundZSetOps.range(start, end); }
@Override public Set<E> range(long start, long end) { return boundZSetOps.range(start, end); }
@Override public E first() { Set<E> members = boundZSetOps.range(0, 0); checkResult(members); Iterator<E> iterator = members.iterator(); if (iterator.hasNext()) { return iterator.next(); } throw new NoSuchElementException(); }
@Override public E first() { Set<E> members = boundZSetOps.range(0, 0); checkResult(members); Iterator<E> iterator = members.iterator(); if (iterator.hasNext()) { return iterator.next(); } throw new NoSuchElementException(); }
protected Collection<EmailSchedulingData> getNextBatchOps(final String orderingKey, final int batchMaxSize) { Preconditions.checkArgument(batchMaxSize > 0, "Batch size should be a positive integer."); final BoundZSetOperations<String, String> boundZSetOperations = orderingTemplate.boundZSetOps(orderingKey); final long amount = boundZSetOperations.size(); final Set<String> valueIds = boundZSetOperations.range(0, max(0, min(amount, batchMaxSize) - 1)); return valueIds.stream() .map(id -> getOps(id)) .filter(Objects::nonNull) .collect(Collectors.toSet()); }
protected Collection<EmailSchedulingData> getNextBatchOps(final String orderingKey, final int batchMaxSize) { Preconditions.checkArgument(batchMaxSize > 0, "Batch size should be a positive integer."); final BoundZSetOperations<String, String> boundZSetOperations = orderingTemplate.boundZSetOps(orderingKey); final long amount = boundZSetOperations.size(); final Set<String> valueIds = boundZSetOperations.range(0, max(0, min(amount, batchMaxSize) - 1)); return valueIds.stream() .map(id -> getOps(id)) .filter(Objects::nonNull) .collect(Collectors.toSet()); }
@Override public List<Notification> getNotificationsByJobId( JobType jobType, String jobId ) { List<Notification> notifications = new LinkedList<>(); redisTemplate.boundZSetOps( generateNotificationKey( jobType, jobId ) ).range( 0, -1 ).forEach( x -> { try { notifications.add( objectMapper.readValue( x, Notification.class ) ); } catch ( IOException ex ) { log.warn( String.format( NOTIFIER_ERROR, ex.getMessage() ) ); } } ); return notifications; }
@Override public Iterator<E> iterator() { Set<E> members = boundZSetOps.range(0, -1); checkResult(members); return new DefaultRedisSortedSetIterator(members.iterator()); }
@Override public Map<String, LinkedList<Notification>> getNotificationsByJobType( JobType jobType ) { Set<String> notificationKeys = redisTemplate.boundZSetOps( generateNotificationOrderKey( jobType ) ).range( 0, -1 ); LinkedHashMap<String, LinkedList<Notification>> uidNotificationMap = new LinkedHashMap<>(); notificationKeys .forEach( j -> uidNotificationMap.put( j, new LinkedList<>( getNotificationsByJobId( jobType, j ) ) ) ); return uidNotificationMap; }
@Override public Iterator<E> iterator() { Set<E> members = boundZSetOps.range(0, -1); checkResult(members); return new DefaultRedisSortedSetIterator(members.iterator()); }
public Iterable<Metric<?>> findAll() { // This set is sorted Set<String> keys = this.zSetOperations.range(0, -1); Iterator<String> keysIt = keys.iterator(); List<Metric<?>> result = new ArrayList<Metric<?>>(keys.size()); List<String> values = this.redisOperations.opsForValue().multiGet(keys); for (String v : values) { String key = keysIt.next(); Metric<?> value = deserialize(key, v, this.zSetOperations.score(key)); if (value != null) { result.add(value); } } return result; }
@Override public List<Notification> getLastNotificationsByJobType( JobType jobType, String lastId ) { List<Notification> list = new ArrayList<>(); Set<String> lastJobUidSet = redisTemplate.boundZSetOps( generateNotificationOrderKey( jobType ) ).range( -1, -1 ); if ( !lastJobUidSet.iterator().hasNext() ) { return list; } String lastJobUid = (String) lastJobUidSet.iterator().next(); for ( Notification notification : getNotificationsByJobId( jobType, lastJobUid ) ) { if ( lastId != null && lastId.equals( notification.getUid() ) ) { break; } list.add( notification ); } return list; }
@Override public Object getJobSummary( JobType jobType ) { String existingSummaryTypeStr = redisTemplate.boundValueOps( generateSummaryTypeKey( jobType ) ).get(); if ( existingSummaryTypeStr == null ) { return null; } try { Class<?> existingSummaryType = Class.forName( existingSummaryTypeStr ); Set<String> lastJobUidSet = redisTemplate.boundZSetOps( generateSummaryOrderKey( jobType ) ).range( -1, -1 ); if ( !lastJobUidSet.iterator().hasNext() ) { return null; } String lastJobUid = (String) lastJobUidSet.iterator().next(); Object serializedSummary = redisTemplate.boundHashOps( generateSummaryKey( jobType ) ).get( lastJobUid ); return serializedSummary != null ? objectMapper.readValue( (String) serializedSummary, existingSummaryType ) : null; } catch ( IOException | ClassNotFoundException ex ) { log.warn( String.format( NOTIFIER_ERROR, ex.getMessage() ) ); } return null; }
@Override public Notifier notify( JobConfiguration id, NotificationLevel level, String message, boolean completed ) { if ( id != null && !(level != null && level.isOff()) ) { Notification notification = new Notification( level, id.getJobType(), new Date(), message, completed ); String notificationKey = generateNotificationKey( id.getJobType(), id.getUid() ); String notificationOrderKey = generateNotificationOrderKey( id.getJobType() ); Date now = new Date(); try { if ( redisTemplate.boundZSetOps( notificationOrderKey ).zCard() >= MAX_POOL_TYPE_SIZE ) { Set<String> deleteKeys = redisTemplate.boundZSetOps( notificationOrderKey ).range( 0, 0 ); redisTemplate.delete( deleteKeys ); redisTemplate.boundZSetOps( notificationOrderKey ).removeRange( 0, 0 ); } redisTemplate.boundZSetOps( notificationKey ).add( objectMapper.writeValueAsString( notification ), now.getTime() ); redisTemplate.boundZSetOps( notificationOrderKey ).add( id.getUid(), now.getTime() ); } catch ( JsonProcessingException ex ) { log.warn( String.format( NOTIFIER_ERROR, ex.getMessage() ) ); } log.info( notification ); } return this; }
if ( redisTemplate.boundZSetOps( summaryOrderKey ).zCard() >= MAX_POOL_TYPE_SIZE ) Set<String> summaryKeyToBeDeleted = redisTemplate.boundZSetOps( summaryOrderKey ).range( 0, 0 ); redisTemplate.boundZSetOps( summaryOrderKey ).removeRange( 0, 0 ); summaryKeyToBeDeleted.forEach( d -> redisTemplate.boundHashOps( summaryKey ).delete( d ) );