Example usage for java.util.concurrent.atomic AtomicBoolean AtomicBoolean

List of usage examples for java.util.concurrent.atomic AtomicBoolean AtomicBoolean

Introduction

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

Prototype

public AtomicBoolean() 

Source Link

Document

Creates a new AtomicBoolean with initial value false .

Usage

From source file:com.gargoylesoftware.js.CodeStyleTest.java

private boolean isSvnPropertiesDefined(final File file) {
    try {/*from  ww  w . j  a  v  a 2s .c om*/
        final AtomicBoolean eol = new AtomicBoolean();
        svnWCClient_.doGetProperty(file, null, SVNRevision.WORKING, SVNRevision.WORKING, SVNDepth.EMPTY,
                new ISVNPropertyHandler() {

                    @Override
                    public void handleProperty(final long revision, final SVNPropertyData property) {
                        // nothing to do
                    }

                    @Override
                    public void handleProperty(final SVNURL url, final SVNPropertyData property) {
                        // nothing to do
                    }

                    @Override
                    public void handleProperty(final File path, final SVNPropertyData property) {
                        final String name = property.getName();
                        final String value = property.getValue().getString();
                        if ("svn:eol-style".equals(name) && "native".equals(value)) {
                            eol.set(true);
                        }
                    }
                }, null);

        final String fileName = file.getName().toLowerCase(Locale.ROOT);

        for (final String extension : EOL_EXTENSIONS_) {
            if (fileName.endsWith(extension)) {
                return eol.get();
            }
        }
        return true;
    } catch (final Exception e) {
        //nothing
    }
    final String path = file.getAbsolutePath();
    // automatically generated and is outside SVN control
    return (path.contains("jQuery") && path.contains("WEB-INF") && path.contains("cgi"))
            || (path.contains("jQuery") && path.contains("csp.log"));
}

From source file:ddf.catalog.resource.download.ReliableResourceDownloaderTest.java

@Test
public void testIOExceptionDuringRead() throws Exception {
    ResourceResponse mockResponse = getMockResourceResponse(mockStream);
    when(mockStream.read(any(byte[].class))).thenThrow(new IOException());

    int retries = 5;
    downloaderConfig.setMaxRetryAttempts(retries);

    ReliableResourceDownloader downloader = new ReliableResourceDownloader(downloaderConfig,
            new AtomicBoolean(), DOWNLOAD_ID, mockResponse, getMockRetriever());
    downloader.setupDownload(mockMetacard, new DownloadStatusInfoImpl());
    downloader.run();/*from   w w  w .  ja v  a  2s.c  om*/

    verify(mockPublisher, times(retries)).postRetrievalStatus(any(ResourceResponse.class),
            eq(ProductRetrievalStatus.RETRYING), any(Metacard.class), anyString(), anyLong(), eq(DOWNLOAD_ID));

}

From source file:fr.inria.oak.paxquery.pact.io.XmlConsTreePatternOutputFormat.java

@Override
public void writeRecord(Record record) throws IOException {
    RecordList recordList = new RecordList();
    recordList.add(record);//ww w .j a va2s. co  m
    StringBuilder sb = writeRecord(recordList, this.signature, new ConstructionTreePattern[] { this.ctp },
            new AtomicBoolean[] { new AtomicBoolean() })[0][0];
    this.wrt.append(sb);
}

From source file:ch.cyberduck.core.editor.AbstractEditorTest.java

@Test
public void testOpen() throws Exception {
    final AtomicBoolean t = new AtomicBoolean();
    final NullSession session = new NullSession(new Host(new TestProtocol())) {
        @Override//from w w  w.j a  v  a  2  s . c  om
        @SuppressWarnings("unchecked")
        public <T> T _getFeature(final Class<T> type) {
            if (type.equals(Read.class)) {
                return (T) new Read() {
                    @Override
                    public InputStream read(final Path file, final TransferStatus status,
                            final ConnectionCallback callback) throws BackgroundException {
                        t.set(true);
                        return IOUtils.toInputStream("content", Charset.defaultCharset());
                    }

                    @Override
                    public boolean offset(final Path file) {
                        assertEquals(new Path("/f", EnumSet.of(Path.Type.file)), file);
                        return false;
                    }
                };
            }
            return super._getFeature(type);
        }
    };
    final AtomicBoolean e = new AtomicBoolean();
    final Path file = new Path("/f", EnumSet.of(Path.Type.file));
    file.attributes().setSize("content".getBytes().length);
    final AbstractEditor editor = new AbstractEditor(new Application("com.editor"),
            new StatelessSessionPool(new TestLoginConnectionService(), session, PathCache.empty(),
                    new DisabledTranscriptListener(), new DefaultVaultRegistry(new DisabledPasswordCallback())),
            file, new DisabledProgressListener()) {
        @Override
        protected void edit(final ApplicationQuitCallback quit, final FileWatcherListener listener)
                throws IOException {
            e.set(true);
        }

        @Override
        protected void watch(final Local local, final FileWatcherListener listener) throws IOException {
            //
        }
    };
    editor.open(new DisabledApplicationQuitCallback(), new DisabledTransferErrorCallback(),
            new DisabledFileWatcherListener()).run(session);
    assertTrue(t.get());
    assertNotNull(editor.getLocal());
    assertTrue(e.get());
    assertTrue(editor.getLocal().exists());
}

From source file:ch.cyberduck.core.pool.DefaultSessionPoolTest.java

@Test
public void testCheckReconnectApplicationFailure() throws Exception {
    final AtomicBoolean interrupt = new AtomicBoolean();
    final Host bookmark = new Host(new TestProtocol());
    final TestLoginConnectionService connect = new TestLoginConnectionService() {
        @Override/* w w  w  .  j a  v a 2 s  . c  o m*/
        public boolean check(final Session<?> session, final Cache<Path> cache, final CancelCallback callback)
                throws BackgroundException {
            return true;
        }
    };
    final DefaultSessionPool pool = new DefaultSessionPool(connect,
            new DefaultVaultRegistry(new DisabledPasswordCallback()), PathCache.empty(),
            new DisabledTranscriptListener(), bookmark,
            new GenericObjectPool<Session>(new PooledSessionFactory(connect, new DisabledX509TrustManager(),
                    new DefaultX509KeyManager(), PathCache.empty(), bookmark,
                    new DefaultVaultRegistry(new DisabledPasswordCallback())) {
                @Override
                public Session create() {
                    return new NullSession(bookmark) {
                        @Override
                        public void interrupt() throws BackgroundException {
                            interrupt.set(true);
                            super.interrupt();
                        }
                    };
                }
            }));
    final Session<?> session = pool.borrow(BackgroundActionState.running);
    pool.release(session, new BackgroundException("m", "d"));
    assertFalse(interrupt.get());
}

From source file:li.strolch.runtime.main.MainStarter.java

public int keepAlive() {

    final AtomicBoolean atomicBoolean = new AtomicBoolean();

    Runtime.getRuntime().addShutdownHook(new Thread() {
        @Override/*from  ww  w .  ja v a2 s  . c o m*/
        public void run() {
            synchronized (MainStarter.class) {
                System.out.println("VM Shutting down. Stopping Strolch...");
                System.out.println("");
                System.out.println("Strolch application " + MainStarter.this.getAgent().getApplicationName()
                        + " shutting down...");
                MainStarter.this.getAgent().stop();
                MainStarter.this.getAgent().destroy();
                System.out.println("Strolch application " + MainStarter.this.getAgent().getApplicationName()
                        + " shut down. Exiting VM.");

                atomicBoolean.set(true);
                MainStarter.class.notify();
            }
        }
    });

    logger.info("");
    logger.info("Strolch application " + getAgent().getApplicationName() + " started ");
    while (!atomicBoolean.get()) {
        synchronized (MainStarter.class) {
            try {
                MainStarter.class.wait();
            } catch (InterruptedException e) {
                logger.error("Interrupted.");
                return 1;
            }
        }
    }

    return 0;
}

From source file:com.clxcommunications.xms.ApiConnectionTest.java

@Test
public void leavesExternalHttpClientAlone() throws Exception {
    final AtomicBoolean clientClosed = new AtomicBoolean();

    ApiConnection conn = ApiConnection.builder().token("token").servicePlanId("spid")
            .httpClient(new DummyClient() {

                @Override//from  www  .  j  a  va 2s.  c  o  m
                public void close() throws IOException {
                    clientClosed.set(true);
                }

            }).build();

    conn.start();
    conn.close();

    assertThat(clientClosed.get(), is(false));
}

From source file:ddf.catalog.resource.download.ReliableResourceDownloaderTest.java

@Test
public void testCacheExceptionDuringWrite() throws Exception {

    downloaderConfig.setCacheEnabled(true);

    ResourceCache mockCache = mock(ResourceCache.class);
    when(mockCache.isPending(anyString())).thenReturn(false);
    when(mockCache.getProductCacheDirectory()).thenReturn(productCacheDirectory);
    downloaderConfig.setResourceCache(mockCache);

    mis = new MockInputStream(productInputFilename);
    ResourceResponse mockResponse = getMockResourceResponse(mis);

    ReliableResourceDownloader downloader = new ReliableResourceDownloader(downloaderConfig,
            new AtomicBoolean(), "123", mockResponse, getMockRetriever());
    downloader.setupDownload(mockMetacard, new DownloadStatusInfoImpl());

    FileOutputStream mockFos = mock(FileOutputStream.class);
    doThrow(new IOException()).when(mockFos).write(any(byte[].class), anyInt(), anyInt());

    downloader.setFileOutputStream(mockFos);
    downloader.run();/*from w  w  w  .  j ava2s  .  co  m*/

    verify(mockPublisher, times(1)).postRetrievalStatus(any(ResourceResponse.class),
            eq(ProductRetrievalStatus.RETRYING), any(Metacard.class), anyString(), anyLong(), eq(DOWNLOAD_ID));
    verify(mockCache, times(1)).removePendingCacheEntry(anyString());
    assertThat(downloaderConfig.isCacheEnabled(), is(false));

}

From source file:ch.cyberduck.core.sftp.auth.SFTPPublicKeyAuthenticationTest.java

@Test(expected = LoginFailureException.class)
public void testAuthenticateOpenSSHKeyWithPassword() throws Exception {
    final Credentials credentials = new Credentials(System.getProperties().getProperty("sftp.user"), "");
    final Local key = new Local(System.getProperty("java.io.tmpdir"), UUID.randomUUID().toString());
    try {//from www .j  a va 2 s. c  o  m
        credentials.setIdentity(key);
        new DefaultLocalTouchFeature().touch(key);
        IOUtils.copy(new StringReader(System.getProperties().getProperty("sftp.key.openssh.rsa")),
                key.getOutputStream(false), Charset.forName("UTF-8"));
        final Host host = new Host(new SFTPProtocol(), "test.cyberduck.ch", credentials);
        final SFTPSession session = new SFTPSession(host);
        session.open(new DisabledHostKeyCallback());
        final AtomicBoolean b = new AtomicBoolean();
        assertTrue(new SFTPPublicKeyAuthentication(session).authenticate(host, new DisabledPasswordStore(),
                new DisabledLoginCallback() {
                    @Override
                    public Credentials prompt(final Host bookmark, String username, String title, String reason,
                            LoginOptions options) throws LoginCanceledException {
                        b.set(true);
                        throw new LoginCanceledException();
                    }
                }, new DisabledCancelCallback()));
        assertTrue(b.get());
        session.close();
    } finally {
        key.delete();
    }
}

From source file:ch.cyberduck.core.sds.SDSMissingFileKeysSchedulerFeatureTest.java

@Test(expected = LoginCanceledException.class)
public void testWrongPassword() throws Exception {
    final Host host = new Host(new SDSProtocol(), "duck.ssp-europe.eu", new Credentials(
            System.getProperties().getProperty("sds.user"), System.getProperties().getProperty("sds.key")));
    final SDSSession session = new SDSSession(host, new DisabledX509TrustManager(),
            new DefaultX509KeyManager());
    session.open(new DisabledHostKeyCallback());
    session.login(new DisabledPasswordStore(), new DisabledLoginCallback(), new DisabledCancelCallback());
    final SDSMissingFileKeysSchedulerFeature background = new SDSMissingFileKeysSchedulerFeature(session);
    final AtomicBoolean prompt = new AtomicBoolean();
    final List<UserFileKeySetRequest> processed = background.operate(new PasswordCallback() {
        @Override//from  w  w  w .ja va  2 s . c om
        public Credentials prompt(final Host bookmark, final String title, final String reason,
                final LoginOptions options) throws LoginCanceledException {
            if (prompt.get()) {
                throw new LoginCanceledException();
            }
            prompt.set(true);
            return new VaultCredentials("n");
        }
    }, null);
    assertTrue(prompt.get());
    session.close();
}