blob: 495299369014b618ecdab85f2166611a96cdb314 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.search.query;
import com.yahoo.container.Server;
import java.util.concurrent.atomic.AtomicLong;
/**
* A query id which is unique across this cluster - consisting of
* container runtime id + timestamp + serial.
*
* @author bratseth
*/
public class UniqueRequestId {
private static final AtomicLong sequenceCounter = new AtomicLong();
private final String id;
private UniqueRequestId(String serverId, long timestamp, long sequence) {
this.id = serverId + "." + timestamp + "." + sequence;
}
@Override
public String toString() { return id; }
/**
* Creates a session id which is unique across the cluster this runtime is a member of each time this is called.
* Calling this causes synchronization.
*
* @deprecated use nextId(serverId) instead
*/
@Deprecated
public static UniqueRequestId next() {
return new UniqueRequestId(Server.get().getServerDiscriminator(), System.currentTimeMillis(), sequenceCounter.getAndIncrement());
}
/**
* Creates a session id which is unique across the cluster this runtime is a member of each time this is called.
* Calling this causes synchronization.
*/
public static UniqueRequestId next(String serverId) {
return new UniqueRequestId(serverId, System.currentTimeMillis(), sequenceCounter.getAndIncrement());
}
}
|