Module: ASIR::UUID
Overview
Provides an RFC4122-compliant random (version 4) UUID service.
Constant Summary collapse
- PROC_SYS_FILE =
Return an RFC4122-compliant random (version 4) UUID, represented as a string of 36 characters.
Possible (but unlikely!) return value:
"e29fc859-8d6d-4c5d-aa5a-1ab726f4a192".
Possible exceptions:
Errno::ENOENT
"/proc/sys/kernel/random/uuid".freeze
- UUID_REGEX =
/\A[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\Z/i
- COUNTER_UUID_REGEX =
/\A([0-9]+)-([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})\Z/i
- @@pid =
@@process_uuid = nil
- @@process_uuid_mutex =
Mutex.new
- @@counter_mutex =
Mutex.new
- @@thread_uuid_mutex =
Mutex.new
Instance Method Summary collapse
- #counter_uuid ⇒ Object
- #process_uuid ⇒ Object
-
#thread_uuid(thr = nil) ⇒ Object
Returns a unique counter_uuid for a Thread.
Instance Method Details
#counter_uuid ⇒ Object
45 46 47 48 49 50 |
# File 'lib/asir/uuid.rb', line 45 def counter_uuid i = @@counter_mutex.synchronize do @@counter += 1 end "#{i}-#{process_uuid}" end |
#process_uuid ⇒ Object
33 34 35 36 37 38 39 40 41 |
# File 'lib/asir/uuid.rb', line 33 def process_uuid @@process_uuid_mutex.synchronize do if @@pid != $$ @@pid = $$ @@process_uuid = nil end @@process_uuid ||= new_uuid end end |
#thread_uuid(thr = nil) ⇒ Object
Returns a unique counter_uuid for a Thread. thr defaults to Thread.current.
57 58 59 60 61 62 |
# File 'lib/asir/uuid.rb', line 57 def thread_uuid thr = nil thr ||= Thread.current @@thread_uuid_mutex.synchronize do thr[:'ASIR::UUID.thread_uuid'] ||= counter_uuid end end |