How to generate periodic events?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|

How to generate periodic events?

Jerome Chan
How do I get an application to generate a periodic event? I need
something to run once every 24 hours.


Reply | Threaded
Open this post in threaded view
|

Re: How to generate periodic events?

Bill Schwab
Jerome,

> How do I get an application to generate a periodic event? I need
> something to run once every 24 hours.

This sounds like one of those Linux chron gizmos; I believe NT offers a way
to do that kind of thing too, and you might want to build an app just for
the purpose.  With that said, I have Dolphin apps that run 7x24 on a few
different machines.  They usually do things on the scale of 10 to 30
minutes, but, I do have one task that occurs just after midnight each day.
The 00:00 task is triggered by looking at the current date vs. the date it
was last performed, and done (and the "flag" updated) when they don't match.
It  runs out of a background thread that does automated backups every 5(??)
minutes.  I routinely use 30 minute delays; I don't recall trying anything
longer than that.

Have a good one,

Bill

--
Wilhelm K. Schwab, Ph.D.
[hidden email]


Reply | Threaded
Open this post in threaded view
|

Re: How to generate periodic events?

Dmitry Zamotkin-3
In reply to this post by Jerome Chan
Hi Jerome,

"Jerome Chan" <[hidden email]> wrote in message
news:[hidden email]...
> How do I get an application to generate a periodic event? I need
> something to run once every 24 hours.

I've included a small implementation of such class, based on
BlockingCallMonitor. I suppose no comments needed...

Have a good one,
Dmitry
























begin 666 SynchronizationServer.cls
M(D9I;&5D(&]U="!F<F]M($1O;'!H:6X@4VUA;&QT86QK(#(P,# @<F5L96%S
M92 T+C Q(B$-"@T*3V)J96-T('-U8F-L87-S.B C4WEN8VAR;VYI>F%T:6]N
M4V5R=F5R#0H):6YS=&%N8V5687)I86)L94YA;65S.B G;6]N:71O<B!R=6Y"
M;&]C:R!L87-T4G5N)PT*"6-L87-S5F%R:6%B;&5.86UE<SH@)T1E9F%U;'0G
M#0H)<&]O;$1I8W1I;VYA<FEE<SH@)R<-"@EC;&%S<TEN<W1A;F-E5F%R:6%B
M;&5.86UE<SH@)R<A#0I3>6YC:')O;FEZ871I;VY397)V97(@8V]M;65N=#H@
M)R<A#0H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("$-"@T*
`
end


Reply | Threaded
Open this post in threaded view
|

Re: How to generate periodic events?

Alan Wostenberg-3
In reply to this post by Jerome Chan
> How do I get an application to generate a periodic event? I need
> something to run once every 24 hours.

If the image runs 24x7 and it's just one event every 24 hours try a
fork with a sleep as Bill suggests:

AnObject>> initialize
 [Processor sleep: (60 * 60 * 24 * 1000). self whatever] fork.

The TimeStamp classes contain date arithmetic so you can calculate the
proper millisecond delay from the current time of day. You might have
to deal with problems of larger durations and multiprocessing.

In Windows and/or VB there is limit on the size of these delay
durations -- I think it's a 16 bit unsigned integer. If Dolphin
doesn't wrapper that you'll have to put it into a loop of smaller naps
spanning your 24 hour sleep:

 [1 to: (60 * 24) do: [:i | Processor sleep 60 * 1000]. self whatever]
fork

This fork has a side effect of sending the message from process other
than the user interface, which posess the usual problems of
synchronizing critical regions. If you have no user interface this is
no problem. If you do, and there is any chance your enduser is
something when the clock strikces 24:00, synchronize the critical
region using Semaphore.

Just curious, what what kind of application are you building? I have
to do realtime delay stuff in a voice server application and am
exploring Dolphin as a solution.

-Alan


Reply | Threaded
Open this post in threaded view
|

Re: How to generate periodic events?

Chris Uppal-3
Alan Wostenberg

>  [1 to: (60 * 24) do: [:i | Processor sleep 60 * 1000]. self whatever]
> fork
>
> This fork has a side effect of sending the message from process other
> than the user interface, which posess the usual problems of
> synchronizing critical regions. If you have no user interface this is
> no problem. If you do, and there is any chance your enduser is
> something when the clock strikces 24:00, synchronize the critical
> region using Semaphore.

You can, and possibly should, arrange for code to be executed in the main UI
thread (at the next idle time) by using:

    SessionManager inputState queueDeferredAction: [...code...].

Depending on your app this may be any of:

Necessary -- if you are changing UI elements while a user may be doing
something; the UI framework is (by design, correctly IMO) not inherently
threadsafe.

Desirable -- if it means you can get away without additional explicit
synchronisation.

Pointless -- e.g. if your app has no UI (or the timer never affects the UI)
and is fully threadsafe, or if it never does anything *except* in response
to the timer going off (and it doesn't matter if the timer does go off while
the app is shutting down).

> -Alan

    -- chris


Reply | Threaded
Open this post in threaded view
|

Re: How to generate periodic events?

Jerome Chan
In article <[hidden email]>,
 "Chris Uppal" <[hidden email]> wrote:

> You can, and possibly should, arrange for code to be executed in the main UI
> thread (at the next idle time) by using:
>
>     SessionManager inputState queueDeferredAction: [...code...].

This is the method that I use but I sometimes get a message not
understood exception even when the classes involve have them defined!


Reply | Threaded
Open this post in threaded view
|

Re: How to generate periodic events?

Chris Uppal-3
Jerome,

> >     SessionManager inputState queueDeferredAction: [...code...].
>
> This is the method that I use but I sometimes get a message not
> understood exception even when the classes involve have them defined!

Odd!  I've never seen anything like this at all.

Do you mean that you got a walkback, and were able to confirm that the
message really was being sent to an object of the class you expected ?

    -- chris


Reply | Threaded
Open this post in threaded view
|

Re: How to generate periodic events?

Jerome Chan
In article <[hidden email]>,
 "Chris Uppal" <[hidden email]> wrote:

> Jerome,
>
> > >     SessionManager inputState queueDeferredAction: [...code...].
> >
> > This is the method that I use but I sometimes get a message not
> > understood exception even when the classes involve have them defined!
>
> Odd!  I've never seen anything like this at all.
>
> Do you mean that you got a walkback, and were able to confirm that the
> message really was being sent to an object of the class you expected ?
>
>     -- chris
>
>

No, I get a pop up dialog box. This happens once or twice when I start
up and then goes away.


Reply | Threaded
Open this post in threaded view
|

Re: How to generate periodic events?

Bill Schwab
Jerome,

> No, I get a pop up dialog box. This happens once or twice when I start
> up and then goes away.

I'm with Chris on this one :)  I've never had any problems with
#queueDeferredAction:.  In fact, it's bailed me out of some ugly situations.
Just yesterday, I had a thread that was clobbering itself before it could
clobber something else, and it's great for updating a GUI from background
threads as has been mentioned already.

One crazy thought is that your image might have a large number of
Process(es) lurking such that things might not be executing as soon as you'd
like, and might even be getting executed on startup of a new session rather
than during the session that queueed them????  What do you see in the
Process Monitor?  If it's more than five threads and they don't look
familiar to you, it might be time to terminate them and/or panic your image.
The usual Dolphin threads are timing, undertaker, finalizer, idler, and
main.  Most if not all of the essential Dolphin threads will start another
thread of the same type if they are terminated, but, a backup wouldn't hurt.

Have a good one,

Bill

--
Wilhelm K. Schwab, Ph.D.
[hidden email]


Reply | Threaded
Open this post in threaded view
|

Re: How to generate periodic events?

Chris Uppal-3
In reply to this post by Jerome Chan
Jerome,

> > Do you mean that you got a walkback, and were able to confirm that the
> > message really was being sent to an object of the class you expected ?
>[...]
> No, I get a pop up dialog box. This happens once or twice when I start
> up and then goes away.

Maybe I'm misunderstanding you, but to me that sounds like a walkback
dialog.  If so, then if you choose the "debug" option then you'll be able to
see what the object actually is (as opposed to what you think it is) that
doesn't understand the selector in question.  My *guess* is that you'll find
that you have an uninitialised instvar, or something of that sort.

    -- chris