All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.litongjava.tio.websocket.common.WebsocketSnowflakeId Maven / Gradle / Ivy

There is a newer version: 3.7.3.v20241201-RELEASE
Show newest version
package com.litongjava.tio.websocket.common;

import java.util.concurrent.ThreadLocalRandom;

import com.litongjava.aio.AioId;
import com.litongjava.tio.utils.hutool.Snowflake;


public class WebsocketSnowflakeId implements AioId {
  private Snowflake snowflake;

  public WebsocketSnowflakeId() {
    snowflake = new Snowflake(ThreadLocalRandom.current().nextInt(1, 30), ThreadLocalRandom.current().nextInt(1, 30));
  }

  public WebsocketSnowflakeId(long workerId, long datacenterId) {
    snowflake = new Snowflake(workerId, datacenterId);
  }

  /**
   * @return
   * @author tanyaowu
   */
  @Override
  public String id() {
    return snowflake.nextId() + "";
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy