List of usage examples for com.google.common.collect Multimaps synchronizedListMultimap
public static <K, V> ListMultimap<K, V> synchronizedListMultimap(ListMultimap<K, V> multimap)
From source file:org.eclipse.milo.opcua.sdk.server.api.AbstractNodeManager.java
public AbstractNodeManager() { nodeMap = makeNodeMap(new MapMaker()); referenceMultimap = Multimaps.synchronizedListMultimap(ArrayListMultimap.create()); }
From source file:com.android.tools.adtui.workbench.WorkBenchManager.java
public WorkBenchManager() { myWorkBenches = Multimaps.synchronizedListMultimap(ArrayListMultimap.create()); }
From source file:cascading.flow.local.stream.element.LocalGroupByGate.java
private ListMultimap<Tuple, Tuple> initNewValueMap() { return Multimaps.synchronizedListMultimap(ArrayListMultimap.<Tuple, Tuple>create()); }
From source file:com.cubeia.games.poker.cache.ActionCache.java
@Inject public ActionCache(SystemTime dateFetcher) { this.dateFetcher = dateFetcher; LinkedListMultimap<Integer, ActionContainer> linkedListMultimap = LinkedListMultimap.create(); // TODO: this map is fully synchronized but we only need to synchronize on table id (events on the same table are never concurrent) cache = Multimaps.synchronizedListMultimap(linkedListMultimap); }
From source file:com.facebook.presto.execution.TaskExecutorSimulator.java
public void run() throws Exception { Multimap<Integer, SimulationTask> tasks = Multimaps .synchronizedListMultimap(ArrayListMultimap.<Integer, SimulationTask>create()); Set<ListenableFuture<?>> finishFutures = newConcurrentHashSet(); AtomicBoolean done = new AtomicBoolean(); long start = System.nanoTime(); // large tasks for (int userId = 0; userId < 2; userId++) { ListenableFuture<?> future = createUser("large_" + userId, 100, taskExecutor, done, tasks); finishFutures.add(future);//from w w w. j av a2 s . com } // small tasks for (int userId = 0; userId < 4; userId++) { ListenableFuture<?> future = createUser("small_" + userId, 5, taskExecutor, done, tasks); finishFutures.add(future); } // tiny tasks for (int userId = 0; userId < 1; userId++) { ListenableFuture<?> future = createUser("tiny_" + userId, 1, taskExecutor, done, tasks); finishFutures.add(future); } // warm up for (int i = 0; i < 30; i++) { TimeUnit.MILLISECONDS.sleep(1000); System.out.println(taskExecutor); } tasks.clear(); // run for (int i = 0; i < 60; i++) { TimeUnit.MILLISECONDS.sleep(1000); System.out.println(taskExecutor); } // capture finished tasks Map<Integer, Collection<SimulationTask>> middleTasks; synchronized (tasks) { middleTasks = new TreeMap<>(tasks.asMap()); } // wait for finish done.set(true); Futures.allAsList(finishFutures).get(1, TimeUnit.MINUTES); Duration runtime = Duration.nanosSince(start).convertToMostSuccinctTimeUnit(); synchronized (this) { System.out.println(); System.out.println("Simulation finished in " + runtime); System.out.println(); for (Entry<Integer, Collection<SimulationTask>> entry : middleTasks.entrySet()) { Distribution durationDistribution = new Distribution(); Distribution taskParallelismDistribution = new Distribution(); for (SimulationTask task : entry.getValue()) { long taskStart = Long.MAX_VALUE; long taskEnd = 0; long totalCpuTime = 0; for (SimulationSplit split : task.getSplits()) { taskStart = Math.min(taskStart, split.getStartNanos()); taskEnd = Math.max(taskEnd, split.getDoneNanos()); totalCpuTime += TimeUnit.MILLISECONDS.toNanos(split.getRequiredProcessMillis()); } Duration taskDuration = new Duration(taskEnd - taskStart, NANOSECONDS) .convertTo(TimeUnit.MILLISECONDS); durationDistribution.add(taskDuration.toMillis()); double taskParallelism = 1.0 * totalCpuTime / (taskEnd - taskStart); taskParallelismDistribution.add((long) (taskParallelism * 100)); } System.out.println("Splits " + entry.getKey() + ": Completed " + entry.getValue().size()); Map<Double, Long> durationPercentiles = durationDistribution.getPercentiles(); System.out.printf( " wall time ms :: p01 %4s :: p05 %4s :: p10 %4s :: p97 %4s :: p50 %4s :: p75 %4s :: p90 %4s :: p95 %4s :: p99 %4s\n", durationPercentiles.get(0.01), durationPercentiles.get(0.05), durationPercentiles.get(0.10), durationPercentiles.get(0.25), durationPercentiles.get(0.50), durationPercentiles.get(0.75), durationPercentiles.get(0.90), durationPercentiles.get(0.95), durationPercentiles.get(0.99)); Map<Double, Long> parallelismPercentiles = taskParallelismDistribution.getPercentiles(); System.out.printf( " parallelism :: p99 %4.2f :: p95 %4.2f :: p90 %4.2f :: p75 %4.2f :: p50 %4.2f :: p25 %4.2f :: p10 %4.2f :: p05 %4.2f :: p01 %4.2f\n", parallelismPercentiles.get(0.99) / 100.0, parallelismPercentiles.get(0.95) / 100.0, parallelismPercentiles.get(0.90) / 100.0, parallelismPercentiles.get(0.75) / 100.0, parallelismPercentiles.get(0.50) / 100.0, parallelismPercentiles.get(0.25) / 100.0, parallelismPercentiles.get(0.10) / 100.0, parallelismPercentiles.get(0.05) / 100.0, parallelismPercentiles.get(0.01) / 100.0); } } Thread.sleep(10); }
From source file:edu.cmu.lti.oaqa.bioqa.providers.kb.TmToolConceptProvider.java
@Override public List<Concept> getConcepts(List<JCas> jcases) throws AnalysisEngineProcessException { // send request List<String> normalizedTexts = jcases.stream().map(JCas::getDocumentText) .map(PubAnnotationConvertUtil::normalizeText).collect(toList()); ListMultimap<Integer, PubAnnotation.Denotation> index2denotations = Multimaps .synchronizedListMultimap(ArrayListMultimap.create()); ExecutorService es = Executors.newCachedThreadPool(); for (String trigger : triggers) { es.submit(() -> {//ww w. j a v a 2 s .c o m try { List<String> denotationStrings = requestConcepts(normalizedTexts, trigger); assert denotationStrings.size() == jcases.size(); for (int i = 0; i < jcases.size(); i++) { PubAnnotation.Denotation[] denotations = gson.fromJson(denotationStrings.get(i), PubAnnotation.Denotation[].class); index2denotations.putAll(i, Arrays.asList(denotations)); } } catch (Exception e) { throw TmToolConceptProviderException.unknownException(trigger, e); } }); } es.shutdown(); try { boolean status = es.awaitTermination(Long.MAX_VALUE, TimeUnit.NANOSECONDS); if (!status) { throw new AnalysisEngineProcessException(); } } catch (InterruptedException e) { throw new AnalysisEngineProcessException(e); } // convert denotation strings List<Concept> concepts = new ArrayList<>(); for (int i = 0; i < jcases.size(); i++) { JCas jcas = jcases.get(i); List<PubAnnotation.Denotation> denotations = index2denotations.get(i); try { concepts.addAll(PubAnnotationConvertUtil.convertDenotationsToConcepts(jcas, denotations)); } catch (StringIndexOutOfBoundsException e) { throw TmToolConceptProviderException.offsetOutOfBounds(jcas.getDocumentText(), denotations, e); } } return concepts; }
From source file:fr.inria.eventcloud.webservices.EventCloudsManagementServiceImpl.java
/** * Creates a {@link EventCloudsManagementServiceImpl}. * //from ww w. j av a2 s. c o m * @param registryUrl * the URL of the EventClouds registry to use to manage * EventClouds. * @param wsnServicePort * the port on which to deploy the WS-Notification services. */ public EventCloudsManagementServiceImpl(String registryUrl, int wsnServicePort) { this.nodeProvidersManager = new NodeProvidersManager(); this.wsnServicePort = wsnServicePort; this.registryUrl = registryUrl; // the following data structures maybe be updated concurrently through // parallel web service calls this.componentPoolManagers = new MapMaker().concurrencyLevel(2).makeMap(); this.monitoringSubscriptions = new MapMaker().concurrencyLevel(2).makeMap(); this.wsInfos = new MapMaker().concurrencyLevel(2).makeMap(); this.assignedNumberIds = Multimaps.synchronizedListMultimap(ArrayListMultimap.<String, Integer>create()); this.publishWsnServiceEndpointUrls = Multimaps .synchronizedListMultimap(ArrayListMultimap.<String, String>create()); this.subscribeWsnServiceEndpointUrls = Multimaps .synchronizedListMultimap(ArrayListMultimap.<String, String>create()); this.publishWsProxyEndpointUrls = Multimaps .synchronizedListMultimap(ArrayListMultimap.<String, String>create()); this.subscribeWsProxyEndpointUrls = Multimaps .synchronizedListMultimap(ArrayListMultimap.<String, String>create()); this.putgetWsProxyEndpointUrls = Multimaps .synchronizedListMultimap(ArrayListMultimap.<String, String>create()); }
From source file:org.eclipse.emf.compare.rcp.EMFCompareRCPPlugin.java
/** * Set the Adapter Factory Registry.//from w ww . j a va 2s . c om * * @param registry * {@link IExtensionRegistry} to listen in order to fill the registry */ private void setUpAdapterFactoryRegistry(final IExtensionRegistry registry) { adapterFactoryRegistryBackingMultimap = Multimaps.synchronizedListMultimap( ArrayListMultimap.<Collection<?>, RankedAdapterFactoryDescriptor>create()); adapterFactoryRegistryListener = new AdapterFactoryDescriptorRegistryListener( EMFCompareEditPlugin.PLUGIN_ID, FACTORY_PPID, getLog(), adapterFactoryRegistryBackingMultimap); registry.addListener(adapterFactoryRegistryListener, EMFCompareEditPlugin.PLUGIN_ID + '.' + FACTORY_PPID); adapterFactoryRegistryListener.readRegistry(registry); rankedAdapterFactoryRegistry = new RankedAdapterFactoryDescriptorRegistryImpl( ComposedAdapterFactory.Descriptor.Registry.INSTANCE, Multimaps.unmodifiableMultimap(adapterFactoryRegistryBackingMultimap)); }
From source file:com.floragunn.searchguard.configuration.PrivilegesEvaluator.java
public boolean evaluate(final User user, final String action, final ActionRequest<?> request) { if (action.startsWith("cluster:admin/snapshot/restore")) { auditLog.logMissingPrivileges(action, request); log.warn(action + " is not allowed for a regular user"); return false; }//from w w w. ja va2 s. c o m final TransportAddress caller = Objects .requireNonNull((TransportAddress) request.getFromContext(ConfigConstants.SG_REMOTE_ADDRESS)); if (log.isDebugEnabled()) { log.debug("evaluate permissions for {}", user); log.debug("requested {} from {}", action, caller); } final ClusterState clusterState = clusterService.state(); final MetaData metaData = clusterState.metaData(); final Tuple<Set<String>, Set<String>> requestedResolvedAliasesIndicesTypes = resolve(user, action, request, metaData); final Set<String> requestedResolvedIndices = Collections .unmodifiableSet(requestedResolvedAliasesIndicesTypes.v1()); final Set<IndexType> requestedResolvedIndexTypes; { final Set<IndexType> requestedResolvedIndexTypes0 = new HashSet<IndexType>( requestedResolvedAliasesIndicesTypes.v1().size() * requestedResolvedAliasesIndicesTypes.v2().size()); for (String index : requestedResolvedAliasesIndicesTypes.v1()) { for (String type : requestedResolvedAliasesIndicesTypes.v2()) { requestedResolvedIndexTypes0.add(new IndexType(index, type)); } } requestedResolvedIndexTypes = Collections.unmodifiableSet(requestedResolvedIndexTypes0); } if (log.isDebugEnabled()) { log.debug("requested resolved indextypes: {}", requestedResolvedIndexTypes); } if (requestedResolvedIndices.contains(searchguardIndex) && WildcardMatcher.matchAny(deniedActionPatterns, action)) { auditLog.logSgIndexAttempt(request, action); log.warn(action + " for '{}' index is not allowed for a regular user", searchguardIndex); return false; } if (requestedResolvedIndices.contains("_all") && WildcardMatcher.matchAny(deniedActionPatterns, action)) { auditLog.logSgIndexAttempt(request, action); log.warn(action + " for '_all' indices is not allowed for a regular user"); return false; } if (requestedResolvedIndices.contains(searchguardIndex) || requestedResolvedIndices.contains("_all")) { if (request instanceof SearchRequest) { ((SearchRequest) request).requestCache(Boolean.FALSE); if (log.isDebugEnabled()) { log.debug("Disable search request cache for this request"); } } if (request instanceof RealtimeRequest) { ((RealtimeRequest) request).realtime(Boolean.FALSE); if (log.isDebugEnabled()) { log.debug("Disable realtime for this request"); } } } final Set<String> sgRoles = mapSgRoles(user, caller); if (log.isDebugEnabled()) { log.debug("mapped roles for {}: {}", user.getName(), sgRoles); } if (privilegesInterceptor.getClass() != PrivilegesInterceptor.class) { final boolean denyRequest = privilegesInterceptor.replaceKibanaIndex(request, action, user, config, requestedResolvedIndices, mapTenants(user, caller)); if (denyRequest) { auditLog.logMissingPrivileges(action, request); return false; } } boolean allowAction = false; final Map<String, Set<String>> dlsQueries = new HashMap<String, Set<String>>(); final Map<String, Set<String>> flsFields = new HashMap<String, Set<String>>(); final Set<IndexType> leftovers = new HashSet<PrivilegesEvaluator.IndexType>(); for (final Iterator<String> iterator = sgRoles.iterator(); iterator.hasNext();) { final String sgRole = (String) iterator.next(); final Settings sgRoleSettings = roles.getByPrefix(sgRole); if (sgRoleSettings.names().isEmpty()) { if (log.isDebugEnabled()) { log.debug("sg_role {} is empty", sgRole); } continue; } if (log.isDebugEnabled()) { log.debug("---------- evaluate sg_role: {}", sgRole); } final boolean compositeEnabled = config.getAsBoolean("searchguard.dynamic.composite_enabled", false); if (action.startsWith("cluster:") || action.startsWith("indices:admin/template/delete") || action.startsWith("indices:admin/template/get") || action.startsWith("indices:admin/template/put") || action.startsWith("indices:data/read/scroll") //M* || (compositeEnabled && action.equals(BulkAction.NAME)) || (compositeEnabled && action.equals(IndicesAliasesAction.NAME)) || (compositeEnabled && action.equals(MultiGetAction.NAME)) || (compositeEnabled && action.equals(MultiPercolateAction.NAME)) || (compositeEnabled && action.equals(MultiSearchAction.NAME)) || (compositeEnabled && action.equals(MultiTermVectorsAction.NAME)) || (compositeEnabled && action.equals("indices:data/read/coordinate-msearch")) //|| (compositeEnabled && action.startsWith(MultiPercolateAction.NAME)) ) { final Set<String> resolvedActions = resolveActions( sgRoleSettings.getAsArray(".cluster", new String[0])); if (log.isDebugEnabled()) { log.debug(" resolved cluster actions:{}", resolvedActions); } if (WildcardMatcher.matchAny(resolvedActions.toArray(new String[0]), action)) { if (log.isDebugEnabled()) { log.debug(" found a match for '{}' and {}, skip other roles", sgRole, action); } return true; } else { //check other roles #108 if (log.isDebugEnabled()) { log.debug(" not match found a match for '{}' and {}, check next role", sgRole, action); } continue; } } final Map<String, Settings> permittedAliasesIndices0 = sgRoleSettings.getGroups(".indices"); final Map<String, Settings> permittedAliasesIndices = new HashMap<String, Settings>( permittedAliasesIndices0.size()); for (String origKey : permittedAliasesIndices0.keySet()) { permittedAliasesIndices.put( origKey.replace("${user.name}", user.getName()).replace("${user_name}", user.getName()), permittedAliasesIndices0.get(origKey)); } /* sg_role_starfleet: indices: sf: #<--- is an alias or cindex, can contain wildcards, will be resolved to concrete indices # if this contain wildcards we do a wildcard based check # if contains no wildcards we resolve this to concrete indices an do a exact check # ships: <-- is a type, can contain wildcards - READ public: - 'indices:*' students: - READ alumni: - READ 'admin*': - READ 'pub*': '*': - READ */ final ListMultimap<String, String> resolvedRoleIndices = Multimaps .synchronizedListMultimap(ArrayListMultimap.<String, String>create()); final Set<IndexType> _requestedResolvedIndexTypes = new HashSet<IndexType>(requestedResolvedIndexTypes); //iterate over all beneath indices: permittedAliasesIndices: for (final String permittedAliasesIndex : permittedAliasesIndices.keySet()) { //final Map<String, Settings> permittedTypes = sgRoleSettings.getGroups(".indices."+permittedAliasesIndex); //System.out.println(permittedTypes); if (WildcardMatcher.containsWildcard(permittedAliasesIndex)) { if (log.isDebugEnabled()) { log.debug(" Try wildcard match for {}", permittedAliasesIndex); } handleIndicesWithWildcard(action, permittedAliasesIndex, permittedAliasesIndices, requestedResolvedIndexTypes, _requestedResolvedIndexTypes, requestedResolvedIndices); } else { if (log.isDebugEnabled()) { log.debug(" Resolve and match {}", permittedAliasesIndex); } handleIndicesWithoutWildcard(action, permittedAliasesIndex, permittedAliasesIndices, requestedResolvedIndexTypes, _requestedResolvedIndexTypes); } if (log.isDebugEnabled()) { log.debug("For index {} remaining requested indextype: {}", permittedAliasesIndex, _requestedResolvedIndexTypes); } if (_requestedResolvedIndexTypes.isEmpty()) { int filteredAliasCount = 0; //check filtered aliases for (String requestAliasOrIndex : requestedResolvedIndices) { //System.out.println(clusterState.metaData().getAliasAndIndexLookup().get(requestAliasOrIndex)); IndexMetaData indexMetaData = clusterState.metaData().getIndices().get(requestAliasOrIndex); if (indexMetaData == null) { log.warn("{} does not exist in cluster metadata", requestAliasOrIndex); continue; } ImmutableOpenMap<String, AliasMetaData> aliases = indexMetaData.getAliases(); log.debug("Aliases for {}: {}", requestAliasOrIndex, aliases); if (aliases != null && aliases.size() > 0) { UnmodifiableIterator<String> it = aliases.keysIt(); while (it.hasNext()) { String a = it.next(); AliasMetaData aliasMetaData = aliases.get(a); if (aliasMetaData != null && aliasMetaData.filteringRequired()) { filteredAliasCount++; log.debug(a + " is a filtered alias " + aliasMetaData.getFilter()); } else { log.debug(a + " is not an alias or does not have a filter"); } } } } if (filteredAliasCount > 1) { //TODO add queries as dls queries (works only if dls module is installed) log.warn( "More than one ({}) filtered alias found for same index ({}). This is currently not supported", filteredAliasCount, permittedAliasesIndex); continue permittedAliasesIndices; } if (log.isDebugEnabled()) { log.debug("found a match for '{}.{}', evaluate other roles", sgRole, permittedAliasesIndex); } resolvedRoleIndices.put(sgRole, permittedAliasesIndex); } } // end loop permittedAliasesIndices if (!resolvedRoleIndices.isEmpty()) { for (String resolvedRole : resolvedRoleIndices.keySet()) { for (String indexPattern : resolvedRoleIndices.get(resolvedRole)) { String dls = roles.get(resolvedRole + ".indices." + indexPattern + "._dls_"); final String[] fls = roles.getAsArray(resolvedRole + ".indices." + indexPattern + "._fls_"); //only when dls and fls != null String[] concreteIndices = new String[0]; if ((dls != null && dls.length() > 0) || (fls != null && fls.length > 0)) { concreteIndices = resolver.concreteIndices(clusterService.state(), DEFAULT_INDICES_OPTIONS/*??*/, indexPattern); } if (dls != null && dls.length() > 0) { //TODO use UserPropertyReplacer, make it registerable for ldap user dls = dls.replace("${user.name}", user.getName()).replace("${user_name}", user.getName()); if (dlsQueries.containsKey(indexPattern)) { dlsQueries.get(indexPattern).add(dls); } else { dlsQueries.put(indexPattern, new HashSet<String>()); dlsQueries.get(indexPattern).add(dls); } for (int i = 0; i < concreteIndices.length; i++) { final String ci = concreteIndices[i]; if (dlsQueries.containsKey(ci)) { dlsQueries.get(ci).add(dls); } else { dlsQueries.put(ci, new HashSet<String>()); dlsQueries.get(ci).add(dls); } } if (log.isDebugEnabled()) { log.debug("dls query {} for {}", dls, Arrays.toString(concreteIndices)); } } if (fls != null && fls.length > 0) { if (flsFields.containsKey(indexPattern)) { flsFields.get(indexPattern).addAll(Sets.newHashSet(fls)); } else { flsFields.put(indexPattern, new HashSet<String>()); flsFields.get(indexPattern).addAll(Sets.newHashSet(fls)); } for (int i = 0; i < concreteIndices.length; i++) { final String ci = concreteIndices[i]; if (flsFields.containsKey(ci)) { flsFields.get(ci).addAll(Sets.newHashSet(fls)); } else { flsFields.put(ci, new HashSet<String>()); flsFields.get(ci).addAll(Sets.newHashSet(fls)); } } if (log.isDebugEnabled()) { log.debug("fls fields {} for {}", Sets.newHashSet(fls), Arrays.toString(concreteIndices)); } } } } allowAction = true; } leftovers.addAll(_requestedResolvedIndexTypes); } // end sg role loop if (!allowAction && log.isInfoEnabled()) { log.info("No perm match for {} {} [Action [{}]] [RolesChecked {}]", user, requestedResolvedIndexTypes, action, sgRoles); } if (!dlsQueries.isEmpty()) { request.putHeader(ConfigConstants.SG_DLS_QUERY, Base64Helper.serializeObject((Serializable) dlsQueries)); } if (!flsFields.isEmpty()) { request.putHeader(ConfigConstants.SG_FLS_FIELDS, Base64Helper.serializeObject((Serializable) flsFields)); } if (!allowAction && privilegesInterceptor.getClass() != PrivilegesInterceptor.class) { return privilegesInterceptor.replaceAllowedIndices(request, action, user, config, leftovers); } return allowAction; }