Download AD212: Advanced Techniques for Java Programming in Lotus Notes

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
Advanced Java Programming Technique
ƒTarget
AD212: Advanced Techniques for
Java Programming in Lotus Notes
and Lotus Domino
Wai-Ki Yip
Manager and Project Leader
Language Services
Audience
–Some Java knowledge
–Some experience programming Java in Notes/Domino
ƒPurpose
–Provide detail technical information
–Explain what happens behind the scene
ƒResult
–Answer some questions
–Write better Java programs
Keith Kimball
Software Engineer
Agenda
JRE Versions
ƒJRE
ƒThe
Versions
Customization using NOTES.INI Variables
ƒDomino Objects and Memory Management
ƒAccessing Domino Classes from a Java main program
ƒJVM
–Local access
–Remote access
ƒAdditional
Packages
ƒInstalling a Java Extension
ƒIntersection of Java and Notes Security
ƒTrouble Shooting Tips
JRE is packaged and shipped with Notes/Domino or it is
installed as part of the Operating System
–Tested thoroughly
–Should just work
–In most cases, you don't have to worry about it.
ƒNotes/Domino
ƒNotes/Domino
5 - JRE 1.1.8
6 - JRE 1.3.1
1
Notes/Domino 5
ƒJDK
Notes/Domino 6
1.1.6 in early releases, 1.1.8 by now
Platform
Version
Win32
JDK 1.3.1 (IBM)
Solaris
JRE 1.3.1 (Sun)
LINUX
JRE 1.3.1 (IBM)
JRE 1.1.8 (IBM)
AIX
JRE 1.3.1 (IBM)
JDK 1.1.8 (IBM)
AS/400 (iSeries)
JDK 1.3.1 (IBM)
OS/2
not applicable
OS/390 (zSeries)
JDK 1.3.1 (IBM)
HPUX
not applicable
MAC OS/9
MRJ 1.2/JDK 1.1.8 (Apple)
Platform
Version
Win32
JDK 1.1.8 (Sun)
Solaris
JRE 1.1.8 (Sun)
Linux
JRE 1.1.8 (Sun)
AIX
AS/400 (iSeries)
OS/2
JRE 1.1.8 (IBM)
OS/390 (zSeries)
JDK 1.1.8 (IBM)
HPUX
JRE 1.1.6 -> JRE 1.1.8 (HP)
MAC
(mostly 1.3.1)
no support
JRE - Java Runtime Environment
JDK - Java Development Kit
Changes from ND5 to ND6
Importance of Java Releases/Versions
ƒJRE
ƒIncreased
1.1.8
->
JRE 1.3.1
–skipped JRE 1.2 and JRE 1.3.0
ƒSun
->
IBM
functionality
performance and scalability
ƒJava Releases are like Operating System releases
ƒBetter
–Win32, LINUX
–changed implementation (Sun to IBM)
–the underlying JVMs are actually quite different
–changed internally
–deprecated APIs
2
What Lotus Does With the New Release ?
Don't Recommend Change JVM Yourself
ƒWork
to make sure it functions properly in Notes/Domino
ƒCertain
–Rebuild all our Java code
ƒOther
–Test existing and new functionality
features may fail
subtle problems
–Performance
–Monitor any performance/scalability, memory consumption
–Scalability
characteristics change
–Memory consumption
–Accommodate all changes
–Normally, it took us about 3 months of continuous running to notice
deprecate APIs
–directory structure changes
–take advantage of new interfaces
these kind of problems
–
JVM Directory Structure in ND5
JVM Directory Structure in ND6
ƒJVM
ƒA
binaries installed with the other Notes/Domino executables
–c:\Lotus\Notes on the client or
–c:\Lotus\Domino on the server
Core JVM
–Native method libraries used by the core Java classes
–Archives (.jar) containing the JVM core classes
–Subdirectory lib (java.home system property)
–font.properties, awt.properties, etc...
–
complete JRE subtree in the Notes executable directory
–Subdirectory jvm
Content is platform dependent
JVM core libraries, core classes, misc files
–Relative path for its subdirectories
–Bin
–Lib
–
–
3
Do You Need to Know About This ?
Agenda
ƒDifficult
ƒJRE
to replace the 1.1.8 JVM in ND5 with 1.3 or 1.4 JVM
–Need special knowledge about directory structure
–Need to remove all 1.1.8 files. Otherwise, you may running a mixture
of 1.1.8 and 1.3 JVM. You may encounter some very interesting
problems.
ƒInstall
Customization using NOTES.INI Variables
ƒDomino
Objects and Memory Management
Domino Classes from a Java main program
ƒAccessing
an extension package
–JSSE 1.0.3_01
Versions
ƒJVM
–local access
–remote access
ƒAdditional
Packages
a Java Extension
ƒIntersection of Java and Notes Security
ƒTrouble Shooting Tips
ƒInstalling
JVM Customization using NOTES.INI
Variables
JVM Selection INI Variables
ƒJVM
ƒINI
Selection
ƒStacksize
ƒClasspath
ƒGarbage
collection
ƒVerbose information
ƒVerification
ƒJIT
ƒOS400
variables
–JavaClientVM (-client)
–JavaServerVM (-server)
–JavaHotspotVM (-hotspot)
ƒExample
–JavaClientVM=1
4
Stacksize INI Variables
Classpath INI Variables
ƒINI
ƒINI
Variables
variable
–JavaStackSize (-oss)
–JavaNativeStackSize (-ss)
ƒSize
is number optionally followed by one of
–JavaUserClasses (-classpath)
ƒNote
–Contains a list of directories, jar, and zip files on local disk
–k or K (kilobytes)
–Classes are loaded by System ClassLoader
–m or M (megabytes)
–Loaded classes are “trusted”
ƒExample
–Files on local disk are not replicated
–JavaStackSize=400k
–Consider putting in shared library within Notes
ƒND5
Restriction
–NOTES.ini variables limited to 256 characters
ƒExample
–JavaUserClasses=c:\domino\data\local;f:\jserv\lib\classes.zip
Garbage Collection INI Variables
Verbose INI Variables
ƒHeapsize
ƒINI
ƒClass
INI variables
variables
–JavaMinHeapSize (-ms)
–JavaVerbose (-verbose:class)
–JavaMaxHeapSize (-mx)
–JavaVerboseGC (-verbose:gc)
collection INI variable
–JavaNoClassGC (-noclassgc)
–JavaNoAsyncGC (JRE 1.1.8 Only)
ƒExamples
–JavaMaxHeapSize=256m
–JavaNoClassGC=1
–JavaVerboseJNI (-verbose:jni)
ƒVerbose
output about
–classes loaded and each source files compiled
–garbage collection events
–use of native methods
ƒExample
–JavaVerbose=1
5
Verification INI Variables
JIT INI Variables
ƒINI
ƒINI
Variables
Variables
–JavaNoVerify (-noverify)
–JavaEnableJIT
–JavaVerify (-verify)
–JavaDisableJIT
–JavaVerifyRemote (-verifyremote)
ƒExample
–JavaJITName
ƒExample
–JavaEnableJIT=1
–JavaVerify=1
OS400 INI Variables
Agenda
ƒJavaOS400LoadLib
ƒJRE
ƒJavaOS400Optimize
ƒJVM
ƒJavaOS400CHKPATH
ƒDomino
Objects and Memory Management
ƒJavaOS400RegisterNatives
ƒAccessing
Domino Classes from a Java main program
ƒJavaUserClassesExt
Versions
Customization using NOTES.INI Variables
–local access
–remote access
ƒAdditional
Packages
a Java Extension
ƒIntersection of Java and Notes Security
ƒTrouble Shooting Tips
ƒInstalling
6
Domino Objects and Memory Management
Domino Objects & Memory Management
after recycle( )
parent
parent
Java
Object
Java
Object
Java
Heap
Java
Heap
C++
Object
BackEnd
Heap
BackEnd
Heap
Domino Objects & Memory Management
Memory Management Web Agents & Servlets
ƒrecycle(
ƒAgents
)
–destroys Back End objects
–Small agents are easy
–Java wrappers visible to GC
ƒDo
it yourself
–leave only crumbs for GC
–Larger agents need help
ƒServlets
ƒHave
must be managed
a plan!
7
Web Agents Must Keep a Small Footprint
Servlets & Long-Running Agents
ƒServlets
–Use message handler structure
–Create Session for each Request
doGet( )
Session.recycle( ) when finished
–doPost( )
–fully consider data contention
–
–
ƒAgents
less obvious
–Agent owns the Session
–Examine structure
–
Raising the Bar: Multithreading
capitalize on opportunities to clean up
Multithreading
ƒDesign
must be carefully done
management more involved
ƒDebugging difficult
ƒNo win for CPU bound tasks
ƒEfficient for heavy I/O tasks
ƒMemory
8
Multithreading Domino Objects
Multithreading - Notes on Backend
Architecture
ƒAll
ƒWithin
D.O. threads must be registered
a Session
–sInitThread( )
–Objects shared across threads
–sTermThread( )
–Methods are synchronized
–AWT event handlers
ƒNotesThread
will do this for you
ƒControlling thread must be kept alive
–Parents must be preserved
–Containment model is important
–Use DbDirectory on only one thread
ƒAcross
Sessions
–Objects are independent
–Data contention possible
ƒProfile
–join( ) is helpful
Documents cached per thread
–Last one in wins!
Multithreading - Memory management
R5 Vs R6 Memory Management
ƒRecycled
ƒR6
ƒBe
ƒUse
object unavailable to any thread
aware of parent/child relationships
ƒDocuments serve many masters
–Item access
–Collection member
–Best to design these situations out
Architecture is more GC/Robust
R5 rules for backwards compatibility
–Recycle!
ƒR6
more flexible for complex situations
ƒGC remains lazy
ƒDB
access OK from any thread
ƒrecycle Database on opening thread
9
Agenda
Environment Setup for Java Main Program
accessing local Domino Classes
ƒJRE
ƒAdd
Notes.jar to CLASSPATH
ƒAdd
directory to PATH
Versions
Customization using NOTES.INI Variables
ƒDomino Objects and Memory Management
ƒJVM
ƒAccessing
program
Domino Classes from a Java main
–Set CLASSPATH=.;C:\Lotus\Notes\Notes.jar
–Set PATH=%PATH%;C:\Lotus\Notes
ƒAlternative:
use java's and javac's–classpath option
–local access
–remote access
ƒAdditional
Packages
a Java Extension
ƒIntersection of Java and Notes Security
ƒTrouble Shooting Tips
ƒInstalling
Java and Javac Commands
Local Access to Domino Classes
ƒUse
ƒ3
java command shipped with Notes located in jvm\bin in
program directory.
–c:\lotus\notes\jvm\bin\java JavaMain
ƒJavac
command not shipped with Notes.
–Use version on system
Choices
–Extend NotesThread class
–Implement Runable Interface
–Static NotesThread method
ƒImportant
Concept:
–Domino must be aware of threads using classes
10
Extend NotesThread Class
import lotus.domino.*;
public class JavaMain1 extends NotesThread {
public static void main(String a[]){
JavaMain1 t = new JavaMain1();
t.start();
}
public void runNotes(){
try {
Session s = NotesFactory.createSession();
String p = s.getPlatform());
System.out.println("Platform = " + p);
} catch (Exception e){}
}
}
Static NotesThread Method
import lotus.domino.*;
public class JavaMain3 {
public static void main(String a[]){
try {
NotesThread.sinitThread();
Session s = NotesFactory.createSession();
String p = s.getPlatform());
System.out.println("Platform = " + p);
} catch (Exception e) {
} finally { NotesThread.stermThread();}
}
}
Implement Runnable Interface
import lotus.domino.*;
public class JavaMain2 implements Runnable {
public static void main(String a[]){
JavaMain2 t = new JavaMain2();
NotesThread nt = new NotesThread((Runnable)t);
nt.start();
}
public void run(){
try {
Session s = NotesFactory.createSession();
String p = s.getPlatform());
System.out.println("Platform = " + p);
} catch (Exception e){}
}
}
Key Concepts
ƒEstablish
environment
Javac command from System
ƒUse Java command from Notes
ƒUse one of the suggested approaches
ƒUse
11
Remote Access to Domino Classes
ƒDon't
use NotesThread
CORBA usage
ƒOnly need NSCO.jar on remote machine
ƒTransparent
–Location: C:\Lotus\{notes or domino}\Data\domino\java\NSCO.jar
–Put on CLASSPATH
ƒHint:
ALLOW_NOTES_PACKAGE_APPLETS=1 if using applets
must be running http and diiop
ƒFollowing example:
ƒServer
–java JavaRemote myserver.ibm.com user password
Remote Access to Domino Classes
import lotus.domino.*;
public class JavaRemote {
public static void main(String argv[]) {
try {
String host = argv[0],
user = argv[1],
pwd = argv[2];
Session s = NotesFactory.createSession
(host, user, pwd);
System.out.print(s.getPlatform());
} catch (Exception e) {
e.printStackTrace();
}
}}
Agenda
Java Packages
ƒJRE
ƒJavaMail
Versions
Customization using NOTES.INI Variables
ƒDomino Objects and Memory Management
ƒAccessing Domino Classes from a Java main program
–Imap.jar
–Mail.jar
–Mailapi.jar
–local access
–Pop3.jar
–remote access
ƒAdditional
–Smtp.jar
Packages
ƒInstalling a Java Extension
ƒJavaHelp
ƒIntersection
ƒXML
ƒTrouble
of Java and Notes Security
Shooting Tips
(Sun)
–Activation.jar
ƒJVM
(Sun)
–Jhall.jar
(Apache)
–LotusXSL.jar (Xalan)
–XML4J.jar (Xerces)
–See other sessions
12
Using Java Extensions
Adding JSSE Java Extension
ƒHTTP
vs HTTPS
ƒDownload
–http - net package
ƒShutdown
–https - security package
ƒJRE
1.3.1 does not officially support https
–Sun does provide an extension package
–need to install into the jvm subdirectory
ƒJRE
1.4 will support https
Agenda
JSSE 1.0.3_01 from Sun website
notes
ƒInstall the JSSE jar files into <program_directory>\jvm\lib\ext\
ƒPackage specific operations (from INSTALL.txt)
–Edit <program_directory>\jvm\lib\security\java.security
ƒRestart
ƒTest
Notes
Installation
Applet Security (File->Preferences->User Preferences)
ƒJRE
Versions
Customization using NOTES.INI Variables
ƒDomino Objects and Memory Management
ƒAccessing Domino Classes from a Java main program
ƒJVM
–local access
–remote access
ƒAdditional
ƒInstalling
Packages
a Java Extension
ƒIntersection
ƒTrouble
of Java and Notes Security
Shooting Tips
13
Applet Security (File->Security->User Security)
Workstation Security (File->Security->User Security)
Workstation to Java Security
Workstation to Java Security (Cont)
14
Server Restricted Access
Agenda
ƒcheckAccept
ƒcheckMemberAccess
ƒJRE
ƒcheckAccess
ƒcheckMulticast
ƒJVM
ƒcheckConnect
ƒcheckPackageDefinition
ƒcheckCreateClassLoader
ƒcheckPropertiesAccess
ƒcheckDelete
ƒcheckPropertyAccess
ƒcheckExec
ƒcheckRead
ƒcheckExit
ƒcheckSetFactory
ƒcheckLink
ƒcheckWrite
ƒcheckListen
Versions
Customization using NOTES.INI Variables
ƒDomino Objects and Memory Management
ƒAccessing Domino Classes from a Java main program
–local access
–remote access
ƒAdditional
Packages
a Java Extension
ƒIntersection of Java and Notes Security
ƒInstalling
ƒTrouble
Shooting Tips
Trouble Shooting Tip #1
Trouble Shooting Tip #2
ƒrequires
ƒCheck
a minimum of 256 color on the monitor
–not an issue with client but usually people throw in a cheap monitor
(16 color) for the server
–java won't start as a result
which platform it does not have support
–ND 6 uses IBM's 1.3.1 which does not run on Win95
–no support on MAC OS/X yet
–later version of ND5 and ND6 will raise an exception.
15
Trouble Shooting Tip #3
Trouble Shooting Tip #4
ƒDon't
ƒThere
catch thread death exception in your code
–For java agent, we created a thread group
create 3 threads
–agent loader - load the agent
–agent launcher - launch the agent
–timer thread to check for time out and control break
–threadgroup.kill
–raise a thread death exception to each of its threads
–catching thread death and continue will make your agent not
terminable
–
Resources
is no general way of limiting the resources that Java
uses.
ƒDon't rely on Java Garbage Collector for efficient memory
consumption in Notes/Domino.
ƒUse recycle
Questions?
ƒwww.java.sun.com
ƒwww.ibm.com/java
ƒwww.apache.org
ƒwww.notes.net
ƒwww.lotus.com
?
16