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



28
29
30
# File 'lib/poseidon/cluster.rb', line 28

def self.guid
  [::Socket.gethostname, ::Process.pid, 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
17
18
19
20
21
22
23
24
# File 'lib/poseidon/cluster.rb', line 14

def self.inc!
  @@sem.synchronize do
    @@inc += 1;

    if @@inc > MAX_INT32
      @@inc = 1
    end

    @@inc
  end
end