org.apache.ignite.Ignite.atomicLong()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(6.6k)|赞(0)|评价(0)|浏览(214)

本文整理了Java中org.apache.ignite.Ignite.atomicLong()方法的一些代码示例,展示了Ignite.atomicLong()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Ignite.atomicLong()方法的具体详情如下:
包路径:org.apache.ignite.Ignite
类名称:Ignite
方法名:atomicLong

Ignite.atomicLong介绍

[英]Will get a atomic long from cache and create one if it has not been created yet and create flag is true.
[中]将从缓存中获取一个原子长度,如果尚未创建,则创建一个原子长度,并且create标志为true。

代码示例

代码示例来源:origin: apache/ignite

  1. @Override public Void call() throws Exception {
  2. ignite.atomicLong(name, 0, true);
  3. return null;
  4. }
  5. }, IgniteException.class, null);

代码示例来源:origin: apache/ignite

  1. /** {@inheritDoc} */
  2. @Nullable @Override public IgniteAtomicLong atomicLong(String name, long initVal, boolean create) {
  3. checkIgnite();
  4. return g.atomicLong(name, initVal, create);
  5. }

代码示例来源:origin: apache/ignite

  1. @Override public Void call() throws Exception {
  2. ignite.atomicLong(name, 0, false);
  3. return null;
  4. }
  5. }, IgniteException.class, null);

代码示例来源:origin: apache/ignite

  1. @Override public IgniteAtomicLong atomicLong(String name, AtomicConfiguration cfg, long initVal,
  2. boolean create) throws IgniteException {
  3. checkIgnite();
  4. return g.atomicLong(name, cfg, initVal, create);
  5. }

代码示例来源:origin: apache/ignite

  1. @Override public Object call() throws Exception {
  2. boolean failed = false;
  3. try {
  4. client.atomicLong("testAtomic", 41, true);
  5. }
  6. catch (IgniteClientDisconnectedException e) {
  7. failed = true;
  8. checkAndWait(e);
  9. }
  10. assertTrue(failed);
  11. return client.atomicLong("testAtomic", 41, true);
  12. }
  13. },

代码示例来源:origin: apache/ignite

  1. @Override public Object apply(Ignite ignite) {
  2. assert ignite.atomicLong(STRUCTURE_NAME, 1, true).get() > 0;
  3. return null;
  4. }
  5. });

代码示例来源:origin: apache/ignite

  1. /** {@inheritDoc} */
  2. @Override public Void call() throws Exception {
  3. IgniteAtomicLong cntr = ignite(0).atomicLong(ATOMIC_LONG_NAME, 0, true);
  4. while (run.get())
  5. queue.add(cntr.getAndIncrement());
  6. return null;
  7. }
  8. }, 4, "increment-runner");

代码示例来源:origin: apache/ignite

  1. @Override public void apply(Ignite ignite) {
  2. for (int i = 0; i < 100; i++) {
  3. IgniteAtomicLong l = ignite.atomicLong("long-" + 1, 0, true);
  4. l.close();
  5. }
  6. }
  7. });

代码示例来源:origin: apache/ignite

  1. @Override public void applyx(Ignite ignite) {
  2. IgniteAtomicLong al = ignite.atomicLong(TEST_LONG_NAME, 0, true);
  3. for (int i = 0; i < operationsPerTx; i++) {
  4. al.addAndGet(RAND.nextInt(MAX_INT));
  5. long cnt = writes.incrementAndGet();
  6. if (cnt % WRITE_LOG_MOD == 0)
  7. info("Performed " + cnt + " writes.");
  8. }
  9. }
  10. };

代码示例来源:origin: apache/ignite

  1. @Override public void applyx(Ignite ignite) {
  2. IgniteAtomicLong al = ignite.atomicLong(TEST_LONG_NAME, 0, true);
  3. for (int i = 0; i < operationsPerTx; i++) {
  4. al.get();
  5. long cnt = reads.incrementAndGet();
  6. if (cnt % READ_LOG_MOD == 0)
  7. info("Performed " + cnt + " reads.");
  8. }
  9. }
  10. };

代码示例来源:origin: apache/ignite

  1. @Override public Object call() throws Exception {
  2. Ignite g = startGrid(NEW_IGNITE_INSTANCE_NAME);
  3. try {
  4. g.transactions().txStart();
  5. g.cache(TRANSACTIONAL_CACHE_NAME).put(1, 1);
  6. assertEquals(val + 1, g.atomicLong(STRUCTURE_NAME, val, false).incrementAndGet());
  7. }
  8. finally {
  9. stopGrid(NEW_IGNITE_INSTANCE_NAME);
  10. }
  11. return null;
  12. }
  13. }).get();

代码示例来源:origin: apache/ignite

  1. /**
  2. * @throws Exception If failed.
  3. */
  4. @Test
  5. public void testGetAndSet() throws Exception {
  6. info("Running test [name=" + getName() + ", cacheMode=" + atomicsCacheMode() + ']');
  7. Ignite ignite = grid(0);
  8. IgniteAtomicLong atomic = ignite.atomicLong("atomic", 0, true);
  9. long newVal = RND.nextLong();
  10. long curAtomicVal = atomic.get();
  11. assert curAtomicVal == atomic.getAndSet(newVal);
  12. assert newVal == atomic.get();
  13. }

代码示例来源:origin: apache/ignite

  1. /**
  2. * @throws Exception If failed.
  3. */
  4. @Test
  5. public void testGetAndAdd() throws Exception {
  6. info("Running test [name=" + getName() + ", cacheMode=" + atomicsCacheMode() + ']');
  7. Ignite ignite = grid(0);
  8. IgniteAtomicLong atomic = ignite.atomicLong("atomic", 0, true);
  9. long delta = RND.nextLong();
  10. long curAtomicVal = atomic.get();
  11. assert curAtomicVal == atomic.getAndAdd(delta);
  12. assert curAtomicVal + delta == atomic.get();
  13. }

代码示例来源:origin: apache/ignite

  1. /**
  2. * @throws Exception If failed.
  3. */
  4. @Test
  5. public void testAddAndGet() throws Exception {
  6. info("Running test [name=" + getName() + ", cacheMode=" + atomicsCacheMode() + ']');
  7. Ignite ignite = grid(0);
  8. IgniteAtomicLong atomic = ignite.atomicLong("atomic", 0, true);
  9. long delta = RND.nextLong();
  10. long curAtomicVal = atomic.get();
  11. assert curAtomicVal + delta == atomic.addAndGet(delta);
  12. assert curAtomicVal + delta == atomic.get();
  13. }

代码示例来源:origin: apache/ignite

  1. /**
  2. *
  3. */
  4. private void checkAtomics() {
  5. Ignite node0 = grid(0);
  6. node0.atomicLong("l1", 0, true).incrementAndGet();
  7. node0.atomicSequence("s1", 10, true);
  8. for (int i = 0; i < 3; i++) {
  9. assertEquals(1, ignite(i).atomicLong("l1", 0, false).get());
  10. assertNotNull(ignite(i).atomicSequence("s1", 0, false));
  11. ignite(i).atomicSequence("s1", 0, false).getAndIncrement();
  12. }
  13. }

代码示例来源:origin: apache/ignite

  1. /**
  2. * @throws Exception If failed.
  3. */
  4. @Test
  5. public void testAtomicLongTopologyChange() throws Exception {
  6. try (IgniteAtomicLong atomic = grid(0).atomicLong(STRUCTURE_NAME, 10, true)) {
  7. Ignite g = startGrid(NEW_IGNITE_INSTANCE_NAME);
  8. assertEquals(10, g.atomicLong(STRUCTURE_NAME, 10, false).get());
  9. assertEquals(20, g.atomicLong(STRUCTURE_NAME, 10, false).addAndGet(10));
  10. stopGrid(NEW_IGNITE_INSTANCE_NAME);
  11. assertEquals(20, grid(0).atomicLong(STRUCTURE_NAME, 10, true).get());
  12. }
  13. }

代码示例来源:origin: apache/ignite

  1. /**
  2. * @throws Exception If failed.
  3. */
  4. @Test
  5. public void testGetAndIncrement() throws Exception {
  6. info("Running test [name=" + getName() + ", cacheMode=" + atomicsCacheMode() + ']');
  7. Ignite ignite = grid(0);
  8. IgniteAtomicLong atomic = ignite.atomicLong("atomic", 0, true);
  9. long curAtomicVal = atomic.get();
  10. assert curAtomicVal == atomic.getAndIncrement();
  11. assert curAtomicVal + 1 == atomic.get();
  12. }

代码示例来源:origin: apache/ignite

  1. /**
  2. * @throws Exception If failed.
  3. */
  4. @Test
  5. public void testGetAndDecrement() throws Exception {
  6. info("Running test [name=" + getName() + ", cacheMode=" + atomicsCacheMode() + ']');
  7. Ignite ignite = grid(0);
  8. IgniteAtomicLong atomic = ignite.atomicLong("atomic", 0, true);
  9. long curAtomicVal = atomic.get();
  10. assert curAtomicVal == atomic.getAndDecrement();
  11. assert curAtomicVal - 1 == atomic.get();
  12. }

代码示例来源:origin: apache/ignite

  1. /**
  2. * @throws Exception If failed.
  3. */
  4. @Test
  5. public void testIncrementAndGet() throws Exception {
  6. info("Running test [name=" + getName() + ", cacheMode=" + atomicsCacheMode() + ']');
  7. Ignite ignite = grid(0);
  8. IgniteAtomicLong atomic = ignite.atomicLong("atomic", 0, true);
  9. long curAtomicVal = atomic.get();
  10. assert curAtomicVal + 1 == atomic.incrementAndGet();
  11. assert curAtomicVal + 1 == atomic.get();
  12. }

代码示例来源:origin: apache/ignite

  1. /**
  2. * @throws Exception If failed.
  3. */
  4. @Test
  5. public void testDecrementAndGet() throws Exception {
  6. info("Running test [name=" + getName() + ", cacheMode=" + atomicsCacheMode() + ']');
  7. Ignite ignite = grid(0);
  8. IgniteAtomicLong atomic = ignite.atomicLong("atomic", 0, true);
  9. long curAtomicVal = atomic.get();
  10. assert curAtomicVal - 1 == atomic.decrementAndGet();
  11. assert curAtomicVal - 1 == atomic.get();
  12. }

相关文章