Examples of CyclicBarrier


Examples of java.util.concurrent.CyclicBarrier

      throws NoSuchFieldException, IllegalAccessException, InterruptedException, BrokenBarrierException, ClassNotFoundException {
    // Stop iconsLoader of iconManager
    IconManager iconManager = IconManager.getInstance();
    iconManager.clear();
    // Replace icon manager by an executor that controls the start of a task with a barrier
    final CyclicBarrier iconLoadingStartBarrier = new CyclicBarrier(2);
    final ThreadPoolExecutor replacingIconsLoader =
      new ThreadPoolExecutor(1, 1, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>()) {
        @Override
        protected void beforeExecute(Thread t, Runnable r) {
          super.beforeExecute(t, r);
View Full Code Here

Examples of java.util.concurrent.CyclicBarrier

    URLContent waitIconContent =
        (URLContent)TestUtilities.getField(iconManager, "waitIconContent");
    URLContent errorIconContent =
        (URLContent)TestUtilities.getField(iconManager, "errorIconContent");
   
    final CyclicBarrier waitingComponentBarrier = new CyclicBarrier(2);
    // A dummy waiting component that waits on a barrier in its repaint method
    Component waitingComponent = new Component() {
      public void repaint() {
        awaitBarrier(waitingComponentBarrier);
      }
    };

    Content iconContent = new URLContent(iconURL);
    Icon icon = iconManager.getIcon(iconContent, HEIGHT, waitingComponent);
    assertEquals("Icon not equal to wait icon while loading", waitIconContent.getURL(), icon);

    // Let iconManager load the iconContent
    iconLoadingStartBarrier.await();
    // Wait iconContent loading completion
    waitingComponentBarrier.await();
    if (goodIcon) {
      assertEquals("Icon not equal to icon read from resource", iconURL, icon);
    } else {
      assertEquals("Wrong icon not equal to errorIcon", errorIconContent.getURL(), icon);
    }
View Full Code Here

Examples of java.util.concurrent.CyclicBarrier

        if (data.length % blockSize != 0) {
            throw new IllegalArgumentException("Number of bytes is not a multiple of the blocksize!");
        }

        int parts = (blocks >= devices.length) ? devices.length : (int)blocks;
        barrier = new CyclicBarrier(parts + 1);
        int targetBlockCount;
        List<byte[]> targetData = new Vector<byte[]>();
        int targetBlockAddress = (int)address;

        for (int i = 0; i < parts; i++) {
View Full Code Here

Examples of java.util.concurrent.CyclicBarrier

        if (data.length % blockSize != 0) {
            throw new IllegalArgumentException("Number of bytes is not a multiple of the blocksize!");
        }

        barrier = new CyclicBarrier(devices.length + 1);
        for (int i = 0; i < devices.length; i++) {
            executor.execute(new WriteThread(devices[i], (int)address, data));
        }
        barrier.await();
    }
View Full Code Here

Examples of java.util.concurrent.CyclicBarrier

            long adr = address < 0 ? address : address + blocks - 1;
            throw new IllegalArgumentException("Address " + adr + " out of range.");
        }

        int parts = (fragments >= devices.length) ? devices.length : fragments;
        barrier = new CyclicBarrier(parts + 1);
        long actualAddress = ((address / blockFactor) / devices.length) * blockFactor;
        int actualDevice = (int)((address / blockFactor) % devices.length);
        List<byte[]> deviceData = new Vector<byte[]>();
        int deviceBlockCount;
        for (int i = 0; i < parts; i++) {
View Full Code Here

Examples of java.util.concurrent.CyclicBarrier

        int parts = (fragments >= devices.length) ? devices.length : fragments;
        List<byte[]> deviceData = new Vector<byte[]>();
        long actualAddress = ((address / blockFactor) / devices.length) * blockFactor;
        int actualDevice = (int)((address / blockFactor) % devices.length);
        int deviceBlockCount;
        barrier = new CyclicBarrier(parts + 1);
        for (int i = 0; i < parts; i++) {
            deviceBlockCount = fragments / devices.length * blockFactor;
            if (i < (fragments % devices.length)) {
                deviceBlockCount += blockFactor;
            }
View Full Code Here

Examples of java.util.concurrent.CyclicBarrier

           
        // barrier for document processing threads.  When their next document is
        // outside of the time range, the immediately increase the release on
        // this semaphore and lock on the an object while the serialization
        // thread writes out the current time span's .sspace
        final CyclicBarrier exceededTimeSpanBarrier =
            new CyclicBarrier(numThreads, serializeTimeSpan);
                   
       
        for (int i = 0; i < numThreads; ++i) {

            Thread processingThread = new Thread() {
                   
                    public void run() {
                        // repeatedly try to process documents while some still
                        // remain
                        while (docIter.hasNext()) {
                           
                            TemporalDocument doc = docIter.next();
                            int docNumber = count.incrementAndGet();
                            long docTime = doc.timeStamp();

                            // special case for first document
                            if (docNumber == 1) {
                                curSSpaceStartTime.set(docTime);
                                startBarrier.set(true);
                            }
                           
                            // Spin until the Thread with the first document
                            // sets the initial starting document time.  Note
                            // that we spin here instead of block, because this
                            // is expected that another thread will immediately
                            // set this and so it will be a quick no-op
                            while (startBarrier.get() == false)
                                ;

                            // Check whether the time for this document would
                            // exceed the maximum time span for any TRI
                            // partition.  Loop to ensure that if this thread
                            // does loop and another thread has an earlier time
                            // that would cause this thread's time span to
                            // exceeds the other thread's time period, then this
                            // thread will block and loop again.
                            while (!timeSpan.insideRange(
                                   curSSpaceStartTime.get(), docTime)) {
                                try {
                                    // notify the barrier that this Thread is
                                    // now processing a document in the next
                                    // time span and so the serialization thread
                                    // should write the .sspace to disk.  In
                                    // addition, enqueue the time for this
                                    // document so the serialization thread can
                                    // reset the correct s-sspace start time
                                    futureStartTimes.offer(docTime);
                                    exceededTimeSpanBarrier.await();
                                } catch (InterruptedException ex) {
                                    return;
                                } catch (BrokenBarrierException ex) {
                                    return;
                                }
View Full Code Here

Examples of java.util.concurrent.CyclicBarrier

  }

  @Test
  public void testGroupCommit() throws Exception {
    final FlumeEvent eventIn = TestUtils.newPersistableEvent(250);
    final CyclicBarrier barrier = new CyclicBarrier(20);
    ExecutorService executorService = Executors.newFixedThreadPool(20);
    ExecutorCompletionService<Void> completionService = new
      ExecutorCompletionService<Void>(executorService);
    final LogFile.Writer writer = logFileWriter;
    final AtomicLong txnId = new AtomicLong(++transactionID);
    for (int i = 0; i < 20; i++) {
      completionService.submit(new Callable<Void>() {
        @Override
        public Void call() {
          try {
            Put put = new Put(txnId.incrementAndGet(),
              WriteOrderOracle.next(), eventIn);
            ByteBuffer bytes = TransactionEventRecord.toByteBuffer(put);
            writer.put(bytes);
            writer.commit(TransactionEventRecord.toByteBuffer(
              new Commit(txnId.get(), WriteOrderOracle.next())));
            barrier.await();
            writer.sync();
          } catch (Exception ex) {
            Throwables.propagate(ex);
          }
          return null;
View Full Code Here

Examples of java.util.concurrent.CyclicBarrier

 
  protected void sendMessages() {
    final AtomicInteger num_msgs_sent = new AtomicInteger(0); // all threads will increment this
    final AtomicLong seqno = new AtomicLong(1); // monotonically increasing seqno, to be used by all threads
    final Sender[] senders = new Sender[num_threads];
    final CyclicBarrier barrier = new CyclicBarrier(num_threads + 1);
    final byte[] payload = new byte[msg_size];

        for(int i=0; i < num_threads; i++) {
            senders[i]=new Sender(barrier, num_msgs_sent, seqno, payload);
            senders[i].setName("sender-" + i);
            senders[i].start();
        }
        try {
            System.out.println("-- sending " + num_msgs + " msgs");
            barrier.await();
        }
        catch(Exception e) {
            System.err.println("failed triggering send threads: " + e);
        }
    }
View Full Code Here

Examples of java.util.concurrent.CyclicBarrier

                }
                examinedListeners[i] = new ExaminedListener(fail);
            }

            final AtomicBoolean condition = new AtomicBoolean(true);
            final CyclicBarrier trigger = new CyclicBarrier(2);
            final CountDownLatch latch = new CountDownLatch(10);

            ExecutorService notificationsPool = Executors.newFixedThreadPool(4);
            notificationsPool.submit(new Callable<Void>() {
                public Void call() throws Exception {
                    trigger.await();
                    while (condition.get()) {
                        fNotifier.fireTestStarted(null);
                        latch.countDown();
                    }
                    fNotifier.fireTestStarted(null);
                    return null;
                }
            });

            // Wait for callable to start
            trigger.await(TIMEOUT, TimeUnit.SECONDS);

            // Wait for callable to fire a few events
            latch.await(TIMEOUT, TimeUnit.SECONDS);

            for (ExaminedListener examinedListener : examinedListeners) {
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.