Skip to content

Commit

Permalink
[INLONG-11457][SDK] Optimize SequentialID class implementation (apach…
Browse files Browse the repository at this point in the history
…e#11458)



Co-authored-by: gosonzhang <[email protected]>
  • Loading branch information
gosonzhang and gosonzhang authored Nov 5, 2024
1 parent d9fd8bf commit d339ed7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,32 +17,26 @@

package org.apache.inlong.sdk.dataproxy.network;

import java.util.concurrent.atomic.AtomicLong;
import java.security.SecureRandom;
import java.util.concurrent.atomic.AtomicInteger;

public class SequentialID {

private static final long maxId = 2000000000;
private String ip = null;
private AtomicLong id = new AtomicLong(0);
private static final SecureRandom sRandom = new SecureRandom(
Long.toString(System.nanoTime()).getBytes());
private final String ip;
private final AtomicInteger id = new AtomicInteger(sRandom.nextInt());

public SequentialID(String theIp) {
ip = theIp;
}

public synchronized String getNextId() {
if (id.get() > maxId) {
id.set(0);
}
id.incrementAndGet();
return ip + "#" + id.toString() + "#" + System.currentTimeMillis();
public String getNextId() {
return ip + "#" + id.incrementAndGet() + "#" + System.currentTimeMillis();
}

public synchronized long getNextInt() {
if (id.get() > maxId) {
id.set(0);
}
id.incrementAndGet();
return id.get();
public int getNextInt() {
return id.incrementAndGet();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ public boolean tryAcquire() {
* acquireUninterruptibly
*/
public void acquireUninterruptibly() {
packToken.acquireUninterruptibly();;
packToken.acquireUninterruptibly();
}

/**
Expand Down

0 comments on commit d339ed7

Please sign in to comment.