Search in sources :

Example 91 with CopyOnWriteArrayList

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);
}
Also used : java.util(java.util) VirtualFile(com.intellij.openapi.vfs.VirtualFile) Reflections(org.reflections.Reflections) Constructor(java.lang.reflect.Constructor) JavaRecursiveElementVisitor(com.intellij.psi.JavaRecursiveElementVisitor) Gson(com.google.gson.Gson) PsiElement(com.intellij.psi.PsiElement) PsiRewrite(il.org.spartan.Leonidas.auxilary_layer.PsiRewrite) PsiFile(com.intellij.psi.PsiFile) Modifier.isAbstract(java.lang.reflect.Modifier.isAbstract) PropertiesComponent(com.intellij.ide.util.PropertiesComponent) ApplicationComponent(com.intellij.openapi.components.ApplicationComponent) TipperUnderConstruction(il.org.spartan.Leonidas.plugin.tippers.leonidas.LeonidasTipperDefinition.TipperUnderConstruction) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Collectors(java.util.stream.Collectors) Leonidas.plugin.tippers(il.org.spartan.Leonidas.plugin.tippers) Utils(il.org.spartan.Leonidas.auxilary_layer.Utils) Tipper(il.org.spartan.Leonidas.plugin.tipping.Tipper) Wrapper(il.org.spartan.Leonidas.auxilary_layer.Wrapper) LeonidasTipperDefinition(il.org.spartan.Leonidas.plugin.tippers.leonidas.LeonidasTipperDefinition) Modifier(java.lang.reflect.Modifier) ApplicationManager(com.intellij.openapi.application.ApplicationManager) Logger(il.org.spartan.Leonidas.plugin.utils.logging.Logger) GenericEncapsulator(il.org.spartan.Leonidas.plugin.leonidas.BasicBlocks.GenericEncapsulator) NotNull(org.jetbrains.annotations.NotNull) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) Gson(com.google.gson.Gson) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList)

Example 92 with CopyOnWriteArrayList

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;
}
Also used : BundleWire(org.osgi.framework.wiring.BundleWire) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList)

Example 93 with CopyOnWriteArrayList

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);
    }
}
Also used : JsfModuleConfig(org.apache.deltaspike.jsf.api.config.JsfModuleConfig) FacesMessageEntry(org.apache.deltaspike.jsf.impl.message.FacesMessageEntry) WindowMetaData(org.apache.deltaspike.jsf.impl.listener.phase.WindowMetaData) ContextNotActiveException(javax.enterprise.context.ContextNotActiveException) ArrayList(java.util.ArrayList) List(java.util.List) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList)

Example 94 with CopyOnWriteArrayList

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());
}
Also used : MetricRegistry(com.codahale.metrics.MetricRegistry) Logger(org.slf4j.Logger) MethodHandles(java.lang.invoke.MethodHandles) LoggerFactory(org.slf4j.LoggerFactory) Set(java.util.Set) MetricsMap(org.apache.solr.metrics.MetricsMap) HashSet(java.util.HashSet) TimeUnit(java.util.concurrent.TimeUnit) SolrException(org.apache.solr.common.SolrException) NAME(org.apache.solr.common.params.CommonParams.NAME) List(java.util.List) Map(java.util.Map) SolrMetricManager(org.apache.solr.metrics.SolrMetricManager) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ConcurrentLFUCache(org.apache.solr.util.ConcurrentLFUCache) MetricsMap(org.apache.solr.metrics.MetricsMap) MetricsMap(org.apache.solr.metrics.MetricsMap) Map(java.util.Map)

Example 95 with CopyOnWriteArrayList

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();
}
Also used : DirectoryReader(org.apache.lucene.index.DirectoryReader) Term(org.apache.lucene.index.Term) Analyzer(org.apache.lucene.analysis.Analyzer) MockAnalyzer(org.apache.lucene.analysis.MockAnalyzer) Document(org.apache.lucene.document.Document) IntPoint(org.apache.lucene.document.IntPoint) CyclicBarrier(java.util.concurrent.CyclicBarrier) MockAnalyzer(org.apache.lucene.analysis.MockAnalyzer) RandomIndexWriter(org.apache.lucene.index.RandomIndexWriter) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) Test(org.junit.Test)

Aggregations

CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)97 CountDownLatch (java.util.concurrent.CountDownLatch)38 IOException (java.io.IOException)23 ArrayList (java.util.ArrayList)23 List (java.util.List)23 Test (org.junit.Test)20 ExecutionException (java.util.concurrent.ExecutionException)15 DiscoveryNode (org.elasticsearch.cluster.node.DiscoveryNode)13 CyclicBarrier (java.util.concurrent.CyclicBarrier)11 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)11 BrokenBarrierException (java.util.concurrent.BrokenBarrierException)10 MockTransportService (org.elasticsearch.test.transport.MockTransportService)10 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)9 HashMap (java.util.HashMap)8 AtomicReference (java.util.concurrent.atomic.AtomicReference)7 HashSet (java.util.HashSet)6 Map (java.util.Map)6 TimeUnit (java.util.concurrent.TimeUnit)6 Settings (org.elasticsearch.common.settings.Settings)6 Config (com.hazelcast.config.Config)5