class Pigato::Base

Public Instance Methods

get_iid() click to toggle source
# File lib/pigato/base.rb, line 24
def get_iid 
  iid = get_thread_id + '#' + @iid
  iid
end
get_mtx() click to toggle source
# File lib/pigato/base.rb, line 34
def get_mtx
  tid = get_thread_id

  if @@mtxs[tid].nil?
    @@mtxs[tid] = Mutex.new
  end 

  return @@mtxs[tid]
end
get_proc_id() click to toggle source
# File lib/pigato/base.rb, line 19
def get_proc_id
  pid = "#" + Process.pid.to_s
  pid
end
get_socket() click to toggle source
# File lib/pigato/base.rb, line 29
def get_socket
  socket = @@sockets[get_iid]
  socket
end
get_thread_id() click to toggle source
# File lib/pigato/base.rb, line 14
def get_thread_id
  tid = get_proc_id() + "#" + Thread.current.object_id.to_s
  tid
end
init() click to toggle source
# File lib/pigato/base.rb, line 10
def init 
  @iid = SecureRandom.uuid
end
sock_close() click to toggle source
# File lib/pigato/base.rb, line 68
def sock_close
  @@mtx.synchronize {
    pid = get_proc_id()

    iid = get_iid

    socket = @@sockets[iid]
    if socket
      begin
        socket.close
      rescue
      end
      @@sockets.delete(iid)
      @@sockets_ids.delete(iid)
    end
  }
end
sock_create() click to toggle source
# File lib/pigato/base.rb, line 44
def sock_create
  @@mtx.synchronize {
    pid = get_proc_id()
 
    ctx = ZMQ::context
    if ctx == nil then
      ctx = ZMQ::Context.new
      ctx.linger = 0
    end

    socket = ctx.socket ZMQ::DEALER
    sid = SecureRandom.uuid
    socket.identity = sid 
    socket.connect @broker

    if !@conf[:timeout].nil? then
      socket.rcvtimeo = @conf[:timeout]
    end

    @@sockets[get_iid] = socket
    @@sockets_ids[get_iid] = sid 
  }
end
start() click to toggle source
# File lib/pigato/base.rb, line 86
def start
  @active = 1
end
stop() click to toggle source
# File lib/pigato/base.rb, line 90
def stop
  @active = 0
end