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

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

本文整理了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

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

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

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

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

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

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

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

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

@Override public Object call() throws Exception {
    boolean failed = false;
    try {
      client.atomicLong("testAtomic", 41, true);
    }
    catch (IgniteClientDisconnectedException e) {
      failed = true;
      checkAndWait(e);
    }
    assertTrue(failed);
    return client.atomicLong("testAtomic", 41, true);
  }
},

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

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

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

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

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

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

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

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

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

@Override public void applyx(Ignite ignite) {
    IgniteAtomicLong al = ignite.atomicLong(TEST_LONG_NAME, 0, true);
    for (int i = 0; i < operationsPerTx; i++) {
      al.get();
      long cnt = reads.incrementAndGet();
      if (cnt % READ_LOG_MOD == 0)
        info("Performed " + cnt + " reads.");
    }
  }
};

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

@Override public Object call() throws Exception {
    Ignite g = startGrid(NEW_IGNITE_INSTANCE_NAME);
    try {
      g.transactions().txStart();
      g.cache(TRANSACTIONAL_CACHE_NAME).put(1, 1);
      assertEquals(val + 1, g.atomicLong(STRUCTURE_NAME, val, false).incrementAndGet());
    }
    finally {
      stopGrid(NEW_IGNITE_INSTANCE_NAME);
    }
    return null;
  }
}).get();

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

/**
 * @throws Exception If failed.
 */
@Test
public void testGetAndSet() throws Exception {
  info("Running test [name=" + getName() + ", cacheMode=" + atomicsCacheMode() + ']');
  Ignite ignite = grid(0);
  IgniteAtomicLong atomic = ignite.atomicLong("atomic", 0, true);
  long newVal = RND.nextLong();
  long curAtomicVal = atomic.get();
  assert curAtomicVal == atomic.getAndSet(newVal);
  assert newVal == atomic.get();
}

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

/**
 * @throws Exception If failed.
 */
@Test
public void testGetAndAdd() throws Exception {
  info("Running test [name=" + getName() + ", cacheMode=" + atomicsCacheMode() + ']');
  Ignite ignite = grid(0);
  IgniteAtomicLong atomic = ignite.atomicLong("atomic", 0, true);
  long delta = RND.nextLong();
  long curAtomicVal = atomic.get();
  assert curAtomicVal == atomic.getAndAdd(delta);
  assert curAtomicVal + delta == atomic.get();
}

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

/**
 * @throws Exception If failed.
 */
@Test
public void testAddAndGet() throws Exception {
  info("Running test [name=" + getName() + ", cacheMode=" + atomicsCacheMode() + ']');
  Ignite ignite = grid(0);
  IgniteAtomicLong atomic = ignite.atomicLong("atomic", 0, true);
  long delta = RND.nextLong();
  long curAtomicVal = atomic.get();
  assert curAtomicVal + delta == atomic.addAndGet(delta);
  assert curAtomicVal + delta == atomic.get();
}

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

/**
 *
 */
private void checkAtomics() {
  Ignite node0 = grid(0);
  node0.atomicLong("l1", 0, true).incrementAndGet();
  node0.atomicSequence("s1", 10, true);
  for (int i = 0; i < 3; i++) {
    assertEquals(1, ignite(i).atomicLong("l1", 0, false).get());
    assertNotNull(ignite(i).atomicSequence("s1", 0, false));
    ignite(i).atomicSequence("s1", 0, false).getAndIncrement();
  }
}

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

/**
 * @throws Exception If failed.
 */
@Test
public void testAtomicLongTopologyChange() throws Exception {
  try (IgniteAtomicLong atomic = grid(0).atomicLong(STRUCTURE_NAME, 10, true)) {
    Ignite g = startGrid(NEW_IGNITE_INSTANCE_NAME);
    assertEquals(10, g.atomicLong(STRUCTURE_NAME, 10, false).get());
    assertEquals(20, g.atomicLong(STRUCTURE_NAME, 10, false).addAndGet(10));
    stopGrid(NEW_IGNITE_INSTANCE_NAME);
    assertEquals(20, grid(0).atomicLong(STRUCTURE_NAME, 10, true).get());
  }
}

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

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

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

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

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

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

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

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

相关文章