Module: Poseidon::Cluster

Defined in:
lib/poseidon/cluster.rb

Constant Summary collapse

MAX_INT32 =
0x7fffffff
@@sem =
Mutex.new
@@inc =
0

Class Method Summary collapse

Class Method Details

.guidString

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns an globally unique identifier

Returns:

  • (String)

    an globally unique identifier


20
21
22
# File 'lib/poseidon/cluster.rb', line 20

def self.guid
  [::Socket.gethostname, ::Process.pid, ::Time.now.to_i, inc!].join("-")
end

.inc!Integer

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns an incremented number

Returns:

  • (Integer)

    an incremented number


14
15
16
# File 'lib/poseidon/cluster.rb', line 14

def self.inc!
  @@sem.synchronize { @@inc += 1; @@inc = 1 if @@inc > MAX_INT32; @@inc }
end