Class: Pione::Notification::Transmitter
- Inherits:
-
Object
- Object
- Pione::Notification::Transmitter
- Defined in:
- lib/pione/notification/transmitter.rb
Overview
Notification::Transmitter
is a class for transmitting notification
messages to target URI.
Constant Summary collapse
- LOCK =
a lock for transmitting notification messages
Mutex.new
Instance Attribute Summary collapse
-
#uri ⇒ Object
readonly
target URI that the transmitter transmits notification messages to.
Class Method Summary collapse
-
.transmit(message, targets = Global.notification_targets) ⇒ Object
Transmit the notification message to the targets.
Instance Method Summary collapse
-
#close ⇒ Object
Close the transmitter's socket.
-
#initialize(uri) ⇒ Transmitter
constructor
A new instance of Transmitter.
-
#transmit(message) ⇒ void
Transmit the notification message to target URI.
Constructor Details
#initialize(uri) ⇒ Transmitter
Returns a new instance of Transmitter.
33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/pione/notification/transmitter.rb', line 33 def initialize(uri) # URI scheme should be "pnb"(UDP broadcast), "pnm"(UDP multicast), or # "pnu"(UDP unicast) unless ["pnb", "pnm", "pnu"].include?(uri.scheme) raise ArgumentError.new(uri) end if uri.host.nil? or uri.port.nil? raise ArgumentError.new(uri) end @uri = uri open end |
Instance Attribute Details
#uri ⇒ Object (readonly)
target URI that the transmitter transmits notification messages to
29 30 31 |
# File 'lib/pione/notification/transmitter.rb', line 29 def uri @uri end |
Class Method Details
.transmit(message, targets = Global.notification_targets) ⇒ Object
Transmit the notification message to the targets.
12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/pione/notification/transmitter.rb', line 12 def self.transmit(, targets=Global.notification_targets) targets.each do |uri| transmitter = self.new(uri) begin transmitter.transmit() rescue => e Log::SystemLog.warn('Notification transmitter has failed to transmit to "%s": %s' % [uri, e.]) ensure transmitter.close end end end |
Instance Method Details
#close ⇒ Object
Close the transmitter's socket.
60 61 62 |
# File 'lib/pione/notification/transmitter.rb', line 60 def close @socket.close end |
#transmit(message) ⇒ void
This method returns an undefined value.
Transmit the notification message to target URI.
53 54 55 56 57 |
# File 'lib/pione/notification/transmitter.rb', line 53 def transmit() LOCK.synchronize do @socket.send(.dump, 0, @uri.host, @uri.port) end end |