/** * Uses {@link PartitionKey} annotations from the specified class to generate partition context in the built proxy. * <p> * NOTE: This is only useful if building a proxy with {@link #buildProxy(com.bazaarvoice.ostrich.RetryPolicy)}. If * partition context is necessary with a normal service pool, then can be provided directly by calling * {@link com.bazaarvoice.ostrich.ServicePool#execute(com.bazaarvoice.ostrich.PartitionContext, * com.bazaarvoice.ostrich.RetryPolicy, com.bazaarvoice.ostrich.ServiceCallback)}. * * @param annotatedServiceClass A service class with {@link PartitionKey} annotations. * @return this */ public ServicePoolBuilder<S> withPartitionContextAnnotationsFrom(Class<? extends S> annotatedServiceClass) { checkNotNull(annotatedServiceClass); _partitionContextSupplier = new AnnotationPartitionContextSupplier(_serviceType, annotatedServiceClass); return this; }
/** * Returns an array indexed by argument index with the value of the @PartitionKey annotation for each argument, * or null if no arguments are annotated with @PartitionKey. */ private String[] collectPartitionKeyAnnotations(Method method) { Annotation[][] annotations = method.getParameterAnnotations(); String[] keyMappings = new String[annotations.length]; boolean keyMappingFound = false; Map<String, Integer> unique = Maps.newHashMap(); for (int i = 0; i < annotations.length; i++) { PartitionKey annotation = findPartitionKeyAnnotation(annotations[i]); if (annotation == null) { continue; } String key = checkNotNull(annotation.value()); Integer prev = unique.put(key, i); checkState(prev == null, "Method '%s' has multiple arguments annotated with the same @PartitionKey " + "value '%s': arguments %s and %s", method, key, prev, i); keyMappings[i] = key; keyMappingFound = true; } return keyMappingFound ? keyMappings : null; }
String[] keyMappings = collectPartitionKeyAnnotations(implMethod); if (keyMappings == null) { continue; // Not annotated
String[] keyMappings = collectPartitionKeyAnnotations(implMethod); if (keyMappings == null) { continue; // Not annotated
/** * Uses {@link PartitionKey} annotations from the specified class to generate partition context in the built proxy. * <p> * NOTE: This is only useful if building a proxy with {@link #buildProxy(com.bazaarvoice.ostrich.RetryPolicy)}. If * partition context is necessary with a normal service pool, then can be provided directly by calling * {@link com.bazaarvoice.ostrich.ServicePool#execute(com.bazaarvoice.ostrich.PartitionContext, * com.bazaarvoice.ostrich.RetryPolicy, com.bazaarvoice.ostrich.ServiceCallback)}. * * @param annotatedServiceClass A service class with {@link PartitionKey} annotations. * @return this */ public ServicePoolBuilder<S> withPartitionContextAnnotationsFrom(Class<? extends S> annotatedServiceClass) { checkNotNull(annotatedServiceClass); _partitionContextSupplier = new AnnotationPartitionContextSupplier(_serviceType, annotatedServiceClass); return this; }
/** * Returns an array indexed by argument index with the value of the @PartitionKey annotation for each argument, * or null if no arguments are annotated with @PartitionKey. */ private String[] collectPartitionKeyAnnotations(Method method) { Annotation[][] annotations = method.getParameterAnnotations(); String[] keyMappings = new String[annotations.length]; boolean keyMappingFound = false; Map<String, Integer> unique = Maps.newHashMap(); for (int i = 0; i < annotations.length; i++) { PartitionKey annotation = findPartitionKeyAnnotation(annotations[i]); if (annotation == null) { continue; } String key = checkNotNull(annotation.value()); Integer prev = unique.put(key, i); checkState(prev == null, "Method '%s' has multiple arguments annotated with the same @PartitionKey " + "value '%s': arguments %s and %s", method, key, prev, i); keyMappings[i] = key; keyMappingFound = true; } return keyMappingFound ? keyMappings : null; }