Package com.hazelcast.core

Examples of com.hazelcast.core.IdGenerator.newId()


    private static void assertNewIdAfterInit(int initialValue) {
        IdGenerator idGenerator = createIdGenerator();

        assertTrue(idGenerator.init(initialValue));

        assertEquals(initialValue + 1, idGenerator.newId());
    }

    private static IdGenerator createIdGenerator() {
        String name = "id-" + UUID.randomUUID().toString();
View Full Code Here


    public void testIdGenerator() throws Exception {
        String partitionKey = "hazelcast";
        HazelcastInstance hz = getHazelcastInstance(partitionKey);

        IdGenerator idGenerator = hz.getIdGenerator("idgenerator@" + partitionKey);
        idGenerator.newId();
        assertEquals("idgenerator@" + partitionKey, idGenerator.getName());
        assertEquals(partitionKey, idGenerator.getPartitionKey());

        AtomicLongService service = getNodeEngine(hz).getService(AtomicLongService.SERVICE_NAME);
        assertTrue(service.containsAtomicLong("hz:atomic:idGenerator:" + idGenerator.getName()));
View Full Code Here

   * Id from Hazelcast. In this way if the Hazelcast counter is restarted (for example after a cluster shutdown or
   * restart) then the Ids will still be unique afterwards.
   */
  public long uniqueVersionId() {
    IdGenerator idGenerator = hz.getIdGenerator(CoordinationStructures.VERSION_GENERATOR);
    long id = idGenerator.newId();
    int timeSeconds = (int) (System.currentTimeMillis() / 1000);
    long paddedId = id << 32;
    return paddedId + timeSeconds;
  }

View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.