File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to schedule a subscriber program to continuously run for a specified duration

 
Sindhu Kodoor
Ranch Hand
Posts: 66
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

There is a requirement to schedule the subscriber stand alone program to keep running for duration of system date + 6 days , when it is system date + 6days it should stop running or if there is a stop file ( any file named as stop file) within a specified directory, then also it should stop running.

Please can you suggest me ways of continuously keep the subscriber program running ( esp the onMessage() method ), even though there are messages published for that topic or not , it should keep running and once a message is published then it should retrieve the message.

Kindly help!

 
Sindhu Kodoor
Ranch Hand
Posts: 66
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please anyone reply
 
Sindhu Kodoor
Ranch Hand
Posts: 66
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Since the subscriber is a standalone program i.e, with the main method , is it ok to use the current Thread.sleep(Long l) or Thread.wait() ?
 
ramprasad madathil
Ranch Hand
Posts: 489
Eclipse IDE Java Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please can you suggest me ways of continuously keep the subscriber program running ( esp the onMessage() method ), even though there are messages published for that topic or not , it should keep running and once a message is published then it should retrieve the message.


The start() method of the Connection object is a bootstrap facility that precisely does that. There is no need to do anything more.
Create a connection from the connection factory, a session from the connection and a subscriber from the session. Calling start() on the connection ensures that the messages start flowing into the subscriber until stop() is called.

Going back to your original question of scheduling a subscriber for a specific period of time, you would have to have a seperate thread that polls the directory for your stop file or else checks for elapsed time. This thread would have a handle to the connection object and would call stop() and close() on the connection object whenever a condition evaluates to true.

cheers,
ram.

 
Sindhu Kodoor
Ranch Hand
Posts: 66
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot ramprasad it works now !!
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic