Search in sources :

Example 46 with Multimap

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;
}
Also used : NotFoundException(co.cask.cdap.common.NotFoundException) QueueBarrier(co.cask.cdap.data2.transaction.queue.hbase.QueueBarrier) TransactionExecutor(org.apache.tephra.TransactionExecutor) TransactionNotInProgressException(org.apache.tephra.TransactionNotInProgressException) TransactionFailureException(org.apache.tephra.TransactionFailureException) NotFoundException(co.cask.cdap.common.NotFoundException) HBaseConsumerStateStore(co.cask.cdap.data2.transaction.queue.hbase.HBaseConsumerStateStore) Multimap(com.google.common.collect.Multimap) Collection(java.util.Collection) Map(java.util.Map)

Example 47 with Multimap

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;
}
Also used : JsonProperty(com.fasterxml.jackson.annotation.JsonProperty) JacksonXmlProperty(com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty) ReflectionUtils(org.hisp.dhis.system.util.ReflectionUtils) JacksonXmlRootElement(com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement) JacksonXmlElementWrapper(com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper) Multimap(com.google.common.collect.Multimap) Function(java.util.function.Function) EmbeddedObject(org.hisp.dhis.common.EmbeddedObject) AnnotationUtils(org.hisp.dhis.system.util.AnnotationUtils) ArrayList(java.util.ArrayList) Map(java.util.Map) Method(java.lang.reflect.Method) SchemaUtils(org.hisp.dhis.system.util.SchemaUtils) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject) NameableObject(org.hisp.dhis.common.NameableObject) Iterator(java.util.Iterator) Collection(java.util.Collection) Field(java.lang.reflect.Field) Maps(com.google.common.collect.Maps) Collectors(java.util.stream.Collectors) Primitives(com.google.common.primitives.Primitives) List(java.util.List) ParameterizedType(java.lang.reflect.ParameterizedType) Description(org.hisp.dhis.common.annotation.Description) Type(java.lang.reflect.Type) Log(org.apache.commons.logging.Log) LogFactory(org.apache.commons.logging.LogFactory) StringUtils(org.springframework.util.StringUtils) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Method(java.lang.reflect.Method) JsonProperty(com.fasterxml.jackson.annotation.JsonProperty) JacksonXmlProperty(com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty)

Aggregations

Multimap (com.google.common.collect.Multimap)47 HashMultimap (com.google.common.collect.HashMultimap)16 Test (org.junit.Test)15 List (java.util.List)13 InetAddress (java.net.InetAddress)11 Map (java.util.Map)9 IOException (java.io.IOException)8 ImmutableList (com.google.common.collect.ImmutableList)7 Collection (java.util.Collection)7 ArrayListMultimap (com.google.common.collect.ArrayListMultimap)6 ImmutableMap (com.google.common.collect.ImmutableMap)6 ImmutableMultimap (com.google.common.collect.ImmutableMultimap)6 ArrayList (java.util.ArrayList)6 Set (java.util.Set)6 ImmutableSet (com.google.common.collect.ImmutableSet)5 LinkedListMultimap (com.google.common.collect.LinkedListMultimap)5 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)5 Collectors (java.util.stream.Collectors)5 Token (org.apache.cassandra.dht.Token)4 HashMap (java.util.HashMap)3