Sha256: 8fafe6280a0600e58d7136463229f6970a75dde69136c94e86ec9ae8fa1d4de0

Contents?: true

Size: 888 Bytes

Versions: 20

Compression:

Stored size: 888 Bytes

Contents

require 'asir/uuid'
require 'thread' # Mutex

module ASIR
  # !SLIDE
  # Message Identity
  #
  module Identity
    attr_accessor :identifier, :timestamp

    # Optional: Opaque data about the Client that created the Message.
    attr_accessor :client

    # Optional: Opaque data about the Service that handled the Result.
    attr_accessor :server

    # Creates a thread-safe unique identifier.
    def create_identifier!
      @identifier ||= 
        @@identifier_mutex.synchronize do
          if @@uuid_pid != $$
            @@uuid_pid = $$
            @@uuid = nil
          end
          "#{@@counter += 1}-#{@@uuid ||= ::ASIR::UUID.generate}".freeze
        end
    end
    @@counter ||= 0; @@uuid ||= nil; @@uuid_pid = nil; @@identifier_mutex ||= Mutex.new

    # Creates a timestamp.
    def create_timestamp!
      @timestamp ||= 
        ::Time.now.gmtime
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
asir-1.1.12 lib/asir/identity.rb
asir-1.1.11 lib/asir/identity.rb
asir-1.1.10 lib/asir/identity.rb
asir-1.1.9 lib/asir/identity.rb
asir-1.1.8 lib/asir/identity.rb
asir-1.1.7 lib/asir/identity.rb
asir-1.1.6 lib/asir/identity.rb
asir-1.1.5 lib/asir/identity.rb
asir-1.1.4 lib/asir/identity.rb
asir-1.1.3 lib/asir/identity.rb
asir-1.1.2 lib/asir/identity.rb
asir-1.1.1 lib/asir/identity.rb
asir-1.1.0 lib/asir/identity.rb
asir-1.0.8 lib/asir/identity.rb
asir-1.0.7 lib/asir/identity.rb
asir-1.0.6 lib/asir/identity.rb
asir-1.0.5 lib/asir/identity.rb
asir-1.0.4 lib/asir/identity.rb
asir-1.0.1 lib/asir/identity.rb
asir-0.2.0 lib/asir/identity.rb