List of usage examples for java.util.concurrent.atomic AtomicBoolean AtomicBoolean
public AtomicBoolean(boolean initialValue)
From source file:com.qwazr.crawler.web.manager.CurrentSessionImpl.java
CurrentSessionImpl(WebCrawlDefinition crawlDefinition, String name, TimeTracker timeTracker) { this.crawlDefinition = crawlDefinition; this.timeTracker = timeTracker; this.name = name; abort = new AtomicBoolean(false); this.variables = new ConcurrentHashMap<>(); if (crawlDefinition.variables != null) for (Map.Entry<String, String> entry : crawlDefinition.variables.entrySet()) if (entry.getKey() != null && entry.getValue() != null) this.variables.put(entry.getKey(), entry.getValue()); }
From source file:com.amazon.alexa.avs.http.MultipartParser.java
public MultipartParser(MultipartParserConsumer consumer) { this.consumer = consumer; this.shutdown = new AtomicBoolean(false); }
From source file:org.apache.metamodel.couchdb.CouchDbDatabaseDocumentSource.java
public CouchDbDatabaseDocumentSource(CouchDbInstance couchDbInstance, String databaseName, int maxRows) { _couchDbInstance = couchDbInstance;/*w ww . j ava 2s. c om*/ _databaseName = databaseName; _closed = new AtomicBoolean(false); final CouchDbConnector tableConnector = _couchDbInstance.createConnector(databaseName, false); if (maxRows > -1) { _view = tableConnector .queryForStreamingView(new ViewQuery().allDocs().includeDocs(true).limit(maxRows)); } else { _view = tableConnector.queryForStreamingView(new ViewQuery().allDocs().includeDocs(true)); } _rowIterator = _view.iterator(); }
From source file:com.spectralogic.ds3client.helpers.FileObjectGetter_Test.java
@Test public void testThatNamedPipeThrows() throws IOException, InterruptedException { Assume.assumeFalse(Platform.isWindows()); final String tempPathPrefix = null; final Path tempDirectory = Files.createTempDirectory(Paths.get("."), tempPathPrefix); final String FIFO_NAME = "bFifo"; final AtomicBoolean caughtException = new AtomicBoolean(false); try {/*from w ww. j a va2 s . co m*/ Runtime.getRuntime().exec("mkfifo " + Paths.get(tempDirectory.toString(), FIFO_NAME)).waitFor(); new FileObjectGetter(tempDirectory).buildChannel(FIFO_NAME); } catch (final UnrecoverableIOException e) { assertTrue(e.getMessage().contains(FIFO_NAME)); caughtException.set(true); } finally { FileUtils.deleteDirectory(tempDirectory.toFile()); } assertTrue(caughtException.get()); }
From source file:ar.com.iron.android.extensions.connections.InetDataClient.java
public static InetDataClient create(Context context) { InetDataClient connection = new InetDataClient(); connection.context = context;/*from ww w . j av a 2s .co m*/ connection.hasConnectivity = new AtomicBoolean(true); connection.connectionClient = new ConnectionClient(); connection.initListeners(); return connection; }
From source file:com.jivesoftware.os.filer.queue.guaranteed.delivery.FileQueueBackGuaranteedDeliveryFactory.java
/** * * @param serviceConfig//from ww w . j a v a2 s. co m * @param deliveryCallback * @return * @throws IOException */ public static GuaranteedDeliveryService createService( FileQueueBackGuaranteedDeliveryServiceConfig serviceConfig, DeliveryCallback deliveryCallback) throws IOException { final MutableLong undelivered = new MutableLong(0); final MutableLong delivered = new MutableLong(0); final FileQueueImpl queue = new FileQueueImpl(serviceConfig.getPathToQueueFiles(), serviceConfig.getQueueName(), serviceConfig.getTakableWhenCreationTimestampIsOlderThanXMillis(), serviceConfig.getTakableWhenLastAppendedIsOlderThanXMillis(), serviceConfig.getTakableWhenLargerThanXEntries(), serviceConfig.getMaxPageSizeInBytes(), serviceConfig.getPushbackAtEnqueuedSize(), serviceConfig.isDeleteOnExit(), undelivered, serviceConfig.isTakeFullQueuesOnly()); final GuaranteedDeliveryServiceStatus status = new GuaranteedDeliveryServiceStatus() { @Override public long undelivered() { return undelivered.longValue(); } @Override public long delivered() { return delivered.longValue(); } }; final QueueProcessorPool processorPool = new QueueProcessorPool(queue, serviceConfig.getNumberOfConsumers(), serviceConfig.getQueueProcessorConfig(), delivered, deliveryCallback); GuaranteedDeliveryService service = new GuaranteedDeliveryService() { private final AtomicBoolean running = new AtomicBoolean(false); @Override public void add(List<byte[]> add) throws DeliveryServiceException { if (running.compareAndSet(false, true)) { processorPool.start(); } if (add == null) { return; } for (int i = 0; i < add.size(); i++) { byte[] value = add.get(i); if (value == null) { continue; } try { queue.add(PhasedQueueConstants.ENQUEUED, System.currentTimeMillis(), value); } catch (Exception ex) { throw new DeliveryServiceException(add, "failed tp deliver the following items", ex); } } } @Override public GuaranteedDeliveryServiceStatus getStatus() { return status; } @Override public void close() { if (running.compareAndSet(true, false)) { processorPool.stop(); } } }; return service; }
From source file:com.nesscomputing.jackson.datatype.TestCustomUuidModule.java
@Test public void testCustomUUIDDeserialization() throws Exception { final UUID orig = UUID.fromString("550e8400-e29b-41d4-a716-446655440000"); final AtomicBoolean called = new AtomicBoolean(false); ObjectMapper mapper = getObjectMapper(new AbstractModule() { @Override//from ww w. j a v a 2s . c om protected void configure() { bind(new TypeLiteral<JsonDeserializer<UUID>>() { }).toInstance(new CustomUuidDeserializer() { private static final long serialVersionUID = 1L; @Override protected UUID _deserialize(String value, DeserializationContext ctxt) throws IOException, JsonProcessingException { UUID foo = super._deserialize(value, ctxt); called.set(true); return foo; } }); } }); UUID uuid = mapper.readValue('"' + orig.toString() + '"', new TypeReference<UUID>() { }); Assert.assertEquals(orig, uuid); Assert.assertTrue(called.get()); }
From source file:com.jivesoftware.os.server.http.jetty.jersey.endpoints.killswitch.KillSwitchsRestEndpointsTest.java
@Test public void testListKillSwitches() throws IOException { Mockito.when(killSwitchService.getAll()).thenReturn(new ArrayList<KillSwitch>()); Response result = instance.listKillSwitches(); ArrayNode array = mapper.readValue(result.getEntity().toString(), ArrayNode.class); Assert.assertTrue(array.size() == 0); Mockito.when(killSwitchService.getAll()) .thenReturn(Arrays.asList(new KillSwitch("hi", new AtomicBoolean(true)))); result = instance.listKillSwitches(); array = mapper.readValue(result.getEntity().toString(), ArrayNode.class); Assert.assertTrue(array.size() == 1); }
From source file:ch.cyberduck.ui.cocoa.PromptLimitedListProgressListener.java
@Override public void chunk(final Path parent, final AttributedList<Path> list) throws ListCanceledException { if (suppressed) { return;/*from w ww . jav a 2 s . com*/ } try { super.chunk(parent, list); } catch (ListCanceledException e) { if (controller.isVisible()) { final AtomicBoolean c = new AtomicBoolean(true); final NSAlert alert = NSAlert.alert( MessageFormat.format(LocaleFactory.localizedString("Listing directory {0}", "Status"), StringUtils.EMPTY), MessageFormat.format( LocaleFactory.localizedString( "Continue listing directory with more than {0} files.", "Alert"), e.getChunk().size()), LocaleFactory.localizedString("Continue", "Credentials"), null, LocaleFactory.localizedString("Cancel")); alert.setShowsSuppressionButton(true); alert.suppressionButton().setTitle(LocaleFactory.localizedString("Always")); final AlertController sheet = new AlertController(controller, alert) { @Override public void callback(final int returncode) { if (returncode == SheetCallback.DEFAULT_OPTION) { suppressed = true; } if (returncode == SheetCallback.CANCEL_OPTION) { c.set(false); } if (alert.suppressionButton().state() == NSCell.NSOnState) { disable(); } } }; sheet.beginSheet(); if (!c.get()) { throw e; } } } }
From source file:cc.gospy.example.google.GoogleSpider.java
public Collection<String> getResultLinks(final String keyword, final int pageFrom, final int pageTo) { if (pageFrom < 1) throw new IllegalArgumentException(pageFrom + "<" + 1); if (pageFrom >= pageTo) throw new IllegalArgumentException(pageFrom + ">=" + pageTo); final AtomicInteger currentPage = new AtomicInteger(pageFrom); final AtomicBoolean returned = new AtomicBoolean(false); final Collection<String> links = new LinkedHashSet<>(); Gospy googleSpider = Gospy.custom()/*from w w w .j a va2 s. c o m*/ .setScheduler( Schedulers.VerifiableScheduler.custom().setExitCallback(() -> returned.set(true)).build()) .addFetcher(Fetchers.HttpFetcher.custom() .before(request -> request.setConfig( RequestConfig.custom().setProxy(new HttpHost("127.0.0.1", 8118)).build())) .build()) .addProcessor(Processors.XPathProcessor.custom() .extract("//*[@id='ires']/ol/div/h3/a/@href", (task, resultList, returnedData) -> { resultList.forEach(a -> { if (a.startsWith("/url?q=")) { String link = a.substring(7); int end = link.indexOf("&sa="); links.add(link.substring(0, end != -1 ? end : link.length())); } }); currentPage.incrementAndGet(); if (pageFrom <= currentPage.get() && currentPage.get() < pageTo) { return Arrays.asList( new Task(String.format("http://www.google.com/search?q=%s&start=%d&*", keyword, (currentPage.get() - 1) * 10))); } else { return Arrays.asList(); } }).build()) .build().addTask(String.format("http://www.google.com/search?q=%s&start=%d&*", keyword, pageFrom)); googleSpider.start(); while (!returned.get()) ; // block until spider returned googleSpider.stop(); return links; }