Class: Expedite::Server::AgentPool

Inherits:
Object
  • Object
show all
Defined in:
lib/expedite/server/agent_pool.rb

Instance Method Summary collapse

Constructor Details

#initialize(name, env) ⇒ AgentPool

Returns a new instance of AgentPool.



7
8
9
10
11
12
# File 'lib/expedite/server/agent_pool.rb', line 7

def initialize(name, env)
  @name = name
  @env = env
  @checked_in = []
  @checked_out = Set.new
end

Instance Method Details

#allObject

Returns all agents, both checked in and checked out



34
35
36
# File 'lib/expedite/server/agent_pool.rb', line 34

def all
  @checked_in + @checked_out.to_a
end

#build_agentObject



29
30
31
# File 'lib/expedite/server/agent_pool.rb', line 29

def build_agent
  Server::AgentManager.new(@name, @env)
end

#checkin(agent) ⇒ Object



24
25
26
27
# File 'lib/expedite/server/agent_pool.rb', line 24

def checkin(agent)
  @checked_out.delete(agent)
  @checked_in.push(agent)
end

#checkoutObject

Get a free agent from the pool



15
16
17
18
19
20
21
22
# File 'lib/expedite/server/agent_pool.rb', line 15

def checkout
  agent = @checked_in.pop

  agent = build_agent if agent.nil?
  @checked_out.add(agent)

  agent
end