Java 类com.hazelcast.core.IAtomicLong 实例源码

项目:esBench    文件:SlaveNodeInsertAction.java   
private void init(HazelcastInstance hz, DefaultProperties slaveProperties) throws IOException, InterruptedException {
    IAtomicLong nodeId = hz.getAtomicLong(NODE_ID);
    id = nodeId.getAndIncrement();

    prepLatch = hz.getCountDownLatch(PREP_LATCH);
    if(id < 1) {
        prepLatch.trySetCount(1);
    }
    prepLatch.await(DEFAULT_WAIT_UNIT, TimeUnit.MINUTES);

    execLatch = hz.getCountDownLatch(EXEC_LATCH);

    configMap = hz.getMap(CONF_MAP);
    DefaultProperties masterProperties = (DefaultProperties) configMap.get(DEFAULT_PROPS);
    DefaultProperties merged = DefaultProperties.merge(slaveProperties, masterProperties);
    executeSend(merged);
    LOGGER.info("Leader finished");
}
项目:esBench    文件:MasterNodeInsertAction.java   
private void init(HazelcastInstance hz, DefaultProperties properties, InsertProperties insProperties) throws IOException, InterruptedException {
    IAtomicLong nodeId = hz.getAtomicLong(NODE_ID);
    id = nodeId.getAndIncrement();
    prepLatch = hz.getCountDownLatch(PREP_LATCH);
    if(id < 1) {
        prepLatch.trySetCount(SINGLE_PREP_LATCH_VALUE);
    }

    execLatch = hz.getCountDownLatch(EXEC_LATCH);

    int numOfNodes = insProperties.getClusterNodes();
    LOGGER.info("Establishing master node... Waiting for {} nodes (including master node)", numOfNodes);
    Validate.isTrue(execLatch.trySetCount(numOfNodes), "Execution latch could not be set");

    IMap<String, Object> configMap = hz.getMap(CONF_MAP);
    configMap.put(DEFAULT_PROPS, properties);
    Reader reader = guessReader(insProperties.getWorkloadLocation());
    String workloadAsText = IOUtils.toString(reader);
    configMap.put(WORKLOAD, workloadAsText);

    prepLatch.countDown();
}
项目:runrightfast-vertx    文件:HazelcastConfigFactoryTest.java   
private void test(final HazelcastInstance hazelcast1, final HazelcastInstance hazelcast2) {
    final IAtomicLong counterA = hazelcast1.getAtomicLong("counter-a");
    final long countA = counterA.incrementAndGet();
    LOG.log(INFO, "expecting {0} = {1}", new Object[]{counterA.get(), hazelcast1.getAtomicLong("counter-a").get()});
    assertThat(countA, is(hazelcast1.getAtomicLong("counter-a").get()));

    assertThat(hazelcast2.getAtomicLong("counter-a").get(), is(hazelcast1.getAtomicLong("counter-a").get()));

    final Member member2 = hazelcast2.getCluster().getLocalMember();
    LOG.log(INFO, member2.getAttributes().entrySet().stream()
            .map(entry -> entry.getKey() + " -> " + entry.getValue() + " : " + entry.getValue().getClass().getName())
            .collect(Collectors.joining("\n", "member 2 attributes\n", "\n"))
    );

    assertThat(member2.getStringAttribute("string"), is("hello"));
    assertThat(member2.getIntAttribute("int"), is(1));
    assertThat(member2.getBooleanAttribute("bool"), is(true));
}
项目:chuidiang-ejemplos    文件:AtomicExample.java   
public static void main( String[] args ) throws FileNotFoundException, InterruptedException
{
   Config config = new Config();
   HazelcastInstance hazelcastInstance = Hazelcast.newHazelcastInstance(config);

   IAtomicLong atomicLong = hazelcastInstance.getAtomicLong("soy productor");

   boolean cambiado = atomicLong.compareAndSet(0, 1);

   if (cambiado){
      produce(hazelcastInstance);
   } else {
      consume(hazelcastInstance);
   }

}
项目:jcconf2014-hazelcast-sample    文件:HazelcastHelper.java   
/**
 * Creates and returns a new producer.
 *
 * @param cloudNode the cloud node which runs this new producer
 * @return a new producer
 */
private Runnable createProducer(final CloudNode cloudNode) {
    return () -> {
        logger.info("Producer thread started.");
        while (this.isMaster(cloudNode)) {
            try {
                final Set<String> nodes = new HashSet<>(HazelcastHelper.this.getActiveNodes());
                nodes.remove(cloudNode.getName());
                if (nodes.size() > 0) {
                    final IAtomicLong serialNumber = getAtomicLong(TASK_NUMBER);
                    final String taskName = String.format("TASK-%d-%d", serialNumber.incrementAndGet(), System.currentTimeMillis());
                    HazelcastHelper.this.getTaskQueue().put(taskName);
                    logger.info("Added task {}", taskName);
                }
                Thread.sleep(RandomUtils.nextInt(1500, 4000));
            } catch (final Exception ex) {
                logger.error("Exception occurred!", ex);
            }
        }
    };
}
项目:ahome-tooling-server-hazelcast    文件:HazelcastContextInstance.java   
@Override
public IAtomicLong getIAtomicLong(String name)
{
    name = Objects.requireNonNull(name);

    final IAtomicLong valu = getBeanSafely(name, IAtomicLong.class);

    if (null != valu)
    {
        return valu;
    }
    return hz().getAtomicLong(name);
}
项目:spring-open    文件:HZClient.java   
/**
 * {@inheritDoc}
 * <p />
 * Warning: The counter is a different object from {@code key} entry on
 * IKVTable with {@code tableId}. You cannot use table API to read/write
 * counters.
 *
 * @param tableId Only getTableName() will be used.
 * @param key tableId + key will be used as Counter name
 */
@Override
public void createCounter(final IKVTableID tableId,
                          final byte[] key, final long initialValue)
                                  throws ObjectExistsException {

    IAtomicLong counter = getAtomicLong(tableId, key);
    // Assumption here is that AtomicLong is initialized to 0L
    final boolean success = counter.compareAndSet(0L, initialValue);
    if (!success) {
        throw new ObjectExistsException("Atomic counter "
                + getCounterName(tableId, key)
                + " already exist with value:" + counter.get());
    }
}
项目:spring-open    文件:HZClient.java   
@Override
public void setCounter(final IKVTableID tableId,
                       final byte[] key, final long value) {

    IAtomicLong counter = getAtomicLong(tableId, key);
    counter.set(value);
}
项目:spring-open    文件:HZClient.java   
@Override
public long incrementCounter(final IKVTableID tableId,
                             final byte[] key, final long incrementValue) {

    IAtomicLong counter = getAtomicLong(tableId, key);
    return counter.addAndGet(incrementValue);
}
项目:spring-open    文件:HZClient.java   
@Override
public long getCounter(final IKVTableID tableId, final byte[] key)
        throws ObjectDoesntExistException {

    IAtomicLong counter = getAtomicLong(tableId, key);
    return counter.get();
}
项目:hazelcast-simulator    文件:AsyncAtomicLongTest.java   
@Teardown
public void teardown() {
    if (isMemberNode(targetInstance)) {
        for (IAtomicLong counter : counters) {
            counter.destroy();
        }
    }
    totalCounter.destroy();
    logger.info(getOperationCountInformation(targetInstance));
}
项目:hazelcast-simulator    文件:AtomicLongTest.java   
@Setup
public void setup() {
    totalCounter = targetInstance.getAtomicLong(name + ":TotalCounter");
    counters = new IAtomicLong[countersLength];

    String[] names = generateStringKeys(name, countersLength, keyLocality, targetInstance);
    for (int i = 0; i < countersLength; i++) {
        counters[i] = targetInstance.getAtomicLong(names[i]);
    }
}
项目:hazelcast-simulator    文件:AtomicLongTest.java   
@Teardown
public void teardown() {
    for (IAtomicLong counter : counters) {
        counter.destroy();
    }
    totalCounter.destroy();
}
项目:hazelcast-simulator    文件:SimpleLockTest.java   
@Prepare(global = true)
public void prepare() {
    for (int i = 0; i < maxAccounts; i++) {
        IAtomicLong account = targetInstance.getAtomicLong(name + i);
        account.set(INITIAL_VALUE);
    }
    totalValue = INITIAL_VALUE * maxAccounts;
}
项目:hazelcast-simulator    文件:SimpleLockTest.java   
@TimeStep
public void timeStep(BaseThreadState state) {
    int key1 = state.randomInt(maxAccounts);
    int key2;
    do {
        key2 = state.randomInt(maxAccounts);
    } while (key1 == key2);

    ILock lock1 = targetInstance.getLock(name + key1);
    if (lock1.tryLock()) {
        try {
            ILock lock2 = targetInstance.getLock(name + key2);
            if (lock2.tryLock()) {
                try {
                    IAtomicLong account1 = targetInstance.getAtomicLong(name + key1);
                    IAtomicLong account2 = targetInstance.getAtomicLong(name + key2);

                    int delta = state.randomInt(100);
                    if (account1.get() >= delta) {
                        account1.set(account1.get() - delta);
                        account2.set(account2.get() + delta);
                    }
                } finally {
                    lock2.unlock();
                }
            }
        } finally {
            lock1.unlock();
        }
    }
}
项目:hazelcast-simulator    文件:SimpleLockTest.java   
@Verify
public void verify() {
    int value = 0;
    for (int i = 0; i < maxAccounts; i++) {
        ILock lock = targetInstance.getLock(name + i);
        IAtomicLong account = targetInstance.getAtomicLong(name + i);

        logger.info(format("%s %d", account, account.get()));

        assertFalse(name + ": Lock should be unlocked", lock.isLocked());
        assertTrue(name + ": Amount is < 0 ", account.get() >= 0);
        value += account.get();
    }
    assertEquals(name + " totals not adding up ", totalValue, value);
}
项目:hazelcast-simulator    文件:LockTest.java   
@Prepare(global = true)
public void prepare() {
    for (int i = 0; i < lockCount; i++) {
        long key = lockCounter.getAndIncrement();
        targetInstance.getLock(getLockId(key));
        IAtomicLong account = targetInstance.getAtomicLong(getAccountId(key));
        account.set(initialAmount);
    }
}
项目:hazelcast-simulator    文件:LockTest.java   
@TimeStep
public void timeStep(ThreadState state) {
    long key1 = state.getRandomAccountKey();
    long key2 = state.getRandomAccountKey();
    int randomAmount = state.randomInt(amount);

    ILock lock1 = targetInstance.getLock(getLockId(key1));
    ILock lock2 = targetInstance.getLock(getLockId(key2));
    IAtomicLong account1 = targetInstance.getAtomicLong(getAccountId(key1));
    IAtomicLong account2 = targetInstance.getAtomicLong(getAccountId(key2));

    if (!lock1.tryLock()) {
        return;
    }
    try {
        if (!lock2.tryLock()) {
            return;
        }
        try {
            if (account1.get() < 0 || account2.get() < 0) {
                throw new TestException("Amount on account can't be smaller than 0");
            }
            if (account1.get() < randomAmount) {
                return;
            }
            account1.set(account1.get() - randomAmount);
            account2.set(account2.get() + randomAmount);
        } finally {
            lock2.unlock();
        }
    } finally {
        lock1.unlock();
    }
}
项目:xm-ms-entity    文件:WebConfigurerIntTest.java   
@Override
public IAtomicLong getAtomicLong(String s) {
    return null;
}
项目:bagri    文件:ModelManagementImpl.java   
public void setPathGen(IAtomicLong pathGen) {
    this.pathGen = new IdGeneratorImpl(pathGen);
}
项目:bagri    文件:IdGeneratorImpl.java   
public IdGeneratorImpl(IAtomicLong idGen) {
    this.idGen = idGen;
}
项目:hazelcast-locks    文件:HazelcastAtomicLong.java   
public HazelcastAtomicLong(IAtomicLong delegate)
{
    this.delegate = delegate;
}
项目:Cherry    文件:HazelcastService.java   
@Override
public IAtomicLong getAtomicLong(final String name) {
  return getHazelcastInstance().getAtomicLong(name);
}
项目:vertx-hazelcast    文件:HazelcastInternalAsyncCounter.java   
public HazelcastInternalAsyncCounter(Vertx vertx, IAtomicLong atomicLong) {
    this.vertx = vertx;
    this.atomicLong = atomicLong;
}
项目:vertx-hazelcast    文件:HazelcastClusterManager.java   
private HazelcastCounter(IAtomicLong atomicLong) {
  this.atomicLong = atomicLong;
}
项目:spring-open    文件:HZClient.java   
private IAtomicLong getAtomicLong(final IKVTableID tableId, final byte[] key) {
    // TODO we probably want to implement some sort of caching
    return hazelcastInstance.getAtomicLong(getCounterName(tableId, key));
}
项目:spring-open    文件:HZClient.java   
@Override
public void destroyCounter(final IKVTableID tableId, final byte[] key) {
    IAtomicLong counter = getAtomicLong(tableId, key);
    counter.destroy();

}
项目:spring-open    文件:HazelcastRuntime.java   
@Override
public SeqNum getLatestSnapShotId(SharedLogObjectID oid) {
    IAtomicLong latest = getLatestSnapshotStore(oid);
    final long ssId = latest.get();
    return SeqNum.anyValueOf(ssId);
}
项目:hazelcast-simulator    文件:AtomicLongTest.java   
private IAtomicLong randomCounter() {
    int index = randomInt(counters.length);
    return counters[index];
}
项目:jcconf2014-hazelcast-sample    文件:HazelcastHelper.java   
/**
 * Returns the atomic long integer related with the given name.
 *
 * @param numberName the atomic long integer
 * @return the name of atomic long integer
 * @throws NullPointerException if the given name is {@code null}
 */
private static IAtomicLong getAtomicLong(final String numberName) {
    Objects.requireNonNull(numberName, "The given atomic integer name must not be null.");
    return Holder.INSTANCE.getInstance().getAtomicLong(numberName);
}
项目:spring-open    文件:HazelcastRuntime.java   
/**
 * Gets the store holding latest snapshot version.
 *
 * @param oid {@link SharedLogObjectID}
 * @return IAtomicLong
 */
private IAtomicLong getLatestSnapshotStore(SharedLogObjectID oid) {
    return instance.getAtomicLong(LATEST_SNAPSHOT_PREFIX + oid.getObjectName());
}
项目:spring-open    文件:HazelcastSequencer.java   
/**
 * Constructor.
 *
 * @param value IAtomicLong to use as Sequencer
 */
public HazelcastSequencer(IAtomicLong value) {
    this.value = checkNotNull(value);
}
项目:ahome-tooling-server-hazelcast    文件:IHazelcastContext.java   
public IAtomicLong getIAtomicLong(String name);