Class: SmscManager::BroadcastTopic

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

Raises:



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

#attemptsObject

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

#listObject

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_threadsObject

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

#sentObject

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_senderObject

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

#sourceObject

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

#textObject

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
# 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}" 
             }
  puts "populate topic sent #{self.sent}"
  sleep(1)
  self.sms_sender.disconnect_stomp
end

#send_it(txt, dst) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/smsc_manager/broadcast_topic.rb', line 51

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.message}"
  end
 # self.sms_sender.close_topic
end