Skip to content

Commit

Permalink
Make sure a pool can be re-used
Browse files Browse the repository at this point in the history
  • Loading branch information
jarib committed May 12, 2012
1 parent 304507a commit 9d962db
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions lib/vnctools/server_pool.rb
Expand Up @@ -3,16 +3,21 @@ class ServerPool
include Observable include Observable


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

create_servers
end end


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

create_servers
end end


def size def size
Expand Down Expand Up @@ -58,6 +63,10 @@ def next_server
server server
end end


def create_servers
@servers = Array.new(@capacity) { @server_class.new }
end

class TooManyDisplaysError < StandardError class TooManyDisplaysError < StandardError
end end


Expand Down

0 comments on commit 9d962db

Please sign in to comment.