aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/mauve/mauve_thread.rb41
-rw-r--r--lib/mauve/notifier.rb9
-rw-r--r--lib/mauve/server.rb2
3 files changed, 22 insertions, 30 deletions
diff --git a/lib/mauve/mauve_thread.rb b/lib/mauve/mauve_thread.rb
index e255653..f6c0cbc 100644
--- a/lib/mauve/mauve_thread.rb
+++ b/lib/mauve/mauve_thread.rb
@@ -50,8 +50,8 @@ module Mauve
end
def freeze
- logger.debug("Freezing")
-
+ logger.debug("Freezing") unless @frozen
+
@frozen = true
20.times { Kernel.sleep 0.1 ; break if @thread.stop? }
@@ -60,36 +60,33 @@ module Mauve
end
def frozen?
- self.alive? and self.stop? and @frozen
+ self.stop?
end
- def thaw
- logger.debug("Thawing")
- @frozen = false
- @thread.wakeup if @thread.stop?
- end
-
- def start
- @logger = nil
- logger.debug("Starting")
- @stop = false
- @thread = Thread.new{ self.run_thread { self.main_loop } }
- end
-
def run
- if self.alive?
- self.thaw
+ if self.alive?
+ if self.stop?
+ logger.debug("Thawing") if @frozen
+ @frozen = false
+ @thread.wakeup
+ end
else
- self.start
+ @logger = nil
+ logger.debug("Starting") if @stop
+ @stop = false
+ @thread = Thread.new{ self.run_thread { self.main_loop } }
end
end
+ alias start run
+ alias thaw run
+
def alive?
@thread.is_a?(Thread) and @thread.alive?
end
def stop?
- !@thread.is_a?(Thread) or @thread.stop?
+ self.alive? and @thread.stop?
end
def join(ok_exceptions=[])
@@ -110,7 +107,7 @@ module Mauve
end
def stop
- logger.debug("Stopping")
+ logger.debug("Stopping") unless @stop
@stop = true
@@ -131,7 +128,7 @@ module Mauve
def kill
logger.debug("Killing")
- @frozen = true
+ @frozen = @stop = true
@thread.kill
logger.debug("Killed")
end
diff --git a/lib/mauve/notifier.rb b/lib/mauve/notifier.rb
index e62f7f4..5bedeb9 100644
--- a/lib/mauve/notifier.rb
+++ b/lib/mauve/notifier.rb
@@ -48,7 +48,6 @@ module Mauve
end
def start
- super
if Configuration.current.notification_methods['xmpp']
#
@@ -76,19 +75,15 @@ module Mauve
Configuration.current.people[username].xmpp = jid unless jid.nil?
end
end
+ super
end
def stop
+ super
if Configuration.current.notification_methods['xmpp']
Configuration.current.notification_methods['xmpp'].close
end
- super
-
- #
- # flush the queue
- #
- main_loop
end
end
diff --git a/lib/mauve/server.rb b/lib/mauve/server.rb
index f9ea769..57ddca8 100644
--- a/lib/mauve/server.rb
+++ b/lib/mauve/server.rb
@@ -30,7 +30,7 @@ module Mauve
#
# This is the order in which the threads should be started.
#
- THREAD_CLASSES = [UDPServer, HTTPServer, Processor, Notifier, Timer]
+ THREAD_CLASSES = [UDPServer, HTTPServer, Processor, Timer, Notifier]
attr_accessor :web_interface
attr_reader :stopped_at, :started_at, :initial_sleep, :packet_buffer, :notification_buffer