public synchronized long nextId()

in common/src/main/java/org/apache/rocketmq/schema/registry/common/utils/SnowFlakeIdGenerator.java [89:116]


    public synchronized long nextId() {
        long timestamp = System.currentTimeMillis();
        if (timestamp < lastTimestamp) {
            throw new SchemaException("SchemaId generating error, clock moved backwards, please try later");
        }

        // if timestamp equals to lastTimestamp, diff the sequenceId
        if (lastTimestamp == timestamp) {
            // prevent sequenceId greater than 4095 (number of 'sequenceIdBits')
            sequenceId = (sequenceId + 1) & sequenceIdMask;
            // if sequenceId equals to 0, it means that
            // the 'sequenceIdBits' has been exhausted at the current timestamp, then
            // it would be blocked for a new timestamp
            if (sequenceId == 0) {
                timestamp = waitNextMillis(lastTimestamp);
            }
        } else {
            sequenceId = 0L;
        }

        lastTimestamp = timestamp;

        // computing the 64 bits unique id
        return ((timestamp - startTime) << timestampMoveBits)
            | (regionId << regionIdMoveBits)
            | (nodeId << nodeIdMoveBits)
            | (sequenceId << sequenceIdMoveBits);
    }