logo

More On Running Both LotusScript and Java WQS Agents Simultaneously

In response to yesterday's ponderings it was quickly pointed out that I could easily run two agents in a Form's WQS event by simply calling one from within the other. Imagine this code in the first agent:

Dim agentTwo As NotesAgent
Set agentTwo = database.GetAgent("(wqs Agent Two)")

agentTwo.Run( document.NoteID )

All seems fairly obvious and I don't know why I didn't think to try it in the first place.

However, there's a problem with this approach. Running the second agent against the document in which the first WQS agent was triggered only works if you save the document before running Agent Two and then again before leaving Agent Two.

The first save within Agent One is needed for two reasons.

  1. A new document doesn't have a NoteID, which you need to pass to the other agent, until it's been saved.
  2. Any changes you make to the document in the code in Agent One won't be reflected in the document you see in Agent Two. This is because Agent Two is getting a handle on the document that has been committed to the disk and not the context document, which Agent One is working on.

The second save is called at the end of Agent Two and is needed because we're operating outside the context of the document being saved. We won't be able to access the altered values in Agent One after Agent Two has run as we're effectively working on different instances of the same document. At least that's how I understand it. Although in practice I found that changes made in Agent Two don't commit anyway as they're over-written by the impending save of the document from the completion of Agent One, which is the controlling WQS agent.

All in all, while testing this, I found it doesn't really pan out like you'd hope it would and it's not an approach I'd recommend or like to use myself. The only time I'd use it is if the code in Agent Two was merely reading the document and not making any changes. Then there's the matter of calling doc.save() from within a WQS agent, which I never like to do. It just seems wrong.

In summary, if you want to run two agents in the WQS event -- one LotusScript, one Java -- then I'd still recommend running them one after the other, as shown yesterday and avoid having to save a document which is already being saved. If you want to run Java that merely needs read access to the document then it might work for you.

If you're interested in seeing how I came to the above conclusions here's the database I was messing about with. Put it on a server and watch the console while saving documents. You should get an idea of what's going on.

I'm still leaning toward re-writing the agent in Java though...

Comments

    • avatar
    • Ferdy
    • Fri 18 Jul 2008 04:43 AM

    hi Jake,

    "We won't be able to access the altered values in Agent One after Agent Two has run as we're effectively working on different instances of the same document"

    If memory serves me well, I believe it is possible to get a fresh instance of a document from disk by setting the document handle to nothing, and then doing a lookup by UNID. I needed this once to detect if the on disk doc was changed while another user was editing it.

    • avatar
    • Jake Howlett
    • Fri 18 Jul 2008 05:11 AM

    Hi Ferdy. Just had a go and that seems to work. Thanks for the solution. So simple...

    Although this is solved now I still think it's something I'd avoid doing. I just don't like the idea of messing with the document context while Domino is trying to save it.

    Here's a copy of the database with your fix in it:

  1. I'm curious as to why you don't like calling doc.Save.

    • avatar
    • Richard Collette
    • Fri 18 Jul 2008 09:34 AM

    This points out one of my big complaints to Lotus. If you are like me and you try to write reusable well designed code using an object oriented and layered software architecture (domain model, controller, service, ui, etc.), you wind up having to do that in LotusScript so that the UI tier (notes client) works with the lower layers. But when you want to do the more interesting things that Java allows, you're "reusable" code is nearly useless due to the limitations of LS2J.

    I wish that Lotus would make the effort to implement the Lotus UI classes in Java. It would remove this whole decision of do I code my agent in Java or LotusScript, bring a great more deal of power to client application programming, and bring Notes developers into the "mainstream" as Java developers.

    Lotus' effort to deliver Eclipse IDE development to Notes would also have been simplified as well, turning that issue more into one of code deployment rather than parsing, compilation, etc.

  2. Hi Jake,

    As you know I run a lot of Java WQS agents, and ran into JAVAMAXHEAPSIZE probs, which made me think and go back to LS on a lot of stuff.

    Don't know if it's just that my Java sucks, or because i make a lot of graphical stuff in the WQS's but support told me they'd run into this problem before.

    Be interested if any more knowledgeable of your readers on the subject could shed more light on Java vs LS performance in the Domino http server, but i now think twice before using Java, which was becoming my No1 dev language.

  3. My apologies..The start of my last para looks horrible.... I mean of course more knowledgeable than I.

Your Comments

Name:
E-mail:
(optional)
Website:
(optional)
Comment:


About This Page

Written by Jake Howlett on Fri 18 Jul 2008

Share This Page

# ( ) '

Comments

The most recent comments added:

Skip to the comments or add your own.

You can subscribe to an individual RSS feed of comments on this entry.

Let's Get Social


About This Website

CodeStore is all about web development. Concentrating on Lotus Domino, ASP.NET, Flex, SharePoint and all things internet.

Your host is Jake Howlett who runs his own web development company called Rockall Design and is always on the lookout for new and interesting work to do.

You can find me on Twitter and on Linked In.

Read more about this site »

More Content