/** Print the state of the container. Useful for debugging. */ private synchronized void printState(String prefix) { StringBuilder builder = new StringBuilder(prefix).append("->"); builder.append("BatchedPermitsRequester state (").append(hashCode()).append("): "); builder.append("TotalPermits: ").append(this.totalAvailablePermits).append(" "); builder.append("Batches(").append(this.batches.size()).append("): "); for (PermitBatch batch : this.batches.values()) { builder.append(batch.getPermits()).append(","); } log.info(builder.toString()); }
/** * @return the number of permits we should request in the next request. */ private long computeNextPermitRequest() { long candidatePermits = 0; long unsatisfiablePermits = this.permitsOutstanding.getTotalWeight() - this.permitBatchContainer.totalAvailablePermits; if (unsatisfiablePermits > 0) { candidatePermits = unsatisfiablePermits; } if (this.permitBatchContainer.batches.size() > 1) { // If there are multiple batches in the queue, don't create a new request return candidatePermits; } PermitBatch firstBatch = Iterables.getFirst(this.permitBatchContainer.batches.values(), null); if (firstBatch != null) { // If the current batch has more than 20% permits left, don't create a new request if ((double) firstBatch.getPermits() / firstBatch.getInitialPermits() > 0.2) { return candidatePermits; } double averageDepletionRate = firstBatch.getAverageDepletionRate(); long candidatePermitsByDepletion = Math.min((long) (averageDepletionRate * this.targetMillisBetweenRequests), MAX_GROWTH_REQUEST * firstBatch.getInitialPermits()); return Math.max(candidatePermits, candidatePermitsByDepletion); } else { return candidatePermits; } }
/** * Adds an object to the results of the search as long as maxCapacity nor maxDistance is not exceeded. * * @param entry The object to add to the results of the search */ void addEntry(Entry<T> entry) { results.put(entry.distance, entry); int size = results.size(); if (size > maxCapacity) { //Removes some entries if maxCapacity is exceeded Float maxDistanceInResults = results.keySet().last(); NavigableSet<Entry<T>> entriesAtThisDistance = results.get(maxDistanceInResults); entriesAtThisDistance.pollLast(); if (entriesAtThisDistance.size() == 0) { results.removeAll(maxDistanceInResults); } maxDistance = results.keySet().last(); } else if (size == maxCapacity) { //If the size is at maxCapacity, then set maxDistance to the distance of the last entry maxDistance = results.keySet().last(); } } }
public void testTailSetClear() { TreeMultimap<String, Integer> multimap = TreeMultimap.create(); multimap.put("a", 1); multimap.put("a", 11); multimap.put("b", 2); multimap.put("c", 3); multimap.put("d", 4); multimap.put("e", 5); multimap.put("e", 55); multimap.keySet().tailSet("d").clear(); assertEquals(ImmutableSet.of("a", "b", "c"), multimap.keySet()); assertEquals(4, multimap.size()); assertEquals(4, multimap.values().size()); assertEquals(4, multimap.keys().size()); }
LOGGER.info("size of urlMapping: " + urlMappings.size());
int greatestNumCompleteFutures = valuesSortedByCount.size() == 0 ? 0 : valuesSortedByCount.keySet().iterator().next(); if (greatestNumCompleteFutures >= quorum) { // normal exit, quorum
public void reloadServices() { final Map<String, com.isuwang.dapeng.core.metadata.Service> services = new TreeMap<>(); urlMappings.clear(); Map<ProcessorKey, TProcessor<?>> processorMap = RegistryAgentProxy.getCurrentInstance(RegistryAgentProxy.Type.Server).getProcessorMap(); Set<ProcessorKey> keys = processorMap.keySet(); for (ProcessorKey key : keys) { TProcessor<?> processor = processorMap.get(key); if (processor.getInterfaceClass().getClass() != null) { Service service = processor.getInterfaceClass().getAnnotation(Service.class); String serviceName = service.name(); String version = service.version(); String metadata = ""; try { metadata = new MetadataClient(serviceName, version).getServiceMetadata(); } catch (TException e) { LOGGER.error(e.getMessage(), e); } if (metadata != null) { try (StringReader reader = new StringReader(metadata)) { com.isuwang.dapeng.core.metadata.Service serviceData = JAXB.unmarshal(reader, com.isuwang.dapeng.core.metadata.Service.class); loadResource(serviceData, services); } catch (Exception e) { LOGGER.error("生成SERVICE出错", e); } } } } this.services = services; LOGGER.info("size of urlMapping: " + urlMappings.size()); }
LOGGER.info("size of urlMapping: " + urlMappings.size());
LOGGER.info("size of urlMapping: " + urlMappings.size());
tablespaces.put(entry.getKey().getTablespace(), entry.getValue()); log.info("Analyzing " + tablespaces.keySet().size() + " tablespaces with a total of " + tablespaces.size() + " versions...");
/** * Asserts that a {@link JavaCheck} will raise the expected issue provided as method parameter, and not more. Expected issues are provided as a parameter. * * @see ExpectedIssuesCollector * @param testFileName the name of the test file that has to be checked for issues * @param check the {@link JavaCheck} that is to be run against the test file * @param expectedLine the line number on which the issue message is expected (or 0 if it is a file wide issue) * @param expectedMessage the expected message */ public static void assertHasSingleIssue(final String testFileName, final JavaFileScanner check, @Nonnull @Nonnegative final Integer expectedLine, final String expectedMessage) { final TreeMultimap<Integer, String> actualIssues = ActualIssuesCollector.collect(new File(testFileName), check); final SoftAssertions softly = new SoftAssertions(); softly.assertThat(actualIssues.get(expectedLine)) .overridingErrorMessage(EXPECTED_MESSAGE_PREFIX, formatIssue(expectedLine, expectedMessage)) .contains(expectedMessage); actualIssues.remove(expectedLine, expectedMessage); softly.assertThat(actualIssues.size()) .overridingErrorMessage(UNEXPECTED_MESSAGE_PREFIX, formatIssues(actualIssues)) .isEqualTo(0); softly.assertAll(); }
log.trace("size is " + this.children.size());
public void testTailSetClear() { TreeMultimap<String, Integer> multimap = TreeMultimap.create(); multimap.put("a", 1); multimap.put("a", 11); multimap.put("b", 2); multimap.put("c", 3); multimap.put("d", 4); multimap.put("e", 5); multimap.put("e", 55); multimap.keySet().tailSet("d").clear(); assertEquals(ImmutableSet.of("a", "b", "c"), multimap.keySet()); assertEquals(4, multimap.size()); assertEquals(4, multimap.values().size()); assertEquals(4, multimap.keys().size()); }