If you get "Can't run a private agent belonging to someone else" error when you trigger a Lotus Notes agent from your Java application, make sure that the agent is initiated in the same thread as it's parent Database. Looks like you can't simply get agent object from another thread without getting it through it's parent database object. Well, you actually get the valid object but the agent can not start. This applies only to local calls, not to DIIOP. And it looks that sometimes it can work anyway.
You might ask why would you have separate sessions/threads in the first place? There are many reasons for that, especially in large applications where Domino objects might have been initiated in different classes.
Incorrect:
class ClassA{
Session s = null;
Database db = null;
Agent agent = null;
NotesThread.sinitThread();
s = NotesFactory.createSession();
db=s.getDatabase(null, "mydb.nsf");
agent = db.getAgent("agent123");
// NotesThread.stermThread(); //Notes thread is still running!
}
class ClassB{
NotesThread.sinitThread();
Agent agent=classA.agent; //this is valid call and we do get valid agent object!
agent.run(); //here we get error "Can't run a private agent belonging to someone else"
NotesThread.stermThread();
}
Correct:
class ClassA{
Session s = null;
Database mydb = null;
NotesThread.sinitThread();
s = NotesFactory.createSession();
db=s.getDatabase(null, "mydb.nsf");
// NotesThread.stermThread(); //Notes thread is still running!
}
class ClassB{
NotesThread.sinitThread();
Agent agent=classA.mydb.getAgent("agent123");
agent.run(); //agent gets triggered without error
NotesThread.stermThread();
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment