boogaloo 0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. data/CHANGELOG +2 -0
  2. data/DEBUGGING +4 -0
  3. data/MIT-LICENSE +7 -0
  4. data/README +106 -0
  5. data/RUNNING_UNIT_TESTS +5 -0
  6. data/Rakefile +44 -0
  7. data/bin/boogaloo +159 -0
  8. data/doc/classes/Boogaloo.html +149 -0
  9. data/doc/classes/Boogaloo/Cache.html +121 -0
  10. data/doc/classes/Boogaloo/Cache/Base.html +664 -0
  11. data/doc/classes/Boogaloo/Cache/Persistent.html +122 -0
  12. data/doc/classes/Boogaloo/Cache/Temporary.html +439 -0
  13. data/doc/classes/Boogaloo/Client.html +111 -0
  14. data/doc/classes/Boogaloo/Client/Connection.html +228 -0
  15. data/doc/classes/Boogaloo/Config.html +540 -0
  16. data/doc/classes/Boogaloo/ServiceGateway.html +176 -0
  17. data/doc/classes/Boogaloo/ServiceRequest.html +210 -0
  18. data/doc/classes/Boogaloo/ThreadPool.html +205 -0
  19. data/doc/classes/Boogaloo/WorkerThread.html +239 -0
  20. data/doc/created.rid +1 -0
  21. data/doc/files/DEBUGGING.html +113 -0
  22. data/doc/files/MIT-LICENSE.html +129 -0
  23. data/doc/files/README.html +261 -0
  24. data/doc/files/examples/boogaloo_conf.html +130 -0
  25. data/doc/files/lib/boogaloo/cache/base_rb.html +101 -0
  26. data/doc/files/lib/boogaloo/cache/persistent_rb.html +108 -0
  27. data/doc/files/lib/boogaloo/cache/temporary_rb.html +101 -0
  28. data/doc/files/lib/boogaloo/client/connection_rb.html +101 -0
  29. data/doc/files/lib/boogaloo/config_rb.html +109 -0
  30. data/doc/files/lib/boogaloo/service_gateway_rb.html +110 -0
  31. data/doc/files/lib/boogaloo/service_request_rb.html +108 -0
  32. data/doc/files/lib/boogaloo/thread_pool_rb.html +101 -0
  33. data/doc/files/lib/boogaloo/util_rb.html +240 -0
  34. data/doc/files/lib/boogaloo/version_rb.html +114 -0
  35. data/doc/files/lib/boogaloo/worker_thread_rb.html +101 -0
  36. data/doc/fr_class_index.html +38 -0
  37. data/doc/fr_file_index.html +41 -0
  38. data/doc/fr_method_index.html +67 -0
  39. data/doc/index.html +24 -0
  40. data/doc/rdoc-style.css +208 -0
  41. data/examples/boogaloo.conf +17 -0
  42. data/lib/boogaloo/cache/base.rb +222 -0
  43. data/lib/boogaloo/cache/persistent.rb +15 -0
  44. data/lib/boogaloo/cache/temporary.rb +173 -0
  45. data/lib/boogaloo/client/connection.rb +55 -0
  46. data/lib/boogaloo/config.rb +206 -0
  47. data/lib/boogaloo/service_gateway.rb +37 -0
  48. data/lib/boogaloo/service_request.rb +39 -0
  49. data/lib/boogaloo/thread_pool.rb +40 -0
  50. data/lib/boogaloo/util.rb +29 -0
  51. data/lib/boogaloo/version.rb +1 -0
  52. data/lib/boogaloo/worker_thread.rb +46 -0
  53. data/test/test_persistent_cache.rb +99 -0
  54. data/test/test_service_gateway.rb +27 -0
  55. data/test/test_synchronicity.rb +29 -0
  56. data/test/test_temporary_cache.rb +42 -0
  57. metadata +113 -0
data/CHANGELOG ADDED
@@ -0,0 +1,2 @@
1
+ * October 14th 2006 - Ian Leitch
2
+ - Release 0.1
data/DEBUGGING ADDED
@@ -0,0 +1,4 @@
1
+ == Debugging Boogaloo
2
+
3
+ You can either enable debugging via the configuration file by putting 'debug = true' in the _Server_ section, or enable it as the server is running by sending a USR1 signal:
4
+ kill -SIGUSR1 `pidof boogaloo`
data/MIT-LICENSE ADDED
@@ -0,0 +1,7 @@
1
+ Copyright (c) 2006 Refreshing Software
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README ADDED
@@ -0,0 +1,106 @@
1
+ = Boogaloo Simple Cache Server
2
+
3
+ Boogaloo is a very simple cache server that provides permanent and temporary object persistence, with the ability for objects to "expire".
4
+ Boogaloo can also be used for housing custom services, such as a registry or specialized cache implementation.
5
+
6
+ Boogaloo was initially developed for a RubyOnRails application that needed basic persistant object caching across multiple web nodes
7
+ and a mechanism for caching objects related to a user temporarily rather than storing them in the session.
8
+
9
+ == Getting Started
10
+
11
+ Caches are created in Boogaloo by specifying them in the configuration file. For example, to host one persistent and one temporary cache,
12
+ your config may look something like this:
13
+
14
+ Server:
15
+ host: localhost
16
+ port: 7777
17
+ worker_threads: 3
18
+
19
+ PersistentCaches:
20
+
21
+ MyPersistentCache:
22
+ instance_name: main_cache
23
+
24
+ TemporaryCaches:
25
+
26
+ MyTempCache:
27
+ instance_name: temp_cache
28
+ check_frequency: 10
29
+
30
+ 1. +instance_name+ is the method via which the cache instance will be accessed by the client.
31
+ 2. +check_frequency+ is the frequency in seconds at which the cache will check for stale objects to delete.
32
+
33
+ An example configuration file can be found in examples/boogalooo.conf[link:files/examples/boogaloo_conf.html].
34
+
35
+ Next start the Boogaloo server:
36
+
37
+ boogaloo -d -f boogaloo.conf
38
+
39
+ Now on the client we access the caches like this:
40
+
41
+ boogaloo_cache = Boogaloo::Client::Connection.new('localhost', 7777, true)
42
+ boogaloo_cache.main_cache.set(nil, "some_string", "Hello, World!")
43
+ boogaloo_cache.temp_cache.set(nil, "some_string", "Hello, World!", 20)
44
+
45
+ "Hello, World!" will persist for the lifetime of the server in _main_cache_, yet will be deleted in 20 seconds unless touched in _temp_cache_. By "unless touched" we mean that if the object is fetched from the cache with get() 10 seconds after being added, it's expiration
46
+ time will be reset to 20 seconds from the time it was fetched.
47
+
48
+ The boolean value passed into Connection[link:classes/Boogaloo/Client/Connection.html] tells the connection to return nil for all requests if the cache server
49
+ is offline rather than throwing an exception.
50
+
51
+ == Command Line Options
52
+
53
+ [<tt>--config -c</tt>]
54
+ The configuration file to use.
55
+ [<tt>--daemon -d</tt>]
56
+ Run as a stand-alone process.
57
+
58
+ == Custom Services
59
+
60
+ You can also use Boogaloo to house your own custom services. These services can perform any task you want them to, all Boogaloo cares about is that you provide it with an interface to use.
61
+
62
+ Let say we create a new service called _MyService_ and put it in a folder called /home/me/BoogalooServices/MyService, the only required file is an interface.rb
63
+
64
+ module MyService
65
+
66
+ class Interface
67
+
68
+ def initialize(arg1, arg2)
69
+
70
+ self.arg1 = arg1
71
+ self.arg2 = arg2
72
+
73
+ end
74
+
75
+ def arg1
76
+
77
+ self.arg1
78
+
79
+ end
80
+
81
+ def arg2
82
+
83
+ self.arg2
84
+
85
+ end
86
+
87
+ end
88
+
89
+ end
90
+
91
+ And then in our configuration file we put something like:
92
+
93
+ Services:
94
+
95
+ MyService:
96
+ instance_name: my_service
97
+ path: /home/me/BoogalooServices/MyService
98
+ arguments:
99
+ - Hello
100
+ - World
101
+
102
+ Restart Boogaloo and you'll your service will be available as _my_service_ on the client.
103
+
104
+ Boogaloo requires that your _Interface_ class is contained within a module with the same name as specified in the configuration, in this case its _MyService_.
105
+
106
+ Boogaloo can also manage your $LOAD_PATH for you, see the detailed configuration documentation[link:classes/Boogaloo/Config.html] for more information.
@@ -0,0 +1,5 @@
1
+ == Running Unit Tests
2
+
3
+ To run Boogaloo's unit tests:
4
+
5
+ rake test
data/Rakefile ADDED
@@ -0,0 +1,44 @@
1
+ require 'test/unit'
2
+ require 'rake/rdoctask'
3
+ require 'rake/gempackagetask'
4
+ require 'lib/boogaloo/version'
5
+
6
+
7
+ Rake::RDocTask.new do |rd|
8
+
9
+ rd.main = "README"
10
+ rd.rdoc_dir = "doc"
11
+ rd.options << "--inline-source"
12
+ rd.title = "Boogaloo Documentation"
13
+ rd.rdoc_files.include("README", "MIT-LICENSE", "DEBUGGING", "lib/**/*.rb", "examples/*")
14
+
15
+ end
16
+
17
+ task :release => [ :clean, :rerdoc, :build_gem, :create_archive ]
18
+
19
+ task :build_gem do
20
+
21
+ system "gem build boogaloo.gemspec"
22
+
23
+ end
24
+
25
+ task :create_archive do
26
+
27
+ system "tar cvf boogaloo-#{PKG_VERSION}.tar lib/ examples/ doc/ bin/ test/ README MIT-LICENSE CHANGELOG Rakefile RUNNING_UNIT_TESTS"
28
+ system "gzip boogaloo-#{PKG_VERSION}.tar"
29
+
30
+ end
31
+
32
+ task :clean do
33
+
34
+ system "rm examples/*~"
35
+
36
+ end
37
+
38
+ task :test do
39
+
40
+ runner = Test::Unit::AutoRunner.new(true)
41
+ runner.to_run << "test"
42
+ runner.run
43
+
44
+ end
data/bin/boogaloo ADDED
@@ -0,0 +1,159 @@
1
+ #!/usr/bin/ruby
2
+ # Boogaloo Simple Cache Server
3
+ # Copyright 2006 Ian Leitch, Refreshing Software.
4
+
5
+ require 'drb'
6
+ require 'getoptlong'
7
+ require 'rdoc/usage'
8
+
9
+ require 'boogaloo/config'
10
+ require 'boogaloo/thread_pool'
11
+ require 'boogaloo/service_gateway'
12
+ require 'boogaloo/cache/persistent'
13
+ require 'boogaloo/cache/temporary'
14
+
15
+ opts = GetoptLong.new(
16
+ [ '--help', '-h', GetoptLong::NO_ARGUMENT ],
17
+ [ '--config', '-c', GetoptLong::OPTIONAL_ARGUMENT ],
18
+ [ '--daemon', '-d', GetoptLong::OPTIONAL_ARGUMENT ]
19
+ )
20
+
21
+ $debug = false
22
+ config_file = '/etc/boogaloo.conf'
23
+ daemon = false
24
+
25
+ opts.each do |opt, arg|
26
+
27
+ case opt
28
+
29
+ when '--help'
30
+
31
+ RDoc::usage
32
+
33
+ when '--config'
34
+
35
+ config_file = arg
36
+
37
+ when '--daemon'
38
+
39
+ daemon = true
40
+
41
+ end
42
+
43
+ end
44
+
45
+ config = Boogaloo::Config.new(config_file)
46
+ thread_pool = Boogaloo::ThreadPool.new(config.server_worker_threads)
47
+ services = {}
48
+
49
+ def register_caches(services, conf, klass, type)
50
+
51
+ conf.each do |name, cache_config|
52
+
53
+ notice("Registering #{type} cache '#{name}' as '#{cache_config['instance_name']}'")
54
+ services[cache_config['instance_name']] = klass.new(name, cache_config)
55
+
56
+ end
57
+
58
+ end
59
+
60
+ register_caches(services, config.persistent_caches, Boogaloo::Cache::Persistent, 'persistent')
61
+ register_caches(services, config.temporary_caches, Boogaloo::Cache::Temporary, 'temporary')
62
+
63
+ config.services.each do |name, service_config|
64
+
65
+ paths = []
66
+ base_path = File.join(service_config['path'], '..')
67
+ $LOAD_PATH << base_path
68
+ require File.join(service_config['path'], 'interface')
69
+ $LOAD_PATH.delete(base_path)
70
+
71
+ if service_config.key?('require_path')
72
+
73
+ if service_config.key?('require_path').is_a?(Array)
74
+
75
+ service_config.key?('require_path').each do |path|
76
+
77
+ $LOAD_PATH << path
78
+ paths << path
79
+
80
+ end
81
+
82
+ elsif service_config.key?('require_path').is_a?(String)
83
+
84
+ $LOAD_PATH << service_config.key?('require_path')
85
+ paths << path
86
+
87
+ end
88
+
89
+ end
90
+
91
+ notice("Registering service '#{name}' as '#{service_config['instance_name']}'")
92
+
93
+ if service_config.key?('parameters')
94
+
95
+ services[service_config['instance_name']] = eval("#{name}::Interface").new(*service_config['parameters'])
96
+
97
+ else
98
+
99
+ services[service_config['instance_name']] = eval("#{name}::Interface").new()
100
+
101
+ end
102
+
103
+ paths.each { |path| $LOAD_PATH.delete(path) }
104
+
105
+ end
106
+
107
+ def shutdown(pool)
108
+
109
+ if $shutingdown
110
+
111
+ notice("Shutdown forced.")
112
+ exit 1
113
+
114
+ else
115
+
116
+ $shutingdown = true
117
+ notice("Shuting down...")
118
+ warning("Not all threads joined") if not pool.shutdown
119
+ exit 0
120
+
121
+ end
122
+
123
+ end
124
+
125
+ Signal.trap("INT") { shutdown(thread_pool) }
126
+ Signal.trap("TERM") { shutdown(thread_pool) }
127
+ Signal.trap("SEGV") { shutdown(thread_pool) }
128
+ Signal.trap("KILL") { shutdown(thread_pool) }
129
+ Signal.trap("USR1") { $debug = $debug ? false : true; notice("Debugging #{$debug ? 'enabled' : 'disabled'}") }
130
+
131
+ gateway = Boogaloo::ServiceGateway.new(thread_pool, services)
132
+ gateway.freeze
133
+
134
+ proto_str = "druby://#{config.server_host}:#{config.server_port}"
135
+
136
+ if daemon
137
+
138
+ Process.fork {
139
+
140
+ DRb.start_service(proto_str, gateway)
141
+ $SAFE = 1
142
+ notice("Online (#{proto_str}) (PID: #{Process.pid})")
143
+ [ STDIN, STDOUT, STDERR ].each { |io|
144
+ io.reopen("/dev/null", "r+")
145
+ }
146
+ $0 = "boogaloo"
147
+ DRb.thread.join
148
+ exit!
149
+
150
+ }
151
+
152
+ else
153
+
154
+ DRb.start_service(proto_str, gateway)
155
+ $SAFE = 1
156
+ notice("Online (#{proto_str})")
157
+ DRb.thread.join
158
+
159
+ end
@@ -0,0 +1,149 @@
1
+ <?xml version="1.0" encoding="iso-8859-1"?>
2
+ <!DOCTYPE html
3
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
+
6
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
7
+ <head>
8
+ <title>Module: Boogaloo</title>
9
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10
+ <meta http-equiv="Content-Script-Type" content="text/javascript" />
11
+ <link rel="stylesheet" href=".././rdoc-style.css" type="text/css" media="screen" />
12
+ <script type="text/javascript">
13
+ // <![CDATA[
14
+
15
+ function popupCode( url ) {
16
+ window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
17
+ }
18
+
19
+ function toggleCode( id ) {
20
+ if ( document.getElementById )
21
+ elem = document.getElementById( id );
22
+ else if ( document.all )
23
+ elem = eval( "document.all." + id );
24
+ else
25
+ return false;
26
+
27
+ elemStyle = elem.style;
28
+
29
+ if ( elemStyle.display != "block" ) {
30
+ elemStyle.display = "block"
31
+ } else {
32
+ elemStyle.display = "none"
33
+ }
34
+
35
+ return true;
36
+ }
37
+
38
+ // Make codeblocks hidden by default
39
+ document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
40
+
41
+ // ]]>
42
+ </script>
43
+
44
+ </head>
45
+ <body>
46
+
47
+
48
+
49
+ <div id="classHeader">
50
+ <table class="header-table">
51
+ <tr class="top-aligned-row">
52
+ <td><strong>Module</strong></td>
53
+ <td class="class-name-in-header">Boogaloo</td>
54
+ </tr>
55
+ <tr class="top-aligned-row">
56
+ <td><strong>In:</strong></td>
57
+ <td>
58
+ <a href="../files/lib/boogaloo/config_rb.html">
59
+ lib/boogaloo/config.rb
60
+ </a>
61
+ <br />
62
+ <a href="../files/lib/boogaloo/service_gateway_rb.html">
63
+ lib/boogaloo/service_gateway.rb
64
+ </a>
65
+ <br />
66
+ <a href="../files/lib/boogaloo/service_request_rb.html">
67
+ lib/boogaloo/service_request.rb
68
+ </a>
69
+ <br />
70
+ <a href="../files/lib/boogaloo/worker_thread_rb.html">
71
+ lib/boogaloo/worker_thread.rb
72
+ </a>
73
+ <br />
74
+ <a href="../files/lib/boogaloo/thread_pool_rb.html">
75
+ lib/boogaloo/thread_pool.rb
76
+ </a>
77
+ <br />
78
+ <a href="../files/lib/boogaloo/cache/temporary_rb.html">
79
+ lib/boogaloo/cache/temporary.rb
80
+ </a>
81
+ <br />
82
+ <a href="../files/lib/boogaloo/cache/persistent_rb.html">
83
+ lib/boogaloo/cache/persistent.rb
84
+ </a>
85
+ <br />
86
+ <a href="../files/lib/boogaloo/cache/base_rb.html">
87
+ lib/boogaloo/cache/base.rb
88
+ </a>
89
+ <br />
90
+ <a href="../files/lib/boogaloo/client/connection_rb.html">
91
+ lib/boogaloo/client/connection.rb
92
+ </a>
93
+ <br />
94
+ </td>
95
+ </tr>
96
+
97
+ </table>
98
+ </div>
99
+ <!-- banner header -->
100
+
101
+ <div id="bodyContent">
102
+
103
+
104
+
105
+ <div id="contextContent">
106
+
107
+
108
+
109
+ </div>
110
+
111
+
112
+ </div>
113
+
114
+
115
+ <!-- if includes -->
116
+
117
+ <div id="section">
118
+
119
+ <div id="class-list">
120
+ <h3 class="section-bar">Classes and Modules</h3>
121
+
122
+ Module <a href="Boogaloo/Cache.html" class="link">Boogaloo::Cache</a><br />
123
+ Module <a href="Boogaloo/Client.html" class="link">Boogaloo::Client</a><br />
124
+ Class <a href="Boogaloo/Config.html" class="link">Boogaloo::Config</a><br />
125
+ Class <a href="Boogaloo/ServiceGateway.html" class="link">Boogaloo::ServiceGateway</a><br />
126
+ Class <a href="Boogaloo/ServiceRequest.html" class="link">Boogaloo::ServiceRequest</a><br />
127
+ Class <a href="Boogaloo/ThreadPool.html" class="link">Boogaloo::ThreadPool</a><br />
128
+ Class <a href="Boogaloo/WorkerThread.html" class="link">Boogaloo::WorkerThread</a><br />
129
+
130
+ </div>
131
+
132
+
133
+
134
+
135
+
136
+
137
+
138
+ <!-- if method_list -->
139
+
140
+
141
+ </div>
142
+
143
+
144
+ <div id="validator-badges">
145
+ <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
146
+ </div>
147
+
148
+ </body>
149
+ </html>