rholder / fauxflake Goto Github PK
View Code? Open in Web Editor NEWFauxflake is an easily embeddable, decentralized, k-ordered unique ID generator.
Home Page: http://rholder.github.io/fauxflake/
License: Apache License 2.0
Fauxflake is an easily embeddable, decentralized, k-ordered unique ID generator.
Home Page: http://rholder.github.io/fauxflake/
License: Apache License 2.0
For some reason whenever I run an application using fauxflake inside a docker,
it always generates the same id (this is a single long running instance of a linux container),
even if the container stays up and has net=host set.
private static IdGenerator snowflake = IdGenerators.newSnowflakeIdGenerator();
snowflake.generateId(1000).asString();
always yields ffffffffffc01000
works perfectly outside the container though.
Complete testing of Netflix-style Gradle build, and push it to Maven Central.
Currently, when backwards time is detected it is propagated up as an InterruptedException
.
Add examples and prepare README.md for 1.0.0 release.
Currently, when we exceed the specified wait time, it is propagated up as an InterruptedException
.
'nuff said.
Negative machine IDs are possible, and SnowflakeEncodingProvider left-shifts these without checking, resulting in a small negative number that is OR'ed with the timestamp, erasing the timestamp. Example:
static class FixedIdProvider implements MachineIdProvider {
final long id;
FixedIdProvider(long id) {
this.id = id;
}
public long getMachineId() {
return id;
}
}
public static void main(String[] args) throws Exception
{
IdGenerator g1 = newSnowflakeIdGenerator(new FixedIdProvider(1));
System.out.println(g1.generateId(0).asString());
IdGenerator g2 = newSnowflakeIdGenerator(new FixedIdProvider(-1));
System.out.println(g2.generateId(0).asString());
}
Output:
080f6b18b1001000
fffffffffffff000
Creating a wrapper on e.g. MacPidMachineIdProvider is an easy temporary workaround.
I was a bit surprised to see that this code in a unit test produces two duplicates:
IdGenerator snowflake = IdGenerators.newSnowflakeIdGenerator();
for (int i = 0; i < 10; i++) {
String id = snowflake.generateId(1000).asString();
System.out.println(id);
}
output:
ffffffffffed8000
ffffffffffed8000
ffffffffffed8001
ffffffffffed8002
ffffffffffed8003
ffffffffffed8004
ffffffffffed8005
ffffffffffed8006
ffffffffffed8000
ffffffffffed8001
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.