servolux 0.6.0 → 0.6.1

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1,3 +1,8 @@
1
+ == 0.6.1 / 2009-07-13
2
+
3
+ * 1 Minor Enhancement
4
+ * Added a method to wait for server shutdown in the Server class
5
+
1
6
  == 0.6.0 / 2009-07-07
2
7
 
3
8
  * 2 Minor Enhancements
@@ -1,4 +1,6 @@
1
1
 
2
+ require 'thread'
3
+
2
4
  # == Synopsis
3
5
  # The Server class makes it simple to create a server-type application in
4
6
  # Ruby. A server in this context is any process that should run for a long
@@ -147,6 +149,8 @@ class Servolux::Server
147
149
  @name = name
148
150
  @activity_thread = nil
149
151
  @activity_thread_running = false
152
+ @mutex = Mutex.new
153
+ @shutdown = nil
150
154
 
151
155
  self.logger = opts.getopt :logger
152
156
  self.pid_file = opts.getopt :pid_file
@@ -172,6 +176,10 @@ class Servolux::Server
172
176
  #
173
177
  def startup
174
178
  return self if running?
179
+ @mutex.synchronize {
180
+ @shutdown = ConditionVariable.new
181
+ }
182
+
175
183
  begin
176
184
  create_pid_file
177
185
  trap_signals
@@ -183,9 +191,42 @@ class Servolux::Server
183
191
  return self
184
192
  end
185
193
 
186
- alias :shutdown :stop # for symmetry with the startup method
187
- alias :int :stop # handles the INT signal
188
- alias :term :stop # handles the TERM signal
194
+ # Stop the server if it is running. This method will return after three
195
+ # things have occurred:
196
+ #
197
+ # 1) The 'before_stopping' method has returned.
198
+ # 2) The server's activity thread has stopped.
199
+ # 3) The 'after_stopping' method has returned.
200
+ #
201
+ # It is entirely possible that the activity thread will stop before either
202
+ # the +before_stopping+ or +after_stopping+ methods return. To make sure
203
+ # the server is completely stopped, use the +wait_for_shutdown+ method to
204
+ # be notified when the this +shutdown+ method is finished executing.
205
+ #
206
+ def shutdown
207
+ return self unless running?
208
+ stop
209
+
210
+ @mutex.synchronize {
211
+ @shutdown.signal
212
+ @shutdown = nil
213
+ }
214
+ self
215
+ end
216
+
217
+ # If the server has been started, this method waits till the +shutdown+
218
+ # method has been called and has completed. The current thread will be
219
+ # blocked until the server has been safely stopped.
220
+ #
221
+ def wait_for_shutdown
222
+ @mutex.synchronize {
223
+ @shutdown.wait(@mutex) unless @shutdown.nil?
224
+ }
225
+ self
226
+ end
227
+
228
+ alias :int :shutdown # handles the INT signal
229
+ alias :term :shutdown # handles the TERM signal
189
230
  private :start, :stop
190
231
 
191
232
  # Returns the PID file name used by the server. If none was given, then
data/lib/servolux.rb CHANGED
@@ -4,7 +4,7 @@ require 'logging'
4
4
  module Servolux
5
5
 
6
6
  # :stopdoc:
7
- VERSION = '0.6.0'
7
+ VERSION = '0.6.1'
8
8
  LIBPATH = ::File.expand_path(::File.dirname(__FILE__)) + ::File::SEPARATOR
9
9
  PATH = ::File.dirname(LIBPATH) + ::File::SEPARATOR
10
10
  # :startdoc:
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: servolux
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tim Pease
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-07-07 00:00:00 -06:00
12
+ date: 2009-07-13 00:00:00 -06:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency