use of java.util.concurrent.CopyOnWriteArrayList in project Main by SpartanRefactoring.
the class Toolbox method updateTipperList.
@SuppressWarnings("unchecked")
public void updateTipperList(List<String> list) {
this.tipperMap.values().forEach(element -> element.forEach(tipper -> {
if (!list.contains(tipper.name())) {
element.remove(tipper);
}
}));
this.allTipperMap.values().forEach(element -> element.forEach(tipper -> {
if (list.contains(tipper.name())) {
tipperMap.putIfAbsent(tipper.getOperableType(), new CopyOnWriteArrayList<>());
operableTypes.add(tipper.getOperableType());
tipperMap.get(tipper.getOperableType()).add(tipper);
}
}));
List<String> activeTippersNames = new ArrayList<>();
this.tipperMap.values().forEach(element -> element.forEach(tipper -> {
activeTippersNames.add(tipper.name());
}));
String jsonTips = new Gson().toJson(activeTippersNames);
PropertiesComponent.getInstance().setValue("savedTippers", jsonTips, "");
//TODO: @Amir Sagiv this should be uncommented
// toolboxStateService.updateAllTippers(list);
}
use of java.util.concurrent.CopyOnWriteArrayList in project aries by apache.
the class Phase_Extension method findExtensionDependencies.
List<ExtensionDependency> findExtensionDependencies(BundleWiring bundleWiring) {
List<ExtensionDependency> extensionDependencies = new CopyOnWriteArrayList<>();
List<BundleWire> requiredWires = bundleWiring.getRequiredWires(CdiConstants.CDI_EXTENSION_NAMESPACE);
for (BundleWire wire : requiredWires) {
Map<String, Object> attributes = wire.getCapability().getAttributes();
String extension = (String) attributes.get(CdiConstants.CDI_EXTENSION_NAMESPACE);
if (extension != null) {
ExtensionDependency extensionDependency = new ExtensionDependency(_bundleContext, wire.getProvider().getBundle().getBundleId(), extension);
extensionDependencies.add(extensionDependency);
}
}
return extensionDependencies;
}
use of java.util.concurrent.CopyOnWriteArrayList in project deltaspike by apache.
the class JsfUtils method saveFacesMessages.
public static void saveFacesMessages(ExternalContext externalContext) {
JsfModuleConfig jsfModuleConfig = BeanProvider.getContextualReference(JsfModuleConfig.class);
if (!jsfModuleConfig.isAlwaysKeepMessages()) {
return;
}
try {
WindowMetaData windowMetaData = BeanProvider.getContextualReference(WindowMetaData.class);
Map<String, Object> requestMap = externalContext.getRequestMap();
@SuppressWarnings({ "unchecked" }) List<FacesMessageEntry> facesMessageEntryList = (List<FacesMessageEntry>) requestMap.get(FacesMessageEntry.class.getName());
if (facesMessageEntryList == null) {
facesMessageEntryList = new CopyOnWriteArrayList<FacesMessageEntry>();
}
windowMetaData.setFacesMessageEntryList(facesMessageEntryList);
} catch (ContextNotActiveException e) {
//TODO log it in case of project-stage development
//we can't handle it correctly -> delegate to the jsf-api (which has some restrictions esp. before v2.2)
FacesContext.getCurrentInstance().getExternalContext().getFlash().setKeepMessages(true);
}
}
use of java.util.concurrent.CopyOnWriteArrayList in project lucene-solr by apache.
the class LFUCache method initializeMetrics.
@Override
public void initializeMetrics(SolrMetricManager manager, String registryName, String scope) {
registry = manager.registry(registryName);
cacheMap = new MetricsMap((detailed, map) -> {
if (cache != null) {
ConcurrentLFUCache.Stats stats = cache.getStats();
long lookups = stats.getCumulativeLookups();
long hits = stats.getCumulativeHits();
long inserts = stats.getCumulativePuts();
long evictions = stats.getCumulativeEvictions();
long size = stats.getCurrentSize();
map.put("lookups", lookups);
map.put("hits", hits);
map.put("hitratio", calcHitRatio(lookups, hits));
map.put("inserts", inserts);
map.put("evictions", evictions);
map.put("size", size);
map.put("warmupTime", warmupTime);
map.put("timeDecay", timeDecay);
long clookups = 0;
long chits = 0;
long cinserts = 0;
long cevictions = 0;
// NOTE: It is safe to iterate on a CopyOnWriteArrayList
for (ConcurrentLFUCache.Stats statistics : statsList) {
clookups += statistics.getCumulativeLookups();
chits += statistics.getCumulativeHits();
cinserts += statistics.getCumulativePuts();
cevictions += statistics.getCumulativeEvictions();
}
map.put("cumulative_lookups", clookups);
map.put("cumulative_hits", chits);
map.put("cumulative_hitratio", calcHitRatio(clookups, chits));
map.put("cumulative_inserts", cinserts);
map.put("cumulative_evictions", cevictions);
if (detailed && showItems != 0) {
Map items = cache.getMostUsedItems(showItems == -1 ? Integer.MAX_VALUE : showItems);
for (Map.Entry e : (Set<Map.Entry>) items.entrySet()) {
Object k = e.getKey();
Object v = e.getValue();
String ks = "item_" + k;
String vs = v.toString();
map.put(ks, vs);
}
}
}
});
manager.registerGauge(this, registryName, cacheMap, true, scope, getCategory().toString());
}
use of java.util.concurrent.CopyOnWriteArrayList in project lucene-solr by apache.
the class TestSuggestField method testThreads.
@Test
public void testThreads() throws Exception {
final Analyzer analyzer = new MockAnalyzer(random());
RandomIndexWriter iw = new RandomIndexWriter(random(), dir, iwcWithSuggestField(analyzer, "suggest_field_1", "suggest_field_2", "suggest_field_3"));
int num = Math.min(1000, atLeast(100));
final String prefix1 = "abc1_";
final String prefix2 = "abc2_";
final String prefix3 = "abc3_";
final Entry[] entries1 = new Entry[num];
final Entry[] entries2 = new Entry[num];
final Entry[] entries3 = new Entry[num];
for (int i = 0; i < num; i++) {
int weight = num - (i + 1);
entries1[i] = new Entry(prefix1 + weight, weight);
entries2[i] = new Entry(prefix2 + weight, weight);
entries3[i] = new Entry(prefix3 + weight, weight);
}
for (int i = 0; i < num; i++) {
Document doc = new Document();
doc.add(new SuggestField("suggest_field_1", prefix1 + i, i));
doc.add(new SuggestField("suggest_field_2", prefix2 + i, i));
doc.add(new SuggestField("suggest_field_3", prefix3 + i, i));
iw.addDocument(doc);
if (rarely()) {
iw.commit();
}
}
DirectoryReader reader = iw.getReader();
int numThreads = TestUtil.nextInt(random(), 2, 7);
Thread[] threads = new Thread[numThreads];
final CyclicBarrier startingGun = new CyclicBarrier(numThreads + 1);
final CopyOnWriteArrayList<Throwable> errors = new CopyOnWriteArrayList<>();
final SuggestIndexSearcher indexSearcher = new SuggestIndexSearcher(reader);
for (int i = 0; i < threads.length; i++) {
threads[i] = new Thread() {
@Override
public void run() {
try {
startingGun.await();
PrefixCompletionQuery query = new PrefixCompletionQuery(analyzer, new Term("suggest_field_1", prefix1));
TopSuggestDocs suggest = indexSearcher.suggest(query, num, false);
assertSuggestions(suggest, entries1);
query = new PrefixCompletionQuery(analyzer, new Term("suggest_field_2", prefix2));
suggest = indexSearcher.suggest(query, num, false);
assertSuggestions(suggest, entries2);
query = new PrefixCompletionQuery(analyzer, new Term("suggest_field_3", prefix3));
suggest = indexSearcher.suggest(query, num, false);
assertSuggestions(suggest, entries3);
} catch (Throwable e) {
errors.add(e);
}
}
};
threads[i].start();
}
startingGun.await();
for (Thread t : threads) {
t.join();
}
assertTrue(errors.toString(), errors.isEmpty());
reader.close();
iw.close();
}
Aggregations