public static byte [ ] nextID ( ) { byte [ ] ID = new byte [ 15 ] ; synchronized ( LOCK ) { long timestamp = System . currentTimeMillis ( ) ; if ( timestamp != LAST_TIMESTAMP ) { LAST_TIMESTAMP = timestamp ; LAST_SEQUENCE = 0 ; TIMESTAMP_BUFFER [ 0 ] = ( byte ) ( timestamp >>> 48 ) ; TIMESTAMP_BUFFER [ 1 ] = ( byte ) ( timestamp >>> 40 ) ; TIMESTAMP_BUFFER [ 2 ] = ( byte ) ( timestamp >>> 32 ) ; TIMESTAMP_BUFFER [ 3 ] = ( byte ) ( timestamp >>> 24 ) ; TIMESTAMP_BUFFER [ 4 ] = ( byte ) ( timestamp >>> 16 ) ; TIMESTAMP_BUFFER [ 5 ] = ( byte ) ( timestamp >>> 8 ) ; TIMESTAMP_BUFFER [ 6 ] = ( byte ) ( timestamp >>> 0 ) ; } else if ( ++ LAST_SEQUENCE == 0 ) { throw new RuntimeException ( "Same ID generated in a single milliscond!" ) ; } ByteBuffer bb = ByteBuffer . wrap ( ID ) ; bb . put ( TIMESTAMP_BUFFER ) ; bb . put ( MAC ) ; bb . putShort ( LAST_SEQUENCE ) ; } return ID ; }
Return the next unique ID . See the class description for the format of an ID .