Hallo *,
Ich hätte eine kleine Frage, die ist nicht existenziell, aber doch interessant.
Ich würde gerne Testläufe in unserem API durchführen und dabei Daten vom Domino Server benutzen. Dabei sollen die ensprechenden Klassen, die Sessions brauchen natürlich nicht extra auf eine Corba Session umgeschrieben werden.
Ich habe also eine globale Klasse erstellt, bei der sich dann jeder eine Session, die dann wahlweise über NotesThread oder Corba initialisiert wird.
Beispiel:
import java.io.FileInputStream;
import java.util.Properties;
import lotus.domino.NotesFactory;
import lotus.domino.NotesThread;
import lotus.domino.Session;
/**
* @author tsw
*
*/
public class SessionFactory {
/**
*
*/
static private SessionFactory theInstance;
/**
*
*/
private Properties properties;
/**
*
*/
private SessionFactory() throws ModuleException {
try {
this.properties = new Properties();
this.properties.load(new FileInputStream("factory.properties"));
} catch (Exception e) {
throw new ModuleException ("can not load properties", e);
}
}
/**
* @return
*/
private String getHost() {
return this.properties.getProperty("host");
}
/**
* @return
*/
private String getUser() {
return this.properties.getProperty("user");
}
/**
* @return
*/
private String getPassword() {
return this.properties.getProperty("password");
}
/**
* @return
*/
static private SessionFactory getInstance() throws ModuleException {
if (SessionFactory.theInstance == null) {
SessionFactory.theInstance = new SessionFactory();
}
return SessionFactory.theInstance;
}
/**
* @return
* @throws NotesModulException
*/
static public Session createSession() throws ModuleException {
try {
Session session = null;
if (NotesThread.isLoaded) {
session = NotesFactory.createSession();
} else {
SessionFactory factory = SessionFactory.getInstance();
session = NotesFactory.createSession(
factory.getHost(),
factory.getUser(),
factory.getPassword()
);
}
return session;
} catch (Exception e) {
throw new ModuleException("can not get a session", e);
}
}
}
bei einem externen start passiert auf der Server Console folgendes:
DIIOP Server: xxx.xxx.xxx.xxx connected
DIIOP Server: xxx.xxx.xxx.xxx connected
DIIOP Server: xxx.xxx.xxx.xxx connected
DIIOP Server: xxx.xxx.xxx.xxx connected
DIIOP Server: xxx.xxx.xxx.xxx connected
DIIOP Server: xxx.xxx.xxx.xxx connected
DIIOP Server: xxx.xxx.xxx.xxx connected
DIIOP Server: xxx.xxx.xxx.xxx disconnected
DIIOP Server: xxx.xxx.xxx.xxx disconnected
DIIOP Server: xxx.xxx.xxx.xxx disconnected
DIIOP Server: xxx.xxx.xxx.xxx disconnected
DIIOP Server: xxx.xxx.xxx.xxx disconnected
DIIOP Server: xxx.xxx.xxx.xxx disconnected
DIIOP Server: xxx.xxx.xxx.xxx disconnected
Die Frage ist: Steuert die NotesFactory die Connections über einen ORB - Pool ? Oder muss das selbst gemacht werden?
Gruss Thorsten
Ausgehend von dem SSO Beispiel der IBM habe ich diese Anpassung gemacht.
package testing;
import java.io.FileInputStream;
import java.util.Properties;
import lotus.domino.NotesFactory;
import lotus.domino.NotesThread;
import lotus.domino.Session;
/**
* @author tsw
*
*/
public class SessionFactory {
/**
*
*/
static private SessionFactory theInstance;
/**
*
*/
private String token;
/**
*
*/
private Properties properties;
/**
*
*/
private SessionFactory() throws ModuleException {
try {
this.properties = new Properties();
this.properties.load(new FileInputStream("factory.properties"));
} catch (Exception e) {
throw new ModuleException ("can not load properties", e);
}
}
/**
* @return
*/
private String getHost() {
return this.properties.getProperty("host");
}
/**
* @return
*/
private String getUser() {
return this.properties.getProperty("user");
}
/**
* @return
*/
private String getPassword() {
return this.properties.getProperty("password");
}
/**
* @return Returns the token.
*/
private String getToken() {
return token;
}
/**
* @param token The token to set.
*/
private void setToken(String token) {
this.token = token;
}
/**
* @return
*/
static private SessionFactory getInstance() throws ModuleException {
if (SessionFactory.theInstance == null) {
SessionFactory.theInstance = new SessionFactory();
}
return SessionFactory.theInstance;
}
private void initSession() throws ModuleException {
try {
Session session = NotesFactory.createSession(
this.getHost(),
this.getUser(),
this.getPassword());
this.setToken(session.getSessionToken());
session.recycle();
} catch (Exception e) {
throw new ModuleException ("can not init a session", e);
}
}
protected void finalize () {
try {
if (this.getToken() != null) {
Session session = NotesFactory.createSession(
this.getHost(),
this.getToken());
session.recycle();
}
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* @return
* @throws NotesModulException
*/
synchronized static public Session createSession() throws ModuleException {
try {
Session session = null;
if (NotesThread.isLoaded) {
session = NotesFactory.createSession();
} else {
SessionFactory factory = SessionFactory.getInstance();
if (factory.getToken() == null) {
factory.initSession();
}
session = NotesFactory.createSession(
factory.getHost(),
factory.getToken());
}
return session;
} catch (Exception e) {
throw new ModuleException("can not get a session", e);
}
}
}
allerdings kann ich diese nicht testen, da ich beim Start diese Meldung bekomme:
java.lang.NoClassDefFoundError: org/omg/SecurityLevel2/Credentials
at lotus.domino.NotesFactory.createSession(NotesFactory.java:256)
at lotus.domino.NotesFactory.createSession(NotesFactory.java:276)
at testing.SessionFactory.createSession(SessionFactory.java:119)
at testing.Check.main(Check.java:12)
Exception in thread "main"
jemand eine Idee, in welcher JAR die versteckt ist?
Gruss Thorsten
dann vielleicht so:
....
private ORB createOrb () throws ModuleException {
try {
if ((this.orb == null) && ((this.count++ % 10) == 0)) {
this.orb = NotesFactory.createORB();
}
return this.orb;
} catch (Exception e) {
throw new ModuleException ("can not create orb", e);
}
}
/**
* @return
* @throws NotesModulException
*/
synchronized static public Session createSession() throws ModuleException {
try {
Session session = null;
if (NotesThread.isLoaded) {
session = NotesFactory.createSession();
} else {
SessionFactory factory = SessionFactory.getInstance();
session = NotesFactory.createSession(
factory.getHost(),
factory.createOrb(),
factory.getUser(),
factory.getPassword());
}
return session;
} catch (ModuleException e) {
throw e;
} catch (Exception e) {
throw new ModuleException("can not get a session", e);
}
}
....
Auf diese Art wird auch tatsächlich nur eine Connection aufgebaut und der weitere Verlauf ist schnell.
Allerdings stellen sich dann an anderer Stelle grössere Probleme.
Ohne Umbau, können die Sessions nicht recycled werden, da ich nach dem "Abholen" keine Möglichkeit habe mehr an das Objekt heranzukommen :(
Wenn die Session mit NotesSession.createSession() erstellt wird, dann scheint sich der NotesThread um das recycling zu kümmern.
Gruss Thorsten