Example usage for java.util.concurrent ConcurrentSkipListSet ConcurrentSkipListSet

List of usage examples for java.util.concurrent ConcurrentSkipListSet ConcurrentSkipListSet

Introduction

In this page you can find the example usage for java.util.concurrent ConcurrentSkipListSet ConcurrentSkipListSet.

Prototype

public ConcurrentSkipListSet() 

Source Link

Document

Constructs a new, empty set that orders its elements according to their Comparable natural ordering .

Usage

From source file:com.almende.eve.test.TestZmq.java

/**
 * Run test./*from w  w w .ja v  a 2 s  .com*/
 * 
 * @param test
 *            the test
 * @param test2
 *            the test2
 * @param type
 *            the type
 * @throws IOException
 *             Signals that an I/O exception has occurred.
 * @throws JSONRPCException
 *             the jSONRPC exception
 * @throws InterruptedException
 *             the interrupted exception
 */
private void runTest(final Test2Agent test, final Test2Agent test2, final String type)
        throws IOException, JSONRPCException, InterruptedException {
    final Set<String> results = new ConcurrentSkipListSet<String>();

    final AsyncCallback<String> callback = new AsyncCallback<String>() {

        @Override
        public void onSuccess(final String result) {
            results.add(result);
        }

        @Override
        public void onFailure(final Exception e) {
            LOG.log(Level.SEVERE, "Oeps, exception:", e);
        }

    };
    final URI uri1 = getUrl(type, test.getId());
    final URI uri2 = getUrl(type, test2.getId());

    LOG.warning("uri1:" + uri1 + " uri2:" + uri2);

    ObjectNode parms = JOM.createObjectNode();
    parms.put("message", "1");
    test.sendAsync(uri2, "slowPing", parms, callback, String.class);

    parms = JOM.createObjectNode();
    parms.put("message", "2");
    test.sendAsync(uri2, "slowPing", parms, callback, String.class);

    parms = JOM.createObjectNode();
    parms.put("message", "3");
    test.sendAsync(uri1, "slowPing", parms, callback, String.class);

    parms = JOM.createObjectNode();
    parms.put("message", "4");
    test.sendAsync(uri1, "slowPing", parms, callback, String.class);

    parms = JOM.createObjectNode();
    parms.put("message", "5");
    test2.sendAsync(uri1, "slowPing", parms, callback, String.class);

    parms = JOM.createObjectNode();
    parms.put("message", "6");
    test2.sendAsync(uri1, "slowPing", parms, callback, String.class);

    parms = JOM.createObjectNode();
    parms.put("message", "7");
    test2.sendAsync(uri2, "slowPing", parms, callback, String.class);

    parms = JOM.createObjectNode();
    parms.put("message", "8");
    test2.sendAsync(uri2, "slowPing", parms, callback, String.class);
    Thread.sleep(2000);

    System.err.println("results:" + results);
    assertEquals(8, results.size());

}

From source file:com.apress.prospringintegration.customadapters.inbound.eventdriven.DirectoryMonitorInboundFileEndpointTests.java

@Test
public void testReceivingFiles() throws Throwable {
    final Set<String> files = new ConcurrentSkipListSet<String>();
    integrationTestUtils.createConsumer(this.messageChannel, new MessageHandler() {
        @Override//from  w  ww  . j ava2s  .co m
        public void handleMessage(Message<?> message) throws MessagingException {
            File file = (File) message.getPayload();
            String filePath = file.getPath();
            files.add(filePath);
        }
    });

    int cnt = 10;
    for (int i = 0; i < cnt; i++) {
        File out = new File(directoryToMonitor, i + ".txt");
        Writer w = new BufferedWriter(new FileWriter(out));
        IOUtils.write("test" + i, w);
        IOUtils.closeQuietly(w);
    }

    Thread.sleep(TimeUnit.SECONDS.toMillis(20));
    Assert.assertEquals(cnt, files.size());
}

From source file:annis.gui.flatquerybuilder.SpanBox.java

public SpanBox(final String ebene, final FlatQueryBuilder sq) {
    this.ebene = ebene;
    this.sq = sq;
    sb = new HorizontalLayout();
    sb.setImmediate(true);//  www. java2s . c  o  m
    sb.setSpacing(true);
    sb.setMargin(true);
    ConcurrentSkipListSet<String> annos = new ConcurrentSkipListSet<String>();
    for (String a : sq.getAvailableAnnotationLevels(ebene)) {
        annos.add(a);
    }
    this.annonames = annos;
    Label tf = new Label(ebene);
    sb.addComponent(tf);
    this.cb = new SensitiveComboBox();
    cb.setInputPrompt(ebene);
    cb.setWidth(SB_CB_WIDTH);
    // configure & load content
    cb.setImmediate(true);
    for (String annoname : this.annonames) {
        cb.addItem(annoname);
    }
    cb.setFilteringMode(AbstractSelect.Filtering.FILTERINGMODE_OFF);
    cb.addListener((FieldEvents.TextChangeListener) this);
    sb.addComponent(cb);
    HorizontalLayout sbtoolbar = new HorizontalLayout();
    sbtoolbar.setSpacing(true);
    // searchbox tickbox for regex
    CheckBox tb = new CheckBox("Regex");
    tb.setImmediate(true);
    sbtoolbar.addComponent(tb);
    tb.addListener(new ValueChangeListener() {
        // TODO make this into a nice subroutine
        @Override
        public void valueChange(ValueChangeEvent event) {
            boolean r = reBox.booleanValue();
            cb.setNewItemsAllowed(r);
            if (!r) {
                SpanBox.buildBoxValues(cb, ebene, sq);
            } else if (cb.getValue() != null) {
                String escapedItem = sq.escapeRegexCharacters(cb.getValue().toString());
                cb.addItem(escapedItem);
                cb.setValue(escapedItem);
            }
        }
    });
    reBox = tb;
    // close the searchbox
    btClose = new Button(BUTTON_CLOSE_LABEL, (Button.ClickListener) this);
    btClose.setStyleName(ChameleonTheme.BUTTON_SMALL);
    sbtoolbar.addComponent(btClose);
    // make visable
    sb.addComponent(sbtoolbar);
    setContent(sb);
}

From source file:annis.gui.flatquerybuilder.SearchBox.java

public SearchBox(final String ebene, final FlatQueryBuilder sq, final VerticalNode vn) {
    this.vn = vn;
    this.ebene = ebene;
    this.sq = sq;
    VerticalLayout sb = new VerticalLayout();
    sb.setImmediate(true);/*from w  w w  .  j a v a 2 s.c  o m*/
    sb.setSpacing(true);
    ConcurrentSkipListSet<String> annos = new ConcurrentSkipListSet<String>();
    for (String a : sq.getAvailableAnnotationLevels(ebene)) {
        annos.add(a);
    }
    this.annonames = annos;//by Martin    
    this.cb = new SensitiveComboBox();
    cb.setCaption(ebene);
    cb.setInputPrompt(ebene);
    cb.setWidth(SB_CB_WIDTH);
    // configure & load content
    cb.setImmediate(true);
    for (String annoname : this.annonames) {
        cb.addItem(annoname);
    }
    cb.setFilteringMode(Filtering.FILTERINGMODE_OFF);//necessary?
    cb.addListener((FieldEvents.TextChangeListener) this);
    sb.addComponent(cb);
    HorizontalLayout sbtoolbar = new HorizontalLayout();
    sbtoolbar.setSpacing(true);
    // searchbox tickbox for regex
    CheckBox tb = new CheckBox("Regex");
    tb.setImmediate(true);
    sbtoolbar.addComponent(tb);
    tb.addListener(new ValueChangeListener() {
        // TODO make this into a nice subroutine
        @Override
        public void valueChange(ValueChangeEvent event) {
            boolean r = reBox.booleanValue();
            cb.setNewItemsAllowed(r);
            if (!r) {
                SpanBox.buildBoxValues(cb, ebene, sq);
            } else if (cb.getValue() != null) {
                String escapedItem = sq.escapeRegexCharacters(cb.getValue().toString());
                cb.addItem(escapedItem);
                cb.setValue(escapedItem);
            }
        }
    });
    reBox = tb;
    // close the searchbox
    btClose = new Button(BUTTON_CLOSE_LABEL, (Button.ClickListener) this);
    btClose.setStyleName(ChameleonTheme.BUTTON_SMALL);
    sbtoolbar.addComponent(btClose);
    sb.addComponent(sbtoolbar);
    sb.setSpacing(true);
    setContent(sb);
}

From source file:org.gitools.analysis.clustering.hierarchical.HierarchicalClusterer.java

public HierarchicalCluster cluster(IMatrix matrix, IMatrixLayer<Double> layer,
        IMatrixDimension clusterDimension, IMatrixDimension aggregationDimension, IProgressMonitor monitor) {

    Map<String, HierarchicalCluster> clusters = new HashMap<>(clusterDimension.size());
    SortedSet<ClusterPair> linkages = new ConcurrentSkipListSet<>();

    // Aggregate all the values to sort the clusters by weight
    monitor.begin("Aggregating values...", clusterDimension.size());
    final Map<String, Double> aggregation = new HashMap<>(clusterDimension.size());
    Set<String> allNullValues = new HashSet<>();
    IMatrixPosition position = matrix.newPosition();
    for (String id : position.iterate(clusterDimension)) {

        Double value = aggregator.aggregate(position.iterate(layer, aggregationDimension));

        if (value != null) {
            aggregation.put(id, value);//from  w  w w  .j a  v  a  2 s. co  m
        } else {
            allNullValues.add(id);
        }

    }

    // First sort the clustering dimension to show the clusters ordered by weight at the end
    if (clusterDimension instanceof IMatrixViewDimension) {
        IMatrixViewDimension sortDimension = (IMatrixViewDimension) clusterDimension;
        sortDimension.sort(new Comparator<String>() {
            @Override
            public int compare(String o1, String o2) {
                return SortDirection.ASCENDING.compare(aggregation.get(o1), aggregation.get(o2));
            }
        });
    }

    // Calculate all the distances
    IMatrixPosition position1 = matrix.newPosition();
    IMatrixPosition position2 = matrix.newPosition();
    monitor.begin("Calculating distances...", clusterDimension.size());
    for (String id1 : position1.iterate(clusterDimension)) {

        // Check user cancel action
        monitor.worked(1);
        if (monitor.isCancelled()) {
            throw new CancellationException();
        }

        // Skip all null values
        if (allNullValues.contains(id1)) {
            continue;
        }

        HierarchicalCluster cluster1 = newCluster(clusters, id1);
        cluster1.setWeight(aggregation.get(id1));

        for (String id2 : position2.iterate(clusterDimension.from(id1))) {

            // Skip equal ids
            if (id1.equals(id2))
                continue;

            // Skip all null columns
            if (allNullValues.contains(id2)) {
                continue;
            }

            Double distance = measure.compute(position1.iterate(layer, aggregationDimension),
                    position2.iterate(layer, aggregationDimension));

            HierarchicalCluster cluster2 = newCluster(clusters, id2);

            linkages.add(new ClusterPair(distance, cluster1, cluster2));
        }
    }

    // Create the clusters agglomerating nodes by the nearest distances
    HierarchyBuilder builder = new HierarchyBuilder(newHashSet(clusters.values()), linkages);
    builder.agglomerate(linkageStrategy, monitor, clusterDimension.size());

    // Set cluster names ordered by weight
    HierarchicalCluster root = builder.getRootCluster();
    root.setName("");
    Color color = nameClusters(root.getChildren(), 1);
    root.setColor(color.getRGB());
    root.setName("root");

    return root;
}

From source file:org.apache.pulsar.client.impl.AcknowledgmentsGroupingTracker.java

public AcknowledgmentsGroupingTracker(ConsumerImpl<?> consumer, ConsumerConfigurationData<?> conf,
        EventLoopGroup eventLoopGroup) {
    this.consumer = consumer;
    this.pendingIndividualAcks = new ConcurrentSkipListSet<>();
    this.acknowledgementGroupTimeMicros = conf.getAcknowledgementsGroupTimeMicros();

    if (acknowledgementGroupTimeMicros > 0) {
        scheduledTask = eventLoopGroup.next().scheduleWithFixedDelay(this::flush,
                acknowledgementGroupTimeMicros, acknowledgementGroupTimeMicros, TimeUnit.MICROSECONDS);
    } else {/*from  www  .j  a va2 s  . com*/
        scheduledTask = null;
    }
}

From source file:org.apache.hadoop.hbase.procedure2.TestProcedureSchedulerConcurrency.java

private void testConcurrentWaitWake(final boolean useWakeBatch) throws Exception {
    final int WAIT_THRESHOLD = 2500;
    final int NPROCS = 20;
    final int NRUNS = 500;

    final ProcedureScheduler sched = procSched;
    for (long i = 0; i < NPROCS; ++i) {
        sched.addBack(new TestProcedureWithEvent(i));
    }//from  ww w  .jav a  2s .  com

    final Thread[] threads = new Thread[4];
    final AtomicInteger waitCount = new AtomicInteger(0);
    final AtomicInteger wakeCount = new AtomicInteger(0);

    final ConcurrentSkipListSet<TestProcedureWithEvent> waitQueue = new ConcurrentSkipListSet<TestProcedureWithEvent>();
    threads[0] = new Thread() {
        @Override
        public void run() {
            long lastUpdate = 0;
            while (true) {
                final int oldWakeCount = wakeCount.get();
                if (useWakeBatch) {
                    ProcedureEvent[] ev = new ProcedureEvent[waitQueue.size()];
                    for (int i = 0; i < ev.length; ++i) {
                        ev[i] = waitQueue.pollFirst().getEvent();
                        LOG.debug("WAKE BATCH " + ev[i] + " total=" + wakeCount.get());
                    }
                    sched.wakeEvents(ev.length, ev);
                    wakeCount.addAndGet(ev.length);
                } else {
                    int size = waitQueue.size();
                    while (size-- > 0) {
                        ProcedureEvent ev = waitQueue.pollFirst().getEvent();
                        sched.wakeEvent(ev);
                        LOG.debug("WAKE " + ev + " total=" + wakeCount.get());
                        wakeCount.incrementAndGet();
                    }
                }
                if (wakeCount.get() != oldWakeCount) {
                    lastUpdate = System.currentTimeMillis();
                } else if (wakeCount.get() >= NRUNS
                        && (System.currentTimeMillis() - lastUpdate) > WAIT_THRESHOLD) {
                    break;
                }
                Threads.sleepWithoutInterrupt(25);
            }
        }
    };

    for (int i = 1; i < threads.length; ++i) {
        threads[i] = new Thread() {
            @Override
            public void run() {
                while (true) {
                    TestProcedureWithEvent proc = (TestProcedureWithEvent) sched.poll();
                    if (proc == null)
                        continue;

                    sched.suspendEvent(proc.getEvent());
                    waitQueue.add(proc);
                    sched.waitEvent(proc.getEvent(), proc);
                    LOG.debug("WAIT " + proc.getEvent());
                    if (waitCount.incrementAndGet() >= NRUNS) {
                        break;
                    }
                }
            }
        };
    }

    for (int i = 0; i < threads.length; ++i) {
        threads[i].start();
    }
    for (int i = 0; i < threads.length; ++i) {
        threads[i].join();
    }

    sched.clear();
}

From source file:org.apache.pulsar.client.impl.PersistentAcknowledgmentsGroupingTracker.java

public PersistentAcknowledgmentsGroupingTracker(ConsumerImpl<?> consumer, ConsumerConfigurationData<?> conf,
        EventLoopGroup eventLoopGroup) {
    this.consumer = consumer;
    this.pendingIndividualAcks = new ConcurrentSkipListSet<>();
    this.acknowledgementGroupTimeMicros = conf.getAcknowledgementsGroupTimeMicros();

    if (acknowledgementGroupTimeMicros > 0) {
        scheduledTask = eventLoopGroup.next().scheduleWithFixedDelay(this::flush,
                acknowledgementGroupTimeMicros, acknowledgementGroupTimeMicros, TimeUnit.MICROSECONDS);
    } else {/*from   w  w  w  . j a  v  a  2 s. co  m*/
        scheduledTask = null;
    }
}

From source file:org.apache.qpid.server.security.group.FileGroupDatabase.java

@Override
public synchronized void addUserToGroup(String user, String group) {
    Set<String> users = _groupToUserMap.get(group);
    if (users == null) {
        throw new IllegalArgumentException(
                "Group " + group + " does not exist so could not add " + user + " to it");
    }//  w  w  w  .  j a va2  s.c  o  m

    users.add(user);

    Set<String> groups = _userToGroupMap.get(user);
    if (groups == null) {
        groups = new ConcurrentSkipListSet<String>();
        _userToGroupMap.put(user, groups);
    }
    groups.add(group);

    update();
}

From source file:cn.wanghaomiao.seimi.def.DefaultLocalQueue.java

public ConcurrentSkipListSet<String> getProcessedSet(String crawlerName) {
    ConcurrentSkipListSet<String> set = processedData.get(crawlerName);
    if (set == null) {
        set = new ConcurrentSkipListSet<>();
        processedData.put(crawlerName, set);
    }/*www.ja  v a 2 s. c o m*/
    return set;
}