Example usage for java.util UUID timestamp

List of usage examples for java.util UUID timestamp

Introduction

In this page you can find the example usage for java.util UUID timestamp.

Prototype

public long timestamp() 

Source Link

Document

The timestamp value associated with this UUID.

Usage

From source file:org.olegz.uuid.TimeBasedUUIDGeneratorTests.java

@Test
public void testStructure() {
    long timestamp = System.currentTimeMillis();
    UUID id = TimeBasedUUIDGenerator.generateIdFromTimestamp(timestamp);
    for (int i = 0; i < 30000; i++) {
        UUID newId = TimeBasedUUIDGenerator.generateIdFromTimestamp(timestamp);
        id = newId;/*  w  ww . j  a  v  a 2 s .c o  m*/
    }
    Assert.assertEquals(timestamp, id.timestamp());
}

From source file:org.olegz.uuid.TimeBasedUUIDGeneratorTests.java

/**
 * Tests that UUID which was generated based on the same timestamp will still be unique
 * based on the clockSequence. Theoretically there is a possibility of non-unique ID,
 * but only if more then 16383 ids were generated at the same time by the same machine.
 *//*from  ww  w.  j av  a 2 s  . com*/
@Test
public void testUniqueness() {
    long timestamp = System.currentTimeMillis();
    UUID id = TimeBasedUUIDGenerator.generateIdFromTimestamp(timestamp);
    UUID newId = null;
    for (int i = 0; i < 16383; i++) { // max, due to the amount of bits allocated for clockSequence
        newId = TimeBasedUUIDGenerator.generateIdFromTimestamp(timestamp);
        // tests, that newly created UUID's clockSequence is always greater then the previous one.
        Assert.assertTrue(newId.clockSequence() > id.clockSequence());
        Assert.assertEquals(newId.timestamp(), id.timestamp());
        id = newId;
    }
}

From source file:org.apache.usergrid.persistence.qakka.distributed.actors.QueueActorHelper.java

private Collection<DatabaseQueueMessage> getMessagesFromStorage(String queueName, int numRequested) {

    Collection<DatabaseQueueMessage> queueMessages = new ArrayList<>();

    //        final Optional shardIdOptional;
    //        final String shardKey =
    //            createShardKey( queueName, Shard.Type.DEFAULT, actorSystemFig.getRegionLocal() );
    ////from w ww  .  ja v  a2 s  .  c  o m
    //        Long shardId = startingShards.get( shardKey );
    //        if ( shardId != null ) {
    //            shardIdOptional = Optional.of( shardId );
    //        } else {
    //            shardIdOptional = Optional.empty();
    //        }

    UUID since = newestFetchedUuid.get(queueName);

    String region = actorSystemFig.getRegionLocal();

    ShardIterator shardIterator = new ShardIterator(cassandraClient, queueName, region, Shard.Type.DEFAULT,
            Optional.empty());

    MultiShardMessageIterator multiShardIterator = new MultiShardMessageIterator(cassandraClient, queueName,
            region, DatabaseQueueMessage.Type.DEFAULT, shardIterator, since);

    int count = 0;

    while (multiShardIterator.hasNext() && count < numRequested) {
        DatabaseQueueMessage queueMessage = multiShardIterator.next();

        if (queueMessage != null && putInflight(queueMessage)) {
            long timestamp = queueMessage.getQueueMessageId().timestamp();
            if (since != null && timestamp > since.timestamp()) {
                since = queueMessage.getQueueMessageId();
            }
            queueMessages.add(queueMessage);
            count++;
        }
    }

    updateUUIDPointer(queueName, since);

    //        Shard currentShard = multiShardIterator.getCurrentShard();
    //        if ( currentShard != null ) {
    //            shardId = currentShard.getShardId();
    //            startingShards.put( shardKey, shardId );
    //        }

    //logger.debug("{} returning {} for queue {}", this, queueMessages.size(), queueName);
    return queueMessages;
}