List of usage examples for java.util.concurrent.atomic AtomicInteger getAndIncrement
public final int getAndIncrement()
From source file:org.apache.bookkeeper.metadata.etcd.helpers.HelpersTest.java
private void testKeyIterator(int numKeys, int batchSize) throws Exception { for (int i = 0; i < numKeys; i++) { String key = getKey(scope, i); ByteSequence keyBs = ByteSequence.fromString(key); result(etcdClient.getKVClient().put(keyBs, keyBs)); }// www .j a v a2s .com KeyStream<Integer> ks = openKeyStream(batchSize); KeyIterator<Integer> ki = new KeyIterator<>(ks); AtomicInteger numReceived = new AtomicInteger(0); while (ki.hasNext()) { List<Integer> values = ki.next(); log.info("Received values : {}", values); if (values.isEmpty()) { break; } for (int value : values) { assertEquals(numReceived.getAndIncrement(), value); } } assertEquals(numKeys, numReceived.get()); }
From source file:org.apache.bookkeeper.metadata.etcd.helpers.HelpersTest.java
private void testKeyStream(int numKeys, int batchSize) throws Exception { for (int i = 0; i < numKeys; i++) { String key = getKey(scope, i); ByteSequence keyBs = ByteSequence.fromBytes(key.getBytes(UTF_8)); result(etcdClient.getKVClient().put(keyBs, keyBs)); }//from ww w . j a v a 2 s . c o m KeyStream<Integer> ks = openKeyStream(batchSize); AtomicInteger numReceived = new AtomicInteger(0); while (true) { List<Integer> values = result(ks.readNext()); log.info("Received values : {}", values); if (values.isEmpty()) { break; } for (int value : values) { assertEquals(numReceived.getAndIncrement(), value); } } assertEquals(numKeys, numReceived.get()); }
From source file:com.adobe.acs.commons.httpcache.store.jcr.impl.visitor.mock.RootNodeMockFactory.java
private Node[] generateBucketNodeChain(Node rootNode, boolean isEmpty) throws RepositoryException { final Node[] bucketNodeChain = new Node[settings.bucketDepth]; Node currentParentNode = rootNode; for (int i = 0; i < settings.bucketDepth; i++) { final Node node = mockStandardNode("bucketnode" + (isEmpty ? "-empty" : "") + "-level-" + (i + 1)); bucketNodeChain[i] = node;//from w w w . j a v a 2 s . c o m when(node.getParent()).thenReturn(currentParentNode); when(node.getProperties()).thenReturn(new MockPropertyIterator(IteratorUtils.EMPTY_ITERATOR)); when(node.hasProperty(JCRHttpCacheStoreConstants.PN_ISCACHEENTRYNODE)).thenReturn(false); when(node.hasProperty(JCRHttpCacheStoreConstants.PN_ISBUCKETNODE)).thenReturn(true); currentParentNode = node; } for (int i = 0; i < settings.bucketDepth; i++) { if (i < settings.bucketDepth) { final Node node = bucketNodeChain[i]; final Node childNode = bucketNodeChain[i]; final AtomicInteger deleteCounter = new AtomicInteger(); doAnswer(new Answer<Object>() { @Override public Object answer(InvocationOnMock invocationOnMock) throws Throwable { deleteCounter.getAndIncrement(); return null; } }).when(node).remove(); when(node.getParent().getNodes()).thenAnswer(new Answer<NodeIterator>() { @Override public NodeIterator answer(InvocationOnMock invocationOnMock) throws Throwable { if (deleteCounter.get() > 0) { return new MockNodeIterator(); } else { return new MockNodeIterator(new Node[] { childNode }); } } }); } } return bucketNodeChain; }
From source file:musiccrawler.App.java
private void getMusicByOption(Map<String, String> values, DefaultTableModel defaultTableModel) { List<Music> musics = musicCrawler.getMusicByOption(values); if (!CollectionUtils.isEmpty(musics)) { AtomicInteger count = new AtomicInteger(); musics.forEach(music -> {/*w w w .j a va 2 s .co m*/ Object[] row = { count.getAndIncrement(), music.getId(), music.getTitle(), music.getImage(), music.getUrl(), music.getLyric(), music.getDescription(), music.getStream(), music.getQualityType().toString(), music.getSinger().getName(), music.getSinger().getAge(), music.getSinger().getDescription(), music.getSinger().getAvatar() }; defaultTableModel.addRow(row); }); tbResult.setModel(defaultTableModel); defaultTableModel.fireTableDataChanged(); tbResult.setVisible(true); } }
From source file:musiccrawler.App.java
private void getAllMusic(DefaultTableModel defaultTableModel) { List<Music> musics = musicCrawler.getAllMusic(); if (CollectionUtils.isNotEmpty(musics)) { AtomicInteger count = new AtomicInteger(); musics.forEach(music -> {//from www. ja v a2 s. c om Object[] row = { count.getAndIncrement(), music.getId(), music.getTitle(), music.getImage(), music.getUrl(), music.getLyric(), music.getDescription(), music.getStream(), music.getQualityType().toString(), music.getSinger().getName(), music.getSinger().getAge(), music.getSinger().getDescription(), music.getSinger().getAvatar() }; defaultTableModel.addRow(row); }); tbResult.setModel(defaultTableModel); defaultTableModel.fireTableDataChanged(); tbResult.setVisible(true); } }
From source file:com.btoddb.chronicle.plunkers.HdfsPlunkerImplIT.java
@Test @Ignore("very flakey, need to work out a more stable way of testing") public void testLongRun() throws Exception { plunker.setIdleTimeout(0);//from w w w.jav a2s . c o m plunker.setRollPeriod(2); plunker.setTimeoutCheckPeriod(100); plunker.init(config); final int sleep = 200; final int maxCount = 100; // 20 seconds at 'sleep' interval should be 10 files final AtomicInteger count = new AtomicInteger(); // do this to prime HDFS FileSystem object - otherwise timing is off plunker.handleInternal(Arrays.asList(new Event("the-body").withHeader("customer", "cust") .withHeader("msgId", String.valueOf(count.getAndIncrement())))); ScheduledExecutorService executor = Executors.newScheduledThreadPool(1); System.out.println("start"); executor.scheduleWithFixedDelay(new Runnable() { @Override public void run() { try { System.out.println("time = " + System.currentTimeMillis()); plunker.handleInternal(Arrays.asList(new Event("the-body").withHeader("customer", "cust") .withHeader("msgId", String.valueOf(count.get())))); } catch (Exception e) { e.printStackTrace(); } count.incrementAndGet(); } }, 0, sleep, TimeUnit.MILLISECONDS); while (count.get() < maxCount) { Thread.sleep(sleep / 2); } executor.shutdown(); executor.awaitTermination(60, TimeUnit.SECONDS); Thread.sleep(1500); plunker.shutdown(); Event[] events = new Event[count.get()]; for (int i = 0; i < count.get(); i++) { events[i] = new Event("the-body").withHeader("customer", "cust").withHeader("msgId", String.valueOf(i)); } File theDir = new File(String.format("%s/the/cust/path", baseDir.getPath())); assertThat(theDir, ftUtils.countWithSuffix(".tmp", 0)); assertThat(theDir, ftUtils.countWithSuffix(".avro", 10)); assertThat(theDir, ftUtils.hasEventsInDir(events)); }
From source file:app.androidhive.info.realm.GCM.GcmIntentService.java
private void showJSON(String response) { String id;//from w ww . j a v a2s. co m String name = ""; String adress1 = ""; String adress2 = ""; String phone = ""; try { JSONObject jsonObject = new JSONObject(response); JSONArray result = jsonObject.getJSONArray("Nek"); JSONObject collegeData = result.getJSONObject(0); id = collegeData.getString("ID"); name = collegeData.getString("NekName"); adress1 = collegeData.getString("NekAdress2"); adress2 = collegeData.getString("NekAdress2"); phone = collegeData.getString("NekPhone"); AtomicInteger id2 = new AtomicInteger(); /* if (id == null || id == "" || id == " "){ addInfo(Phone); }*/ //else { Book book = new Book(); book.setId(id2.getAndIncrement()); book.setNekID(id); book.setName(name); book.setPhone(phone); book.setAdress1(adress1); book.setAdress2(adress2); book.setStatus(1); Intent dialogIntent = new Intent(getBaseContext(), MainActivity.class); /* dialogIntent.putExtra("Name", name); dialogIntent.putExtra("Phone", phone); dialogIntent.putExtra("Adress1", adress1); dialogIntent.putExtra("Adress2", adress2); dialogIntent.putExtra("NekID", id); */ dialogIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); getApplication().startActivity(dialogIntent); // } } catch (JSONException e) { e.printStackTrace(); } }
From source file:org.springframework.integration.support.SmartLifecycleRoleController.java
/** * Return the running status of each endpoint in the role. * @param role the role.//from w ww.j a v a 2 s . co m * @return A map of component names : running status * @since 4.3.8 */ public Map<String, Boolean> getEndpointsRunningStatus(String role) { if (this.lazyLifecycles.size() > 0) { addLazyLifecycles(); } if (!this.lifecycles.containsKey(role)) { return Collections.emptyMap(); } AtomicInteger index = new AtomicInteger(); return this.lifecycles.get(role).stream() .collect(Collectors.toMap( e -> (e instanceof NamedComponent) ? ((NamedComponent) e).getComponentName() : (e.getClass().getSimpleName() + "#" + index.getAndIncrement()), Lifecycle::isRunning)); }
From source file:com.twitter.distributedlog.config.TestConfigurationSubscription.java
@Test(timeout = 60000) public void testExceptionInConfigLoad() throws Exception { PropertiesWriter writer = new PropertiesWriter(); writer.setProperty("prop1", "1"); writer.save();//from w ww . j a v a 2 s.co m DeterministicScheduler mockScheduler = new DeterministicScheduler(); FileConfigurationBuilder builder = new PropertiesConfigurationBuilder(writer.getFile().toURI().toURL()); ConcurrentConstConfiguration conf = new ConcurrentConstConfiguration(new DistributedLogConfiguration()); List<FileConfigurationBuilder> fileConfigBuilders = Lists.newArrayList(builder); ConfigurationSubscription confSub = new ConfigurationSubscription(conf, fileConfigBuilders, mockScheduler, 100, TimeUnit.MILLISECONDS); final AtomicInteger count = new AtomicInteger(1); conf.addConfigurationListener(new ConfigurationListener() { @Override public void configurationChanged(ConfigurationEvent event) { LOG.info("config changed {}", event); // Throw after so we actually see the update anyway. if (!event.isBeforeUpdate()) { count.getAndIncrement(); throw new RuntimeException("config listener threw and exception"); } } }); int i = 0; int initial = 0; while (count.get() == initial) { writer.setProperty("prop1", Integer.toString(i++)); writer.save(); mockScheduler.tick(100, TimeUnit.MILLISECONDS); } initial = count.get(); while (count.get() == initial) { writer.setProperty("prop1", Integer.toString(i++)); writer.save(); mockScheduler.tick(100, TimeUnit.MILLISECONDS); } }
From source file:org.apache.distributedlog.common.config.TestConfigurationSubscription.java
@Test(timeout = 60000) public void testExceptionInConfigLoad() throws Exception { PropertiesWriter writer = new PropertiesWriter(); writer.setProperty("prop1", "1"); writer.save();//from w w w .j a v a 2 s . co m DeterministicScheduler mockScheduler = new DeterministicScheduler(); FileConfigurationBuilder builder = new PropertiesConfigurationBuilder(writer.getFile().toURI().toURL()); ConcurrentConstConfiguration conf = new ConcurrentConstConfiguration(new CompositeConfiguration()); List<FileConfigurationBuilder> fileConfigBuilders = Lists.newArrayList(builder); ConfigurationSubscription confSub = new ConfigurationSubscription(conf, fileConfigBuilders, mockScheduler, 100, TimeUnit.MILLISECONDS); final AtomicInteger count = new AtomicInteger(1); conf.addConfigurationListener(new ConfigurationListener() { @Override public void configurationChanged(ConfigurationEvent event) { LOG.info("config changed {}", event); // Throw after so we actually see the update anyway. if (!event.isBeforeUpdate()) { count.getAndIncrement(); throw new RuntimeException("config listener threw and exception"); } } }); int i = 0; int initial = 0; while (count.get() == initial) { writer.setProperty("prop1", Integer.toString(i++)); writer.save(); mockScheduler.tick(100, TimeUnit.MILLISECONDS); } initial = count.get(); while (count.get() == initial) { writer.setProperty("prop1", Integer.toString(i++)); writer.save(); mockScheduler.tick(100, TimeUnit.MILLISECONDS); } }