I've got some Java code that uses the Java Domino API (using the NCSO.jar) to connect with Domino databases over IIOP. A new requirement now is that if the server being connected to is clustered, it should be possible to take advantage of this and switch to a failover server in the cluster should the one currently connected to fail.
Unfortunately the Domino Java API is downright arcane, with subtle differences between using the API locally and remotely over IIOP, few really clear explanations and weird differences depending on the arguments that you feed the methods.
Some information I managed to glean from here... Does the openWithFailoverMethod work?
I've also checked the documentation on the IBM infocenter.
First thing I tried was this:
Session session = NotesFactory.createSession(host + ":" + port, user, password);
Database db = session.getDatabase(null, databaseName, false);
db.openWithFailover(host, databaseName);
The first argument of getDatabase
, the server name, apparently must be null for IIOP operations. I was rather mystified by how it would be necessary to specify the server name again in the openWithFailover
method when it's already in the session, but I suppose you can connecto to a cluster with the session and then specify the primary server in the open method. Why you needed to provide a database name twice wasn't quite clear, however. That last argument states the database should not be created if it can't be accessed (omit that and it's default true; how wonderful).
Unfortunately this spat the exception NotesException: This database object is already open as E:\Lotus\Domino\data\mail-in\EDITEST.nsf
in my face. It occurs on the line with the openWithFailover
method.
So apparently that first call to getDatabase
already opens it, and there's no close method or an option to only get the object without actually opening it.
The Database
class is an interface, so no static methods to obtain such an object or a way of instantiating it otherwise. I checked around and the only alternative I find is using openDatabase
in class DbDirectory
. Guess what that does. Now that method does have an alternative with a boolean that states if you wish to use failover, but according to the documentation it is always false for IIOP oprations.
According to this page, you can get an empty Database
object by calling getDatabase
with two null arguments. So I tried this:
Session session = NotesFactory.createSession(host + ":" + port, user, password);
Database db = session.getDatabase(null, null, false);
db.openWithFailOver(host, databaseName);
Which prompty gives me exception NotesException: A database name must be provided
.
Changing the second line to Database db = session.getDatabase(null, null);
doesn't make a difference.
I can only assume that a database name is mandatory for remote operations? But then how can failover be used at all when connecting remotely? Or am I doing this incorrectly? Maybe I should connect to the cluster instead of the server itself and the failover gets handled automatically? Or is failover plainly impossible for remote connections? The Notes client can do it, so I'd expect it to be possible in your own Java code.
Somebody please help me out here, because the documentation just doesn't provide enough info.
Database db = session.getDbDirectory(null).openDatabase(databaseName);
to see if I could actually connect without failover, and that works fine. – G_H