Sha256: 46c8046a7d69c3ce24903760d9b58ce3f35bc09c88098503d5e94bca909c0ab8

Contents?: true

Size: 1.13 KB

Versions: 9

Compression:

Stored size: 1.13 KB

Contents

module CukeForker
  class VncServerPool
    include Observable

    def initialize(capacity, klass = VncServer)
      @capacity = capacity
      @servers  = Array.new(capacity) { klass.new }
      @running  = []
    end

    def stop
      running.each do |s|
        fire :on_display_stopping, s
        s.stop
      end
    end

    def size
      @servers.size
    end

    def get
      raise OutOfDisplaysError if @servers.empty?

      server = next_server
      fire :on_display_fetched, server

      server
    end

    def release(server)
      raise TooManyDisplaysError if size == @capacity
      fire :on_display_released, server

      @servers.unshift server
    end

    private

    def fire(*args)
      changed
      notify_observers(*args)
    end

    def running
      @running
    end

    def next_server
      server = @servers.shift

      if server.display.nil?
        fire :on_display_starting, server
        server.start
        @running << server
      end

      server
    end

    class TooManyDisplaysError < StandardError
    end

    class OutOfDisplaysError < StandardError
    end

  end # DisplayPool
end # CukeForker

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
cukeforker-0.0.9 lib/cukeforker/vnc_server_pool.rb
cukeforker-0.0.8 lib/cukeforker/vnc_server_pool.rb
cukeforker-0.0.7 lib/cukeforker/vnc_server_pool.rb
cukeforker-0.0.6 lib/cukeforker/vnc_server_pool.rb
cukeforker-0.0.5 lib/cukeforker/vnc_server_pool.rb
cukeforker-0.0.4 lib/cukeforker/vnc_server_pool.rb
cukeforker-0.0.3 lib/cukeforker/vnc_server_pool.rb
cukeforker-0.0.2 lib/cukeforker/vnc_server_pool.rb
cukeforker-0.0.1 lib/cukeforker/vnc_server_pool.rb