Update of /cvsroot/openorb/OpenORB/src/main/org/openorb/orb/rmi In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4887/src/main/org/openorb/orb/rmi Modified Files: DeserializationKernelFactory.java ValueHandlerImpl.java Added Files: LazyInitDeserializationKernel.java Log Message: removed property iiop.useNativeLibrary in favour of iiop.deserializationEngine Allow lazy initialization of DeserializationKernel and make lazy:auto the default behaviour On Sun JDK 1.5 test errors are down to one error in PrimitiveTest.testValuetypes() because of lazy initialization --- NEW FILE: LazyInitDeserializationKernel.java --- /* * Copyright (C) The Community OpenORB Project. All rights reserved. * * This software is published under the terms of The OpenORB Community Software * License version 1.0, a copy of which has been included with this distribution * in the LICENSE.txt file. */ package org.openorb.orb.rmi; /** * A DeserializationKernel that delegates all operations to another kernel, * the delegate is created on demand. * @author lkuehne */ class LazyInitDeserializationKernel implements DeserializationKernel { private DeserializationKernel m_delegate = null; private final String m_delegateShortName; LazyInitDeserializationKernel( String delegateShortName ) { m_delegateShortName = delegateShortName; } private synchronized void ensureDelegateInitialized() { if ( m_delegate == null ) { m_delegate = DeserializationKernelFactory.createDeserializationKernel( m_delegateShortName ); } } public Object allocateNewObject( Class c, Class base ) throws InstantiationException, IllegalAccessException { ensureDelegateInitialized(); return m_delegate.allocateNewObject( c, base ); } public void setObjectField( Class c, String n, Object o, Object v ) { ensureDelegateInitialized(); m_delegate.setObjectField( c, n, o, v ); } public void setBooleanField( Class c, String n, Object o, boolean v ) { ensureDelegateInitialized(); m_delegate.setBooleanField( c, n, o, v ); } public void setByteField( Class c, String n, Object o, byte v ) { ensureDelegateInitialized(); m_delegate.setByteField( c, n, o, v ); } public void setCharField( Class c, String n, Object o, char v ) { ensureDelegateInitialized(); m_delegate.setCharField( c, n, o, v ); } public void setShortField( Class c, String n, Object o, short v ) { ensureDelegateInitialized(); m_delegate.setShortField( c, n, o, v ); } public void setIntField( Class c, String n, Object o, int v ) { ensureDelegateInitialized(); m_delegate.setIntField( c, n, o, v ); } public void setLongField( Class c, String n, Object o, long v ) { ensureDelegateInitialized(); m_delegate.setLongField( c, n, o, v ); } public void setFloatField( Class c, String n, Object o, float v ) { ensureDelegateInitialized(); m_delegate.setFloatField( c, n, o, v ); } public void setDoubleField( Class c, String n, Object o, double v ) { ensureDelegateInitialized(); m_delegate.setDoubleField( c, n, o, v ); } } Index: DeserializationKernelFactory.java =================================================================== RCS file: /cvsroot/openorb/OpenORB/src/main/org/openorb/orb/rmi/DeserializationKernelFactory.java,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -r1.7 -r1.8 --- DeserializationKernelFactory.java 28 Jul 2004 12:08:42 -0000 1.7 +++ DeserializationKernelFactory.java 14 Nov 2004 21:38:35 -0000 1.8 @@ -60,28 +60,29 @@ * </ul> * * @author Michael Rumpf + * @author lkuehne */ public final class DeserializationKernelFactory { /** A static instance of the deserialization native hook. */ private static DeserializationKernel s_kernel = null; - /** True when a native library should be used by the marshaling engine. */ - private static boolean s_use_native_library = false; + /** description of the deserialization mechanism to be used by the marshaling engine. */ + private static String s_deserializationEngine = "lazy:auto"; + private static final String LAZY_PREFIX = "lazy:"; private DeserializationKernelFactory() { } /** - * Set the property whether to use a native library or not. + * Set the deserialization engine to use. * - * @param use_native_library True when a native library should be used, - * false otherwise. + * @param deserializationEngine either auto or native, maybe prefixed with 'lazy:'. */ - public static void setUseNativeLibrary( boolean use_native_library ) + public static void setDeserializationEngine( String deserializationEngine ) { - s_use_native_library = use_native_library; + s_deserializationEngine = deserializationEngine; } /** @@ -92,98 +93,124 @@ * * @return The DeserializationKernel wrapper for the current VM. */ - public static synchronized DeserializationKernel init() + public static synchronized DeserializationKernel retrieveDeserializationKernel() { if ( s_kernel != null ) { return s_kernel; } - if ( s_use_native_library ) + if ( s_deserializationEngine.startsWith( LAZY_PREFIX ) + && s_deserializationEngine.length() > LAZY_PREFIX.length() ) { - s_kernel = new DeserializationKernelNative(); + String delegateShortName = s_deserializationEngine.substring( LAZY_PREFIX.length() ); + s_kernel = new LazyInitDeserializationKernel( delegateShortName ); } else { - try - { - Thread.currentThread().getContextClassLoader().loadClass( - "com.sun.corba.se.internal.io.IIOPInputStream" ); - s_kernel = new DeserializationKernelSun(); - } - catch ( ClassNotFoundException ex ) - { - // no Sun JDK - } + s_kernel = createDeserializationKernel( s_deserializationEngine ); + } - if ( s_kernel == null ) - { - try - { - Thread.currentThread().getContextClassLoader().loadClass( - "com.ibm.rmi.io.JNIReflectField" ); - s_kernel = new DeserializationKernelIBM(); - } - catch ( ClassNotFoundException ex ) - { - // no IBM JDK 1.3.x - } - } + return s_kernel; + } - if ( s_kernel == null ) - { - // The following check is not working under AIX JDK version 1.4.x - // so don'teven try it instead give the following checks a chance - // to succeed - final String os_name = System.getProperty( "os.name" ); - final String vm_version = System.getProperty( "java.vm.version" ); - if ( !os_name.equalsIgnoreCase( "AIX" ) - || !vm_version.startsWith( "1.4." ) ) - { - try - { - Thread.currentThread().getContextClassLoader().loadClass( - "com.ibm.rmi.io.PureReflectField" ); - s_kernel = new DeserializationKernelIBM14(); - } - catch ( ClassNotFoundException ex ) - { - // no valid IBM JDK 1.4.x - } - } - else - { - // This is the broken version - s_kernel = new DeserializationKernelNative(); - } - } - // - // add more VMs here !!!!!!!!!!! - // - /* - if ( s_kernel == null ) - { - try - { - Class clz = Class.forName( "<UNIQUE CLASS FOR VM OF VENDOR XYZ>" ); - // This class needs to be implemented for each JDK - //s_kernel = new DeserializationKernelXYZ(); - } - catch ( ClassNotFoundException ex ) - { - // no XYZ JDK - } - } - */ + /** + * @param deserializationEngine engine descriptor, "lazy:" prefix not allowed here. + * @return the requested DeserializationKernel + */ + static DeserializationKernel createDeserializationKernel( String deserializationEngine ) + { + if ( "auto".equals( deserializationEngine ) ) + { + return createAutoDeserializationKernel(); + } + else if ( "native".equals( deserializationEngine ) ) + { + return new DeserializationKernelNative(); + } + else if ( "none".equals( deserializationEngine ) ) + { + return new NullDeserializationKernel(); + } + throw new IllegalArgumentException( "unsupported iiop.deserializationEngine '" + + deserializationEngine + "', must be 'auto', 'native' or 'none'" ); + } - if ( s_kernel == null ) - { - throw new Error( "Unknown VM vendor. RMIoverIIOP will not work" - + " with this VM. Please contact support at ope...@li...." ); - } + private static DeserializationKernel createAutoDeserializationKernel() + { + try + { + Thread.currentThread().getContextClassLoader().loadClass( + "com.sun.corba.se.internal.io.IIOPInputStream" ); + return new DeserializationKernelSun(); } - return s_kernel; + catch ( ClassNotFoundException ex ) + { + // no Sun JDK + } + + try + { + Thread.currentThread().getContextClassLoader().loadClass( + "com.ibm.rmi.io.JNIReflectField" ); + return new DeserializationKernelIBM(); + } + catch ( ClassNotFoundException ex ) + { + // no IBM JDK 1.3.x + } + + // The following check is not working under AIX JDK version 1.4.x + // so don'teven try it instead give the following checks a chance + // to succeed + final String os_name = System.getProperty( "os.name" ); + final String vm_version = System.getProperty( "java.vm.version" ); + if ( !os_name.equalsIgnoreCase( "AIX" ) + || !vm_version.startsWith( "1.4." ) ) + { + try + { + Thread.currentThread().getContextClassLoader().loadClass( + "com.ibm.rmi.io.PureReflectField" ); + return new DeserializationKernelIBM14(); + } + catch ( ClassNotFoundException ex ) + { + // no valid IBM JDK 1.4.x + } + } + else + { + // This is the broken version + return new DeserializationKernelNative(); + } + + // + // add more VMs here !!!!!!!!!!! + // + /* + try + { + Class clz = Class.forName( "<UNIQUE CLASS FOR VM OF VENDOR XYZ>" ); + // This class needs to be implemented for each JDK + return new DeserializationKernelXYZ(); + } + catch ( ClassNotFoundException ex ) + { + // no XYZ JDK + } + */ + + String vmName = System.getProperty( "java.vm.name" ); // Java HotSpot(TM) Client VM + String vmVersion = System.getProperty( "java.vm.version" ); // 1.4.2-b28 + String vmVendor = System.getProperty( "java.vm.vendor" ); // Sun Microsystems Inc. + + throw new Error( "Unknown VM and iiop.deserializationEngine set to 'auto'. " + + "RMIoverIIOP will not work with this VM (" + + vmName + ' ' + vmVersion + ", " + vmVendor + + "). Please try the native engine or " + + "contact support at ope...@li...." ); } } Index: ValueHandlerImpl.java =================================================================== RCS file: /cvsroot/openorb/OpenORB/src/main/org/openorb/orb/rmi/ValueHandlerImpl.java,v retrieving revision 1.10 retrieving revision 1.11 diff -u -d -r1.10 -r1.11 --- ValueHandlerImpl.java 20 Aug 2004 10:08:13 -0000 1.10 +++ ValueHandlerImpl.java 14 Nov 2004 21:38:35 -0000 1.11 @@ -55,7 +55,8 @@ private static final Object SYNC_INSTANCE = new Object(); private static ValueHandlerImpl s_value_handler_instance; - private static DeserializationKernel s_kernel = DeserializationKernelFactory.init(); + private static DeserializationKernel s_kernel = + DeserializationKernelFactory.retrieveDeserializationKernel(); private static org.omg.CORBA.WStringValueHelper s_string_helper = new org.omg.CORBA.WStringValueHelper(); |