Java Maps and load factors

When writing Java code be that for standalone Java, Domino agents or even XPages you often need a data structure to map keys to values. In Java this is a map (java.util.Map) and it works much like a List in LotusScript. Maps are used a lot but since Map is an interface you need an implementation whih is most often a java.util.HashMap.

The way to construct a HashMap is using one of the constructors and if you are like me a couple of months ago you just use the default constructor that is the one that doesn’t take any arguments. Now this is well and fine if you know what you’re doing. Most times the use of the default constructor is the wrong choice and can / will lead to memory being wasted and even worse is worse performance when adding more than 12 elements.

Lets take each in turn. The wasted memory comes from the classes used internally inside a HashMap to keep track of keys and values. For this post knowing that not filling the map (e.g. creating a HashMap using the default constructor and only stuffing 5 elements in it) will waste memory. A most excellent introduction is From Java Code to Java Heap. On a related note a key take-away from that article is to consider LinkedList instead of ArrayList if you not know the ultimate number of elements and hence cannot size correctly at object construction.

This memory waste can be avoided by always using the constructor that takes an initial size and hence size the Map correctly. Now it turns out that that’s only part of the story as a HashMap also has what’s called a “load factor”. The load factor is a decimal number – i.e. a percentage – specifying how much the map may be filled before an extension and hence a full rehash of the keys take place. This means that with the default load factor of 0.75 you may only put 12 elements in a HashMap before it is extended and hence you take a performance hit. Again size your map correctly from the get go taking the load factor into consideration. The last point is that the size should always a power of 2 meaning that if you specify a size of 20 it will actually be 32.

A most nice discussion that caused me to look deeper into this can be hear on episode 391 of the Java Posse podcast (Java Posse #391 – Newscast for August 10th 2012) from 0:58 to 1:05.

The monkeysphere

This blog post has been lingering for a while but on This Week in Tech (TWIT) episode 344 between 1:06:50-1:11:00 there is an interesting discussion about Dunbar’s number and the concepts of artificiel scarecity. Dunbar’s number is used to discuss what’s called the “monkeysphere” (What is the Monkeysphere?). It’s very interesting and applies very well to our new networked and highly social World. I highly recommend listening to the audio and and reading the acticles if you’re into social software.

Notes 8.x shortcut of the day

If you haven’t docked the Open menu in Notes 8 on the left you want to be able to access it using the keyboard. As always the shortcut list is to the rescue. Ctrl-Shift-L shows a list of all shortcuts and in that list you find “Open list” which is what you want. The shortcut for “Open list” is Alt-B so put away that mouse and use the keyboard.

Update: Just relealized that it works just as well with the Open list docked.

Reusing IBM Connections Atom date formatting for custom widgets


In a recent IBM Connections project I needed to display dates in the same as IBM Connections does it that is full dates sometimes but also using “yesterday”, “today” etc. Plus it needed to cater for the fact that the customer might at some future point in time allow the user to change the UI language. Coding this is tedious and would take quite some time so I wanted to figure out if IBM Connections had some libraries that could help me.

And it did.

By messing around in Firebug I found out that the way IBM Connections does it is by using a nifty JavaScript object called lconn.core.DateUtil.AtomDateToString. This object is actually a helper object that does two things – first it is able to convert an Atom date/time string (such as 2012-08-01T12:44:42.713Z) into a JavaScript Date object and then format it according to i18n settings and the language set in the UI.

Once I knew what to look for in the IBM Connections code it was simple enough. They do it by adding a hidden span-tag (CSS class “lotusHidden”) with a special tagging CSS class called “formatDate” as shown below.

<span class="formatDate lotusHidden">
  2012-08-01T12:44:42.713Z
</span>

Then using dojo.query they locate the nodes with the formatDate CSS class, use the utility class to convert the Atom date string and then remove the “lotusHidden” CSS class to make it visible.

// expand dates
if (lconn && lconn.core && lconn.core.DateUtil &&
lconn.core.DateUtil.AtomDateToString) {
   dojo.query(".formatDate", root).forEach(function(item){
      item.innerHTML=lconn.core.
         DateUtil.AtomDateToString(item.innerHTML);
      dojo.removeClass(item,"lotusHidden");
   });
}

IBM THINK – the app

Explore how progress happens with the THINK exhibit app, for kids, innovators and forward thinkers.

From the very beginning, we’ve sought to improve the way we live. We’ve worked to make our world more efficient, accessible, and safe. While each leap of progress has required its own intelligence and hard work, many seem to follow a distinct, repeatable pattern.

The app is available in the Apple AppStore.

Customizing the feature titles for IBM Connections mobile plus new URL handlers which are (almost) useful

Luis Benitez already blogged this (How To Customize the IBM Connections Mobile App for iOS, Android & BlackBerry) but I think it is so important that it bears mentioning again. With the latest update to IBM Connections (version 3.0.1.1 CR2) you know have the option to customize the mobile apps using a new mobile-config.xml file. It allows you to configure settings to do with login and the general configuration of the app. An important point is also that it allows you to change the title of the features in the app which is great if you have change feature names in the web UI. We have customers that change some of the Danish translations (especially for Community because they feel that the Danish word really isn’t representative of the feature) so making that feature name change apply to the mobile UI’s are great.

To install the fixes simply download the IBM Connections 3.0.1.1 CR2 jar-files and follow the steps from the technote (technote 1595154) to update IBM Connections. Please note that you need the newest update installer to perform the update.

As if this wasn’t enough Chris Reckling recently blogged (Custom URLs in IBM Connections Mobile Apps) on the new URL handlers that were added to the Connections mobile apps for iOS and Android. This means you can add a link in an email to take you directly to Profiles or a profile as well as Communities or a community. The URL’s are easy to use and pretty straight forward – to open John Does profile one could use ibmscp://com.ibm.connections/profiles?email=jdon%40example.com from anywhere on the app. Pretty neat.

There’s also a URL handlers to configure the app for a user to allow for easier set up of the app.

The URL handlers are great but I think it is too bad they didn’t add support for all features now they were at it. For instance having a direct link capability into Activities would be killer as it would allow you to add links to the email notifications that would take you to the mobile app instead of the web UI. Would have been soo cool and would have been something I could use now – having the Communities part is nice but I receive way more Activities notifications by email so a link capability there is worth much more to me. I hoping it will make it into the next update.

@IBMLotusND

Just wanted to point people towards the heir to the “LotusKnows” twitter id which is a good way to stay on top of all things Lotus. The new id to follow is @IBMLotusND.

Fixing a wierd widget installation issue (Content is not allowed in prolog)

For our OnTime Group Calendar 2011 Notes user interface which is Java plugin based we have seen some strange problem reports with customers reporting that the widget installs but after installation an error message is displayed on screen (“The widgets below had issues during the installation. See the log for more details.”). The wierd thing about the reports were that the customers reported that the widget (and hence the plugins) actually installed just fine and worked after a client restart. What’s even funnier is that the same plugins installed without error if the customer used HTTP and not NRPC for their update site access protocol. In the log (Help/Support/View Trace) the below error messages was shown (my highlighting):

Could not access digest on the site: no protocol:
   0/8E4DFE3996CBDD94C1257A33003CE3A9/$file/digest.zip
[Fatal Error] :1:1: Content is not allowed in prolog.
org.eclipse.ui.WorkbenchException: Content is not allowed in prolog.
	at org.eclipse.ui.XMLMemento.createReadRoot(Unknown Source)
	at org.eclipse.ui.XMLMemento.createReadRoot(Unknown Source)
	at com.ibm.rcp.dynamic.extensions...
	at com.ibm.rcp.dynamic.extensions...
	at com.ibm.rcp.dynamic.extensions...
	at com.ibm.rcp.toolbox.internal.management...
	at com.ibm.rcp.toolbox.internal.management...
	at com.ibm.rcp.toolbox.internal.management...
	at com.ibm.rcp.toolbox.internal.management...
	at com.ibm.rcp.toolbox.internal.management...
	at org.eclipse.core.internal.jobs...
Caused by:
org.xml.sax.SAXParseException: Content is not allowed in prolog.
	at org.apache.xerces.parsers.DOMParser.parse(Unknown Source)
	at org.apache.xerces.jaxp.DocumentBuilderImpl...
	... 11 more

This really had me scratching my head.

After reseaching and Googling I found a post called “Java: “Content is not allowed in prolog” – causes of this XML processing error” which led me in right direction.

When I opened the widget XML file in an editor and switched to HEX mode I saw this:



3 invisible bytes were inserted at the start of the file. I copy/pasted the XML into a new file which solved the issues. The 3 bytes actually turn out to be what’s called a Byte order mark or BOM for short. From the wikipedia article I found out that the BOM for a UTF-8 file is those exact bytes and I did save the file as UTF-8 in my editor.

The UTF-8 representation of the BOM is the byte sequence 0xEF,0xBB,0xBF. A text editor or web browser interpreting the text as ISO-8859-1 or CP1252 will display the characters  for this.

But the bytes were not there in my editor but only in the file that I received from a customer. So how did the bytes get there?!

So after more research and playing around I found out that the BOM is added by Notepad on Windows. But of course!! A lot of customers receive the XML file and change the update site URL to point to their own servers and if they use Notepad for this the BOM is added (see “The Notepad file encoding problem, redux” for more details).

But how to fix it? Telling customers not to use Notepad to edit the XML file would be a no-go as many probably no not use another editor. And even if they did the problem would probably still arise in some situations and we would spend time diagnosing it. The solution I’ve opted for is to change the encoding of the file to ASCII and change the encoding declation in the XML file to ASCII as well. The content of the XML file is unchanged and now customers can change it using Notepad without issues.

Watch the names when doing SSO between WAS and Domino

This morning I helped a customer because they couldn’t make the beta of the OnTime Group Calendar for IBM Connections work and it turned out to be a Single-Sign-On issue. For the OnTime widgets to work we require SSO between Websphere Application Server and Domino which is trivial to set up. Simply export the SSO keys from Websphere using the Integrated Solution Console (ISC) and import them into the SSO document in Domino Directory. In Websphere Application Server terms this is called cross-cell SSO and is very easy to set up.

After doing this SSO still didn’t work and right of the bat I suspected the good ol’ “multiple O= identifier” issue. The issue is when you incorrectly configure federated repositories and a username is reported by ISC with an extra organization identifier e.g. I would be “CN=Mikkel Flindt Heisterberg,o=IntraVision,o=IntraVision” and not simply “CN=Mikkel Flindt Heisterberg,o=IntraVision” the latter of course being correct. While WAS (and IBM Connections) will work just fine with that type of configuration is can cause SSO not to work correctly or only work when the user authenticates to Domino first the problem being that the DN that WAS sticks into the LtpaToken isn’t valid in Domino.

Verifying the names is easy using “Users and Group/Manage Users” in the left hand menu in ISC.

After reconfiguring federated repositories and restarting Websphere Application Server SSO functioned and the customer was back to using the OnTime Group Calendar widgets.