• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: fetch loop
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: fetch loop


  • Subject: Re: fetch loop
  • From: Kieran Kelleher <email@hidden>
  • Date: Mon, 24 Apr 2006 13:27:48 -0400

Er, here it is again... hoping I am less than 30K moderator limit this time!
-----------------------
Create a class, say "CheckRemoteTask" that extends java.util.TimerTask and put your webservice checking code in the run() method. If you are interaction with EOF, then create an editing context in your CheckRemoteTask and use a try/finally to make sure you unlock when finished with it like this....

myEditingContext();
try {
// Check webservice for new data
// do stuff here, create new EO's using the new data

myEditingContext().saveChanges();

} finally {
myEditingContext().unlock();
}


Then to schedule the task to run every 30 seconds just override didFinishLaunching in Application to scheduled the CheckRemoteTask, like this ...

    protected Timer myTimer;
    /**
     * Method invoked when the application has finished launching.
     */
    public void didFinishLaunching() {
        super.didFinishLaunching();

        myTimer = new Timer(true);
        
   // run it every 30 seconds starting first task 1 second from now
        myTimer.schedule(new CheckRemoteTask(), 1000l, 30*1000l);

    }


If you have multiple instances of your app running, then you need to create a separate "singleton" app that fires a direct action to your multiple instance app every 30 secs and the DA can run the code. This ensures the code runs only once every 30 secs in whichever of the multiple instances the adaptor passes the DA to ..... but don't worry about that if you have only one instance of your app running.

HTH, 

-Kieran
________________________________________________________________
Blog: http://webobjects.webhop.org/

On Apr 24, 2006, at 10:56 AM, Philippe Lafoucrière wrote:

Is there a way to create a continous loop in wo ?
I have to check a distant webservice every 30 seconds and fetch new data if available.


 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: fetch loop
      • From: Philippe Lafoucrière <email@hidden>
    • Re: fetch loop
      • From: Mike Schrag <email@hidden>
References: 
 >fetch loop (From: Philippe Lafoucrière <email@hidden>)

  • Prev by Date: Re: How to selectively save EO
  • Next by Date: Re: WOHyperlink and bindings
  • Previous by thread: Re: fetch loop
  • Next by thread: Re: fetch loop
  • Index(es):
    • Date
    • Thread