Skip to content
This repository has been archived by the owner on Nov 10, 2017. It is now read-only.

Commit

Permalink
added a couple of comments regarding dependent gems. added initial sq…
Browse files Browse the repository at this point in the history
…lite3 address book
  • Loading branch information
brianmario committed Nov 18, 2008
1 parent d1136a3 commit f2e90a5
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 5 deletions.
8 changes: 5 additions & 3 deletions address_books/csv_address_book.rb
Expand Up @@ -11,9 +11,11 @@ def initialize
end

def configure(config)
CSV.open(config['file']) do |row|
@servers << {:host => row[1], :port => row[2].to_i}
end
@mutex.synchronize {
CSV.open(config['file']) do |row|
@servers << {:host => row[1], :port => row[2].to_i}
end
}
end

# this method should return an array of hosts which this request is qualified to connect to.
Expand Down
33 changes: 33 additions & 0 deletions address_books/sqlite3_address_book.rb
@@ -0,0 +1,33 @@
require 'singleton'
require 'thread'
require 'sqlite3' # gem install sqlite3-ruby

class AddressBook
include Singleton

def initialize
@mutex = Mutex.new
end

def configure(config)
@db = SQLite3::Database.new(config['database'])
@query = config['finder_sql']
end

# this method should return an array of hosts which this request is qualified to connect to.
# which is determined based on the contents of the data passed
def lookup_addresses(data)
# TODO: make this use real parameters from the data payload
# Example:
# req_host = data['host']
# @db.execute(@query, req_host)
servers = []
@mutex.synchronize {
@db.execute(@query) do |row|
servers << {:host => row[0], :port => row[1]}
end
}
return servers if servers.any?
return nil
end
end
2 changes: 1 addition & 1 deletion panels/eventmachine_panel.rb
@@ -1,5 +1,5 @@
require 'rubygems'
require 'eventmachine'
require 'eventmachine' # gem install eventmachine
require 'stringio'

class BackendRequest < EventMachine::Connection
Expand Down
2 changes: 1 addition & 1 deletion panels/rev_panel.rb
@@ -1,5 +1,5 @@
require 'rubygems'
require 'rev'
require 'rev' # gem install rev

class BackendRequest < Rev::TCPSocket
attr_accessor :frontend
Expand Down

0 comments on commit f2e90a5

Please sign in to comment.