• Post Reply Bookmark Topic Watch Topic
  • New Topic

Waiting for something to happen  RSS feed

 
Don Kiddick
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The code below defines an class that extracts various details from a response from a server. We then subscribe to a message server, on a specified topic, specifiy that the responses should be processed by the an instance of the class we just defined.
The message sending is asynchronous. I want to wait after I have sent the request, till when I get a response (in the future I will also want to add a timeout). I really can't work out how to do this, if any one could throw any light, I'd be very grateful.
thanks, D.
 
Mr. C Lamont Gilbert
Ranch Hand
Posts: 1170
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
go here and download a chess program I wrote long ago, its GPLed.
http://www.rigidsoftware.com/Chess/Download/download.html
There is a class called IOProcessor that does exactly what you are looking for. So it shoudl give you good ideas. I have made a few improvements since then which are not there, but they are small and you will likely find them yourself.
 
Don Kiddick
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks, but you couldn't give me some pointers could you ? That file is 641 lines long and I'm not sure where exactly I should be looking.
thanks, D.
 
Don Kiddick
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
CL. Thanks again for your reply. I think I've actually found something that will help me.
Will try it out tomorrow !
D.
 
Mr. C Lamont Gilbert
Ranch Hand
Posts: 1170
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look at the run method only. that is what you are worried about. Look at how it uses a state machine, and how it sleeps when there is no work to be done. Look at how when more work comes in to be done, first the threads state isupdated, then the thread is notified.
ignore all the data parsing stuff.
the point was that this thread reads data from a server. it lays dormant when no data is there. when data arrives its brought to life to process it, then it goes back to sleep. that takes at least 2 threads. one monitoring the server for data, and one that is waiting to process that data.
 
Don Kiddick
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
CL. BTW. The Latch worked out perfectly for me thanks....but I'll be sure to take a look at your code when i have a free moment.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!