Class: OCI8::ConnectionPool
- Defined in:
- lib/oci8/connection_pool.rb,
ext/oci8/connection_pool.c
Overview
Connection pooling is the use of a group (the pool) of reusable physical connections by several sessions to balance loads. See: Oracle Call Interface Manual
This is equivalent to Oracle JDBC Driver OCI Connection Pooling.
Usage:
# Create a connection pool.
# username and password are required to establish an implicit primary session.
cpool = OCI8::ConnectionPool.new(1, 5, 2, username, password, database)
# Get a session from the pool.
# Pass the connection pool to the third argument.
conn1 = OCI8.new(username, password, cpool)
# Get another session.
conn2 = OCI8.new(username, password, cpool)
Instance Method Summary collapse
-
#busy_count ⇒ Integer
Returns the number of busy physical connections.
- #destroy ⇒ Object
-
#incr ⇒ Integer
Returns the connection increment parameter.
-
#max ⇒ Integer
Returns the number of maximum physical connections.
-
#min ⇒ Integer
Returns the number of minimum physical connections.
-
#nowait=(val) ⇒ Object
Changes the behavior when all the connections in the pool are busy and the number of connections has already reached the maximum.
-
#nowait? ⇒ Boolean
If true, an error is thrown when all the connections in the pool are busy and the number of connections has already reached the maximum.
-
#open_count ⇒ Integer
Returns the number of open physical connections.
-
#reinitialize(min, max, incr) ⇒ Object
Changes the the number of minimum connections, the number of maximum connections and the connection increment parameter.
-
#timeout ⇒ Integer
Connections idle for more than this time value (in seconds) are terminated, to maintain an optimum number of open connections.
-
#timeout=(val) ⇒ Object
Changes the timeout in seconds to terminate idle connections.
Instance Method Details
#busy_count ⇒ Integer
Returns the number of busy physical connections.
71 72 73 |
# File 'lib/oci8/connection_pool.rb', line 71 def busy_count attr_get_ub4(OCI_ATTR_CONN_BUSY_COUNT) end |
#destroy ⇒ Object
104 105 106 |
# File 'lib/oci8/connection_pool.rb', line 104 def destroy free end |
#incr ⇒ Integer
Returns the connection increment parameter.
99 100 101 |
# File 'lib/oci8/connection_pool.rb', line 99 def incr attr_get_ub4(OCI_ATTR_CONN_INCR) end |
#max ⇒ Integer
Returns the number of maximum physical connections.
92 93 94 |
# File 'lib/oci8/connection_pool.rb', line 92 def max attr_get_ub4(OCI_ATTR_CONN_MAX) end |
#min ⇒ Integer
Returns the number of minimum physical connections.
85 86 87 |
# File 'lib/oci8/connection_pool.rb', line 85 def min attr_get_ub4(OCI_ATTR_CONN_MIN) end |
#nowait=(val) ⇒ Object
Changes the behavior when all the connections in the pool are busy and the number of connections has already reached the maximum.
64 65 66 |
# File 'lib/oci8/connection_pool.rb', line 64 def nowait=(val) attr_set_ub1(OCI_ATTR_CONN_NOWAIT, val ? 1 : 0) end |
#nowait? ⇒ Boolean
If true, an error is thrown when all the connections in the pool are busy and the number of connections has already reached the maximum. Otherwise the call waits till it gets a connection. The default value is false.
55 56 57 |
# File 'lib/oci8/connection_pool.rb', line 55 def nowait? attr_get_ub1(OCI_ATTR_CONN_NOWAIT) != 0 end |
#open_count ⇒ Integer
Returns the number of open physical connections.
78 79 80 |
# File 'lib/oci8/connection_pool.rb', line 78 def open_count attr_get_ub4(OCI_ATTR_CONN_OPEN_COUNT) end |
#reinitialize(min, max, incr) ⇒ Object
Changes the the number of minimum connections, the number of maximum connections and the connection increment parameter.
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 |
# File 'ext/oci8/connection_pool.c', line 153
static VALUE oci8_cpool_reinitialize(VALUE self, VALUE conn_min, VALUE conn_max, VALUE conn_incr)
{
oci8_cpool_t *cpool = DATA_PTR(self);
OraText *pool_name;
sb4 pool_name_len;
/* check arguments */
Check_Type(conn_min, T_FIXNUM);
Check_Type(conn_max, T_FIXNUM);
Check_Type(conn_incr, T_FIXNUM);
chker2(OCIConnectionPoolCreate(oci8_envhp, oci8_errhp, cpool->base.hp.poolhp,
&pool_name, &pool_name_len, NULL, 0,
FIX2UINT(conn_min), FIX2UINT(conn_max),
FIX2UINT(conn_incr),
NULL, 0, NULL, 0, OCI_CPOOL_REINITIALIZE),
&cpool->base);
return self;
}
|
#timeout ⇒ Integer
Connections idle for more than this time value (in seconds) are terminated, to maintain an optimum number of open connections. If it is zero, the connections are never timed out. The default value is zero.
Note: Shrinkage of the pool only occurs when there is a network round trip. If there are no operations, then the connections stay alive.
40 41 42 |
# File 'lib/oci8/connection_pool.rb', line 40 def timeout attr_get_ub4(OCI_ATTR_CONN_TIMEOUT) end |
#timeout=(val) ⇒ Object
Changes the timeout in seconds to terminate idle connections.
47 48 49 |
# File 'lib/oci8/connection_pool.rb', line 47 def timeout=(val) attr_set_ub4(OCI_ATTR_CONN_TIMEOUT, val) end |