14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
# File 'lib/agent/uuid.rb', line 14
def self.generate
thread = Thread.current
unless thread[:__agent_uuid_limit__]
@counter_mutex.synchronize do
block_base = @counter
@counter += BLOCK_SIZE
thread[:__agent_uuid_counter__] = block_base
thread[:__agent_uuid_limit__] = @counter - 1
end
end
counter = thread[:__agent_uuid_counter__]
if thread[:__agent_uuid_counter__] >= thread[:__agent_uuid_limit__]
thread[:__agent_uuid_counter__] = thread[:__agent_uuid_limit__] = nil
else
thread[:__agent_uuid_counter__] += 1
end
"#{PREFIX}_#{sprintf("%012x", counter)}".freeze
end
|