-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
159 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
...d-appender/src/main/java/com/tersesystems/logback/uniqueid/KsuidSubsecondIdGenerator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.tersesystems.logback.uniqueid; | ||
|
||
import com.github.f4b6a3.ksuid.*; | ||
import java.util.Random; | ||
import java.util.concurrent.ThreadLocalRandom; | ||
|
||
/** | ||
* Creates a subsecond KSUID according to <a | ||
* href="https://github.com/f4b6a3/ksuid-creator">https://github.com/f4b6a3/ksuid-creator</a>. | ||
*/ | ||
public class KsuidSubsecondIdGenerator implements IdGenerator { | ||
|
||
private Random random() { | ||
return ThreadLocalRandom.current(); | ||
} | ||
|
||
private final KsuidFactory factory = KsuidFactory.newSubsecondInstance(() -> random().nextLong()); | ||
|
||
@Override | ||
public String generateId() { | ||
return factory.create().toString(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
...ck-uniqueid-appender/src/main/java/com/tersesystems/logback/uniqueid/TsidIdgenerator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.tersesystems.logback.uniqueid; | ||
|
||
import com.github.f4b6a3.tsid.TsidFactory; | ||
|
||
/** | ||
* Generates a TSID according to <a | ||
* href="https://github.com/f4b6a3/tsid-creator">https://github.com/f4b6a3/tsid-creator</a>. | ||
*/ | ||
public class TsidIdgenerator implements IdGenerator { | ||
|
||
// "tsidcreator.node" system property should be set, | ||
// but small hope of that happening, so choose a large node count. | ||
private final TsidFactory factory = TsidFactory.newInstance4096(); | ||
|
||
@Override | ||
public String generateId() { | ||
return factory.create().toString(); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
...ck-uniqueid-appender/src/main/java/com/tersesystems/logback/uniqueid/UlidIdGenerator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.tersesystems.logback.uniqueid; | ||
|
||
import com.github.f4b6a3.ulid.UlidFactory; | ||
import java.util.Random; | ||
import java.util.concurrent.ThreadLocalRandom; | ||
|
||
/** | ||
* Creates a monotonic ULID using a threadlocal random according to <a | ||
* href="https://github.com/f4b6a3/ulid-creator">https://github.com/f4b6a3/ulid-creator</a>. | ||
*/ | ||
public class UlidIdGenerator implements IdGenerator { | ||
|
||
private Random random() { | ||
return ThreadLocalRandom.current(); | ||
} | ||
|
||
private final UlidFactory factory = UlidFactory.newMonotonicInstance(() -> random().nextLong()); | ||
|
||
@Override | ||
public String generateId() { | ||
return factory.create().toString(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters