List of usage examples for java.util.concurrent.atomic AtomicBoolean AtomicBoolean
public AtomicBoolean(boolean initialValue)
From source file:cc.gospy.example.google.GoogleScholarSpider.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 googleScholarSpider = Gospy.custom() .setScheduler(// w w w . j av a2 s .com 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='gs_ccl_results']/div/div/h3/a/@href", (task, resultList, returnedData) -> { links.addAll(resultList); currentPage.incrementAndGet(); if (pageFrom <= currentPage.get() && currentPage.get() < pageTo) { return Arrays.asList( new Task(String.format("https://scholar.google.com/scholar?start=%d&q=%s", (currentPage.get() - 1) * 10, keyword))); } else { return Arrays.asList(); } }).build()) .build() .addTask(String.format("https://scholar.google.com/scholar?start=%d&q=%s", pageFrom, keyword)); googleScholarSpider.start(); while (!returned.get()) ; // block until spider returned googleScholarSpider.stop(); return links; }
From source file:org.sbq.batch.mains.ActivityEmulator.java
private ActivityEmulator() { super();/*from w w w.j a v a2 s .c o m*/ blockingQueue = new LinkedBlockingQueue<Runnable>(); executor = new ThreadPoolExecutor(10, 10, 0L, TimeUnit.MILLISECONDS, blockingQueue); appCtx = new AnnotationConfigApplicationContext(ActivityEmulatorConfiguration.class); userService = appCtx.getBean(UserService.class); Map<String, AtomicBoolean> writableUserStatusByLogin = new HashMap<String, AtomicBoolean>(); for (User user : userService.findAllUsers()) { writableUserStatusByLogin.put(user.getLogin(), new AtomicBoolean(false)); } userStatusByLogin = Collections.unmodifiableMap(writableUserStatusByLogin); }
From source file:com.netflix.curator.framework.recipes.atomic.TestDistributedAtomicLong.java
@Test public void testCompareAndSet() throws Exception { final CuratorFramework client = CuratorFrameworkFactory.newClient(server.getConnectString(), new RetryOneTime(1)); client.start();/*from ww w .j av a 2 s .co m*/ try { final AtomicBoolean doIncrement = new AtomicBoolean(false); DistributedAtomicLong dal = new DistributedAtomicLong(client, "/counter", new RetryOneTime(1)) { @Override public byte[] valueToBytes(Long newValue) { if (doIncrement.get()) { DistributedAtomicLong inc = new DistributedAtomicLong(client, "/counter", new RetryOneTime(1)); try { // this will force a bad version exception inc.increment(); } catch (Exception e) { throw new Error(e); } } return super.valueToBytes(newValue); } }; dal.forceSet(1L); Assert.assertTrue(dal.compareAndSet(1L, 5L).succeeded()); Assert.assertFalse(dal.compareAndSet(1L, 5L).succeeded()); doIncrement.set(true); Assert.assertFalse(dal.compareAndSet(5L, 10L).succeeded()); } finally { client.close(); } }
From source file:com.jayway.restassured.path.json.JsonPathObjectDeserializationTest.java
@Test public void json_path_supports_custom_deserializer() { // Given/* w ww . j a v a 2s. c o m*/ final AtomicBoolean customDeserializerUsed = new AtomicBoolean(false); final JsonPath jsonPath = new JsonPath(GREETING) .using(new JsonPathConfig().defaultObjectDeserializer(new JsonPathObjectDeserializer() { public <T> T deserialize(ObjectDeserializationContext ctx) { customDeserializerUsed.set(true); final String json = ctx.getDataToDeserialize().asString(); final Greeting greeting = new Greeting(); greeting.setFirstName(StringUtils.substringBetween(json, "\"firstName\":\"", "\"")); greeting.setLastName(StringUtils.substringBetween(json, "\"lastName\":\"", "\"")); return (T) greeting; } })); // When final Greeting greeting = jsonPath.getObject("", Greeting.class); // Then assertThat(greeting.getFirstName(), equalTo("John")); assertThat(greeting.getLastName(), equalTo("Doe")); assertThat(customDeserializerUsed.get(), is(true)); }
From source file:eu.stratosphere.nephele.io.channels.LocalChannelWithAccessInfo.java
LocalChannelWithAccessInfo(final File file, final boolean deleteOnClose) throws IOException { this.file = file; this.channel = new RandomAccessFile(file, "rw").getChannel(); this.reservedWritePosition = new AtomicLong(0L); this.referenceCounter = new AtomicInteger(0); this.deleteOnClose = new AtomicBoolean(deleteOnClose); }
From source file:actor4j.core.DefaultActorThread.java
public DefaultActorThread(ActorSystemImpl system) { super(system); directiveQueue = new MpscArrayQueue<>(system.getQueueSize()); priorityQueue = new PriorityBlockingQueue<>(system.getQueueSize()); serverQueueL2 = new MpscArrayQueue<>(system.getQueueSize()); serverQueueL1 = new ArrayDeque<>(system.getBufferQueueSize()); outerQueueL2 = new MpscArrayQueue<>(system.getQueueSize()); outerQueueL1 = new ArrayDeque<>(system.getBufferQueueSize()); innerQueue = new CircularFifoQueue<>(system.getQueueSize()); newMessage = new AtomicBoolean(true); }
From source file:de.taimos.pipeline.aws.cloudformation.EventPrinter.java
public void waitAndPrintStackEvents(String stack, Waiter<DescribeStacksRequest> waiter) { Date startDate = new Date(); final AtomicBoolean done = new AtomicBoolean(false); waiter.runAsync(new WaiterParameters<>(new DescribeStacksRequest().withStackName(stack)), new WaiterHandler() { @Override/*from w w w .j a v a 2 s.c om*/ public void onWaitSuccess(AmazonWebServiceRequest request) { done.set(true); } @Override public void onWaitFailure(Exception e) { done.set(true); } }); String lastEventId = null; this.printLine(); this.printStackName(stack); this.printLine(); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS"); while (!done.get()) { try { DescribeStackEventsResult result = this.client .describeStackEvents(new DescribeStackEventsRequest().withStackName(stack)); List<StackEvent> stackEvents = new ArrayList<>(); for (StackEvent event : result.getStackEvents()) { if (event.getEventId().equals(lastEventId) || event.getTimestamp().before(startDate)) { break; } stackEvents.add(event); } if (!stackEvents.isEmpty()) { Collections.reverse(stackEvents); for (StackEvent event : stackEvents) { this.printEvent(sdf, event); this.printLine(); } lastEventId = stackEvents.get(stackEvents.size() - 1).getEventId(); } } catch (AmazonCloudFormationException e) { // suppress and continue } try { Thread.sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); } } }
From source file:com.alibaba.otter.node.etl.common.io.download.impl.AbstractCommandDownload.java
public AbstractCommandDownload(String cmdPath, String url, String dir, String[] params) { this.url = url; // ??/* w w w . java 2 s .c o m*/ String fileName = url.substring(url.lastIndexOf("/") + 1).replace("%20", " "); // this.targetDir = dir; // this.targetFile = new File(this.targetDir, fileName); this.buildCmd(cmdPath, params); // ?? completed = new AtomicBoolean(false); // aborted = new AtomicBoolean(false); // ?, ??? paused = new AtomicBoolean(false); // idle status = DownloadStatus.IDLE; }
From source file:com.miserablemind.api.consumer.tradeking.api.impl.StreamDispatcher.java
public StreamDispatcher(Queue<String> queue, List<StreamListener> listeners) { this.queue = queue; this.listeners = listeners; pool = Executors.newCachedThreadPool(); objectMapper = new ObjectMapper(); objectMapper.registerModule(new JodaModule()); objectMapper.addMixInAnnotations(TradeKingObject.class, TradeKingKObjectMixIn.class); objectMapper.addMixInAnnotations(StreamQuoteEvent.class, StreamQuoteMixIn.class); objectMapper.addMixInAnnotations(StreamTradeEvent.class, StreamTradeMixIn.class); objectMapper.configure(DeserializationFeature.UNWRAP_ROOT_VALUE, true); active = new AtomicBoolean(true); }
From source file:io.pravega.test.integration.selftest.Producer.java
/** * Creates a new instance of the Producer class. * * @param id The Id of the producer. * @param config Test Configuration. * @param dataSource DataSource for the Producer. * @param store A StoreAdapter to execute operations on. * @param executor An Executor to use for async operations. *///from w ww . j a v a2 s . com Producer(int id, TestConfig config, ProducerDataSource dataSource, StoreAdapter store, ScheduledExecutorService executor) { super(config, dataSource, store, executor); this.id = id; this.logId = String.format("Producer[%s]", id); this.iterationCount = new AtomicInteger(); this.canContinue = new AtomicBoolean(true); }