Class: Xlogin::SessionPool

Inherits:
Object
  • Object
show all
Defined in:
lib/xlogin/session_pool.rb

Constant Summary collapse

DEFAULT_SIZE =
1
DEFAULT_IDLE =
false

Instance Method Summary collapse

Constructor Details

#initialize(args, **opts) ⇒ SessionPool

Returns a new instance of SessionPool.



10
11
12
13
14
15
16
17
18
19
# File 'lib/xlogin/session_pool.rb', line 10

def initialize(args, **opts)
  @args  = args
  @opts  = opts

  @mutex = Mutex.new
  @queue = Queue.new

  @created  = 0
  @watchdog = Hash.new
end

Instance Method Details

#idleObject



28
29
30
31
32
33
# File 'lib/xlogin/session_pool.rb', line 28

def idle
  case @args
  when String then @opts[:idle] || DEFAULT_IDLE
  when Hash   then @args[:idle] || DEFAULT_IDLE
  end
end

#sizeObject



21
22
23
24
25
26
# File 'lib/xlogin/session_pool.rb', line 21

def size
  case @args
  when String then @opts[:size] || DEFAULT_SIZE
  when Hash   then @args[:size] || DEFAULT_SIZE
  end
end

#withObject



35
36
37
38
39
40
41
42
# File 'lib/xlogin/session_pool.rb', line 35

def with
  session = deq
  begin
    Thread.handle_interrupt(Exception => :immediate) { yield session }
  ensure
    enq(session)
  end
end