Author |
Message
|
danielaphex |
Posted: Tue May 20, 2003 12:26 am Post subject: URGENT!!!!! HOW TO SLEEP A FLOW EXECUTION |
|
|
Apprentice
Joined: 07 Apr 2003 Posts: 28
|
Hi to everyone,
I am getting into trouble when trying to implement a WMQSI Message Flow which must sleep its execution for a concrete period of time.
My first steps led me to develop a code like this:
Quote: |
-- Variables declaration
DECLARE FECHAACTUAL TIMESTAMP;
DECLARE INTERVALO CHAR;
DECLARE VARIACION INTERVAL;
DECLARE FECHAFINAL TIMESTAMP;
-- Extract the current time
SET FECHAACTUAL = CURRENT_TIMESTAMP;
-- An interval of 10 seconds
SET INTERVALO = '10';
-- Casting to IRTERVAL
SET VARIACION = CAST (INTERVALO AS INTERVAL SECOND);
-- Get the final timestamp
SET FECHAFINAL = FECHAACTUAL + VARIACION;
WHILE (FECHAACTUAL <= FECHAFINAL) DO
-- It is calculated a new TIMESTAMP
SET FECHAACTUAL = CURRENT_TIMESTAMP;
-- It is hoped that the flow execution slept here for 10 seconds
END WHILE;
|
But, as WMQSI ESQL Reference Tutorial tells us, the function CURRENT_TIMESTAMP does not change its value from inside a node belonging to a determinated flow so It is not possible to 'stop' a flow execution by following this estrategy.
Does anybody happen any way to get this goal?
I really would appreciate any kind of help.
Thanks a lot, |
|
Back to top |
|
 |
zpat |
Posted: Tue May 20, 2003 12:53 am Post subject: |
|
|
 Jedi Council
Joined: 19 May 2001 Posts: 5866 Location: UK
|
If you code a hard loop like that - you will consume all the CPU in your broker, so even if the timestamp updated - this is not a good idea.
To sleep properly requires that some sort of system wait is used whereby the operating system suspends the thread and later re-dispatches it.
The most obvious way to achieve this would be to code a plug-in node in C or Java that can issue the appropriate system function call.
You can probably adapt one of the support pacs plug-in samples by inserting a sleep call into the code (and removing the other stuff). |
|
Back to top |
|
 |
jefflowrey |
Posted: Tue May 20, 2003 5:29 am Post subject: |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
It is not a recommended practice to have a message flow sleep in any sense.
The main reason it is not recommended is that the message flow is suspended, and so it is not responsive to operational commands. This means it could prevent the broker from shutting down or prevent the execution group from shutting down. What's even worse is that it will prevent the execution group from responding to commands as well. So you can't do ANY full deploys to that broker, as the execution group won't respond.
What are you trying to do, that you want your message flow to pause? And what version are you running, anyway? |
|
Back to top |
|
 |
zpat |
Posted: Tue May 20, 2003 6:03 am Post subject: |
|
|
 Jedi Council
Joined: 19 May 2001 Posts: 5866 Location: UK
|
WMQI/MQSI flows should generally be stateless.
If you want to wait for a reply from another system, then send it a message and end the flow. Have the reply message initiate another flow.
Carry any state data with the message, or store it in the broker database.
The only real reason to wait is to maintain a single unit of work while calling an external system. In such a case you are likely to have to use a plug in node in any event. |
|
Back to top |
|
 |
danielaphex |
Posted: Wed May 21, 2003 7:18 am Post subject: |
|
|
Apprentice
Joined: 07 Apr 2003 Posts: 28
|
I really appreciate everyone,s help but, althought I know that this kind of design is not the best way to implement a funcionality by using WMQSI, I consider I need it.
Lets go to take into account my flow particular considerations.
My goal is to wait until a new record appear in a DB2 database while the time spent does not exceed a predefined time-out. So I think I should code a hard loop that makes a query to the mentioned DB2 table for a determinated period.
Does anybody know any way to cover this requirement?? |
|
Back to top |
|
 |
tbt102 |
Posted: Wed May 21, 2003 8:48 am Post subject: |
|
|
Apprentice
Joined: 21 Apr 2003 Posts: 28
|
Hi danielaphex,
Have you tried attacking this from the DB point of view?
You should be able to set up a trigger and/or stored procedure that will put new records that appear in a DB2 database table onto a queue.
This will add some DB overhead. How much will depend on the number and/or frequency of new records. However the upside is your flow implementation should be cleaner.
Hope this helps. |
|
Back to top |
|
 |
zpat |
Posted: Thu May 22, 2003 12:23 am Post subject: |
|
|
 Jedi Council
Joined: 19 May 2001 Posts: 5866 Location: UK
|
You must use a thread SLEEP function, coding a hard loop is something that most companies would FIRE any programmer for doing on a system that runs more than a single application. You will waste system resources and prevent any other thread from using your processor time.
Get a friendly Java or C programmer to adapt one of the plug-ins to have a thread sleep call in. Code a MQSI flow with a database query and then pass control through the sleep node and loop it around.
Not ideal, but at least you will only lock out the execution group thread and not totally stress the system at the same time. No-one uses "hard loops" unless you were designing something like a imbedded application for use in a kids toy.
The proper design would be to have some other application waiting/looking for the DB2 update and then sending a message into the broker to initiate a flow. You should not really wait in the broker.
If your broker is to be used by any other applications and you do perform any kind of intense loop or wait - please explain to these other guys that you are about to have a major impact on their apps! |
|
Back to top |
|
 |
MikeTamari |
Posted: Thu May 22, 2003 4:15 am Post subject: Use the TIMER plug in... |
|
|
Apprentice
Joined: 04 Feb 2002 Posts: 26
|
I have just started experimenting the TIMER plug in node, IA0K, I also have some flows that need s "wait and check" functionality.
I didn’t fully check my solution to this problem but I think it should work.
Once in the flow, after querying your DB2 and having the need t "wait and retry",
1.send an inhibit message to your queue(that initiated the actual flow)(using pcf commands)
2.initiate a timer flow that periodically sends a message to another queue(very simple, timer can be set to any interval)
3.create a 2nd flow listening to the 2nd queue that queries your DB2
4.Once this 2nd flow finds the appropriate record in the DB2 it will send a "cancel timer" message to the message flow and enable the first queue, thus letting the original flow run, knowing that the required data exists in the DB2.
This may look a little "heavy" but :
The timer plug in is very simple to use.
You will hardly affect cpu usage.
You will achieve your goal.
So what do you think ? |
|
Back to top |
|
 |
kirani |
Posted: Thu May 22, 2003 3:40 pm Post subject: |
|
|
Jedi Knight
Joined: 05 Sep 2001 Posts: 3779 Location: Torrance, CA, USA
|
Writing a plug-in input node could also help in implementing this design. _________________ Kiran
IBM Cert. Solution Designer & System Administrator - WBIMB V5
IBM Cert. Solutions Expert - WMQI
IBM Cert. Specialist - WMQI, MQSeries
IBM Cert. Developer - MQSeries
|
|
Back to top |
|
 |
|