Giter VIP home page Giter VIP logo

flake4j's Introduction

Flake4J - Flake ID generator for Java

This is an implementation of the Flake decentralized, k-ordered ID generation algorithm by Boundary.

There is no server implementation yet. To avoid non-unique IDs, it is the programmer's responsibility to ensure that only one instance of the ID generator is active in a single node (if the MAC address based node identification is used).

This implementation generates 128-bit IDs.

Usage

Artifacts are available on Maven Central.

Gradle:

compile group: 'com.github.charithe', name: 'flake4j', version: '1.0.2'
// Create an ID generator that uses the machine's MAC address for node identification
Flake4J f4j = Flake4J.newInstance();

// Use a custom node identifier instead of the MAC address
NodeIdentifier nodeIdentifier = () -> uniqueNodeIdentifier // long value
Flake4J f4j = Flake4J.newInstance(nodeIdentifier);

flake4j's People

Contributors

charithe avatar thibaultmeyer avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

flake4j's Issues

The MacAddressNodeIdentifier.findViableMacAddress() isn't always giving us the right MAC address

We found that for some NetworkInterface objects, in this case on OsX, it was up, not a loopback, but still had a null MAC address (it was a tunnel). We suggest adding this extra if-statement around the return statement:

      if (!currentNic.isLoopback() && currentNic.isUp()) {
        byte[] macAddress = currentNic.getHardwareAddress();
        if (macAddress != null) {
          return Optional.of(macAddress);
        }
      }

SecureRandom.nextLong as node identifier

Hello.

This is more like a question than an issue: Consider multiple independent services generating IDs on the same host/Mac address, how safe/unsafe is it to generate the node identifier for each service once at bootstrap with something like SecureRandom.nextLong?

Thanks a lot

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.