Class: SmscManager::BroadcastTopic
- Inherits:
-
Object
- Object
- SmscManager::BroadcastTopic
- Defined in:
- lib/smsc_manager/broadcast_topic.rb
Overview
this class helps to broadcast sms to list
Constant Summary collapse
- @@MAX_THROUGHPUT =
in messages per second
5
Instance Attribute Summary collapse
-
#attempts ⇒ Object
old attr_accessor :text, :source, :list, :num_threads, :attempts, :sent.
-
#list ⇒ Object
old attr_accessor :text, :source, :list, :num_threads, :attempts, :sent.
-
#num_threads ⇒ Object
old attr_accessor :text, :source, :list, :num_threads, :attempts, :sent.
-
#sent ⇒ Object
old attr_accessor :text, :source, :list, :num_threads, :attempts, :sent.
-
#sms_sender ⇒ Object
old attr_accessor :text, :source, :list, :num_threads, :attempts, :sent.
-
#source ⇒ Object
old attr_accessor :text, :source, :list, :num_threads, :attempts, :sent.
-
#text ⇒ Object
old attr_accessor :text, :source, :list, :num_threads, :attempts, :sent.
Instance Method Summary collapse
- #common_setup(src) ⇒ Object
-
#initialize(src, lst, txt = nil) ⇒ BroadcastTopic
constructor
initialize with list of destionations, texts eg different text for each destination initialize with common text and list of destinations.
-
#populate_topic(lst) ⇒ Object
populate thread safe queue.
- #send_it(txt, dst) ⇒ Object
Constructor Details
#initialize(src, lst, txt = nil) ⇒ BroadcastTopic
initialize with list of destionations, texts eg different text for each destination initialize with common text and list of destinations
20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/smsc_manager/broadcast_topic.rb', line 20 def initialize(src, lst, txt=nil) common_setup(src) self.list=lst self.text=txt # puts "lst.size is #{lst.size}" raise BadList.new("use send_sms for lists of size 1") if lst.class==String @list_queue=Queue.new self.populate_topic(lst) # raise InvalidPrefix.new("invalid prefix: valid prefix area:" + Sms.valid ) if !prefix_test end |
Instance Attribute Details
#attempts ⇒ Object
old attr_accessor :text, :source, :list, :num_threads, :attempts, :sent
11 12 13 |
# File 'lib/smsc_manager/broadcast_topic.rb', line 11 def attempts @attempts end |
#list ⇒ Object
old attr_accessor :text, :source, :list, :num_threads, :attempts, :sent
11 12 13 |
# File 'lib/smsc_manager/broadcast_topic.rb', line 11 def list @list end |
#num_threads ⇒ Object
old attr_accessor :text, :source, :list, :num_threads, :attempts, :sent
11 12 13 |
# File 'lib/smsc_manager/broadcast_topic.rb', line 11 def num_threads @num_threads end |
#sent ⇒ Object
old attr_accessor :text, :source, :list, :num_threads, :attempts, :sent
11 12 13 |
# File 'lib/smsc_manager/broadcast_topic.rb', line 11 def sent @sent end |
#sms_sender ⇒ Object
old attr_accessor :text, :source, :list, :num_threads, :attempts, :sent
11 12 13 |
# File 'lib/smsc_manager/broadcast_topic.rb', line 11 def sms_sender @sms_sender end |
#source ⇒ Object
old attr_accessor :text, :source, :list, :num_threads, :attempts, :sent
11 12 13 |
# File 'lib/smsc_manager/broadcast_topic.rb', line 11 def source @source end |
#text ⇒ Object
old attr_accessor :text, :source, :list, :num_threads, :attempts, :sent
11 12 13 |
# File 'lib/smsc_manager/broadcast_topic.rb', line 11 def text @text end |
Instance Method Details
#common_setup(src) ⇒ Object
12 13 14 15 16 17 |
# File 'lib/smsc_manager/broadcast_topic.rb', line 12 def common_setup(src) @guard = Mutex.new self.attempts=0 self.sent=0 self.source=src end |
#populate_topic(lst) ⇒ Object
populate thread safe queue
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/smsc_manager/broadcast_topic.rb', line 33 def populate_topic(lst) # puts "list is #{lst}" arg_hash = {:host => 'localhost'} self.sms_sender=SmscManager::SmsSendTopic.new(arg_hash) lst.each {|key, val| # txt=line[1] || # if value set then send it else send default text value txt2 = val==nil ? self.text : val dst = key # puts "text is #{txt2} dest is #{dst}" send_it(txt2,dst) if SmscManager::Sms.check_destination(dst) # puts " dst is #{dst}" } sleep(2) # should we wait till we get receipts for all? puts "populate topic sent #{self.sent}" sleep(self.attempts*0.5+1) if self.sent!=self.attempts puts "populate topic sent after sleep #{self.sent}" self.sms_sender.disconnect_stomp end |
#send_it(txt, dst) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/smsc_manager/broadcast_topic.rb', line 54 def send_it(txt,dst) # puts "hello from send it" begin sms=SmscManager::Sms.new(txt,dst,self.source) self.sms_sender.send_topic_sms_receipt(sms) {|r| # puts "in receipt handler #{r.to_s}" self.sent+=1 } self.attempts+=1 rescue Exception => e self.sent-=1 puts "bad values dst: #{dst} txt: #{txt} msg: #{e.}" end # self.sms_sender.close_topic end |