Package java.util.concurrent.atomic

Examples of java.util.concurrent.atomic.AtomicBoolean


     * (but not the directory itself) will be checked with isAllowed and notified to
     * the listener.  If it is a file, the file will be checked and notified.
     */
    public void start(File startFile) {
        File root = GFileUtils.canonicalise(startFile);
        AtomicBoolean stopFlag = new AtomicBoolean();
        if (root.exists()) {
            if (root.isFile()) {
                processSingleFile(root, stopFlag);
            } else {
               walkDir(root, new RelativePath(false), stopFlag);
View Full Code Here


        }
        if (!zipFile.isFile()) {
            throw new InvalidUserDataException(String.format("Cannot expand %s as it is not a file.", this));
        }

        AtomicBoolean stopFlag = new AtomicBoolean();

        try {
            ZipFile zip = new ZipFile(zipFile);
            try {
                // The iteration order of zip.getEntries() is based on the hash of the zip entry. This isn't much use
                // to us. So, collect the entries in a map and iterate over them in alphabetical order.
                Map<String, ZipEntry> entriesByName = new TreeMap<String, ZipEntry>();
                Enumeration entries = zip.getEntries();
                while (entries.hasMoreElements()) {
                    ZipEntry entry = (ZipEntry) entries.nextElement();
                    entriesByName.put(entry.getName(), entry);
                }
                Iterator<ZipEntry> sortedEntries = entriesByName.values().iterator();
                while (!stopFlag.get() && sortedEntries.hasNext()) {
                    ZipEntry entry = sortedEntries.next();
                    if (entry.isDirectory()) {
                        visitor.visitDir(new DetailsImpl(entry, zip, stopFlag));
                    } else {
                        visitor.visitFile(new DetailsImpl(entry, zip, stopFlag));
View Full Code Here

        }
        if (!tarFile.isFile()) {
            throw new InvalidUserDataException(String.format("Cannot expand %s as it is not a file.", this));
        }

        AtomicBoolean stopFlag = new AtomicBoolean();
        try {
            FileInputStream inputStream = new FileInputStream(tarFile);
            try {
                NoCloseTarInputStream tar = new NoCloseTarInputStream(inputStream);
                TarEntry entry;
                while (!stopFlag.get() && (entry = tar.getNextEntry()) != null) {
                    if (entry.isDirectory()) {
                        visitor.visitDir(new DetailsImpl(entry, tar, stopFlag));
                    } else {
                        visitor.visitFile(new DetailsImpl(entry, tar, stopFlag));
                    }
View Full Code Here

        return files;
    }

    @Override
    public boolean isEmpty() {
        final AtomicBoolean found = new AtomicBoolean();
        visit(new EmptyFileVisitor() {
            public void visitFile(FileVisitDetails fileDetails) {
                found.set(true);
                fileDetails.stopVisiting();
            }
        });
        return !found.get();
    }
View Full Code Here

        assertFalse(task.getOnlyIf().isSatisfiedBy(task));
    }

    @Test
    public void onlyIfPredicateIsTrueWhenTaskIsEnabledAndAllPredicatesAreTrue() {
        final AtomicBoolean condition1 = new AtomicBoolean(true);
        final AtomicBoolean condition2 = new AtomicBoolean(true);

        AbstractTask task = getTask();
        task.onlyIf(new Spec<Task>() {
            public boolean isSatisfiedBy(Task element) {
                return condition1.get();
            }
        });
        task.onlyIf(new Spec<Task>() {
            public boolean isSatisfiedBy(Task element) {
                return condition2.get();
            }
        });

        assertTrue(task.getOnlyIf().isSatisfiedBy(task));

        task.setEnabled(false);
        assertFalse(task.getOnlyIf().isSatisfiedBy(task));

        task.setEnabled(true);
        condition1.set(false);
        assertFalse(task.getOnlyIf().isSatisfiedBy(task));

        condition1.set(true);
        condition2.set(false);
        assertFalse(task.getOnlyIf().isSatisfiedBy(task));

        condition2.set(true);
        assertTrue(task.getOnlyIf().isSatisfiedBy(task));
    }
View Full Code Here

        assertTrue(task.getOnlyIf().isSatisfiedBy(task));
    }

    @Test
    public void canReplaceOnlyIfSpec() {
        final AtomicBoolean condition1 = new AtomicBoolean(true);
        AbstractTask task = getTask();
        task.onlyIf(context.mock(Spec.class, "spec1"));
        task.setOnlyIf(new Spec<Task>() {
            public boolean isSatisfiedBy(Task element) {
                return condition1.get();
            }
        });

        assertTrue(task.getOnlyIf().isSatisfiedBy(task));

        task.setEnabled(false);
        assertFalse(task.getOnlyIf().isSatisfiedBy(task));

        task.setEnabled(true);
        condition1.set(false);
        assertFalse(task.getOnlyIf().isSatisfiedBy(task));

        condition1.set(true);
        assertTrue(task.getOnlyIf().isSatisfiedBy(task));
    }
View Full Code Here

     *
     * @param dialog
     */
    public static void openDialogNativeModal(final IDialog dialog) {
        try {
            final AtomicBoolean active = new AtomicBoolean(true);
           
            dialog.setModal(true);
            dialog.setModal(active);
           
            if (!SwingUtilities.isEventDispatchThread()) {
                SwingUtilities.invokeAndWait(new Runnable() {
                    @Override
                    public void run() {
                        dialog.setVisible(true);
                    }
                });
               
                synchronized (active) {
                    while (active.get() == true)
                        active.wait();
                }
               
            } else {
                dialog.setVisible(true);
            }
View Full Code Here

    /**
     * @deprecated
     */
    public static void waitUntilComplete(final IHttpMessage message, int timeoutMillis) throws SocketTimeoutException, IOException {
       
        final AtomicBoolean isComplete = new AtomicBoolean(false);
       
        if (message.hasBody()) {
           
            if (message.getNonBlockingBody().isComplete()) {
                return;
               
            } else {
                long start = System.currentTimeMillis();

                NonBlockingBodyDataSource ds = message.getNonBlockingBody();
               
                BodyListener bodyListener = new BodyListener(isComplete, message);
                ds.addCompleteListener(bodyListener);
                ds.addDestroyListener(bodyListener);
               

                do {
                    synchronized (message) {
                        if (!isComplete.get()) {
                            try {
                                message.wait(timeoutMillis);
                            } catch (InterruptedException ignore) { }
                           
                            if ((start - System.currentTimeMillis()) > timeoutMillis) {
                                throw new SocketTimeoutException("timeout " + DataConverter.toFormatedDuration(timeoutMillis) + " reached");
                            }
                        }
                    }
                   
                } while (!isComplete.get());
            }
            
        } else {
            return;
        }
View Full Code Here

    int nThread = DEFAULT_WORKER_THREAD_NUM;
    if (workerThreadNum >= 1) {
      nThread = workerThreadNum;
    }
    this.listenerExecutor = Executors.newFixedThreadPool(nThread);
    this.isTerminated = new AtomicBoolean(false);
  }
View Full Code Here

      /* Return early on cancellation */
      if (monitor.isCanceled() || Owl.isShuttingDown())
        return;

      /* Run News Filters */
      final AtomicBoolean someNewsFiltered = new AtomicBoolean(false);
      SafeRunner.run(new LoggingSafeRunnable() {
        public void run() throws Exception {
          newNewsAdded.removeAll(deletedNews);
          boolean result = runNewsFilters(newNewsAdded, monitor);
          someNewsFiltered.set(result);
        }
      });

      /* Return early on cancellation and if no filter was running */
      if ((monitor.isCanceled() || Owl.isShuttingDown()) && !someNewsFiltered.get())
        return;

      try {
        lockNewsObjects(mergeResult);
        saveFeed(mergeResult);
View Full Code Here

TOP

Related Classes of java.util.concurrent.atomic.AtomicBoolean

Copyright © 2018 www.massapicom. 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.