use of com.google.common.collect.Multimap in project cdap by caskdata.
the class HBaseQueueDebugger method scanQueue.
/**
* Only works for {@link co.cask.cdap.data2.transaction.queue.hbase.ShardedHBaseQueueStrategy}.
*/
public QueueStatistics scanQueue(final QueueName queueName, @Nullable Long consumerGroupId) throws Exception {
HBaseConsumerStateStore stateStore;
try {
stateStore = queueAdmin.getConsumerStateStore(queueName);
} catch (IllegalStateException e) {
throw new NotFoundException(queueName);
}
TransactionExecutor txExecutor = Transactions.createTransactionExecutor(txExecutorFactory, stateStore);
Multimap<Long, QueueBarrier> barriers = txExecutor.execute(new TransactionExecutor.Function<HBaseConsumerStateStore, Multimap<Long, QueueBarrier>>() {
@Override
public Multimap<Long, QueueBarrier> apply(HBaseConsumerStateStore input) throws Exception {
return input.getAllBarriers();
}
}, stateStore);
printProgress("Got %d barriers\n", barriers.size());
QueueStatistics stats = new QueueStatistics();
if (consumerGroupId != null) {
barriers = Multimaps.filterKeys(barriers, Predicates.equalTo(consumerGroupId));
}
for (Map.Entry<Long, Collection<QueueBarrier>> entry : barriers.asMap().entrySet()) {
long groupId = entry.getKey();
Collection<QueueBarrier> groupBarriers = entry.getValue();
printProgress("Scanning barriers for group %d\n", groupId);
int currentSection = 1;
PeekingIterator<QueueBarrier> barrierIterator = Iterators.peekingIterator(groupBarriers.iterator());
while (barrierIterator.hasNext()) {
QueueBarrier start = barrierIterator.next();
QueueBarrier end = barrierIterator.hasNext() ? barrierIterator.peek() : null;
printProgress("Scanning section %d/%d...\n", currentSection, groupBarriers.size());
scanQueue(txExecutor, stateStore, queueName, start, end, stats);
printProgress("Current results: %s\n", stats.getReport(showTxTimestampOnly()));
currentSection++;
}
printProgress("Scanning complete");
}
System.out.printf("Results for queue %s: %s\n", queueName.toString(), stats.getReport(showTxTimestampOnly()));
return stats;
}
use of com.google.common.collect.Multimap in project dhis2-core by dhis2.
the class Jackson2PropertyIntrospectorService method collectProperties.
private List<Property> collectProperties(Class<?> klass) {
Multimap<String, Method> multimap = ReflectionUtils.getMethodsMultimap(klass);
List<String> fieldNames = ReflectionUtils.getAllFields(klass).stream().map(Field::getName).collect(Collectors.toList());
List<Property> properties = new ArrayList<>();
Map<String, Method> methodMap = multimap.keySet().stream().filter(key -> {
List<Method> methods = multimap.get(key).stream().filter(method -> AnnotationUtils.isAnnotationPresent(method, JsonProperty.class) && method.getParameterTypes().length == 0).collect(Collectors.toList());
if (methods.size() > 1) {
log.error("More than one web-api exposed method with name '" + key + "' found on class '" + klass.getName() + "' please fix as this is known to cause issues with Schema / Query services.");
log.debug("Methods found: " + methods);
}
return methods.size() == 1;
}).collect(Collectors.toMap(Function.identity(), key -> {
List<Method> collect = multimap.get(key).stream().filter(method -> AnnotationUtils.isAnnotationPresent(method, JsonProperty.class) && method.getParameterTypes().length == 0).collect(Collectors.toList());
return collect.get(0);
}));
methodMap.keySet().forEach(key -> {
String fieldName = getFieldName(methodMap.get(key));
String setterName = "set" + StringUtils.capitalize(fieldName);
Property property = new Property(klass, methodMap.get(key), null);
if (fieldNames.contains(fieldName)) {
property.setFieldName(fieldName);
}
Iterator<Method> methodIterator = multimap.get(setterName).iterator();
if (methodIterator.hasNext()) {
property.setSetterMethod(methodIterator.next());
}
properties.add(property);
});
return properties;
}
Aggregations