Tuesday, October 31, 2006

The forgotten art of StampAll .. or the fastest way to update documents

I've been analyzing an agent and found that it uses NotesDocumentCollection.StampAll(fieldname, value) method. I knew about the existence of the method but didn't remember about actually using it, so I decided to test how effective it was compared with other methods. For comparing I used looping through all documents in a document collection and updating them one by one.
The result was that for updating one field StampAll is 80% faster than any other method. To update field called "testfield" in 15000 documents using StampAll("testfield", "test") took 31 seconds, using doc.testfield="test" tool 54 seconds and doc.ReplaceItemValue("testfield", "test") took 50 seconds.

Surprisingly to update the same field using @Formula (Field testfield:="test") took 120 seconds. Using Simple Action it took 65 seconds.

One disadvantage with StampAll method is that it updates only one field at a time. So if you want to update 2 fields in a document, it would take 2 times as long time, while with other methods the difference is about +10% for each additional field.

Here is the source code of the agent and the agent's output.

Sub Initialize
Dim session As New NotesSession
Dim db As NotesDatabase
Dim coll As NotesDocumentCollection
Dim doc As NotesDocument
Dim item As NotesItem
Set db=session.CurrentDatabase

Set coll=db.AllDocuments
Call coll.StampAll("testfield", "test1")
Print "Elapsed in test nr1: "+Cstr(Timer-timerStart)

Set doc=coll.GetFirstDocument
While Not doc Is Nothing
Call doc.Save(True, False)
Set doc=coll.GetNextDocument(doc)
Print "Elapsed in test nr2: "+Cstr(Timer-timerStart)

Set doc=coll.GetFirstDocument
While Not doc Is Nothing
Call doc.ReplaceItemValue("testfield","test3")
Call doc.Save(True, False)
Set doc=coll.GetNextDocument(doc)
Print "Elapsed in test nr3: "+Cstr(Timer-timerStart)
End Sub

Elapsed in test nr1: 30,89014
Elapsed in test nr2: 54,27002
Elapsed in test nr3: 50,06982

Tuesday, October 24, 2006

Problem with Sametime installation

I hope this post will save some Domino/Sametime administrator time searching for solution.

I had Domino 5 server with Sametime 3.0 installed on my test server. The server was not in autostart mode. I didn't use it much so I decided to upgrade it to Domino 6.5 for making local tests of STWidget application in Anonymous mode. I chose not to update to the latest Sametime 7.0/7.5 because many (50%?) companies still use Domino 6 and Sametime 3.1/6.5.1. Although Sametime 7 Java Toolkit should work fine with Sametime 6, you never know.

I installed the Domino 6.5.5 server to a new folder and tested that it started correctly. Then I tried to install Sametime 6.5.1 server. The installation aborted with following message:
IBM Lotus Sametime 6.5.1 requires that
IBM Lotus Domino 6.0.3 or later
be installed on the same
computer as IBM Lotus Sametime 6.5.1

Install Domino 6.0.3 or later and
then restart this installation.

I checked that PATH environment variable does not point to the old Domino5 installation and even manually registered the nlsxbe.dll file "regsvr32 c:\lotus6\nlsxbe.dll" and un-registered the dll file in R5 folder.
That didn't help. Then I renamed the folder containing the old Domino 5 server files to c:\aaaaaaaLotus5\, hoping that installation will continue after it failed to open non-existant files.
Now when the new Sametime server installation started, it showed "Path not found" error message. This clearly pointed ou that it was just as I suspected that the old R5 server still was somehow found from the new server installation.
With "Path not found" search string I found IBM's technote describing the solution. The solution was simple: delete the HKEY_LOCAL_MACHINE\SOFTWARE\Lotus\Domino\5.0 registry entry.
After deleting the entry, the new Sametime server was installed without problems.


Sunday, October 22, 2006

Skype and Lotus Notes

The View journal has recently published my article "How to add Internet telephony to your Lotus Notes and Domino applications"

The article describes how to integrate Skype telephony and chat into Lotus Notes applications using Skype COM API and how to integrate Skype with Domino web applications using javascript and other solutions.

The article includes a downloadable database with example code. Examples show different ways to trigger Skype functionality from Notes client and to monitor Skype status. You can copy buttons from the examples and paste into your own applications to enable one-click phone calls from Address Book.

Prerequisites for the examples to work: installed Skype client and Skype COM API toolkit, both are free to download and use.

Debugging web applications in Firefox

Finding errors in JavaScript on web pages can be a difficult task. In Internet Explorer you can in best case see the line number where the error occured.

I recently began using Firefox Javascript console for debugging web applications. Besides javascript errors, console also shows invalid properties of CSS stylesheets.
The console can be opened using Tools-JavaScript Console menu in Firefox browser. In the console you can see all the errors which occured, not only the last one as in IE. By clicking on error message, it opens a window with the script file where the error occured and marks the error line.

A strange thing I experienced with Firefox console is that it somehow caches XML-document nodes which results in "ghost" nodes. When I changed WIMBO Sametime chat application to use XML-formatted data instead of plain-text data, the Javascript console reported that the web browser still received the old plain-text data. The data was clearly not a part of the information received from the servlet, so I am still wondering why Firefox appended that data to the real data. Similar problem with ghost nodes happened when I replaced an empty "<RESPONSE></RESPONSE>" root node which caused problem in Firefox to "<RESPONSE><NONE>-</NONE></RESPONSE>".

Wednesday, October 18, 2006

A L33T Java agent one-liner

I noticed that most of the Domino developers split object calls into separate (more manageble?) pieces. What a waste of space in the code editor!

Let's create a one line of code which gets days difference between the first and the last document in a view and the total number of documents in a view, all without any declarations of variables.
The code is written in Java (agent), but the same thing can be done in LotusScript.

System.out.println("Time difference in days: "+String.valueOf(getSession().getAgentContext().getCurrentDatabase().getView("all").getLastDocument().getCreated().timeDifference(getSession().getAgentContext().getCurrentDatabase().getView("all").getFirstDocument().getCreated())/60/60/24)+". Number of documents: "+String.valueOf(getSession().getAgentContext().getCurrentDatabase().getView("all").getAllEntries().getCount()));

Post your own one-line code snippets, maybe we can find a practical use for them :)

Sunday, October 08, 2006

USB phone for Skype

Last week I've buyed a Doro 212IPC USB phone for Skype... and tested it as soon as I came home :) It costed 99 SEK (12.5 USD) at Media Markt

The phone quality is pretty good. Both incoming and outgoing sound is clear. But the integration with Skype and Windows could be improved.
Essentially, the USB phone is nothing more than a phone-formed headset with a keypad. I had some more expectations from a device called "phone", but what can you expect for 13 dollars?

The phone is setup as a sound device in Windows, and when plugged-in to the USB port, all sound goes through the phone instead of regular speakers. This is not very good as you most probably only want the sound from Skype program go through the phone, not sound from other programs. At the same time, this "feature" makes it possible to use the phone with the most of other softphones because it takes over standard audio input/output devices. It worked fine to speak and hear with X-Lite softphone (I dialed using mouse and softphone's virtual keypad) and after I downloaded a special driver, I could even use phone's number pads to dial the number.
Luckily, it's possible to manually change the settings in Windows after plugging in the phone to use standard sound devices instead of "Doro 212IPC" (you can still keep the Doro settings in Skype).

The first thing I noticed that you must manually open the "dial" tab in the Skype client, otherwise you can not dial a phone number. If any other tab than "dial" is selected in the client, the phone's number pad works for navigation up/down/left/right, which e.g. makes it possible to choose a Skype user in the buddy list. But as it's actually a phone, one would expect that when dialing a number from the key pad, the phone puts the Skype client into dial mode by default. As you must visually verify that the Skype client is on "dial" tab, the number pad on the phone is almost useless, as I can as easily type the number in the Skype software client on the computer when I am there anyway checking that the correct tab is open.

The other thing I expected to find in the phone was that incoming calls would ring in the phone. But the ring signal is possible only from the computer. How hard would it be to put a small speaker in the phone and activate it on incoming calls? Without this feature, the phone feels like an odd headset.

Overall impression of the phone device is positive, specially considering the low price. It's OK for making casual calls, but probably too boring if you are making a lot of calls. As the phone does not have a screen showing the dialed number, you will rather soon happen to dial a wrong number if you do not verify it on the computer screen.

Note: you must purchase SkypeOut credits for making outgoing phone calls; and SkypeIn service for accepting incoming phone calls to Skype client. Skype-to-Skype calls are free.