/** * Generate a new UUID with the given time stamp in milliseconds. This method guarantees that subsequent calls will * be of increasing value chronologically. If a large number of subsequent calls are made to this method (>1000) * with the same timestamp, you will have non-unique temporal values stored in your UUID. */ public static UUID newTimeUUID( long ts ) { tsLock.lock(); int pointer = customMicrosPointer.getAndIncrement(); try { if ( pointer > 990 ) { customMicrosPointer.set( 0 ); } } finally { tsLock.unlock(); } return newTimeUUID( ts, MICROS[pointer] ); }
@JsonIgnore public synchronized UUID getUuid() { UUID uuid = uuid( properties.get( MESSAGE_ID ), null ); if ( uuid == null ) { if ( properties.containsKey( MESSAGE_TIMESTAMP ) ) { long ts = getLongValue( properties, MESSAGE_TIMESTAMP ); uuid = newTimeUUID( ts ); } else { uuid = newTimeUUID(); } properties.put( MESSAGE_ID, uuid ); properties.put( MESSAGE_TIMESTAMP, getTimestampInMillis( uuid ) ); } return uuid; }
public QueueIndexUpdate( Mutator<ByteBuffer> batch, String queuePath, UUID queueId, String entryName, Object entryValue, UUID timestampUuid ) { this.batch = batch; this.queuePath = queuePath; this.queueId = queueId; this.entryName = entryName; this.entryValue = entryValue; timestamp = getTimestampInMicros( timestampUuid ); this.timestampUuid = timestampUuid; }
public void setMessageID( String id ) { if ( UUIDUtils.isUUID( id ) ) { properties.put( MESSAGE_ID, UUIDUtils.tryGetUUID( id ) ); } else { throw new RuntimeException( "Not a UUID" ); } }
UUID uuid = UUIDUtils.tryGetUUID( queuePath ); if ( uuid != null ) { return uuid; uuid = UUIDUtils.tryExtractUUID( queuePath, 1 ); if ( uuid != null ) { return uuid; uuid = UUIDUtils.tryExtractUUID( queuePath, 1 ); if ( uuid != null ) { return uuid;
private Entity batchCreateRole( String roleName, String roleTitle, long inactivity, String propertyName, UUID ownerId, Map<String, Object> additionalProperties ) throws Exception { UUID timestampUuid = UUIDUtils.newTimeUUID(); long timestamp = UUIDUtils.getTimestampInMicros( timestampUuid );
@Test public void min() { long start = System.currentTimeMillis(); UUID t1 = newTimeUUID( start, 0 ); UUID t2 = newTimeUUID( start, 1 ); assertEquals( t1, UUIDUtils.min( t1, t2 ) ); }
@Test public void max() { long start = System.currentTimeMillis(); UUID t1 = newTimeUUID( start, 0 ); UUID t2 = newTimeUUID( start, 1 ); assertEquals( t2, UUIDUtils.max( t1, t2 ) ); }
@Test public void testUUIDUtils() { UUID uuid = UUIDUtils.newTimeUUID(); logger.info("" + uuid); logger.info("" + uuid.timestamp()); logger.info("" + UUIDUtils.getTimestampInMillis(uuid)); logger.info("" + UUIDUtils.getTimestampInMillis(UUIDUtils.newTimeUUID())); logger.info("" + System.currentTimeMillis()); logger.info("" + UUIDUtils.getTimestampInMicros(UUIDUtils.newTimeUUID())); logger.info("" + (System.currentTimeMillis() * 1000)); logger.info("" + UUIDUtils.MIN_TIME_UUID); logger.info("" + UUIDUtils.MIN_TIME_UUID.variant()); logger.info("" + UUIDUtils.MIN_TIME_UUID.version()); logger.info("" + UUIDUtils.MIN_TIME_UUID.clockSequence()); logger.info("" + UUIDUtils.MIN_TIME_UUID.timestamp()); logger.info("" + UUIDUtils.MAX_TIME_UUID); logger.info("" + UUIDUtils.MAX_TIME_UUID.variant()); logger.info("" + UUIDUtils.MAX_TIME_UUID.version()); logger.info("" + UUIDUtils.MAX_TIME_UUID.clockSequence()); logger.info("" + UUIDUtils.MAX_TIME_UUID.timestamp()); }
UUID startTimeUUID = UUIDUtils.newTimeUUID( startTime, 0 ); //this exact moment in time + clockseq + node if( params.startId != null && UUIDUtils.compare( params.startId, startTimeUUID ) > 0){ logger.warn( "Our cursor has advanced beyond the end of the queue due to transactions. Was {}, resetting to {}", params.startId, startTimeUUID ); params = new SearchParam( startTimeUUID, params.reversed, false, params.limit ); UUID lastReadId = UUIDUtils.max( lastReadTransactionPointer, lastId ); lastReadId = UUIDUtils.min( lastReadId, bounds.getNewest() );
/** * The start time of this operation as represented by the timestamp embedded in the type-1 UUID of the opTag * property */ public long getStart() { return UUIDUtils.getTimestampInMillis( opTag ); }
long timestamp = UUIDUtils.getTimestampInMicros( UUIDUtils.newTimeUUID() ); if ( UUIDUtils.isTimeBased( importId ) ) { timestampFromImport = UUIDUtils.getTimestampInMicros( importId );
/** * Generate a timeuuid with the given timestamp in milliseconds and the time offset. Useful when you need to * generate sequential UUIDs for the same period in time. I.E * <p/> * newTimeUUID(1000, 0) <br/> newTimeUUID(1000, 1) <br /> newTimeUUID(1000, 2) <br /> * <p/> * etc. * <p/> * Only use this method if you are absolutely sure you need it. When it doubt use the method without the timestamp * offset * * @param ts The timestamp in milliseconds * @param timeoffset The offset, which should always be <= 10000. If you go beyond this range, the millisecond will * be incremented since this is beyond the possible values when coverrting from millis to 1/10 microseconds stored * in the time uuid. */ public static UUID newTimeUUID( long ts, int timeoffset ) { if ( ts == 0 ) { return newTimeUUID(); } byte[] uuidBytes = new byte[16]; // 47 bits of randomness EthernetAddress eth = EthernetAddress.constructMulticastAddress(); eth.toByteArray( uuidBytes, 10 ); setTimestamp( ts, uuidBytes, getRandomClockSequence(), timeoffset ); return uuid( uuidBytes ); }
ArrayList<UUID> oldUUIDs = new ArrayList<>( credsMap.size() ); credsMap.keySet().forEach((uuid) -> oldUUIDs.add(UUID.fromString(uuid))); UUIDUtils.sort( oldUUIDs ); for ( int i = 0; i < oldUUIDs.size() - passwordHistorySize; i++ ) { em.removeFromDictionary( user, CREDENTIALS_HISTORY, oldUUIDs.get( i ).toString() ); UUID uuid = UUIDUtils.newTimeUUID(); em.addToDictionary( user, CREDENTIALS_HISTORY, uuid.toString(), currentCredentials );
private UUID getUuid( Map oldAppInfoMap, String key ) { UUID applicationId; Object uuidObject = oldAppInfoMap.get( key ); if ( uuidObject instanceof UUID ) { applicationId = ( UUID ) uuidObject; } else { applicationId = uuidObject == null ? null : UUIDUtils.tryExtractUUID( uuidObject.toString() ); } return applicationId; }
public static UUID getConsumerId( String consumer ) { if ( consumer == null ) { return null; } if ( isUUID( consumer ) ) { return UUID.fromString( consumer ); } else if ( isNotBlank( consumer ) ) { return nameUUIDFromBytes( ( "consumer:" + consumer ).getBytes() ); } return null; }
@Test public void maxBothNull() { assertNull( UUIDUtils.max( null, null ) ); }
@Test public void minBothNull() { assertNull( UUIDUtils.min( null, null ) ); }
@Test @Category(ExperimentalTest.class) @SuppressWarnings("unchecked") public void verifyOrderingTsOnlyAndUnique() { int count = 500; long ts = System.currentTimeMillis(); List<UUID> uuids = new ArrayList<UUID>( count ); HashSet times = new HashSet(); UUID lastSeen; for ( int i = 0; i < count; i++ ) { lastSeen = newTimeUUID( ts ); uuids.add( lastSeen ); times.add( UUIDUtils.getTimestampInMicros( lastSeen ) ); } assertEquals( 500, times.size() ); for ( int i = 0; i < count - 1; i++ ) { assertEquals( -1, uuids.get( i ).compareTo( uuids.get( i + 1 ) ) ); } }
@Test public void minSecondNull() { long start = System.currentTimeMillis(); UUID t1 = newTimeUUID( start, 0 ); assertEquals( t1, UUIDUtils.min( t1, null ) ); }