sending messages between jade applications

For questions and postings not covered by the other forums
ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

sending messages between jade applications

Postby ConvertFromOldNGs » Fri Aug 07, 2009 12:46 pm

by Callum George >> Mon, 14 Feb 2005 21:34:49 GMT

I've got two jade applications. By double clicking an item in a table in the first application it opens the second application with the object associated with that table item preloaded. This is supposed to work in exactly the same manner as painter does from a jade development environment (when you right click the painter button in the dev environment while a form class is selected it opens painter with that form preloaded, and if painter is already running it loads the form in that running instance of painter).
The problem I'm facing is that I don't know how to load the object into the second application if the second application is already running.

Has anyone done this before? If so can you give me any tips?

More Info:
I use the method app.startApplicationWithParameter to start the second application and it returns a reference to the started process. However there is not much I can do with this reference. I was hoping I could get a reference to the application class instance of the process and send it a message to load the object. I have noticed that you can get a reference to the application class object from the process in Jade 6 using processReference.getProcessApp but I'm using Jade 5.
In saying that I'm not actually sure that I'm on the right track and have also thought of the possibility of using notifications.

ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Re: sending messages between jade applications

Postby ConvertFromOldNGs » Fri Aug 07, 2009 12:46 pm

by allistar >> Tue, 15 Feb 2005 1:44:11 GMT

The second application should listen for a notification (see "beginNotification"). The first application should send an event that the second application picks up (see "causeEvent").

Regards,
Allistar.
--
------------------------------------------------------------------
Allistar Melville
Software Developer, Analyst allistar@silvermoon.co.nz
Auckland, NEW ZEALAND

Silvermoon Software
Specialising in JADE development and consulting
Visit us at: http://www.silvermoon.co.nz
*NEW* Simple web access to Jade at: www.silvermoon.co.nz/jhp.html ------------------------------------------------------------------

ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Re: sending messages between jade applications

Postby ConvertFromOldNGs » Fri Aug 07, 2009 12:46 pm

by Callum George >> Tue, 15 Feb 2005 2:16:19 GMT

Lets call the applications appA and appB. There may be several instances of both appA and appB running at once in a multiuser system. If I have every instance of appB listening for a notification to load and display an object, how do I specify which instance of appB actually reponds to one? I effectively want every instance of appB to have a parent instance of appA so when the object is being loaded by appA it is only loaded in its child instance of appB, or if appA owns no instance of appB then one is created and the object then loaded.

ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Re: sending messages between jade applications

Postby ConvertFromOldNGs » Fri Aug 07, 2009 12:46 pm

by Patwos >> Tue, 15 Feb 2005 2:46:34 GMT

You've already indicated that you utilise startAppWithParam from AppA to initiate AppB. This means that they are both running within the same Node and you could therefore utilise a sharedTransient for communications between these two applications.

ie: Create the sharedTransient in AppA and pass it as the parameter to startAppWithParam when starting AppB from AppA.

You can then target the notifications to the appropriate AppB without all the other AppB instances being notified by using this sharedTransient.

In the closedown of AppB you would need to ensure that AppA knows it needs to initiate a new AppB the next time around by sending an appropriate notification back to AppA using the sharedTransient.

You definitely don't want to try referencing the AppB's application instance as that will result in a 1266 exception:

1266 - A non-shared transient object is being accessed by another process

Hope that helps,
Pat.

ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Re: sending messages between jade applications

Postby ConvertFromOldNGs » Fri Aug 07, 2009 12:46 pm

by Callum George >> Tue, 15 Feb 2005 4:14:15 GMT

If I understand correctly then you are suggesting that if I create a shared transient on appA and get appB to register for notifications on that object, then when the causeEvent method is initiated on the object by appA only appB receives a notification because it is the only other process that can see the object since it is the only instance of appB on that node. Therefore appB can assume that the notification is meant to be a message for itself to load an object (the object to load would be passed into the userInfo parameter of the causeEvent method of appA and received through the userInfo parameter of the userNotification method on appB).

I understand that this would work if every instance of appA was running as a fat client (ie. it has its own node) and that when it creates an instance of appB it is created as a process that resides on that same node. However this would be a problem for us because our client runs all their application instances as thin clients and there could be as many as 20 people running an instance of appB off the same application server node and therefore share the same database of shared transients.

ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Re: sending messages between jade applications

Postby ConvertFromOldNGs » Fri Aug 07, 2009 12:46 pm

by cnwjhp1 >> Tue, 15 Feb 2005 4:34:40 GMT

No, using Pat's sharedTransient idea, each appA would create its own sharedTransient, and each appB would register for notifications on that individual object, not the class. So other appB's would not get the wrong notifications even if they are thin clients on the same node.

Cheers,
John P

ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Re: sending messages between jade applications

Postby ConvertFromOldNGs » Fri Aug 07, 2009 12:47 pm

by John Beaufoy >> Tue, 15 Feb 2005 10:08:47 GMT

If you go with this solution, be careful to cater for the timing holes mentioned already that arise when starting and terminating the app B. ie.

a) make sure app B has 'initialised' prior to firing any causeEvents from app A; if the beginNotifications have not been set by the time app A fires a causeEvent, app B will not receive them.

b) if you close app B and immediately invoke it again, app A may still reference the app B version shutting down (sending it the causeEvent) and the command/event is ignored.

These issues are often easier to replicate by the insertion of a msgBox to halt execution of app B at these critical points. While it is quite difficult to make a completely watertight solution without a level of complexity, the locking and/or updating of this shared transient may be enough to cater for your requirements.

Cheers,

John Beaufoy
www.nwi.co.nz

ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Re: sending messages between jade applications

Postby ConvertFromOldNGs » Fri Aug 07, 2009 12:47 pm

by Torrie Moore >> Tue, 15 Feb 2005 13:03:14 GMT

We have used mechanisms like this in the past. Assuming that the shared transient will exist while both applications are running, we put a reference to the Process object on the shared transient, which are set by each application when they start. This allows the other app to check if the process object is valid (global.isValidObject) before trying to send the other application a notification. The application can clear this reference when they close down. As John suggests locks can be used to reduce the change of timing holes.

It might be an advantage to put a reference to the object to display, on the shared transient so that when AppA starts AppB, it doesn't then have to wait for B to start so the notification can be sent. AppB on startup would check the reference on the Shared Transient and if it was set, display the relevant object. If AppA wanted B to display another object, it could then set the reference and fire a notification on which B would check the shared transient for details of what to display.

ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Re: sending messages between jade applications

Postby ConvertFromOldNGs » Fri Aug 07, 2009 12:47 pm

by cnwjhp1 >> Tue, 15 Feb 2005 4:13:34 GMT

As you mentioned, appA knows appB's process oid. Why not do the causeEvent on appB's process object?

Also, you can register for a delete event on appB's process object, so appA knows if appB dies unexpectedly.

Cheers,
John P

ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Re: sending messages between jade applications

Postby ConvertFromOldNGs » Fri Aug 07, 2009 12:47 pm

by Callum George >> Tue, 15 Feb 2005 20:05:55 GMT

Yes this works. By keeping a reference from appA to the process object returned by the app.startAppWithParameter method I can tell appB to register for notifications on its own process object, so that when appA wants to load an object in appB it calls the causeEvent method on the process object, passing the database object into the userInfo parameter. AppB then receives a user notification, collects the database object from the userInfo parameter and loads it for the user to see.

Thank you everyone for your help. I'll see how this solution works out.


Return to “General Discussion”

Who is online

Users browsing this forum: No registered users and 21 guests