Sha256: bcf0ac0ae31f7ceb5521615714eb84b549a38cb4e43f387a151a37551cc20e09

Contents?: true

Size: 1.17 KB

Versions: 5

Compression:

Stored size: 1.17 KB

Contents

# Author::    Nicolas Despres  <nicolas.despres@gmail.com>.
# Copyright:: Copyright (c) 2004, 2005 TTK team. All rights reserved.
# License::   LGPL
# $Id: Monitor.rb 567 2005-04-13 08:00:06Z polrop $


require 'drb/drb_observable'
require 'timeout'


module TTK

  module Monitors

    class Monitor
      include DRb::DRbObservable

      NOTIFICATION_TIMEOUT = 5

      def initialize
        @notify_q = Queue.new
        @thread = Thread.new do
          loop do
            observable, msg_type, *infos = @notify_q.pop
            begin
              timeout(NOTIFICATION_TIMEOUT) do
                changed
                notify_observers(observable.class.to_s,
                                 msg_type,
                                 Time.now,
                                 *infos)
              end
            rescue Timeout::Error
              #FIXME: report this failure somehow to the logger. We need to
              #know if some buggy monitor client are connected to the server!
            end
          end
        end
      end

      def update(*args, &block)
        @notify_q.push(args)
      end

    end # class Monitor

  end # module Monitors

end # module TTK

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
ttk-0.1.576 lib/ttk/monitors/Monitor.rb
ttk-0.1.579 lib/ttk/monitors/Monitor.rb
ttk-0.2.0 lib/ttk/monitors/Monitor.rb
ttk-0.1.580 lib/ttk/monitors/Monitor.rb
ttk-0.2.1 lib/ttk/monitors/Monitor.rb