Class: Scriptroute::ConnectionPool
- Inherits:
-
Object
- Object
- Scriptroute::ConnectionPool
- Defined in:
- lib/scriptroute.rb
Overview
Connection pool in case the script requires more than one connection to the server (for concurrent tests).
Constant Summary collapse
- @@connections_cache =
[]
- @@connections_mutex =
Connection pool mutex.
Mutex.new
Class Method Summary collapse
-
.get_idle_connection ⇒ ScriptrouteConnection
Fetch from the connection pool or create a new connection.
- .return_idle_connection(c) ⇒ void
Class Method Details
.get_idle_connection ⇒ ScriptrouteConnection
Fetch from the connection pool or create a new connection
155 156 157 158 159 160 161 162 163 164 165 |
# File 'lib/scriptroute.rb', line 155 def ConnectionPool.get_idle_connection @@connections_mutex.lock if @@connections_cache.empty? then @@connections_mutex.unlock return ScriptrouteConnection.new else ret = @@connections_cache.shift @@connections_mutex.unlock return ret end end |
.return_idle_connection(c) ⇒ void
This method returns an undefined value.
168 169 170 171 172 |
# File 'lib/scriptroute.rb', line 168 def ConnectionPool.return_idle_connection(c) @@connections_mutex.synchronize { @@connections_cache.push(c) } end |