Class: Wires::Cluster::UDP::Xceiver

Inherits:
Object
  • Object
show all
Defined in:
lib/wires/cluster/udp.rb

Direct Known Subclasses

RX, TX

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(group, port, **kwargs) ⇒ Xceiver

Returns a new instance of Xceiver.



22
23
24
25
26
27
# File 'lib/wires/cluster/udp.rb', line 22

def initialize(group, port, **kwargs)
  @group = group
  @port  = port
  kwargs.each_pair { |k,v| instance_variable_set("@#{k}".to_sym, v) }
  open
end

Instance Attribute Details

#groupObject (readonly)

Returns the value of attribute group.



13
14
15
# File 'lib/wires/cluster/udp.rb', line 13

def group
  @group
end

#local_ipObject (readonly)

Returns the value of attribute local_ip.



13
14
15
# File 'lib/wires/cluster/udp.rb', line 13

def local_ip
  @local_ip
end

#local_portObject (readonly)

Returns the value of attribute local_port.



13
14
15
# File 'lib/wires/cluster/udp.rb', line 13

def local_port
  @local_port
end

#portObject (readonly)

Returns the value of attribute port.



13
14
15
# File 'lib/wires/cluster/udp.rb', line 13

def port
  @port
end

#socketObject (readonly)

Returns the value of attribute socket.



13
14
15
# File 'lib/wires/cluster/udp.rb', line 13

def socket
  @socket
end

Class Method Details

.new(*args) ⇒ Object



15
16
17
18
19
20
# File 'lib/wires/cluster/udp.rb', line 15

def self.new(*args)
  if (self.class==Xceiver)
    raise TypeError, "#{self.class} is an 'abstract class' only."\
                     "  Inherit it; don't instantiate it!"; end
  super
end

Instance Method Details

#closeObject



40
41
42
43
# File 'lib/wires/cluster/udp.rb', line 40

def close
  @socket.close if @socket
  @socket = nil
end

#openObject



29
30
31
32
33
34
35
36
37
38
# File 'lib/wires/cluster/udp.rb', line 29

def open
  @socket.close if @socket
  @socket = UDPSocket.new
  configure
  @local_ip = Socket.ip_address_list.detect{|intf| intf.ipv4_private?}
  @local_port = @socket.addr[1]
  return @socket
ensure
  @finalizer ||= ObjectSpace.define_finalizer self, Proc.new { close }
end