Class: Hprose::TcpClient::TcpConnPool
- Inherits:
-
Object
- Object
- Hprose::TcpClient::TcpConnPool
- Defined in:
- lib/hprose/tcpclient.rb
Instance Method Summary collapse
- #close(uri) ⇒ Object
- #free(entry) ⇒ Object
- #get(uri) ⇒ Object
-
#initialize ⇒ TcpConnPool
constructor
A new instance of TcpConnPool.
Constructor Details
#initialize ⇒ TcpConnPool
Returns a new instance of TcpConnPool.
42 43 44 45 |
# File 'lib/hprose/tcpclient.rb', line 42 def initialize @pool = [] @mutex = Mutex.new end |
Instance Method Details
#close(uri) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/hprose/tcpclient.rb', line 65 def close(uri) sockets = [] @mutex.synchronize do @pool.each do |entry| if not entry.uri.nil? and entry.uri == uri then if entry.status == TcpConnStatus::Free then sockets << entry.socket entry.socket = nil entry.uri = nil else entry.status = TcpConnStatus::Closing end end end end freeSockets(sockets) end |
#free(entry) ⇒ Object
82 83 84 85 86 87 88 89 90 91 |
# File 'lib/hprose/tcpclient.rb', line 82 def free(entry) if entry.status == TcpConnStatus::Closing then if not entry.socket.nil? then entry.socket.close entry.socket = nil end entry.uri = nil end entry.status = TcpConnStatus::Free end |
#get(uri) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/hprose/tcpclient.rb', line 46 def get(uri) @mutex.synchronize do @pool.each do |entry| if entry.status == TcpConnStatus::Free then if not entry.uri.nil? and entry.uri == uri then entry.status = TcpConnStatus::Using return entry elsif entry.uri.nil? then entry.status = TcpConnStatus::Using entry.uri = uri return entry end end end entry = TcpConnEntry.new(uri) @pool << entry return entry end end |