smsc_manager 0.4.0 → 0.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/CHANGELOG.txt CHANGED
@@ -1,3 +1,6 @@
1
+ Version 0.4.2
2
+
3
+ Activemq support for broacast... other stuff. stomp control file to start/stop projects
1
4
  Version 0.4.0
2
5
  Major improvement to use active mq topics and stomp to send messages and added load test
3
6
 
data/Manifest.txt CHANGED
@@ -19,8 +19,10 @@ lib/smsc_manager/smsc_listener.rb
19
19
  lib/smsc_manager/sms_statistics_listener.rb
20
20
  lib/smsc_manager/sms_send_topic.rb
21
21
  lib/smsc_manager/broadcast.rb
22
+ lib/smsc_manager/broadcast_topic.rb
22
23
  lib/smsc_manager/smsc_connection.rb
23
24
  lib/smsc_manager.rb
24
25
  test/test_helper.rb
25
26
  test/smsc_manager_test.rb
26
27
  examples/receive_sms_controller.rb
28
+ examples/stomp
data/bin/send_sms.rb CHANGED
@@ -2,7 +2,7 @@
2
2
  require 'optparse'
3
3
  def usage
4
4
  puts "Usage: send_sms.rb -u user -m msisdn -s source -t text "
5
- puts "or for example send_sms.rb --user etc."
5
+ puts "or for example send_sms.rb --user etc. -h hostname optional"
6
6
  exit
7
7
  end
8
8
  def parse_options(params)
@@ -12,6 +12,9 @@ def parse_options(params)
12
12
  #puts "paramsp is #{paramsp}"
13
13
  user_flag=msisdn_flag=source_flag=text_flag=true
14
14
  temp_hash = {}
15
+ opts.on("-h","--host VAL", String) {|val| temp_hash[:host ] = val
16
+ puts "host is #{val}"
17
+ }
15
18
  opts.on("-u","--user VAL", String) {|val| temp_hash[:user ] = val
16
19
  puts "user is #{val}"
17
20
  user_flag=false }
@@ -42,10 +45,11 @@ require 'smsc_manager'
42
45
 
43
46
  puts "Finding sms topic to use:"
44
47
  begin
45
- sms_sender=SmscManager::SmsSendTopic.new
48
+ sms_sender=SmscManager::SmsSendTopic.new(arg_hash)
46
49
  rescue Exception => e
47
50
  puts "exception found #{e.backtrace}"
48
51
  end
52
+
49
53
  user=arg_hash[:user]
50
54
  destination=arg_hash[:msisdn]
51
55
  source=arg_hash[:source]
@@ -7,6 +7,11 @@ gem 'daemons'
7
7
  require 'daemons'
8
8
  puts "#{ARGV[0]} Operational Measurement (OM) server:"
9
9
  # begin
10
- Daemons.run('sms_om_server.rb')
11
-
10
+ options = {
11
+ # :ontop => true,
12
+ # :multiple => true,
13
+ :monitor => true
14
+
15
+ }
16
+ Daemons.run(File.join(File.dirname(__FILE__), 'sms_om_server.rb'), options)
12
17
 
@@ -11,8 +11,8 @@ require 'smsc_manager'
11
11
 
12
12
  puts "Starting topic server:"
13
13
  # begin
14
- sms_listener=SmscManager::SmscListener.new.run
15
- sms_listener.join
14
+ SmscManager::SmscListener.new.run
15
+ # sms_listener.join
16
16
  # rescue Exception => e
17
17
  puts "exception found #{e.backtrace}"
18
18
  # end
@@ -7,6 +7,14 @@ gem 'daemons'
7
7
  require 'daemons'
8
8
  puts "#{ARGV[0]} SMS Topic server:"
9
9
  # begin
10
- Daemons.run('sms_topic_server.rb')
10
+ options = {
11
+ # :ontop => true,
12
+ # :multiple => true,
13
+ :monitor => true
14
+
15
+ }
16
+ Daemons.run(File.join(File.dirname(__FILE__), 'sms_topic_server.rb'), options)
17
+
18
+
11
19
 
12
20
 
data/bin/smsc_config.rb CHANGED
@@ -13,7 +13,6 @@ require 'pp'
13
13
  puts "configuring smsc settings"
14
14
  begin
15
15
  smsc=SmscManager::SmscConnection.factory
16
-
17
16
  rescue Exception => e
18
17
  puts "exception found"
19
18
  ensure
data/examples/stomp ADDED
@@ -0,0 +1,37 @@
1
+ #!/bin/bash
2
+ #
3
+ # Copyright (c) Scott Sproule
4
+ #
5
+ # stomp startup Startup script for stomp applications
6
+ #
7
+ # chkconfig: - 85 15
8
+ # description: Stomp manages stomp protocol clients. must start after activemq
9
+ #
10
+
11
+ RETVAL=0
12
+
13
+
14
+
15
+ case "$1" in
16
+ start)
17
+ sms_topic_server_control.rb start
18
+ sms_om_server_control.rb start
19
+ RETVAL=$?
20
+ ;;
21
+ stop)
22
+ sms_topic_server_control.rb stop
23
+ sms_om_server_control.rb stop
24
+ RETVAL=$?
25
+ ;;
26
+ restart)
27
+ sms_topic_server_control.rb restart
28
+ sms_om_server_control.rb restart
29
+ RETVAL=$?
30
+ ;;
31
+ *)
32
+ echo "Usage: stomp {start|stop|restart}"
33
+ exit 1
34
+ ;;
35
+ esac
36
+
37
+ exit $RETVAL
@@ -0,0 +1,58 @@
1
+ # Sms stuff for handling sms
2
+ #require 'monitor'
3
+ require 'thread'
4
+ module SmscManager
5
+ class BadList < RuntimeError
6
+ end
7
+ # this class helps to broadcast sms to list
8
+ class BroadcastTopic
9
+ @@MAX_THROUGHPUT =5 # in messages per second
10
+ # old attr_accessor :text, :source, :list, :num_threads, :attempts, :sent
11
+ attr_accessor :text, :source, :list, :num_threads, :attempts, :sent
12
+ def common_setup(src)
13
+ @guard = Mutex.new
14
+ self.attempts=0
15
+ self.sent=0
16
+ self.source=src
17
+ end
18
+ # initialize with list of destionations, texts eg different text for each destination
19
+ # initialize with common text and list of destinations
20
+ def initialize(src, lst, txt=nil)
21
+ common_setup(src)
22
+ self.list=lst
23
+ self.text=txt
24
+ # puts "lst.size is #{lst.size}"
25
+ raise BadList.new("use send_sms for lists of size 1") if lst.class==String
26
+ @list_queue=Queue.new
27
+ self.populate_topic(lst)
28
+
29
+ # raise InvalidPrefix.new("invalid prefix: valid prefix area:" + Sms.valid ) if !prefix_test
30
+ end
31
+
32
+ # populate thread safe queue
33
+ def populate_topic(lst)
34
+ # puts "list is #{lst}"
35
+ arg_hash = {:host => 'localhost'}
36
+ sms_sender=SmscManager::SmsSendTopic.new(arg_hash)
37
+ lst.each {|key, val|
38
+ # txt=line[1] ||
39
+ # if value set then send it else send default text value
40
+ txt2 = val==nil ? self.text : val
41
+ dst = key
42
+ puts "text is #{txt2} dest is #{dst}"
43
+ begin
44
+ sms=SmscManager::Sms.new(txt2,dst,self.source)
45
+ sms_sender.send_topic(sms)
46
+ self.attempts+=1
47
+ self.sent+=1
48
+ rescue Exception => e
49
+ self.sent-=1
50
+ puts "bad values dst: #{dst} txt: #{txt2} msg: #{e.message}"
51
+ end
52
+
53
+ # puts " dst is #{dst}"
54
+ }
55
+ puts "populate topic sent #{self.sent}"
56
+ end
57
+ end
58
+ end
@@ -8,13 +8,26 @@ class SmsSendTopic
8
8
  attr_accessor :conn
9
9
  #need to define topic, host properly
10
10
  @@TOPIC='/topic/sms'
11
- def initialize
12
- self.conn = Stomp::Connection.open '', '', 'localhost', 61613, false
11
+ def initialize(options={})
12
+ # set up variables using hash
13
+ host = options[:host]==nil ? 'localhost' : options[:host]
14
+ port = options[:port]==nil ? '61613' : options[:port]
15
+ puts "host is: #{host} port is #{port}"
16
+ self.conn = Stomp::Connection.open '', '', host, port, false
13
17
  # self.conn.subscribe @@TOPIC, { :ack =>"auto" }
14
18
  puts "finished initializing"
15
19
  end
20
+ # def initialize()
21
+ # self.conn = Stomp::Connection.open '', '', 'localhost', 61613, false
22
+ # self.conn.subscribe @@TOPIC, { :ack =>"auto" }
23
+ # puts "finished initializing"
24
+ # end
16
25
  def send_sms(text,destination,source)
17
26
  sms=SmscManager::Sms.new(text,destination,source)
27
+ self.send_topic(sms)
28
+ end #send_sms
29
+ def send_topic(sms)
30
+ #sms=SmscManager::Sms.new(text,destination,source)
18
31
  msgbody=sms.to_xml
19
32
  # puts "message body is #{msgbody}"
20
33
  self.conn.send @@TOPIC, msgbody, {'persistent'=>'false'}
@@ -29,7 +29,7 @@ class SmsStatisticsListener
29
29
  }
30
30
  end
31
31
  def run
32
- Thread.new {
32
+ # Thread.new {
33
33
  while true #loop forever
34
34
  # puts "before receive"
35
35
  msg = self.conn.receive
@@ -43,7 +43,7 @@ class SmsStatisticsListener
43
43
  puts "exception found #{e.backtrace}"
44
44
  end
45
45
  end # while
46
- }
46
+ # }
47
47
  # t.join # wait for t to die..
48
48
  end #run
49
49
  end # smsc listener
@@ -18,7 +18,7 @@ class SmscListener
18
18
  puts "finished initializing"
19
19
  end
20
20
  def run
21
- Thread.new {
21
+
22
22
  while true #loop forever
23
23
  # puts "before receive"
24
24
  msg = self.conn.receive
@@ -32,7 +32,7 @@ class SmscListener
32
32
  puts "exception found #{e.backtrace}"
33
33
  end
34
34
  end # while
35
- }
35
+
36
36
  # t.join # wait for t to die..
37
37
  end #run
38
38
  end # smsc listener
@@ -2,7 +2,7 @@ module SmscManager #:nodoc:
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
4
  MINOR = 4
5
- TINY = 0
5
+ TINY = 2
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
@@ -33,6 +33,17 @@ class SmscManagerTest < Test::Unit::TestCase
33
33
  end
34
34
 
35
35
  end
36
+ def test_sms_send_topic
37
+ sms=SmscManager::Sms.new('hello scott','09996557890','websource')
38
+ begin
39
+ smsc=SmscManager::SmsSendTopic.new()
40
+ r=smsc.send_topic(sms)
41
+ end
42
+ puts "test send topic"
43
+ smsc=SmscManager::SmsSendTopic.new({:host => '127.0.0.1'})
44
+ r=smsc.send_topic(sms)
45
+ puts "test send topic after host"
46
+ end
36
47
  def test_smsc_db
37
48
  assert @smsc!=nil, 'smsc nil big problems'
38
49
  oldport=@smsc.port
@@ -54,6 +65,11 @@ class SmscManagerTest < Test::Unit::TestCase
54
65
  b=SmscManager::Broadcast.new('888',list,"hello there")
55
66
  assert b.attempts ==2, "did not send two sms"
56
67
  end
68
+ def test_broadcast_topic_one
69
+ list = %w(9991 9992)
70
+ b=SmscManager::BroadcastTopic.new('888',list,"hello there")
71
+ assert b.attempts ==2, "did not send two sms"
72
+ end
57
73
  def test_broadcast_five
58
74
  list = %w(9991 9992 9993 9994 9995)
59
75
  b=SmscManager::Broadcast.new('888',list,"hello there")
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.4
3
3
  specification_version: 1
4
4
  name: smsc_manager
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.4.0
7
- date: 2007-09-18 00:00:00 +08:00
6
+ version: 0.4.2
7
+ date: 2007-09-19 00:00:00 +08:00
8
8
  summary: connection to smsc via http using kannel
9
9
  require_paths:
10
10
  - lib
@@ -50,11 +50,13 @@ files:
50
50
  - lib/smsc_manager/sms_statistics_listener.rb
51
51
  - lib/smsc_manager/sms_send_topic.rb
52
52
  - lib/smsc_manager/broadcast.rb
53
+ - lib/smsc_manager/broadcast_topic.rb
53
54
  - lib/smsc_manager/smsc_connection.rb
54
55
  - lib/smsc_manager.rb
55
56
  - test/test_helper.rb
56
57
  - test/smsc_manager_test.rb
57
58
  - examples/receive_sms_controller.rb
59
+ - examples/stomp
58
60
  test_files:
59
61
  - test/smsc_manager_test.rb
60
62
  rdoc_options: