MurugaRaj
2009-Dec-24 03:49 UTC
[Backgroundrb-devel] can''t return array object from worker
Hello all, Subject: Not able to return object from backgroundrb worker I am trying to use xmpp4r and backgroundrb for my chat application. I am able to create a connectnion with XMPP4r through a worker in backgrounddrb. I have the problem in returning the object from the worker to my rails application. My code is as follows: class ChatWorker < BackgrounDRb::MetaWorker require ''xmpp4r'' require ''xmpp4r/bytestreams'' require ''xmpp4r/roster/helper/roster'' require ''xmpp4r/roster/iq/roster'' include Jabber Jabber::debug = true set_worker_name :chat_worker def create(args = nil) # this method is called, when worker is loaded for the first time logger.info ''Initializing Chat Worker.......'' end def connect_chat(args) logger.info "Conencting chat.......#{args[:username]} --" jid = Jabber::JID.new(args[:username]) @client = Jabber::Client.new(jid) @client.connect @client.auth(args[:password]) @client.send(Jabber::Presence.new.set_show(nil).set_status(''From Rails!'')) logger.info "Chat Connection status - #{@client.is_connected?}" return @client.is_connected? end def connected? return @client.is_connected? end def get_buddies if self.connected? @buddy_list = [] roster = Jabber::Roster::Helper.new(@client) mainthread = Thread.current roster.add_query_callback { |iq| mainthread.wakeup } Thread.stop roster.groups.each { |group| roster.find_by_group(group).each { |item| @buddy_list << item#[{:name => item.iname, :jid => item.jid, :subscription => item.subscription}] } } logger.info "Buddies\n#{@buddy_list.inspect}" return @buddy_list end end When i call the connect_chat worker method from console i am able to connect to the server as below. MiddleMan.worker(:chat_worker).connect_chat(:arg => {:username => ''xxx at gmail.com'',:password => ''xxxx''}) But when i try to call the get_buddies worker method, i am not able to get the buddy list as below. MiddleMan.worker(:chat_worker).get_buddies Even in the log file, i printed the @buddy_list object and its showing the correct result. But it is not returning the result. The problem is with result returning. Could you please help me in solving the issues. I am struggling with this for the whole day. Thank you for your any kind of suggestions. Regards Murugaraj B