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(boolean initialValue) 

Source Link

Document

Creates a new AtomicBoolean with the given initial value.

Usage

From source file:com.nridge.examples.oss.ds_neo4j.DSNeo4jTask.java

/**
  * If this task is scheduled to be executed (e.g. its run/test
  * name matches the command line arguments), then this method
  * is guaranteed to be executed prior to the thread being
  * started.//from  w w  w  .  j  av  a 2  s.  co  m
  *
  * @param anAppMgr Application manager instance.
  *
  * @throws NSException Application specific exception.
  */
@Override
public void init(AppMgr anAppMgr) throws NSException {
    mAppMgr = anAppMgr;
    Logger appLogger = mAppMgr.getLogger(this, "init");

    appLogger.trace(mAppMgr.LOGMSG_TRACE_ENTER);

    mIsAlive = new AtomicBoolean(false);

    mDocumentIds = new ArrayList<>();

    appLogger.trace(mAppMgr.LOGMSG_TRACE_DEPART);

    mIsAlive.set(true);
}

From source file:com.arrow.acs.client.api.ConnectionManager.java

private void restartExpiredTimer() {
    String method = "restartExpiredTimer";

    if (checkExpiredTimer != null) {
        logInfo(method, "cancelling current timer ...");
        checkExpiredTimer.cancel();/* w  w  w.j ava 2  s. c o  m*/
        checkExpiredTimer = null;
    }

    logDebug(method, "checkExpiredConnectionIntervalMs: %d", checkExpiredConnectionIntervalMs);
    if (checkExpiredConnectionIntervalMs > 0) {
        checkExpiredTimer = new Timer(true);
        checkExpiredTimer.scheduleAtFixedRate(new TimerTask() {
            AtomicBoolean running = new AtomicBoolean(false);

            @Override
            public void run() {
                if (connectionManager != null) {
                    if (running.compareAndSet(false, true)) {
                        try {
                            logDebug(method, "connectionManager.closeExpiredConnections() ...");
                            connectionManager.closeExpiredConnections();
                        } catch (Throwable t) {
                        }
                    }
                } else {
                    logWarn(method, "connectionManager is not available!");
                }
            }
        }, 0, checkExpiredConnectionIntervalMs);
    } else {
        logWarn(method, "timer is NOT scheduled, checkExpiredConnectionIntervalMs: %d",
                checkExpiredConnectionIntervalMs);
    }
}

From source file:com.amazon.alexa.avs.NotificationManager.java

NotificationManager(NotificationIndicator indicator, SimpleAudioPlayer audioPlayer, BasicHttpClient httpClient,
        FileDataStore<NotificationsStatePayload> dataStore) {
    this.notificationIndicator = indicator;
    this.player = audioPlayer;
    this.assets = Collections.synchronizedMap(new HashMap<String, File>());
    this.indicatorExecutor = Executors.newSingleThreadExecutor();
    this.assetDownloader = Executors.newCachedThreadPool();
    this.allowPersistentIndicator = new AtomicBoolean(true);
    this.httpClient = httpClient;
    this.isSetIndicatorPersisted = new AtomicBoolean(false);
    this.indicatorStatus = Status.NONE;
    this.dataStore = dataStore;
    this.indicatorFutures = Collections.synchronizedSet(new HashSet<Future<?>>());
    this.activeAudioAsset = new AtomicReference<String>("");
    this.resLoader = Thread.currentThread().getContextClassLoader();
}

From source file:org.killbill.bus.DefaultPersistentBus.java

@Inject
public DefaultPersistentBus(@Named(QUEUE_NAME) final IDBI dbi, final Clock clock,
        final PersistentBusConfig config, final MetricRegistry metricRegistry,
        final DatabaseTransactionNotificationApi databaseTransactionNotificationApi) {
    super("Bus", Executors.newFixedThreadPool(config.getNbThreads(), new ThreadFactory() {
        @Override//from  w  w w .  jav a2s  . c om
        public Thread newThread(final Runnable r) {
            return new Thread(new ThreadGroup(EVENT_BUS_GROUP_NAME), r, config.getTableName() + "-th");
        }
    }), config.getNbThreads(), config);
    final PersistentBusSqlDao sqlDao = dbi.onDemand(PersistentBusSqlDao.class);
    this.clock = clock;
    final String dbBackedQId = "bus-" + config.getTableName();
    this.dao = new DBBackedQueue<BusEventModelDao>(clock, sqlDao, config, dbBackedQId, metricRegistry,
            databaseTransactionNotificationApi);
    this.eventBusDelegate = new EventBusDelegate("Killbill EventBus");
    this.dispatchTimer = metricRegistry.timer(MetricRegistry.name(DefaultPersistentBus.class, "dispatch"));
    this.isStarted = new AtomicBoolean(false);
}

From source file:com.twitter.hbc.httpclient.ClientBase.java

ClientBase(String name, HttpClient client, Hosts hosts, StreamingEndpoint endpoint, Authentication auth,
        HosebirdMessageProcessor processor, ReconnectionManager manager, RateTracker rateTracker,
        @Nullable BlockingQueue<Event> eventsQueue) {
    this.client = Preconditions.checkNotNull(client);
    this.name = Preconditions.checkNotNull(name);

    this.endpoint = Preconditions.checkNotNull(endpoint);
    this.hosts = Preconditions.checkNotNull(hosts);
    this.auth = Preconditions.checkNotNull(auth);

    this.processor = Preconditions.checkNotNull(processor);
    this.reconnectionManager = Preconditions.checkNotNull(manager);
    this.rateTracker = Preconditions.checkNotNull(rateTracker);

    this.eventsQueue = eventsQueue;

    this.exitEvent = new AtomicReference<Event>();

    this.isRunning = new CountDownLatch(1);
    this.statsReporter = new StatsReporter();

    this.connectionEstablished = new AtomicBoolean(false);
    this.reconnect = new AtomicBoolean(false);
}

From source file:net.sourceforge.ganttproject.io.CsvImportTest.java

public void testIncompleteHeader() throws IOException {
    String header = "A, B";
    String data = "a1, b1";
    final AtomicBoolean wasCalled = new AtomicBoolean(false);
    GanttCSVOpen.RecordGroup recordGroup = new GanttCSVOpen.RecordGroup("ABC",
            ImmutableSet.<String>of("A", "B", "C"), // all fields
            ImmutableSet.<String>of("A", "B")) { // mandatory fields
        @Override/*w ww . j  ava  2 s  .  c  om*/
        protected boolean doProcess(CSVRecord record) {
            wasCalled.set(true);
            assertEquals("a1", record.get("A"));
            assertEquals("b1", record.get("B"));
            return true;
        }
    };
    GanttCSVOpen importer = new GanttCSVOpen(createSupplier(Joiner.on('\n').join(header, data)), recordGroup);
    importer.load();
    assertTrue(wasCalled.get());
}

From source file:com.jivesoftware.os.upena.uba.service.Nanny.java

public Nanny(PasswordStore passwordStore, UpenaClient upenaClient, RepositoryProvider repositoryProvider,
        InstanceDescriptor instanceDescriptor, InstancePath instancePath,
        DeployableValidator deployableValidator, DeployLog deployLog, HealthLog healthLog,
        DeployableScriptInvoker invokeScript, UbaLog ubaLog,
        Cache<String, Boolean> haveRunConfigExtractionCache) {

    this.passwordStore = passwordStore;
    this.upenaClient = upenaClient;
    this.repositoryProvider = repositoryProvider;
    this.instanceDescriptor = new AtomicReference<>(instanceDescriptor);
    this.instancePath = instancePath;
    this.deployableValidator = deployableValidator;
    this.deployLog = deployLog;
    this.healthLog = healthLog;
    this.invokeScript = invokeScript;
    this.ubaLog = ubaLog;
    linkedBlockingQueue = new LinkedBlockingQueue<>(10);
    threadPoolExecutor = new ThreadPoolExecutor(1, 1, 1000, TimeUnit.MILLISECONDS, linkedBlockingQueue);
    boolean exists = instancePath.deployLog().exists();
    LOG.info("Stats script for {} exists == {}", instanceDescriptor, exists);
    redeploy = new AtomicBoolean(!exists);
    destroyed = new AtomicBoolean(false);
    this.haveRunConfigExtractionCache = haveRunConfigExtractionCache;
}

From source file:io.dropwizard.discovery.bundle.ServiceDiscoveryBundleCustomHostPortTest.java

@Before
public void setup() throws Exception {

    when(jerseyEnvironment.getResourceConfig()).thenReturn(new DropwizardResourceConfig());
    when(environment.jersey()).thenReturn(jerseyEnvironment);
    when(environment.lifecycle()).thenReturn(lifecycleEnvironment);
    when(environment.healthChecks()).thenReturn(healthChecks);
    when(environment.getObjectMapper()).thenReturn(new ObjectMapper());
    AdminEnvironment adminEnvironment = mock(AdminEnvironment.class);
    doNothing().when(adminEnvironment).addTask(any());
    when(environment.admin()).thenReturn(adminEnvironment);

    testingCluster.start();/*from w  w  w.  java  2  s  .  co  m*/

    serviceDiscoveryConfiguration = ServiceDiscoveryConfiguration.builder()
            .zookeeper(testingCluster.getConnectString()).namespace("test").environment("testing")
            .connectionRetryIntervalMillis(5000).publishedHost("TestHost").publishedPort(8021)
            .initialRotationStatus(true).build();
    bundle.initialize(bootstrap);

    bundle.run(configuration, environment);
    final AtomicBoolean started = new AtomicBoolean(false);
    executorService.submit(() -> lifecycleEnvironment.getManagedObjects().forEach(object -> {
        try {
            object.start();
            started.set(true);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }));
    while (!started.get()) {
        Thread.sleep(1000);
        log.debug("Waiting for framework to start...");
    }

    bundle.registerHealthcheck(() -> status);
}

From source file:com.navercorp.pinpoint.profiler.sender.NioUdpDataSenderTest.java

private boolean sendMessage_getLimit(TBase tbase, long waitTimeMillis) throws InterruptedException {
    final AtomicBoolean limitCounter = new AtomicBoolean(false);
    final CountDownLatch latch = new CountDownLatch(1);

    NioUDPDataSender sender = newNioUdpDataSender();
    try {//  w ww  .ja v  a2 s .  c om
        sender.send(tbase);
        latch.await(waitTimeMillis, TimeUnit.MILLISECONDS);
    } finally {
        sender.stop();
    }
    return limitCounter.get();
}

From source file:io.restassured.path.xml.XmlPathObjectDeserializationTest.java

@Test
public void xml_path_supports_custom_deserializer() {
    // Given//from   w ww  .  j a  v a 2  s  . c o  m
    final AtomicBoolean customDeserializerUsed = new AtomicBoolean(false);

    final XmlPath xmlPath = new XmlPath(COOL_GREETING)
            .using(XmlPathConfig.xmlPathConfig().defaultObjectDeserializer(new XmlPathObjectDeserializer() {
                public <T> T deserialize(ObjectDeserializationContext ctx) {
                    customDeserializerUsed.set(true);
                    final String xml = ctx.getDataToDeserialize().asString();
                    final Greeting greeting = new Greeting();
                    greeting.setFirstName(StringUtils.substringBetween(xml, "<firstName>", "</firstName>"));
                    greeting.setLastName(StringUtils.substringBetween(xml, "<lastName>", "</lastName>"));
                    return (T) greeting;
                }
            }));

    // When
    final Greeting greeting = xmlPath.getObject("", Greeting.class);

    // Then
    assertThat(greeting.getFirstName(), equalTo("John"));
    assertThat(greeting.getLastName(), equalTo("Doe"));
    assertThat(customDeserializerUsed.get(), is(true));
}