private String style(Collection<?> value) { StringBuilder result = new StringBuilder(value.size() * 8 + 16); result.append(getCollectionTypeString(value)).append('['); for (Iterator<?> i = value.iterator(); i.hasNext();) { result.append(style(i.next())); if (i.hasNext()) { result.append(',').append(' '); } } if (value.isEmpty()) { result.append(EMPTY); } result.append("]"); return result.toString(); }
@Override public RFuture<Boolean> addAllAsync(Collection<? extends String> c) { if (c.isEmpty()) { return RedissonPromise.newSucceededFuture(false); } List<Object> params = new ArrayList<Object>(2*c.size()); params.add(getName()); for (Object param : c) { params.add(0); params.add(param); } return commandExecutor.writeAsync(getName(), StringCodec.INSTANCE, RedisCommands.ZADD_BOOL_RAW, params.toArray()); }
RoutingResult result = new RoutingResult(); if (shardingRule.isAllBroadcastTables(logicTables)) { List<RoutingTable> routingTables = new ArrayList<>(logicTables.size()); for (String each : logicTables) { routingTables.add(new RoutingTable(each, each)); result.getTableUnits().getTableUnits().add(tableUnit); } else if (logicTables.isEmpty()) { result.getTableUnits().getTableUnits().add(new TableUnit(shardingRule.getShardingDataSourceNames().getRandomDataSourceName())); } else if (1 == logicTables.size()) { String logicTableName = logicTables.iterator().next(); DataNode dataNode = shardingRule.getDataNode(logicTableName); TableUnit tableUnit = new TableUnit(dataNode.getDataSourceName()); tableUnit.getRoutingTables().add(new RoutingTable(logicTableName, dataNode.getTableName())); result.getTableUnits().getTableUnits().add(tableUnit); } else { List<RoutingTable> routingTables = new ArrayList<>(logicTables.size()); Set<String> availableDatasourceNames = null; boolean first = true; TableRule tableRule = shardingRule.getTableRule(each); DataNode dataNode = tableRule.getActualDataNodes().get(0); routingTables.add(new RoutingTable(each, dataNode.getTableName())); Set<String> currentDataSourceNames = new HashSet<>(tableRule.getActualDatasourceNames().size()); for (DataNode eachDataNode : tableRule.getActualDataNodes()) {
@Override public RoutingResult route() { Collection<RoutingResult> result = new ArrayList<>(logicTables.size()); Collection<String> bindingTableNames = new TreeSet<>(String.CASE_INSENSITIVE_ORDER); for (String each : logicTables) { if (tableRule.isPresent()) { if (!bindingTableNames.contains(each)) { result.add(new StandardRoutingEngine(shardingRule, tableRule.get().getLogicTable(), shardingConditions).route()); if (result.isEmpty()) { throw new ShardingException("Cannot find table rule and default data source with logic tables: '%s'", logicTables); if (1 == result.size()) { return result.iterator().next();
public Collection<V> values() { processQueue(); Collection<K> keys = map.keySet(); if (keys.isEmpty()) { //noinspection unchecked return Collections.EMPTY_SET; } Collection<V> values = new ArrayList<V>(keys.size()); for (K key : keys) { V v = get(key); if (v != null) { values.add(v); } } return values; }
private static void initIncludesAndExcludes() { CorePlugin corePlugin = Stagemonitor.getPlugin(CorePlugin.class); excludeContaining = new ArrayList<String>(corePlugin.getExcludeContaining().size()); excludeContaining.addAll(corePlugin.getExcludeContaining()); excludes = new ArrayList<String>(corePlugin.getExcludePackages().size()); excludes.add("org.stagemonitor"); excludes.addAll(corePlugin.getExcludePackages()); includes = new ArrayList<String>(corePlugin.getIncludePackages().size()); includes.addAll(corePlugin.getIncludePackages()); if (includes.isEmpty()) { logger.warn("No includes for instrumentation configured. Please set the stagemonitor.instrument.include property."); } }
@Nullable private Collection<CacheOperation> parseCacheAnnotations( DefaultCacheConfig cachingConfig, AnnotatedElement ae, boolean localOnly) { Collection<? extends Annotation> anns = (localOnly ? AnnotatedElementUtils.getAllMergedAnnotations(ae, CACHE_OPERATION_ANNOTATIONS) : AnnotatedElementUtils.findAllMergedAnnotations(ae, CACHE_OPERATION_ANNOTATIONS)); if (anns.isEmpty()) { return null; } final Collection<CacheOperation> ops = new ArrayList<>(1); anns.stream().filter(ann -> ann instanceof Cacheable).forEach( ann -> ops.add(parseCacheableAnnotation(ae, cachingConfig, (Cacheable) ann))); anns.stream().filter(ann -> ann instanceof CacheEvict).forEach( ann -> ops.add(parseEvictAnnotation(ae, cachingConfig, (CacheEvict) ann))); anns.stream().filter(ann -> ann instanceof CachePut).forEach( ann -> ops.add(parsePutAnnotation(ae, cachingConfig, (CachePut) ann))); anns.stream().filter(ann -> ann instanceof Caching).forEach( ann -> parseCachingAnnotation(ae, cachingConfig, (Caching) ann, ops)); return ops; }
/** * Gets size of the given collection with provided optional predicates. * * @param c Collection to size. * @param p Optional predicates that filters out elements from count. * @param <T> Type of the iterator. * @return Number of elements in the collection for which all given predicates * evaluates to {@code true}. If no predicates is provided - all elements are counted. */ public static <T> int size(@Nullable Collection<? extends T> c, @Nullable IgnitePredicate<? super T>... p) { return c == null || c.isEmpty() ? 0 : isEmpty(p) || isAlwaysTrue(p) ? c.size() : size(c.iterator(), p); }
@CanIgnoreReturnValue @Override public boolean putAll(@Nullable K key, Iterable<? extends V> values) { checkNotNull(values); // make sure we only call values.iterator() once // and we only call get(key) if values is nonempty if (values instanceof Collection) { Collection<? extends V> valueCollection = (Collection<? extends V>) values; return !valueCollection.isEmpty() && get(key).addAll(valueCollection); } else { Iterator<? extends V> valueItr = values.iterator(); return valueItr.hasNext() && Iterators.addAll(get(key), valueItr); } }
/** {@inheritDoc} */ @Override public GridClientData pinNodes(GridClientNode node, GridClientNode... nodes) throws GridClientException { Collection<GridClientNode> pinnedNodes = new ArrayList<>(nodes != null ? nodes.length + 1 : 1); if (node != null) pinnedNodes.add(node); if (nodes != null && nodes.length != 0) pinnedNodes.addAll(Arrays.asList(nodes)); return createProjection(pinnedNodes.isEmpty() ? null : pinnedNodes, null, null, new GridClientDataFactory(flags)); }
/** An implementation of {@link Multiset#addAll}. */ static <E> boolean addAllImpl(Multiset<E> self, Collection<? extends E> elements) { checkNotNull(self); checkNotNull(elements); if (elements instanceof Multiset) { return addAllImpl(self, cast(elements)); } else if (elements.isEmpty()) { return false; } else { return Iterators.addAll(self, elements.iterator()); } }
boolean removeEntriesIf(Predicate<? super Entry<K, Collection<V>>> predicate) { Iterator<Entry<K, Collection<V>>> entryIterator = unfiltered.asMap().entrySet().iterator(); boolean changed = false; while (entryIterator.hasNext()) { Entry<K, Collection<V>> entry = entryIterator.next(); K key = entry.getKey(); Collection<V> collection = filterCollection(entry.getValue(), new ValuePredicate(key)); if (!collection.isEmpty() && predicate.apply(Maps.immutableEntry(key, collection))) { if (collection.size() == entry.getValue().size()) { entryIterator.remove(); } else { collection.clear(); } changed = true; } } return changed; }
@Override public RFuture<Boolean> addAllAsync(Collection<? extends String> c) { if (c.isEmpty()) { return RedissonPromise.newSucceededFuture(false); } List<Object> params = new ArrayList<Object>(2*c.size()); params.add(getName()); for (Object param : c) { params.add(0); params.add(param); } return commandExecutor.writeAsync(getName(), StringCodec.INSTANCE, RedisCommands.ZADD_BOOL_RAW, params.toArray()); }
} else if (elements instanceof Collection) { Collection<E> collection = (Collection<E>) elements; if (collection.isEmpty()) { return ImmutableSet.of(); } else { if (itr.hasNext()) { EnumSet<E> enumSet = EnumSet.of(itr.next()); Iterators.addAll(enumSet, itr); return ImmutableEnumSet.asImmutable(enumSet);
/** * Load proxy configuration. * * @return proxy configuration * @throws IOException IO exception */ public ShardingConfiguration load() throws IOException { Collection<String> schemaNames = new HashSet<>(); YamlProxyServerConfiguration serverConfig = loadServerConfiguration(new File(ShardingConfigurationLoader.class.getResource(CONFIG_PATH + SERVER_CONFIG_FILE).getFile())); File configPath = new File(ShardingConfigurationLoader.class.getResource(CONFIG_PATH).getFile()); Collection<YamlProxyRuleConfiguration> ruleConfigurations = new LinkedList<>(); for (File each : findRuleConfigurationFiles(configPath)) { Optional<YamlProxyRuleConfiguration> ruleConfig = loadRuleConfiguration(each, serverConfig); if (ruleConfig.isPresent()) { Preconditions.checkState(schemaNames.add(ruleConfig.get().getSchemaName()), "Schema name `%s` must unique at all rule configurations.", ruleConfig.get().getSchemaName()); ruleConfigurations.add(ruleConfig.get()); } } Preconditions.checkState(!ruleConfigurations.isEmpty() || null != serverConfig.getOrchestration(), "Can not find any sharding rule configuration file in path `%s`.", configPath.getPath()); Map<String, YamlProxyRuleConfiguration> ruleConfigurationMap = new HashMap<>(ruleConfigurations.size(), 1); for (YamlProxyRuleConfiguration each : ruleConfigurations) { ruleConfigurationMap.put(each.getSchemaName(), each); } return new ShardingConfiguration(serverConfig, ruleConfigurationMap); }