Class: RIO::FTP::ConnCache

Inherits:
Object show all
Includes:
Singleton
Defined in:
lib/rio/ftp/conncache.rb

Instance Method Summary collapse

Constructor Details

#initializeConnCache

Returns a new instance of ConnCache.



68
69
70
71
# File 'lib/rio/ftp/conncache.rb', line 68

def initialize()
  @conns = {}
  @count = {}
end

Instance Method Details

#close(uri) ⇒ Object



94
95
96
97
98
# File 'lib/rio/ftp/conncache.rb', line 94

def close(uri)
  key = urikey(uri)
  @count[key] -= 1
  #p "Closed #{uri} count=#{@count[key]}"
end

#connect(uri) ⇒ Object



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/rio/ftp/conncache.rb', line 77

def connect(uri)
  key = urikey(uri)
  unless @conns.has_key?(key)
    @conns[key] = Connection.new(uri)
#          c = @conns[key]
#          ObjectSpace.define_finalizer(c,proc { 
#                                         p "Quit and Close #{uri}"
#                                         if c and !c.closed?
#                                           c.quit 
#                                           c.close
#                                         end
#                                       })
    @count[key] = 0
  end
  @count[key] += 1
  @conns[key]
end

#urikey(uri) ⇒ Object



72
73
74
75
76
# File 'lib/rio/ftp/conncache.rb', line 72

def urikey(uri)
  key_uri = uri.clone
  key_uri.path = ''
  key_uri.to_s
end