Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
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