Refine search
private void processPartitionMovement(TopicPartition partition, String newConsumer, Map<String, List<TopicPartition>> currentAssignment, TreeSet<String> sortedCurrentSubscriptions, Map<TopicPartition, String> currentPartitionConsumer) { String oldConsumer = currentPartitionConsumer.get(partition); sortedCurrentSubscriptions.remove(oldConsumer); sortedCurrentSubscriptions.remove(newConsumer); partitionMovements.movePartition(partition, oldConsumer, newConsumer); currentAssignment.get(oldConsumer).remove(partition); currentAssignment.get(newConsumer).add(partition); currentPartitionConsumer.put(partition, newConsumer); sortedCurrentSubscriptions.add(newConsumer); sortedCurrentSubscriptions.add(oldConsumer); }
@SuppressWarnings("unchecked") @Override public TreeSet<T> update(Number object, TreeSet<T> cache, Object... others) { // TODO Auto-generated method stub if (cache == null) { cache = new TreeSet<T>(comparator); } cache.add((T) object); if (cache.size() > n) { cache.remove(cache.last()); } return cache; }
/** * @return the consumer to which the given partition is assigned. The assignment should improve the overall balance * of the partition assignments to consumers. */ private String assignPartition(TopicPartition partition, TreeSet<String> sortedCurrentSubscriptions, Map<String, List<TopicPartition>> currentAssignment, Map<String, List<TopicPartition>> consumer2AllPotentialPartitions, Map<TopicPartition, String> currentPartitionConsumer) { for (String consumer: sortedCurrentSubscriptions) { if (consumer2AllPotentialPartitions.get(consumer).contains(partition)) { sortedCurrentSubscriptions.remove(consumer); currentAssignment.get(consumer).add(partition); currentPartitionConsumer.put(partition, consumer); sortedCurrentSubscriptions.add(consumer); return consumer; } } return null; }
public Map<Long, V> getLatestAccessedItems(int n) { Map<Long, V> result = new LinkedHashMap<Long, V>(); if (n <= 0) return result; TreeSet<CacheEntry<Long, V>> tree = new TreeSet<CacheEntry<Long, V>>(); // we need to grab the lock since we are changing lastAccessedCopy markAndSweepLock.lock(); try { for (Map.Entry<Long, CacheEntry<Long, V>> entry : map.entrySet()) { CacheEntry<Long, V> ce = entry.getValue(); ce.lastAccessedCopy = ce.lastAccessed; if (tree.size() < n) { tree.add(ce); } else { if (ce.lastAccessedCopy > tree.last().lastAccessedCopy) { tree.remove(tree.last()); tree.add(ce); } } } } finally { markAndSweepLock.unlock(); } for (CacheEntry<Long, V> e : tree) { result.put(e.key, e.value); } return result; }
public Map<Long, V> getLatestAccessedItems(int n) { final Map<Long, V> result = new LinkedHashMap<>(); if (n <= 0) return result; final TreeSet<CacheEntry<Long, V>> tree = new TreeSet<>(); // we need to grab the lock since we are changing lastAccessedCopy markAndSweepLock.lock(); try { for (Map.Entry<Long, CacheEntry<Long, V>> entry : map.entrySet()) { final CacheEntry<Long, V> ce = entry.getValue(); ce.lastAccessedCopy = ce.lastAccessed; if (tree.size() < n) { tree.add(ce); } else { if (ce.lastAccessedCopy > tree.last().lastAccessedCopy) { tree.remove(tree.last()); tree.add(ce); } } } } finally { markAndSweepLock.unlock(); } for (CacheEntry<Long, V> e : tree) { result.put(e.key, e.value); } return result; }
/** * Copies the given span with an updated last access time. Passed span becomes invalid after this * call. * * @param cacheSpan Span to be copied and updated. * @return a span with the updated last access time. * @throws CacheException If renaming of the underlying span file failed. */ public SimpleCacheSpan touch(SimpleCacheSpan cacheSpan) throws CacheException { SimpleCacheSpan newCacheSpan = cacheSpan.copyWithUpdatedLastAccessTime(id); if (!cacheSpan.file.renameTo(newCacheSpan.file)) { throw new CacheException("Renaming of " + cacheSpan.file + " to " + newCacheSpan.file + " failed."); } // Replace the in-memory representation of the span. Assertions.checkState(cachedSpans.remove(cacheSpan)); cachedSpans.add(newCacheSpan); return newCacheSpan; }
void fail (KinesisMessageId kinesisMessageId) { String shardId = kinesisMessageId.getShardId(); BigInteger sequenceNumber = new BigInteger(kinesisMessageId.getSequenceNumber()); LOG.debug("Fail received for shardId: {} sequenceNumber: {}", shardId, sequenceNumber); // for a failed message add it to failed set if it will be retried, otherwise ack it; remove from emitted either way if (kinesisConfig.getFailedMessageRetryHandler().failed(kinesisMessageId)) { if (!failedPerShard.containsKey(shardId)) { failedPerShard.put(shardId, new TreeSet<BigInteger>()); } failedPerShard.get(shardId).add(sequenceNumber); TreeSet<BigInteger> emitted = emittedPerShard.get(shardId); emitted.remove(sequenceNumber); } else { ack(kinesisMessageId); } // keep committing when topology is deactivated since ack and fail keep getting called on deactivated topology if (deactivated) { commit(); } }
if (!canParticipateInReassignment(consumer, currentAssignment, consumer2AllPotentialPartitions, partition2AllPotentialConsumers)) { sortedCurrentSubscriptions.remove(consumer); fixedAssignments.put(consumer, currentAssignment.remove(consumer)); String consumer = entry.getKey(); currentAssignment.put(consumer, entry.getValue()); sortedCurrentSubscriptions.add(consumer);
remainingIds.add(previousId); List<ContiguousIdGroup> idGroups = new ArrayList<>(); long currentIdGroupStart = -1L; if (previousId + 1L == currentId) { if (currentIdGroupStart == -1L) { remainingIds.remove(previousId); currentIdGroupStart = previousId; currentIdGroupEnd = currentId; currentIdGroupStart = -1L; remainingIds.add(currentId);
@Override public TagsArrayAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent,int viewType) { View v = LayoutInflater.from(parent.getContext()) .inflate(R.layout.tags_item_list_dialog, parent, false); ViewHolder vh = new ViewHolder(v.findViewById(R.id.tags_dialog_tag_item)); vh.mTagItemCheckedTextView.setOnClickListener(view -> { CheckedTextView ctv = (CheckedTextView) view; ctv.toggle(); String tag = ctv.getText().toString(); if (ctv.isChecked() && !mCurrentTags.contains(tag)) { mCurrentTags.add(tag); } else if (!ctv.isChecked() && mCurrentTags.contains(tag)) { mCurrentTags.remove(tag); } }); return vh; }
@Override public void processStream(InputStream input) throws IOException { try (BufferedReader in = new BufferedReader(new InputStreamReader(input))) { String line; while ((line = in.readLine()) != null) { String parts[] = line.split(" *"); if (parts.length < 2) { throw new IOException("Tag line contains more than 2 columns: " + line); } // Grrr, how to parse tags with spaces inside? // This solution will loose multiple spaces;-/ String tag = parts[0]; for (int i = 1; i < parts.length - 1; ++i) { tag += " " + parts[i]; } TagEntry tagEntry = new BazaarTagEntry(Integer.parseInt(parts[parts.length - 1]), tag); // Bazaar lists multiple tags on more lines. We need to merge those into single TagEntry TagEntry higher = entries.ceiling(tagEntry); if (higher != null && higher.equals(tagEntry)) { // Found in the tree, merge tags entries.remove(higher); tagEntry.setTags(higher.getTags() + ", " + tag); } entries.add(tagEntry); } } } }