Distributed id generator. Relies on node/worker ids and datacenter ids to prevent collisions.
@return a long unique ID string of digits
499014
public static synchronized String getNewId() {
		// unique across JVMs as long as each has a different workerID
		// based on Twitter's Snowflake algorithm
		long timestamp = timestamp();

		if (lastTimestamp == timestamp) {
			sequence = (sequence + 1) & SEQUENCE_MASK;
			if (sequence == 0) {
				timestamp = tilNextMillis(lastTimestamp);
			}
		} else {
			sequence = 0;
		}

		if (timestamp < lastTimestamp) {
			throw new IllegalStateException(String.format("Clock moved backwards.  "
					+ "Refusing to generate id for %d milliseconds", lastTimestamp - timestamp));
		}

		lastTimestamp = timestamp;
		return Long.toString(((timestamp - TIMER_OFFSET) << TIMESTAMP_LEFT_SHIFT) |
											(dataCenterId << DATACENTER_ID_SHIFT) |
													(workerId << WORKER_ID_SHIFT) |
																	(sequence));

	}
678826
protected String genIdString (int[] userIds)
    {
        // build up the string we need for the query
        StringBuilder ids = new StringBuilder();
        for (int i = 0; i < userIds.length; i++) {
            if (ids.length() > 0) {
                ids.append(",");
            }
            ids.append(userIds[i]);
        }

        return ids.toString();
    }
221054
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;
    }
251386
@Override
	public String getId() {
		StringBuilder strId = new StringBuilder();
		strId.append(id);
		if (nextProcessor != null) {
			strId.append(",").append(nextProcessor.getId());
		}
		return strId.toString();
	}
1272413
protected String generateDefinitionId(DeploymentEntity deployment, DefinitionEntity newDefinition, DefinitionEntity latestDefinition) {
    String nextId = idGenerator.getNextId();

    String definitionKey = newDefinition.getKey();
    int definitionVersion = newDefinition.getVersion();

    String definitionId = definitionKey
      + ":" + definitionVersion
      + ":" + nextId;

    // ACT-115: maximum id length is 64 characters
    if (definitionId.length() > 64) {
      definitionId = nextId;
    }
    return definitionId;
  }
646025
private synchronized long nextId(boolean isPadding, long busId) {

        long timestamp = timeGen();
        long paddingnum = regionId;

        if (isPadding) {
            paddingnum = busId;
        }

        if (timestamp < lastTimestamp) {
            try {
                throw new Exception("Clock moved backwards.  Refusing to generate id for " + (lastTimestamp - timestamp) + " milliseconds");
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

        //如果上次生成时间和当前时间相同,在同一毫秒内
        if (lastTimestamp == timestamp) {
            //sequence自增，因为sequence只有10bit，所以和sequenceMask相与一下，去掉高位
            sequence = (sequence + 1) & sequenceMask;
            //判断是否溢出,也就是每毫秒内超过1024，当为1024时，与sequenceMask相与，sequence就等于0
            if (sequence == 0) {
                //自旋等待到下一毫秒
                timestamp = tailNextMillis(lastTimestamp);
            }
        } else {
            // 如果和上次生成时间不同,重置sequence，就是下一毫秒开始，sequence计数重新从0开始累加,
            // 为了保证尾数随机性更大一些,最后一位设置一个随机数
            sequence = new SecureRandom().nextInt(10);
        }

        lastTimestamp = timestamp;

        return ((timestamp - twepoch) << timestampLeftShift) | (paddingnum << regionIdShift) | (workerId << workerIdShift) | sequence;
    }
1170544
public static String generateRequestId() {
        /* compute a random 256-bit string and hex-encode it */
        final SecureRandom sr = new SecureRandom();
        final byte[] bytes = new byte[32];
        sr.nextBytes(bytes);
        return hexEncode(bytes);
    }
882089
@Override
	public String nextUID() {
		StringBuilder tmp = new StringBuilder(prefix.length + 16);
		tmp.append(prefix);
		tmp.append(counter.incrementAndGet());
		return tmp.toString();
	}
1187968
public String getID() {
        byte[] genBytes = new byte[_byteArraySize];
        synchronized(_random) {
            _random.nextBytes(genBytes);
        }
        String id = convertSessionIdBytesToSessionId(genBytes, _sessionIDLength);
        if (logger.isLoggable(Level.FINE)) {
            logger.logp(Level.FINE, methodClassName, "getSessionID", "sessionID=" + id);
        }
        return id;
    }
822646
synchronized public long generateId48() {
        final long blockSize = 1000L; // block 1000 ms
        long timestamp = System.currentTimeMillis() / blockSize;
        long sequence = 0;
        boolean done = false;
        while (!done) {
            done = true;
            while (timestamp < lastTimestampMillisec.get() / blockSize) {
                timestamp = waitTillNextSecond(timestamp);
            }
            if (timestamp == lastTimestampMillisec.get() / blockSize) {
                // increase sequence
                sequence = sequenceMillisec.incrementAndGet();
                if (sequence > MAX_SEQUENCE_48) {
                    // reset sequence
                    sequenceMillisec.set(sequence = 0);
                    timestamp = waitTillNextSecond(timestamp);
                    done = false;
                }
            }
        }
        sequenceMillisec.set(sequence);
        lastTimestampMillisec.set(timestamp * blockSize);
        timestamp = ((timestamp * blockSize - TIMESTAMP_EPOCH) / blockSize) & MASK_TIMESTAMP_48;
        return timestamp << SHIFT_TIMESTAMP_48 | template48 | (sequence & MASK_SEQUENCE_48);
    }
714029
public synchronized QueryId createNextQueryId()
    {
        // only generate 100,000 ids per day
        if (counter > 99_999) {
            // wait for the second to rollover
            while (MILLISECONDS.toSeconds(nowInMillis()) == lastTimeInSeconds) {
                Uninterruptibles.sleepUninterruptibly(1, TimeUnit.SECONDS);
            }
            counter = 0;
        }

        // if it has been a second since the last id was generated, generate a new timestamp
        long now = nowInMillis();
        if (MILLISECONDS.toSeconds(now) != lastTimeInSeconds) {
            // generate new timestamp
            lastTimeInSeconds = MILLISECONDS.toSeconds(now);
            lastTimestamp = TIMESTAMP_FORMAT.print(now);

            // if the day has rolled over, restart the counter
            if (MILLISECONDS.toDays(now) != lastTimeInDays) {
                lastTimeInDays = MILLISECONDS.toDays(now);
                counter = 0;
            }
        }

        return new QueryId(String.format("%s_%05d_%s", lastTimestamp, counter++, coordinatorId));
    }
298452
public synchronized long nextId() {
        long timestamp = timeGen();
        if (timestamp < lastTimestamp) {
            throw new RuntimeException(
                    String.format("Clock moved backwards.  Refusing to generate id for %d milliseconds", lastTimestamp - timestamp));
        }
        //如果是同一时间生成的，则进行毫秒内序列
        if (lastTimestamp == timestamp) {
            sequence = (sequence + 1) & sequenceMask;
            //毫秒内序列溢出
            if (sequence == 0) {
                //阻塞到下一个毫秒,获得新的时间戳
                timestamp = tilNextMillis(lastTimestamp);
            }
        }
        //时间戳改变，毫秒内序列重置
        else {
            sequence = 0L;
        }
        //上次生成ID的时间截
        lastTimestamp = timestamp;
        //移位并通过或运算拼到一起组成64位的ID
        return ((timestamp - twepoch) << timestampLeftShift)
                | (dataCenterId << dataCenterIdShift)
                | (workerId << workerIdShift)
                | sequence;
    }
611415
public static long getNextGenerationId() {
        // ENG-14511- these calls may hit assertion failures in testing environments
        try {
            return UniqueIdGenerator.makeIdFromComponents(System.currentTimeMillis(),
                    m_generationId.incrementAndGet(),
                    MpInitiator.MP_INIT_PID);
        }
        catch (Throwable t) {
            // Try resetting the generation
            m_generationId.set(0L);
            return UniqueIdGenerator.makeIdFromComponents(System.currentTimeMillis(),
                    m_generationId.incrementAndGet(),
                    MpInitiator.MP_INIT_PID);
        }
    }
731950
def _generate_id(self):
        
        name = self.name.replace(self.special_separator, "-").replace(".", "-")
        loc = "\/"
        if self.location:
            loc = self.location
        _id = "{PREFIX}{SEP}{NAME}{HASH}{SEP}".format(
            PREFIX=constants.CONU_ARTIFACT_TAG,
            NAME=name,
            HASH=hashlib.sha512(loc).hexdigest()[: 10],
            SEP=self.special_separator
        )
        return _id
1179858
public String getId() {
        if (id == null) {
            synchronized (this) {
                if (id == null) {
                    id = "rpc-cfg-" + ID_GENERATOR.getAndIncrement();
                }
            }
        }
        return id;
    }
1200484
public Set<String> getGeneratedIds() {
		synchronized(lock) {
			if(generatedIds == null) return Collections.emptySet();
			if(frozen) return generatedIds;
			return AoCollections.unmodifiableCopySet(generatedIds);
		}
	}
126865
private static synchronized Long generateGuid() {
        StringBuilder builder = new StringBuilder();
        builder.append(System.currentTimeMillis());
        builder.append(guidCounter++);
        // Reset the counter if it gets too high.  It's always a number
        // between 100 and 999 so that the # of digits in the guid is
        // always the same.
        if (guidCounter > 999) {
            guidCounter = 100;
        }
        return Long.parseLong(builder.toString());
    }