Skip to content

Commit

Permalink
Changes to logging. A few other boring things.
Browse files Browse the repository at this point in the history
  • Loading branch information
marick committed Jan 7, 2010
1 parent 3ff9fa0 commit bfccf56
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 12 deletions.
11 changes: 4 additions & 7 deletions src/16-multiple/app/main.rb
Expand Up @@ -16,15 +16,14 @@ class Main

def self.main(hostname, username, password, *item_ids)
item_id = item_ids[0]
App::Log.info("App initializing")
App::Log.debug("App initializing")
connection = connection(hostname, username, password)

main = new
ui = main.start_user_interface
disconnect_when_ui_closes(connection, ui)

item_ids.each do | item_id |
puts "====== loop"
main.join_auction(connection, item_id);
end
end
Expand All @@ -33,12 +32,12 @@ def self.connection(hostname, username, password)
connection = XMPP::Connection.new(hostname)
connection.connect
connection.login(username, password, AUCTION_RESOURCE)
App::Log.info("Main connected to XMPP server")
App::Log.debug("Main connected to XMPP server")
connection
end

def start_user_interface
App::Log.info(me("starting user interface"))
App::Log.debug(me("starting user interface"))
SwingUtilities.invoke_and_wait do
# Note: since Main waits for this block to finish, it's
# safe to use @ui elsewhere.
Expand All @@ -49,17 +48,15 @@ def start_user_interface
end

def join_auction(connection, item_id)
puts "===== UM"
chat = connection.chat_manager.create_chat(auction_id(item_id, connection),
nil)
puts "===== UMOPOOOO"
auction = XMPPAuction.new(chat)
auction_sniper = AuctionSniper.new(auction,
SwingThreadSniperListener.new(@snipers),
item_id)
translator = AuctionMessageTranslator.new(connection.user, auction_sniper)
chat.add_message_listener(translator)
App::Log.info(me("sending join-auction message"));
App::Log.debug(me("sending join-auction message"));
auction.join
end

Expand Down
1 change: 1 addition & 0 deletions src/16-multiple/app/xmpp-auction.rb
Expand Up @@ -12,6 +12,7 @@ def join
end

def send_message(text)
App::Log.debug(me("Sniper sending #{text}"))
@chat.send_message(text)
rescue Exception => ex
puts ex.backtrace
Expand Down
2 changes: 2 additions & 0 deletions src/16-multiple/external/blocking-queue.rb
Expand Up @@ -27,13 +27,15 @@ def has_entry?
end

def enqueue (thing)
Log.debug("Blocking queue adding #{thing.inspect}.")
@queue.synchronize do
@queue << thing
@condition.signal
end
end

def dequeue
Log.debug("Going to dequeue from what is currently #{@queue.inspect}.")
@queue.synchronize do
wait_for_something
@queue.shift
Expand Down
3 changes: 2 additions & 1 deletion src/16-multiple/external/util.rb
@@ -1,5 +1,6 @@
def me(text)
self.class.name + " " + text
# "#{self.class.name}@#{self.object_id}: #{text}"
"#{self.class.name}: #{text}"
end

def NullImplementation
Expand Down
5 changes: 3 additions & 2 deletions src/16-multiple/features/support/env.rb
Expand Up @@ -5,10 +5,11 @@
require 'external/blocking-queue'

TestLogger = Logger.new($stdout)
TestLogger.level = Logger::INFO
App::Log.level = Logger::INFO
TestLogger.level = Logger::WARN
App::Log.level = Logger::WARN
BlockingQueue::Log.level = Logger::WARN
SwingUtilities::Log.level = Logger::INFO
XMPP::Log.level = Logger::WARN

After do
@auctions.each { | auction | auction.stop }
Expand Down
8 changes: 6 additions & 2 deletions src/16-multiple/features/support/fake-auction-server.rb
Expand Up @@ -37,8 +37,10 @@ def start_selling_item

def has_received_join_request_from?(sniper_id)
@message_listener.with_next_message do | message |
TestLogger.debug(me("HIT #{item_id} received #{message.inspect}"))
assert { message.body == SOLText.join }
assert { sniper_id == @current_chat.participant }
assert_equal(@current_chat.participant, sniper_id)
true
end
end

Expand All @@ -49,6 +51,7 @@ def report_price(price, increment, bidder)

def has_received_bid?(bid, sniper_id)
@message_listener.with_next_message do | message |
TestLogger.debug(me("HIT #{item_id} received #{message.inspect}"))
assert_equal SOLText.bid(bid), message.body
assert_equal @current_chat.participant, sniper_id
true
Expand Down Expand Up @@ -76,6 +79,7 @@ def process_message(chat, message) # called from XMPP server
end

def with_next_message
yield @messages.dequeue
message = @messages.dequeue
yield message
end
end

0 comments on commit bfccf56

Please sign in to comment.