Domino Java agents & GUIs

原创 2005年01月01日 12:02:00


I was recently perusing the Notes 6 forum over at the Lotus Developer Domain, as is my wont, and I came across a post entitled, Database access from another class - Java. Now, normally, I would never post a "complete solution" as I did with this thread, but it piqued my interest. It took me a little time in terms of coding, experimenting, and researching Java in Domino, so I thought I'd summarise what I learned in a wee article.

Domino & Java

Whilst I've tinkered a fair bit with Java, one thing I don't have much experience of is creating Java agents. The nearest I got to a Java agent "in production" was a simple implementation of part of the Trackback specification. I did this for fun, but found no further use for it, and let the code languish. So this post on the LDD gave me a chance to "flex my muscles": coding the trackback thing was all "back-end" — Java with no user interface to speak of — whereas this little thing required a front-end that would interact with the agent calling it.

The code & the problem

The original poster in the thread wanted to invoke a simple GUI from a Java agent, collect user input via this GUI, and then do stuff back in the agent. He was using Java because he had a dependency in his code in the form of the JavaMail API. The issue he was experiencing concerned the separation of code into two classes (the main Java agent plus a simple AWT-based class) in that the two weren't talking to each other.

My starting point was to take the code he had, dump it into a dummy database, and get cracking. I called the main agent "DomGUIJavaAgent" and the class it uses for the GUI, "DomGUI". The poster had complained that his code didn't work on two fronts. First, his ViewEntryCollection object came up with inconsistent entry counts. That was easily solved, in that his for loop wasn't properly constructed. The rest of it was harder though...

The problem was that the standard NotesMain method happily instantiated a Database object and all the rest, but couldn't seem to pass these objects over to the default constructor of the GUI class. This meant a lot of head-scratching for me, although I knew it just had to be related to scope. Clearly, the Session and AgentContext classes were key: if they "died" *, then any objects derived with their help weren't going to survive either. I pondered this, and tinkered with different ways of somehow creating "new" AgentContext/ Session objects in the GUI code: not good. Eventually, my sorry excuse for a brain had an epiphany: we're getting into threads!

* - the Domino Java classes and interfaces are "wrappers" around core C functionality in Notes. As such, standard Java garbage collection doesn't work. A good Java coder needs to explicitly "recycle" Document objects and so forth. I gather that the exceptions to this rule are AgentContext and Session. For the sake of brevity in the source code, all recycle calls have been omitted.

Yup, threads

I've always been a bit leery of threads. They're one of those things, along with bit-signing and inner classes, that I seem to have a bit of blind spot with (getting better though!). Now, as I looked more and more into the Domino Java implementation, I discovered that AgentBase, the base class for all Java agents, is a sub-class of the NotesThread class, which makes sense. So, returning to our code, how about running the second GUI object in its own thread? That should work. But we still need to keep the "trigger" — the AgentBase object — alive.

They key to this is getting one thread to "sleep" until the other one is done. So here's my implementation:

In the constructor for the GUI object, I pass through a reference to the Database object we're playing with. The key thing though, is that the method in the DomGUI class that uses this Database object fires off in its own thread and that the Java agent's NotesMain method waits for it. This waiting is accomplished by making the Java agent thread "sleep" for as long as a public boolean variable, belonging to DomGUI, is set to "false." Whilst the thread is alive DomGUI can happily work with the passed-through Database object. Only two things can change the "isClosed" variable to "true": once the relevant button has been pressed or when the window is closed by the user. Splendid.

So, here's the actual agent code in full (it's very brief):

public class DomGUIJavaAgent extends AgentBase {
	private AgentContext ac;
	private Database db;
	private DomGUI myWin;

	public void NotesMain() {
		try {
			ac = session.getAgentContext();
			db = ac.getCurrentDatabase();

			myWin = new DomGUI(db);
			while (!myWin.isClosed) {
		} catch(Exception e) {

And here's a snippet of the action listener method in the DomGUI class which manipulates "isClosed", the crucial public boolean which holds this all together (sendToAll() is a simple demo method, as you'll see in the full source):

public void actionPerformed (ActionEvent e) {
	if (e.getSource() == btnSend) {
		isClosed = true;

The threads

If you look at the full source, you'll notice that a method in the DomGUI code (sendToAll()) initialises its own thread. This thread isn't terminated until the whole window is closed.


I hope this is useful to any beginning Java coders out there like me... it's the fruit of a fair bit of playing, testing, and actually reading the Domino Designer help... [smiley Shock]. Hopefully, it will act as a good starting point for any Domino-based Java you need to write that requires a UI. I appreciate that this isn't the prettiest GUI, but it's really just to show what can be done... and it's also R5-compliant!

My thanks to Joseph Millar of Brightline Technology for making a really useful observation concerning thread termination which I took on board in this code. Additional comments from those more experienced than I are more than welcome!

Attachment(s): (0 KB) (4 KB)

用 Lotus Domino Designer 8.5.1 创建 Java 代理

用 Lotus Domino Designer 8.5.1 创建 Java 代理 本文介绍了利用 Lotus Domino Designer 8.5.1 开发和调试 Domino J...
  • simon631
  • simon631
  • 2014年11月12日 11:10
  • 290


  • starrow
  • starrow
  • 2014年07月25日 18:25
  • 8368

Java 利用http协议与Domino实现sso单点登录

// 单点登录测试  @RequestMapping(value = "sso")  public String sso(HttpServletRequest request, HttpServlet...
  • pgbiao
  • pgbiao
  • 2015年03月23日 15:35
  • 3660


was与domino需要共享一个用户注册表,domino不支持自定义的用户注册表一。domino方面    配置并启动Lotus Domino的LDAP服务配置并启动Lotus Domino的LDAP...
  • fastrunner2003
  • fastrunner2003
  • 2006年08月31日 11:20
  • 1731


一、概述Java 对 Domino Objects 的访问是通过高级包 lotus.domino 进行的。根据运行时环境,这个包中的接口是在其他两个包中的一个包中实现的: lotus.domino.l...
  • adeyi
  • adeyi
  • 2011年03月02日 17:28
  • 3667


1. 背景 看到网上别人写的Java通过DIIOP访问domino对象的实例,自己也试着写了一下,其实挺简单。 2. 开发工具 a) IBM/Lo...
  • Gavid0124
  • Gavid0124
  • 2015年02月06日 14:15
  • 1497


环境:DOMINO6.02    主机:as400-820  我用JAVA写了一个代理,编译和运行均正常。但此代理运行几百次后,就会报错:java.lang.OutOfMemoryError,估计是内...
  • wangdeq
  • wangdeq
  • 2007年10月10日 13:11
  • 4059

Domino 单点登录(SSO)用户名映射功能

Technote (troubleshooting) 问题 当使用 Domino 单点登录(Lotus Domino 6 服务器环境也被称为多个服务器基于会话的验证)时,在复杂配置中你可能...
  • Gavid0124
  • Gavid0124
  • 2015年02月28日 16:29
  • 1244


  • hbcui1984
  • hbcui1984
  • 2010年06月17日 23:05
  • 4309


其他系统与domino系统单点登录的实现方式 •【背景】 随着企业中业务不断增多,用户处理不同的业务则需要频繁的切换不同的系统进行操作,而用户则需要记住各个系统的用户名、密码,频繁的登录。如果各...
  • Gavid0124
  • Gavid0124
  • 2014年09月29日 14:42
  • 3466
您举报文章:Domino Java agents & GUIs