Modified: geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/ValueType.java URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/ValueType.java?view=diff&r1=158861&r2=158862 ============================================================================== --- geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/ValueType.java (original) +++ geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/ValueType.java Wed Mar 23 18:30:30 2005 @@ -17,50 +17,60 @@ */ package org.apache.geronimo.interop.rmi.iiop; -import org.apache.geronimo.interop.*; -import org.apache.geronimo.interop.rmi.*; -import org.apache.geronimo.interop.util.*; -import java.io.*; -import java.lang.reflect.*; -import java.security.*; -import java.util.*; +import java.io.ByteArrayOutputStream; +import java.io.DataOutputStream; +import java.io.ObjectInput; +import java.io.ObjectOutput; +import java.io.ObjectStreamClass; +import java.io.Serializable; +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.lang.reflect.Modifier; +import java.security.DigestOutputStream; +import java.security.MessageDigest; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; + import org.omg.CORBA.TCKind; -public class ValueType -{ - //public static final Component component = new Component(ValueType.class); - - public static ValueType getInstance(Class forClass) - { - ValueType vt = (ValueType)_valueTypeMap.get(forClass); - if (vt == null) - { - synchronized (_valueTypeMap) - { - vt = (ValueType)_valueTypeMap.get(forClass); - if (vt == null) - { - //vt = (ValueType)component.getInstance(); +import org.apache.geronimo.interop.SystemException; +import org.apache.geronimo.interop.util.ArrayUtil; +import org.apache.geronimo.interop.util.ExceptionUtil; +import org.apache.geronimo.interop.util.JavaClass; +import org.apache.geronimo.interop.util.JavaType; +import org.apache.geronimo.interop.util.SystemUtil; + + +/** + * * A wrapper over java.lang.Class to help improve performance of using + * * the Java reflection API for valuetype marshalling. We keep as much + * * derived information as possible for optimal performance. + */ +public class ValueType { + public static ValueType getInstance(Class forClass) { + ValueType vt = (ValueType) _valueTypeMap.get(forClass); + if (vt == null) { + synchronized (_valueTypeMap) { + vt = (ValueType) _valueTypeMap.get(forClass); + if (vt == null) { vt = new ValueType(); - _valueTypeMap.put(forClass, vt); vt.init(forClass); + _valueTypeMap.put(forClass, vt); } } } return vt; } - public static ValueType getInstanceByID(String id) - { + public static ValueType getInstanceByID(String id) { // TODO: handle multiple class loaders??? - ValueType vt = (ValueType)_idTypeMap.get(id); - if (vt == null) - { - synchronized (_idTypeMap) - { - vt = (ValueType)_idTypeMap.get(id); - if (vt == null) - { + ValueType vt = (ValueType) _idTypeMap.get(id); + if (vt == null) { + synchronized (_idTypeMap) { + vt = (ValueType) _idTypeMap.get(id); + if (vt == null) { Class theClass = getClass(id); vt = getInstance(theClass); _idTypeMap.put(id, vt); @@ -109,13 +119,13 @@ // package-private data // ----------------------------------------------------------------------- - static final int NULL_VALUE_TAG = 0; - static final int NO_TYPE_VALUE_TAG = 0x7fffff00; - static final int SINGLE_TYPE_VALUE_TAG = 0x7fffff02; - static final int TRUNCATABLE_NO_TYPE_VALUE_TAG = 0x7fffff08; + static final int NULL_VALUE_TAG = 0; + static final int NO_TYPE_VALUE_TAG = 0x7fffff00; + static final int SINGLE_TYPE_VALUE_TAG = 0x7fffff02; + static final int TRUNCATABLE_NO_TYPE_VALUE_TAG = 0x7fffff08; static final int TRUNCATABLE_SINGLE_TYPE_VALUE_TAG = 0x7fffff0a; - static final int TYPE_LIST_VALUE_TAG = 0x7fffff06; - static final int INDIRECTION_TAG = 0xffffffff; + static final int TYPE_LIST_VALUE_TAG = 0x7fffff06; + static final int INDIRECTION_TAG = 0xffffffff; static final int CASE_ARRAY = 1; static final int CASE_CLASS = 2; @@ -168,27 +178,20 @@ // static initializer // ----------------------------------------------------------------------- - static - { + static { TC_ABSTRACT_BASE = new TypeCode(TCKind.tk_abstract_interface); TC_ABSTRACT_BASE.id("IDL:omg.org/CORBA/AbstractBase:1.0"); TC_ABSTRACT_BASE.name(""); - try - { - if (JDK14) - { - _newInstance = java.io.ObjectStreamClass.class.getDeclaredMethod("newInstance", new Class[] {}); + try { + if (JDK14) { + _newInstance = java.io.ObjectStreamClass.class.getDeclaredMethod("newInstance", new Class[]{}); _newInstance.setAccessible(true); - } - else - { - _allocateNewObject = java.io.ObjectInputStream.class.getDeclaredMethod("allocateNewObject", new Class[] { Class.class, Class.class }); + } else { + _allocateNewObject = java.io.ObjectInputStream.class.getDeclaredMethod("allocateNewObject", new Class[]{Class.class, Class.class}); _allocateNewObject.setAccessible(true); } - } - catch (Exception ex) - { + } catch (Exception ex) { throw ExceptionUtil.getRuntimeException(ex); } } @@ -197,105 +200,70 @@ // public methods // ----------------------------------------------------------------------- - public Object newInstance() - { - try - { - if (JDK14) - { - if (_class == Object.class) - { + public Object newInstance() { + try { + if (JDK14) { + if (_class == Object.class) { return new Object(); - } - else - { + } else { return _newInstance.invoke(_objectStreamClass, ArrayUtil.EMPTY_OBJECT_ARRAY); } - } - else - { + } else { return _allocateNewObject.invoke(null, _allocateNewObjectArgs); } - } - catch (Exception ex) - { + } catch (Exception ex) { throw ExceptionUtil.getRuntimeException(ex); } } - public String toString() - { + public String toString() { return "ValueType:" + JavaType.getName(_class); } - public void readObject(Object _this, org.apache.geronimo.interop.rmi.iiop.ObjectInputStream input) - { - try - { + public void readObject(Object _this, org.apache.geronimo.interop.rmi.iiop.ObjectInputStream input) { + try { _readObject.invoke(_this, input.thisAsObjectArray); - } - catch (Exception ex) - { + } catch (Exception ex) { throw ExceptionUtil.getRuntimeException(ex); } } - public void writeObject(Object _this, org.apache.geronimo.interop.rmi.iiop.ObjectOutputStream output) - { - try - { + public void writeObject(Object _this, org.apache.geronimo.interop.rmi.iiop.ObjectOutputStream output) { + try { _writeObject.invoke(_this, output.thisAsObjectArray); - } - catch (Exception ex) - { + } catch (Exception ex) { throw ExceptionUtil.getRuntimeException(ex); } } - public Object readResolve(Object _this) - { - try - { + public Object readResolve(Object _this) { + try { return _readResolve.invoke(_this, ArrayUtil.EMPTY_OBJECT_ARRAY); - } - catch (Exception ex) - { + } catch (Exception ex) { throw ExceptionUtil.getRuntimeException(ex); } } - public Object writeReplace(Object _this) - { - try - { + public Object writeReplace(Object _this) { + try { return _writeReplace.invoke(_this, ArrayUtil.EMPTY_OBJECT_ARRAY); - } - catch (Exception ex) - { + } catch (Exception ex) { throw ExceptionUtil.getRuntimeException(ex); } } - public void readExternal(Object _this, org.apache.geronimo.interop.rmi.iiop.ObjectInputStream input) - { - try - { + public void readExternal(Object _this, org.apache.geronimo.interop.rmi.iiop.ObjectInputStream input) { + try { _readExternal.invoke(_this, input.thisAsObjectArray); - } - catch (Exception ex) - { + } catch (Exception ex) { throw ExceptionUtil.getRuntimeException(ex); } } - public void writeExternal(Object _this, org.apache.geronimo.interop.rmi.iiop.ObjectOutputStream output) - { - try - { + public void writeExternal(Object _this, org.apache.geronimo.interop.rmi.iiop.ObjectOutputStream output) { + try { _writeExternal.invoke(_this, output.thisAsObjectArray); - } - catch (Exception ex) - { + } catch (Exception ex) { throw ExceptionUtil.getRuntimeException(ex); } } @@ -304,67 +272,50 @@ // protected methods // ----------------------------------------------------------------------- - protected void init(Class theClass) - { + protected void init(Class theClass) { boolean recursive = false; - if (_initMap.get(theClass) != null) - { + if (_initMap.get(theClass) != null) { // recursive = true; return; // Already initializing (recursive 'init' call). } _initMap.put(theClass, Boolean.TRUE); - try - { + try { _class = theClass; _objectStreamClass = ObjectStreamClass.lookup(_class); if (org.omg.CORBA.Object.class.isAssignableFrom(theClass) || javax.ejb.EJBHome.class.isAssignableFrom(theClass) || javax.ejb.EJBObject.class.isAssignableFrom(theClass) - || java.rmi.Remote.class.isAssignableFrom(theClass)) - { + || java.rmi.Remote.class.isAssignableFrom(theClass)) { helper = ObjectRefHelper.getInstance(theClass); isObjectRef = true; readWriteCase = CASE_IDL_OBJECT; - } - else if (org.omg.CORBA.portable.IDLEntity.class.isAssignableFrom(theClass)) - { + } else if (org.omg.CORBA.portable.IDLEntity.class.isAssignableFrom(theClass)) { helper = IDLEntityHelper.getInstance(theClass); isIDLEntity = true; readWriteCase = CASE_IDL_ENTITY; - } - else if (theClass == String.class) - { + } else if (theClass == String.class) { helper = StringHelper.SINGLETON; readWriteCase = CASE_STRING; - } - else if (theClass.isArray()) - { + } else if (theClass.isArray()) { Class elementClass = theClass.getComponentType(); element = getInstance(elementClass); isArray = true; - if (elementClass.isPrimitive()) - { + if (elementClass.isPrimitive()) { primitiveArray = PrimitiveType.get(elementClass); helper = PrimitiveType.getArrayHelper(elementClass); - } - else - { + } else { helper = new ArrayHelper(elementClass); } readWriteCase = CASE_ARRAY; - } - else if (theClass == Class.class) - { + } else if (theClass == Class.class) { readWriteCase = CASE_CLASS; } - if (_allocateNewObject != null) - { + if (_allocateNewObject != null) { Class bc = _class; - while (Serializable.class.isAssignableFrom(bc) && (bc.getSuperclass() != null)) - { + while (Serializable.class.isAssignableFrom(bc) && (bc.getSuperclass() != null)) { bc = bc.getSuperclass(); } - _allocateNewObjectArgs = new Object[] { _class, bc }; + _allocateNewObjectArgs = new Object[]{_class, bc}; } isAny = _class == java.lang.Object.class @@ -372,15 +323,13 @@ || _class == java.io.Serializable.class; isExternalizable = java.io.Externalizable.class.isAssignableFrom(_class); - if (isExternalizable) - { - _readExternal = _class.getDeclaredMethod("readExternal", new Class[] { ObjectInput.class } ); - _writeExternal = _class.getDeclaredMethod("writeExternal", new Class[] { ObjectOutput.class } ); + if (isExternalizable) { + _readExternal = _class.getDeclaredMethod("readExternal", new Class[]{ObjectInput.class}); + _writeExternal = _class.getDeclaredMethod("writeExternal", new Class[]{ObjectOutput.class}); } // SG: Hopefully we got all the info that is needed - if(recursive) - { + if (recursive) { return; } @@ -388,89 +337,75 @@ java.lang.Class tmpClass = _class; ArrayList fieldList = new ArrayList(); Field[] javaFields = tmpClass.getDeclaredFields(); - + // TODO: suppress sort for IDL-generated valuetypes Arrays.sort(javaFields, FieldComparator.SINGLETON); - + // Create vector of non-static, non-transient fields. // Ensure that all fields are readable/writable using reflection. int nf = javaFields.length; - for (int f = 0; f < nf; f++) - { + for (int f = 0; f < nf; f++) { Field javaField = javaFields[f]; int modifiers = javaField.getModifiers(); - if ((modifiers & (Modifier.STATIC | Modifier.TRANSIENT)) != 0) - { + if ((modifiers & (Modifier.STATIC | Modifier.TRANSIENT)) != 0) { continue; } - if (! javaField.isAccessible()) - { + if (!javaField.isAccessible()) { javaField.setAccessible(true); } ValueTypeField field = new ValueTypeField(javaField); fieldList.add(field); } - fields = (ValueTypeField[])fieldList.toArray(new ValueTypeField[fieldList.size()]); + fields = (ValueTypeField[]) fieldList.toArray(new ValueTypeField[fieldList.size()]); // Check methods for readObject/writeObject. Also check for // abstract interfaces. Method[] methods = _class.getDeclaredMethods(); int countThrowsRemoteException = 0; int nm = methods.length; - for (int m = 0; m < nm; m++) - { + for (int m = 0; m < nm; m++) { Method method = methods[m]; Class[] types = method.getParameterTypes(); if (types.length == 1 && types[0] == java.io.ObjectInputStream.class && (method.getModifiers() & Modifier.PRIVATE) != 0 - && method.getName().equals("readObject")) - { + && method.getName().equals("readObject")) { _readObject = method; - if (! _readObject.isAccessible()) - { + if (!_readObject.isAccessible()) { _readObject.setAccessible(true); } } if (types.length == 1 && types[0] == java.io.ObjectOutputStream.class && (method.getModifiers() & Modifier.PRIVATE) != 0 - && method.getName().equals("writeObject")) - { + && method.getName().equals("writeObject")) { _writeObject = method; - if (! _writeObject.isAccessible()) - { + if (!_writeObject.isAccessible()) { _writeObject.setAccessible(true); } } if (types.length == 0 && method.getReturnType() == java.lang.Object.class - && method.getName().equals("writeReplace")) - { + && method.getName().equals("writeReplace")) { _writeReplace = method; - if (! _writeReplace.isAccessible()) - { + if (!_writeReplace.isAccessible()) { _writeReplace.setAccessible(true); } } if (types.length == 0 - && method.getReturnType() == java.lang.Object.class - && method.getName().equals("readResolve")) - { + && method.getReturnType() == java.lang.Object.class + && method.getName().equals("readResolve")) { _readResolve = method; - if (! _readResolve.isAccessible()) - { + if (!_readResolve.isAccessible()) { _readResolve.setAccessible(true); } } Class[] exceptions = method.getExceptionTypes(); - for (int i = 0; i < exceptions.length; i++) - { + for (int i = 0; i < exceptions.length; i++) { Class exception = exceptions[i]; - if (exception.isAssignableFrom(java.rmi.RemoteException.class)) - { + if (exception.isAssignableFrom(java.rmi.RemoteException.class)) { // TODO: check Java to IDL wording for this countThrowsRemoteException++; break; @@ -484,21 +419,20 @@ hasWriteReplace = _writeReplace != null; hasReadResolve = _readResolve != null; - isAbstractInterface = ! isObjectRef - && _class.isInterface() - && countThrowsRemoteException == methods.length; + isAbstractInterface = !isObjectRef + && _class.isInterface() + && countThrowsRemoteException == methods.length; Class superclass = _class.getSuperclass(); - if((superclass != null) && (superclass != java.lang.Object.class) && (!isIDLEntity )) - { + if ((superclass != null) && (superclass != java.lang.Object.class) && (!isIDLEntity)) { parent = getInstance(superclass); } hasParentState = parent != null - && (parent.fields.length > 0 - || parent.isExternalizable - || parent.hasReadOrWriteObject - || parent.hasParentState); + && (parent.fields.length > 0 + || parent.isExternalizable + || parent.hasReadOrWriteObject + || parent.hasParentState); requiresCustomSerialization = hasWriteObject || isExternalizable; @@ -506,57 +440,44 @@ initTypeCode(); isAnyOrObjectRefOrAbstractInterface = isAny || isObjectRef || isAbstractInterface; - } - catch (Exception ex) - { + } catch (Exception ex) { throw ExceptionUtil.getRuntimeException(ex); - } - finally - { - if(!recursive) - { - _initMap.remove(theClass); + } finally { + if (!recursive) { + _initMap.remove(theClass); + } } } - } - protected void initRepositoryID() - { + protected void initRepositoryID() { final String sixteenZeros = "0000000000000000"; final int requiredLength = 16; - if (isAny) - { + if (isAny) { id = "#ANY-TODO#"; return; } - if (isArray && primitiveArray != 0) - { + if (isArray && primitiveArray != 0) { id = "#ARRAY-TODO#"; return; } - if (_class == String.class) - { + if (_class == String.class) { id = "IDL:omg.org/CORBA/WStringValue:1.0"; return; } - if (isObjectRef) - { + if (isObjectRef) { id = "RMI:" + _class.getName() + ":" + sixteenZeros; return; } - if (_class == java.lang.Class.class) - { + if (_class == java.lang.Class.class) { id = "RMI:javax.rmi.CORBA.ClassDesc:2BABDA04587ADCCC:CFBF02CF5294176B"; return; } - if (_class == java.math.BigInteger.class) - { + if (_class == java.math.BigInteger.class) { id = "RMI:java.math.BigInteger:8CAD1A3C6C0A9DF0:8CFC9F1FA93BFB1D"; skipCustomFlags = true; // TODO: move this and check usage return; } - if (_objectStreamClass == null) - { + if (_objectStreamClass == null) { id = "???"; return; } @@ -567,80 +488,56 @@ int currentLength; int lengthNeeded; currentLength = structuralUIDString.length(); - if (currentLength < requiredLength) - { + if (currentLength < requiredLength) { lengthNeeded = requiredLength - currentLength; structuralUIDString = sixteenZeros.substring(0, lengthNeeded) + structuralUIDString; } currentLength = serialVersionUIDString.length(); - if (currentLength < requiredLength) - { + if (currentLength < requiredLength) { lengthNeeded = requiredLength - currentLength; serialVersionUIDString = sixteenZeros.substring(0, lengthNeeded) + serialVersionUIDString; } id = "RMI:" + _class.getName() + ":" + structuralUIDString + ":" + serialVersionUIDString; } - protected void initTypeCode() - { - if (isObjectRef) - { + protected void initTypeCode() { + if (isObjectRef) { tc = new TypeCode(TCKind.tk_objref); tc.id(id); tc.name(""); - } - else if (isArray || isIDLEntity || _class == String.class) - { + } else if (isArray || isIDLEntity || _class == String.class) { tc = new TypeCode(TCKind.tk_value_box); tc.id(id); tc.name(""); - if (_class == String.class) - { + if (_class == String.class) { tc.content_type(new TypeCode(TCKind.tk_wstring)); - } - else if (isArray) - { + } else if (isArray) { TypeCode seqTC = new TypeCode(TCKind.tk_sequence); - if (primitiveArray != 0) - { + if (primitiveArray != 0) { seqTC.content_type(PrimitiveType.getTypeCode(primitiveArray)); - } - else - { + } else { seqTC.content_type(element.tc); } tc.content_type(seqTC); - } - else if (isIDLEntity) - { + } else if (isIDLEntity) { // TODO tc.content_type(helper.type()); } - } - else - { + } else { tc = new TypeCode(TCKind.tk_value); tc.id(id); tc.name(""); // TODO: value modifier - if (requiresCustomSerialization) - { - tc.type_modifier((short)1); - } - else if (isAbstractInterface) - { - tc.type_modifier((short)2); - } - else - { - tc.type_modifier((short)0); + if (requiresCustomSerialization) { + tc.type_modifier((short) 1); + } else if (isAbstractInterface) { + tc.type_modifier((short) 2); + } else { + tc.type_modifier((short) 0); } - if (parent == null) - { + if (parent == null) { tc.concrete_base_type(TC_NULL); - } - else - { + } else { // TODO: check validity of this tc.concrete_base_type(TC_NULL); // tc.concrete_base_type(getTypeCode(parent)); @@ -650,119 +547,128 @@ } } - static long computeStructuralUID(ValueType vt) - { + static long computeStructuralUID(ValueType vt) { Class c = vt._class; ObjectStreamClass osc = vt._objectStreamClass; ByteArrayOutputStream devnull = new ByteArrayOutputStream(512); long h = 0; - try - { - if (! java.io.Serializable.class.isAssignableFrom(c) - || c.isInterface()) - { + try { + if (!java.io.Serializable.class.isAssignableFrom(c) + || c.isInterface()) { return 0; } - if (java.io.Externalizable.class.isAssignableFrom(c)) - { + if (java.io.Externalizable.class.isAssignableFrom(c)) { return 1; } MessageDigest md = MessageDigest.getInstance("SHA"); DigestOutputStream mdo = new DigestOutputStream(devnull, md); DataOutputStream data = new DataOutputStream(mdo); - if (vt.parent != null) - { + if (vt.parent != null) { data.writeLong(computeStructuralUID(vt.parent)); } - if (vt.hasWriteObject) - { + if (vt.hasWriteObject) { data.writeInt(2); - } - else - { + } else { data.writeInt(1); } List fieldList = new ArrayList(vt.fields.length); - for (int i = 0; i < vt.fields.length; i++) - { + for (int i = 0; i < vt.fields.length; i++) { fieldList.add(vt.fields[i].javaField); } - Field[] fields = (Field[])fieldList.toArray(new Field[fieldList.size()]); + Field[] fields = (Field[]) fieldList.toArray(new Field[fieldList.size()]); Arrays.sort(fields, FieldByNameComparator.SINGLETON); - for (int i = 0; i < vt.fields.length; i++) - { + for (int i = 0; i < vt.fields.length; i++) { Field f = fields[i]; data.writeUTF(f.getName()); data.writeUTF(JavaClass.getSignature(f.getType())); } data.flush(); byte[] hasharray = md.digest(); - for (int i = 0; i < Math.min(8, hasharray.length); i++) - { - h += (long)(hasharray[i] & 255) << (i * 8); + for (int i = 0; i < Math.min(8, hasharray.length); i++) { + h += (long) (hasharray[i] & 255) << (i * 8); } return h; - } - catch (Exception ex) - { + } catch (Exception ex) { throw new SystemException(ex); } } /** - ** Map an RMI/IDL Repository ID to a java.lang.Class. - **/ - static Class getClass(String id) - { - if (id.startsWith("RMI:")) - { + * * Map an RMI/IDL Repository ID to a java.lang.Class. + */ + static Class getClass(String id) { + if (id.startsWith("RMI:")) { int endClass = id.indexOf(':', 4); - if (endClass == -1) - { + if (endClass == -1) { throw new org.omg.CORBA.INV_IDENT(id); } String className = id.substring(4, endClass); - if (className.equals("javax.rmi.CORBA.ClassDesc")) - { + if (className.equals("javax.rmi.CORBA.ClassDesc")) { return Class.class; - } - else - { + } else { return loadClass(className); } - } - else if (id.equals("IDL:omg.org/CORBA/WStringValue:1.0")) - { + } else if (id.equals("IDL:omg.org/CORBA/WStringValue:1.0")) { return java.lang.String.class; - } - else if (id.startsWith("IDL:omg.org/")) - { + } else if (id.startsWith("IDL:omg.org/")) { int endClass = id.indexOf(':', 12); - if (endClass == -1) - { + if (endClass == -1) { throw new org.omg.CORBA.INV_IDENT(id); } - String className = "org.omg" + id.substring( "IDL:omg.org".length(), endClass).replace('/', '.'); + String className = "org.omg" + id.substring("IDL:omg.org".length(), endClass).replace('/', '.'); return loadClass(className); - } - else if (id.startsWith("IDL:")) - { + } else if (id.startsWith("IDL:")) { int endClass = id.indexOf(':', 4); - if (endClass == -1) - { + if (endClass == -1) { throw new org.omg.CORBA.INV_IDENT(id); } String className = id.substring(4, endClass).replace('/', '.'); return loadClass(className); - } - else - { + } else { throw new org.omg.CORBA.INV_IDENT(id); } } - static Class loadClass(String className) - { - return ThreadContext.loadClass(className); + static Class loadClass(String className) { + Class c = null; + + System.out.println("loadClass(): " + className); + + try { + //c = Class.forName( className ); + c = ClassLoader.getSystemClassLoader().loadClass(className); + } catch (Exception e) { + e.printStackTrace(); + } + + //return ThreadContext.loadClass(className); + return c; + } + + public static void main(String args[]) + throws Exception { + Class c = Class.forName(args[0]); + ValueType vt = ValueType.getInstance(c); + System.out.println("vt = " + vt.toString()); + System.out.println("vt.id = " + vt.id); + System.out.println("vt.tc = " + vt.tc.id()); + + c = Class.forName("org.omg.CosNaming.NameComponent"); + vt = ValueType.getInstance(c); + System.out.println("vt = " + vt.toString()); + System.out.println("vt.id = " + vt.id); + System.out.println("vt.tc = " + vt.tc.id()); + + c = ValueType.getClass("RMI:mark.comps.Add:0000000000000000"); + System.out.println("c.getName() = " + c.getName()); + + c = ValueType.getClass("RMI:org.omg.CosNaming.NameComponent:7FD3FB2290230F5E:F164A2194A66282A"); + System.out.println("c.getName() = " + c.getName()); + + c = ValueType.getClass("IDL:omg.org/CosNaming/NameComponent:1.0"); + System.out.println("c.getName() = " + c.getName()); + + c = ValueType.getClass("RMI:mark.AddData:4165959D0B2418DD:747FE23938318E95"); + System.out.println("c.getName() = " + c.getName()); } } Modified: geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/ValueTypeField.java URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/ValueTypeField.java?view=diff&r1=158861&r2=158862 ============================================================================== --- geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/ValueTypeField.java (original) +++ geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/ValueTypeField.java Wed Mar 23 18:30:30 2005 @@ -17,320 +17,169 @@ */ package org.apache.geronimo.interop.rmi.iiop; -import org.apache.geronimo.interop.*; -import java.lang.reflect.*; +import java.lang.reflect.Field; -public class ValueTypeField -{ +import org.apache.geronimo.interop.SystemException; + + +public class ValueTypeField { public final Field javaField; public final int primitive; public final ValueType type; - private final boolean isFinal; - - private FinalFieldSetter finalFieldSetter; - - public ValueTypeField(Field field) - { + public ValueTypeField(Field field) { javaField = field; - if (field.getType().isPrimitive()) - { + if (field.getType().isPrimitive()) { primitive = PrimitiveType.get(field.getType()); type = null; - } - else - { + } else { primitive = 0; type = ValueType.getInstance(field.getType()); } - if(Modifier.isFinal(field.getModifiers())) - { - isFinal = true; - finalFieldSetter = FinalFieldSetter.getInstance(field); - } - else - { - isFinal = false; - } } - public boolean getBoolean(Object that) - { - try - { + public boolean getBoolean(Object that) { + try { return javaField.getBoolean(that); - } - catch (Exception ex) - { + } catch (Exception ex) { throw new SystemException(ex); } } - public byte getByte(Object that) - { - try - { + public byte getByte(Object that) { + try { return javaField.getByte(that); - } - catch (Exception ex) - { + } catch (Exception ex) { throw new SystemException(ex); } } - public char getChar(Object that) - { - try - { + public char getChar(Object that) { + try { return javaField.getChar(that); - } - catch (Exception ex) - { + } catch (Exception ex) { throw new SystemException(ex); } } - public double getDouble(Object that) - { - try - { + public double getDouble(Object that) { + try { return javaField.getDouble(that); - } - catch (Exception ex) - { + } catch (Exception ex) { throw new SystemException(ex); } } - public float getFloat(Object that) - { - try - { + public float getFloat(Object that) { + try { return javaField.getFloat(that); - } - catch (Exception ex) - { + } catch (Exception ex) { throw new SystemException(ex); } } - public int getInt(Object that) - { - try - { + public int getInt(Object that) { + try { return javaField.getInt(that); - } - catch (Exception ex) - { + } catch (Exception ex) { throw new SystemException(ex); } } - public long getLong(Object that) - { - try - { + public long getLong(Object that) { + try { return javaField.getLong(that); - } - catch (Exception ex) - { + } catch (Exception ex) { throw new SystemException(ex); } } - public short getShort(Object that) - { - try - { + public short getShort(Object that) { + try { return javaField.getShort(that); - } - catch (Exception ex) - { + } catch (Exception ex) { throw new SystemException(ex); } } - public Object get(Object that) - { - try - { + public Object get(Object that) { + try { return javaField.get(that); - } - catch (Exception ex) - { + } catch (Exception ex) { throw new SystemException(ex); } } - public void setBoolean(Object that, boolean value) - { - try - { - if(isFinal) - { - finalFieldSetter.setBoolean(that, value); - } - else - { - javaField.setBoolean(that, value); - } - } - catch (Exception ex) - { + public void setBoolean(Object that, boolean value) { + try { + javaField.setBoolean(that, value); + } catch (Exception ex) { throw new SystemException(ex); } } - public void setByte(Object that, byte value) - { - try - { - if(isFinal) - { - finalFieldSetter.setByte(that, value); - } - else - { - javaField.setByte(that, value); - } - } - catch (Exception ex) - { + public void setByte(Object that, byte value) { + try { + javaField.setByte(that, value); + } catch (Exception ex) { throw new SystemException(ex); } } - public void setChar(Object that, char value) - { - try - { - if(isFinal) - { - finalFieldSetter.setChar(that, value); - } - else - { - javaField.setChar(that, value); - } - } - catch (Exception ex) - { + public void setChar(Object that, char value) { + try { + javaField.setChar(that, value); + } catch (Exception ex) { throw new SystemException(ex); } } - public void setDouble(Object that, double value) - { - try - { - if(isFinal) - { - finalFieldSetter.setDouble(that, value); - } - else - { - javaField.setDouble(that, value); - } - } - catch (Exception ex) - { + public void setDouble(Object that, double value) { + try { + javaField.setDouble(that, value); + } catch (Exception ex) { throw new SystemException(ex); } } - public void setFloat(Object that, float value) - { - try - { - if(isFinal) - { - finalFieldSetter.setFloat(that, value); - } - else - { - javaField.setFloat(that, value); - } - } - catch (Exception ex) - { + public void setFloat(Object that, float value) { + try { + javaField.setFloat(that, value); + } catch (Exception ex) { throw new SystemException(ex); } } - public void setInt(Object that, int value) - { - try - { - if(isFinal) - { - finalFieldSetter.setInt(that, value); - } - else - { - javaField.setInt(that, value); - } - } - catch (Exception ex) - { + public void setInt(Object that, int value) { + try { + javaField.setInt(that, value); + } catch (Exception ex) { throw new SystemException(ex); } } - public void setLong(Object that, long value) - { - try - { - if(isFinal) - { - finalFieldSetter.setLong(that, value); - } - else - { - javaField.setLong(that, value); - } - } - catch (Exception ex) - { + public void setLong(Object that, long value) { + try { + javaField.setLong(that, value); + } catch (Exception ex) { throw new SystemException(ex); } } - public void setShort(Object that, short value) - { - try - { - if(isFinal) - { - finalFieldSetter.setShort(that, value); - } - else - { - javaField.setShort(that, value); - } - } - catch (Exception ex) - { + public void setShort(Object that, short value) { + try { + javaField.setShort(that, value); + } catch (Exception ex) { throw new SystemException(ex); } } - public void set(Object that, Object value) - { - try - { - if(isFinal) - { - finalFieldSetter.set(that, value); - } - else - { - javaField.set(that, value); - } - } - catch (Exception ex) - { + public void set(Object that, Object value) { + try { + javaField.set(that, value); + } catch (Exception ex) { throw new SystemException(ex); } } Modified: geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/client/ClientNamingContext.java URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/client/ClientNamingContext.java?view=diff&r1=158861&r2=158862 ============================================================================== --- geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/client/ClientNamingContext.java (original) +++ geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/client/ClientNamingContext.java Wed Mar 23 18:30:30 2005 @@ -36,23 +36,27 @@ import org.apache.geronimo.interop.rmi.iiop.compiler.StubFactory; import org.apache.geronimo.interop.util.ExceptionUtil; -public class ClientNamingContext implements Context, java.io.Serializable { +public class ClientNamingContext implements Context, java.io.Serializable { public static ClientNamingContext getInstance(Hashtable env) { - ClientNamingContext nc = (ClientNamingContext) contextMap.get(env); + ClientNamingContext nc = (ClientNamingContext) _contextMap.get(env); if (nc == null) { - synchronized (contextMap) { - nc = (ClientNamingContext) contextMap.get(env); + synchronized (_contextMap) { + nc = (ClientNamingContext) _contextMap.get(env); if (nc == null) { nc = new ClientNamingContext(); nc.init(env); - contextMap.put(env, nc); + _contextMap.put(env, nc); } } } return nc; } + // ----------------------------------------------------------------------- + // properties + // ----------------------------------------------------------------------- + public static final StringProperty usernameProperty = new StringProperty(SystemProperties.class, "java.naming.security.principal"); @@ -63,45 +67,64 @@ new IntProperty(SystemProperties.class, "org.apache.geronimo.interop.rmi.idleConnectionTimeout") .defaultValue(60); // seconds - private static int idleConnectionTimeout = + // ----------------------------------------------------------------------- + // private data + // ----------------------------------------------------------------------- + + private static int _idleConnectionTimeout = idleConnectionTimeoutProperty.getInt(); - private static int namingContextCacheTimeout = + private static int _namingContextCacheTimeout = SystemProperties.rmiNamingContextCacheTimeoutProperty.getInt(); - private static HashMap contextMap = new HashMap(); - private static HashMap hostListCache = new HashMap(); - private static HashMap multiHostMap = new HashMap(); - private static Random random = new Random(); - private HashMap cache = new HashMap(); - private Hashtable env; - private ConnectionPool connectionPool; - private PropertyMap connectionProperties; - static private HashMap nameMap = new HashMap(); - private String prefix; - private String username; - private String password; + private static HashMap _contextMap = new HashMap(); + + private static HashMap _hostListCache = new HashMap(); + + private static HashMap _multiHostMap = new HashMap(); + + private static Random _random = new Random(); + + private HashMap _cache = new HashMap(); + + private Hashtable _env; + + private ConnectionPool _connectionPool; - private org.apache.geronimo.interop.CosNaming.NamingContext serverNamingContext; + private PropertyMap _connectionProperties; + + private org.apache.geronimo.interop.CosNaming.NamingContext _serverNamingContext; + static private HashMap _nameMap = new HashMap(); + + + private String _prefix; + + private String _username; + + private String _password; + + // ----------------------------------------------------------------------- + // public methods + // ----------------------------------------------------------------------- public ConnectionPool getConnectionPool() { - return connectionPool; + return _connectionPool; } public PropertyMap getConnectionProperties() { - return connectionProperties; + return _connectionProperties; } public int getIdleConnectionTimeout() { - return idleConnectionTimeout; + return _idleConnectionTimeout; } public String getUsername() { - return username; + return _username; } public String getPassword() { - return password; + return _password; } // ----------------------------------------------------------------------- @@ -117,22 +140,22 @@ name = name.substring(14); } - String newName = (String) nameMap.get(name); + String newName = (String) _nameMap.get(name); if (newName != null) { name = newName; } - NameBinding nb = (NameBinding) cache.get(name); + NameBinding nb = (NameBinding) _cache.get(name); if (nb == null) { - synchronized (cache) { - nb = (NameBinding) cache.get(name); + synchronized (_cache) { + nb = (NameBinding) _cache.get(name); if (nb != null && nb.hasExpired()) { - cache.remove(name); + _cache.remove(name); nb = null; } if (nb == null) { nb = resolve(name); - cache.put(name, nb); + _cache.put(name, nb); } } } @@ -140,16 +163,17 @@ } public HostList lookupHost(String name) { - NameBinding nb = (NameBinding) hostListCache.get(name); + NameBinding nb = (NameBinding) _hostListCache.get(name); if (nb == null) { - synchronized (hostListCache) { - nb = (NameBinding) hostListCache.get(name); + synchronized (_hostListCache) { + nb = (NameBinding) _hostListCache.get(name); if (nb != null && nb.hasExpired()) { - hostListCache.remove(name); + _hostListCache.remove(name); nb = null; } - if (nb == null) { - hostListCache.put(name, nb); + if (nb == null) { + nb = resolve_host(name); + _hostListCache.put(name, nb); } } } @@ -157,7 +181,7 @@ } public static void bind(String bindName, String name) throws NamingException { - nameMap.put(bindName, name); + _nameMap.put(bindName, name); } public void bind(Name name, Object obj) throws NamingException { @@ -193,18 +217,22 @@ } public NamingEnumeration list(Name name) throws NamingException { + // TODO: support this throw new OperationNotSupportedException(); } public NamingEnumeration list(String name) throws NamingException { + // TODO: support this throw new OperationNotSupportedException(); } public NamingEnumeration listBindings(Name name) throws NamingException { + // TODO: support this throw new OperationNotSupportedException(); } public NamingEnumeration listBindings(String name) throws NamingException { + // TODO: support this throw new OperationNotSupportedException(); } @@ -225,10 +253,12 @@ } public Object lookupLink(Name name) throws NamingException { + // TODO: support this throw new OperationNotSupportedException(); } public Object lookupLink(String name) throws NamingException { + // TODO: support this throw new OperationNotSupportedException(); } @@ -241,10 +271,12 @@ } public Name composeName(Name name, Name prefix) throws NamingException { + // TODO: support this throw new OperationNotSupportedException(); } public String composeName(String name, String prefix) throws NamingException { + // TODO: support this throw new OperationNotSupportedException(); } @@ -268,8 +300,12 @@ throw new OperationNotSupportedException(); } + // ----------------------------------------------------------------------- + // protected methods + // ----------------------------------------------------------------------- + protected void init(Hashtable env) { - env = env; + _env = env; Object urlObject = env.get(Context.PROVIDER_URL); if (urlObject == null) { System.out.println("ClientNamingContext.init(): TODO: urlObject was null, create one based on the current hostname."); @@ -278,16 +314,16 @@ } String url = urlObject.toString(); UrlInfo urlInfo = UrlInfo.getInstance(url); - serverNamingContext = (org.apache.geronimo.interop.CosNaming.NamingContext) + _serverNamingContext = (org.apache.geronimo.interop.CosNaming.NamingContext) StubFactory.getInstance().getStub(org.apache.geronimo.interop.CosNaming.NamingContext.class); - ObjectRef ncRef = (ObjectRef) serverNamingContext; + ObjectRef ncRef = (ObjectRef) _serverNamingContext; ncRef.$setNamingContext(this); ncRef.$setProtocol(urlInfo.getProtocol()); ncRef.$setHost("ns~" + urlInfo.getHost()); ncRef.$setPort(urlInfo.getPort()); ncRef.$setObjectKey(urlInfo.getObjectKey()); - connectionProperties = urlInfo.getProperties(); - connectionPool = ConnectionPool.getInstance(this); + _connectionProperties = urlInfo.getProperties(); + _connectionPool = ConnectionPool.getInstance(this); Object u = env.get(Context.SECURITY_PRINCIPAL); Object p = env.get(Context.SECURITY_CREDENTIALS); if (u == null) { @@ -296,8 +332,8 @@ if (p == null) { p = passwordProperty.getString(); } - username = u != null ? u.toString() : null; - password = p != null ? p.toString() : null; + _username = u != null ? u.toString() : null; + _password = p != null ? p.toString() : null; /* if (_serverNamingContext._is_a("IDL:org.apache.geronimo.interop/rmi/iiop/NameService:1.0")) @@ -319,21 +355,34 @@ if (value != null) { NameBinding nb = new NameBinding(); nb.object = value; - nb.cacheTimeout = System.currentTimeMillis() + namingContextCacheTimeout; + nb.cacheTimeout = System.currentTimeMillis() + _namingContextCacheTimeout; return nb; } try { org.apache.geronimo.interop.CosNaming.NameComponent[] resolveName = {new org.apache.geronimo.interop.CosNaming.NameComponent(name, "")}; - org.omg.CORBA.Object object = serverNamingContext.resolve(resolveName); + org.omg.CORBA.Object object = _serverNamingContext.resolve(resolveName); NameBinding nb = new NameBinding(); nb.object = object; - nb.cacheTimeout = System.currentTimeMillis() + namingContextCacheTimeout; + nb.cacheTimeout = System.currentTimeMillis() + _namingContextCacheTimeout; return nb; } catch (org.apache.geronimo.interop.CosNaming.NamingContextPackage.NotFound notFound) { throw new NameNotFoundException(name); } catch (Exception ex) { throw new javax.naming.NamingException(ExceptionUtil.getStackTrace(ex)); } + } + + protected NameBinding resolve_host(String host) { + HostList list = null; + if (_serverNamingContext instanceof org.apache.geronimo.interop.rmi.iiop.NameService) { + org.apache.geronimo.interop.rmi.iiop.NameService nameService = (org.apache.geronimo.interop.rmi.iiop.NameService) _serverNamingContext; + list = new HostList(nameService.resolve_host(host)); + } + NameBinding nb = new NameBinding(); + nb.object = list; + //nb.cacheTimeout = System.currentTimeMillis() + // + (list != null ? list.getCacheTimeout() : _namingContextCacheTimeout); + return nb; } } Modified: geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/client/Connection.java URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/client/Connection.java?view=diff&r1=158861&r2=158862 ============================================================================== --- geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/client/Connection.java (original) +++ geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/client/Connection.java Wed Mar 23 18:30:30 2005 @@ -39,8 +39,8 @@ import org.apache.geronimo.interop.util.ThreadContext; import org.apache.geronimo.interop.util.UTF8; -public class Connection { +public class Connection { public Connection() { } @@ -50,6 +50,10 @@ return conn; } + // ----------------------------------------------------------------------- + // properties + // ----------------------------------------------------------------------- + public static final BooleanProperty simpleIDLProperty = new BooleanProperty(SystemProperties.class, "org.apache.geronimo.interop.simpleIDL"); @@ -57,56 +61,104 @@ new IntProperty(Connection.class, "socketTimeout") .defaultValue(SystemProperties.rmiSocketTimeoutProperty.getInt()); - private static final boolean SIMPLE_IDL = false; // simpleIDLProperty.getBoolean(); - private ServiceContext[] EMPTY_SERVICE_CONTEXT = {}; - private String url; - private boolean ok; - private InstancePool pool; - private String serverHost; - private Socket socket; - private CdrOutputStream parameters; - private CdrOutputStream requestOut; - private CdrInputStream results; - private String exceptionType; - private Exception exception; - private RequestHeader_1_2 requestHeader; - private int callForget; + // ----------------------------------------------------------------------- + // private data + // ----------------------------------------------------------------------- + + private static final boolean SIMPLE_IDL = simpleIDLProperty.getBoolean(); + + private ServiceContext[] EMPTY_SERVICE_CONTEXT = {}; + + private String _url; + + private boolean _ok; + + private InstancePool _pool; + + private String _serverHost; + + private Socket _socket; + + private org.apache.geronimo.interop.rmi.iiop.ObjectInputStream _input; + + private org.apache.geronimo.interop.rmi.iiop.ObjectOutputStream _output; + + private CdrOutputStream _parameters; - private org.apache.geronimo.interop.rmi.iiop.ObjectInputStream input; - private org.apache.geronimo.interop.rmi.iiop.ObjectOutputStream output; + private CdrOutputStream _requestOut; - protected java.io.InputStream socketIn; - protected java.io.OutputStream socketOut; + private CdrInputStream _results; + + private String _exceptionType; + + private Exception _exception; + + private RequestHeader_1_2 _requestHeader; + + private int _callForget; + + // ----------------------------------------------------------------------- + // protected data + // ----------------------------------------------------------------------- + + protected java.io.InputStream _socketIn; + + protected java.io.OutputStream _socketOut; + + // ----------------------------------------------------------------------- + // public methods + // ----------------------------------------------------------------------- public String getInstanceName() { - return url; + return _url; } public void close() { - parameters = null; - input = null; - output = null; - if (ok) { - pool.put(this); + _parameters = null; +// _results.recycle(); +// _results = null; + _input = null; + _output = null; + if (_ok) { + _pool.put(this); } else { shutdown(); } } public void beforeInvoke() { - ok = false; - parameters = CdrOutputStream.getInstance(); + _ok = false; + _parameters = CdrOutputStream.getInstance(); } public void forget(Object requestKey) { + if (_callForget != 0) { + /* + String key = (String)requestKey; + try + { + ClusterService cs = _results.getNamingContext().getClusterService(); + if (_callForget == 0xCFCFCFCF) + { + cs.forgetRequest(key); + } + else if (_callForget == 0xDFDFDFDF) + { + cs.forgetResponse(key); + } + } + catch (Exception ignore) + { + // TODO: log in debug mode? + } + */ + } } public void invoke(ObjectRef object, String method, Object requestKey, int retryCount) { - RequestHeader_1_2 request = requestHeader; + _callForget = 0; // see 'forget' and 'processReplyServiceContext' - System.out.println( "object = " + object ); - System.out.println( "method = " + method ); - System.out.println( "requestKey = " + requestKey ); + RequestHeader_1_2 request = _requestHeader; request.request_id = 0; request.response_flags = 3; @@ -117,15 +169,13 @@ request.reserved = new byte[3]; // Sun's generated org.omg.GIOP.RequestHeader_1_2Helper wants this.... - if (requestOut == null) { - System.out.println( "requestOut == null" ); - requestOut = CdrOutputStream.getInstance(); + if (_requestOut == null) { + _requestOut = CdrOutputStream.getInstance(); } - System.out.println( "write_request" ); - requestOut.write_request(request, parameters); + _requestOut.write_request(request, _parameters); try { - requestOut.send_message(socketOut, url);//_serverHost); + _requestOut.send_message(_socketOut, _url);//_serverHost); } catch (RuntimeException ex) { //if (object.$getAutomaticFailover()) //{ @@ -134,18 +184,18 @@ throw ex; } - requestOut.reset(); + _requestOut.reset(); - if (results == null) { - results = CdrInputStream.getInstance(); + if (_results == null) { + _results = CdrInputStream.getInstance(); } else { - results.reset(); + _results.reset(); } - results.setNamingContext(object.$getNamingContext()); + _results.setNamingContext(object.$getNamingContext()); GiopMessage message; try { - message = results.receive_message(socketIn, url);//_serverHost); + message = _results.receive_message(_socketIn, _url);//_serverHost); } catch (BadMagicException ex) { throw new SystemException(ex); } catch (UnsupportedProtocolVersionException ex) { @@ -163,84 +213,88 @@ throw new SystemException("TODO: message type = " + message.type); } - ok = true; + _ok = true; } public InstancePool getInstancePool() { - return pool; + return _pool; } public void setInstancePool(InstancePool pool) { - this.pool = pool; + _pool = pool; } public org.apache.geronimo.interop.rmi.iiop.ObjectInputStream getInputStream() { if (SIMPLE_IDL) { return getSimpleInputStream(); } - if (input == null) { - input = org.apache.geronimo.interop.rmi.iiop.ObjectInputStream.getInstance(results); + if (_input == null) { + _input = org.apache.geronimo.interop.rmi.iiop.ObjectInputStream.getInstance(_results); } - return input; + return _input; } public org.apache.geronimo.interop.rmi.iiop.ObjectOutputStream getOutputStream() { if (SIMPLE_IDL) { return getSimpleOutputStream(); } - if (output == null) { - output = org.apache.geronimo.interop.rmi.iiop.ObjectOutputStream.getInstance(parameters); + if (_output == null) { + _output = org.apache.geronimo.interop.rmi.iiop.ObjectOutputStream.getInstance(_parameters); } - return output; + return _output; } public org.apache.geronimo.interop.rmi.iiop.ObjectInputStream getSimpleInputStream() { - if (input == null) { - input = org.apache.geronimo.interop.rmi.iiop.SimpleObjectInputStream.getInstance(results); + if (_input == null) { + _input = org.apache.geronimo.interop.rmi.iiop.SimpleObjectInputStream.getInstance(_results); } - return input; + return _input; } public org.apache.geronimo.interop.rmi.iiop.ObjectOutputStream getSimpleOutputStream() { - if (output == null) { - output = org.apache.geronimo.interop.rmi.iiop.SimpleObjectOutputStream.getInstance(parameters); + if (_output == null) { + _output = org.apache.geronimo.interop.rmi.iiop.SimpleObjectOutputStream.getInstance(_parameters); } - return output; + return _output; } public String getExceptionType() { - return exceptionType; + return _exceptionType; } public Exception getException() { - if (exception == null) { - if (exceptionType != null) { - return new SystemException(exceptionType, new org.omg.CORBA.UNKNOWN()); + if (_exception == null) { + if (_exceptionType != null) { + return new SystemException(_exceptionType, new org.omg.CORBA.UNKNOWN()); } else { throw new IllegalStateException("no exception"); } } else { - return exception; + return _exception; } } + // ----------------------------------------------------------------------- + // protected methods + // ----------------------------------------------------------------------- + // TODO: check why we have 'objectRef' parameter??? protected void init(String endpoint, ObjectRef objectRef, PropertyMap connProps) { - url = "iiop://" + endpoint; - UrlInfo urlInfo = UrlInfo.getInstance(url); + _url = "iiop://" + endpoint; + UrlInfo urlInfo = UrlInfo.getInstance(_url); String host = urlInfo.getHost(); int port = urlInfo.getPort(); int socketTimeout = socketTimeoutProperty.getInt(endpoint, connProps); try { - socket = new Socket(host, port); - socketIn = socket.getInputStream(); - socketOut = socket.getOutputStream(); - socket.setSoTimeout(1000 * socketTimeout); - serverHost = host; + _socket = new Socket(host, port); + _socketIn = _socket.getInputStream(); + _socketOut = _socket.getOutputStream(); + _socket.setSoTimeout(1000 * socketTimeout); + _serverHost = host; } catch (Exception ex) { throw new SystemException(errorConnectFailed(host, port, ex)); } - requestHeader = new RequestHeader_1_2(); + _requestHeader = new RequestHeader_1_2(); } public ServiceContext[] getServiceContext(ObjectRef object, Object requestKey, int retryCount) { @@ -332,7 +386,7 @@ || sc.context_id == 0xDFDFDFDF) { // "CF..." indicates "Call Forget Request" // "DF..." indicates "Call Forget Response" - callForget = sc.context_id; + _callForget = sc.context_id; } } } @@ -342,31 +396,31 @@ } protected void processUserException(ReplyHeader_1_2 reply) { - exception = null; - exceptionType = results.read_string(); - ok = true; + _exception = null; + _exceptionType = _results.read_string(); + _ok = true; } protected void processSystemException(ReplyHeader_1_2 reply) { - exceptionType = "???"; - SystemExceptionReplyBody replyBody = SystemExceptionReplyBodyHelper.read(results); + _exceptionType = "???"; + SystemExceptionReplyBody replyBody = SystemExceptionReplyBodyHelper.read(_results); String id = replyBody.exception_id; id = StringUtil.removePrefix(id, "IDL:omg.org/CORBA/"); id = StringUtil.removeSuffix(id, ":1.0"); String stackTrace = null; - if (results.hasMoreData()) { - stackTrace = results.read_string() + ExceptionUtil.getDivider(); + if (_results.hasMoreData()) { + stackTrace = _results.read_string() + ExceptionUtil.getDivider(); } - ok = true; + _ok = true; String exceptionClassName = "org.omg.CORBA." + id; try { Class exceptionClass = ThreadContext.loadClass(exceptionClassName); org.omg.CORBA.SystemException corbaException = (org.omg.CORBA.SystemException) exceptionClass.newInstance(); corbaException.minor = replyBody.minor_code_value; corbaException.completed = org.omg.CORBA.CompletionStatus.from_int(replyBody.completion_status); - exception = new org.apache.geronimo.interop.SystemException(stackTrace, corbaException); + _exception = new org.apache.geronimo.interop.SystemException(stackTrace, corbaException); } catch (Exception ex) { - exception = new org.apache.geronimo.interop.SystemException(stackTrace, + _exception = new org.apache.geronimo.interop.SystemException(stackTrace, new org.omg.CORBA.UNKNOWN(replyBody.exception_id, replyBody.minor_code_value, org.omg.CORBA.CompletionStatus.from_int(replyBody.completion_status))); @@ -374,28 +428,30 @@ } public void shutdown() { - if (socketOut != null) { + if (_socketOut != null) { try { - socketOut.close(); + _socketOut.close(); } catch (Exception ignore) { } - socketOut = null; + _socketOut = null; } - if (socketIn != null) { + if (_socketIn != null) { try { - socketIn.close(); + _socketIn.close(); } catch (Exception ignore) { } - socketIn = null; + _socketIn = null; } - if (socket != null) { + if (_socket != null) { try { - socket.close(); + _socket.close(); } catch (Exception ignore) { } - socket = null; + _socket = null; } } + + // log methods protected String errorConnectFailed(String host, int port, Exception ex) { String msg; Modified: geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/client/ConnectionPool.java URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/client/ConnectionPool.java?view=diff&r1=158861&r2=158862 ============================================================================== --- geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/client/ConnectionPool.java (original) +++ geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/client/ConnectionPool.java Wed Mar 23 18:30:30 2005 @@ -27,6 +27,7 @@ import org.apache.geronimo.interop.util.InstancePool; import org.apache.geronimo.interop.util.StringUtil; + public class ConnectionPool { public static ConnectionPool getInstance(ClientNamingContext namingContext) { ConnectionPool object = new ConnectionPool(); @@ -34,21 +35,17 @@ return object; } - private ClientNamingContext namingContext; - private HashMap poolMap; + // private data - public Connection get(int protocol, String endpoint, ObjectRef objectRef) { - //System.out.println("ConnectionPool.get(): protocol: " + protocol + ", endpoint: " + endpoint + ", objectRef: " + objectRef); + private ClientNamingContext _namingContext; - InstancePool pool = getInstancePool(protocol, endpoint); - System.out.println("ConnectionPool.get(): pool: " + pool); - Connection conn = (Connection) pool.get(); - if (conn == null) { - conn = newConnection(protocol, endpoint, objectRef, pool); - } - return conn; + private HashMap _poolMap; + + // public methods + + public Connection get(int protocol, String endpoint, ObjectRef objectRef) { + System.out.println("ConnectionPool.get(): protocol: " + protocol + ", endpoint: " + endpoint + ", objectRef: " + objectRef); - /* HostList hostList = resolve(endpoint, objectRef); System.out.println("ConnectionPool.get(): hostlist: " + hostList); if (hostList == null) { @@ -90,16 +87,17 @@ // TODO: I18N throw new SystemException("CONNECT FAILED: host list = " + hostList); } - */ } public void put(Connection conn) { conn.getInstancePool().put(conn); } + // protected methods + protected void init(ClientNamingContext namingContext) { - this.namingContext = namingContext; - poolMap = new HashMap(); + _namingContext = namingContext; + _poolMap = new HashMap(); } /** @@ -156,14 +154,40 @@ protected InstancePool getInstancePool(final int protocol, final String endpoint) { System.out.println("ConnectionPool.getInstancePool(): protocol: " + protocol + ", endpoint: " + endpoint); - InstancePool pool = (InstancePool) poolMap.get(endpoint); + InstancePool pool = (InstancePool) _poolMap.get(endpoint); if (pool == null) { - synchronized (poolMap) { - pool = (InstancePool) poolMap.get(endpoint); + synchronized (_poolMap) { + pool = (InstancePool) _poolMap.get(endpoint); if (pool == null) { String poolName = Protocol.getName(protocol) + "://" + endpoint; + //long idleTimeout = 1000 * _namingContext.getIdleConnectionTimeout(); + //if (idleTimeout > 0) + //{ +/* + pool = new InstancePool + ( + poolName, + idleTimeout, + new TimeoutObject() + { + public void onTimeout(Object object) + { + Connection conn = (Connection)object; + if (RmiTrace.CONNECT) + { + RmiTrace.getInstance().traceDisconnect(Protocol.getName(protocol) + "://" + endpoint); + } + conn.shutdown(); + } + } + ); + */ + //} + //else + //{ pool = new InstancePool(poolName); - poolMap.put(endpoint, pool); + //} + _poolMap.put(endpoint, pool); } } } @@ -207,10 +231,7 @@ } protected Connection iiopConnection(String endpoint, ObjectRef objectRef) { - System.out.println( "endpoint : " + endpoint ); - System.out.println( "objectRef : " + objectRef ); - System.out.println( "namingContext : " + namingContext ); - return Connection.getInstance(endpoint, objectRef, namingContext.getConnectionProperties()); + return Connection.getInstance(endpoint, objectRef, _namingContext.getConnectionProperties()); } protected Connection iiopsConnection(String endpoint, ObjectRef objectRef) { @@ -225,15 +246,14 @@ throw new SystemException("TODO"); } - /* protected HostList resolve(String endpoint, ObjectRef objectRef) { - - //if (objectRef instanceof org.apache.geronimo.interop.rmi.iiop.NameService - // && ! endpoint.startsWith("ns~mh~")) - //{ - // return null; // Avoid unbounded recursion - //} - +/* + if (objectRef instanceof org.apache.geronimo.interop.rmi.iiop.NameService + && ! endpoint.startsWith("ns~mh~")) + { + return null; // Avoid unbounded recursion + } + */ HostList hostList = _namingContext.lookupHost(objectRef.$getHost()); // this uses a cache for good performance if (hostList != null && hostList.getPreferredServers().size() == 0 @@ -244,5 +264,4 @@ } return hostList; } - */ } Modified: geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/client/NameBinding.java URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/client/NameBinding.java?view=diff&r1=158861&r2=158862 ============================================================================== --- geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/client/NameBinding.java (original) +++ geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/client/NameBinding.java Wed Mar 23 18:30:30 2005 @@ -18,8 +18,9 @@ package org.apache.geronimo.interop.rmi.iiop.client; public class NameBinding { - public Object object; - public long cacheTimeout; + public Object object; + + public long cacheTimeout; public boolean hasExpired() { long timeout = cacheTimeout; Modified: geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/client/UrlInfo.java URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/client/UrlInfo.java?view=diff&r1=158861&r2=158862 ============================================================================== --- geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/client/UrlInfo.java (original) +++ geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/client/UrlInfo.java Wed Mar 23 18:30:30 2005 @@ -29,6 +29,7 @@ import org.apache.geronimo.interop.util.NamedValueList; import org.apache.geronimo.interop.util.StringUtil; + public class UrlInfo { public static UrlInfo getInstance(String url) { UrlInfo object = new UrlInfo(); @@ -45,84 +46,94 @@ return list; } - private int protocol; - private String host; - private int port; - private String objectKey; - private PropertyMap properties; + // private data + + private int _protocol; + + private String _host; + + private int _port; + + private String _objectKey; + + private PropertyMap _properties; + + // internal methods protected void init(String urlString) { int cssPos = urlString.indexOf("://"); if (cssPos == -1) { throw new IllegalArgumentException(urlString); } - protocol = Protocol.getNumber(urlString.substring(0, cssPos)); + _protocol = Protocol.getNumber(urlString.substring(0, cssPos)); try { URL url = new URL("http" + urlString.substring(cssPos)); - host = url.getHost(); - port = url.getPort(); - if (port == -1) { - switch (protocol) { + _host = url.getHost(); + _port = url.getPort(); + if (_port == -1) { + switch (_protocol) { case Protocol.HTTP: - port = 80; // see http://www.iana.org/assignments/port-numbers + _port = 80; // see http://www.iana.org/assignments/port-numbers break; case Protocol.HTTPS: - port = 443; // see http://www.iana.org/assignments/port-numbers + _port = 443; // see http://www.iana.org/assignments/port-numbers break; case Protocol.IIOP: - port = 683; // see http://www.iana.org/assignments/port-numbers + _port = 683; // see http://www.iana.org/assignments/port-numbers break; case Protocol.IIOPS: - port = 684; // see http://www.iana.org/assignments/port-numbers + _port = 684; // see http://www.iana.org/assignments/port-numbers break; default: throw new IllegalStateException("url = " + urlString); } } - objectKey = url.getFile(); - if (objectKey == null) { - objectKey = ""; + _objectKey = url.getFile(); + if (_objectKey == null) { + _objectKey = ""; } - int queryPos = objectKey.indexOf('?'); + int queryPos = _objectKey.indexOf('?'); if (queryPos != -1) { - objectKey = objectKey.substring(0, queryPos); + _objectKey = _objectKey.substring(0, queryPos); } - objectKey = StringUtil.removePrefix(objectKey, "/"); - if (objectKey.length() == 0) { - objectKey = "NameService"; + _objectKey = StringUtil.removePrefix(_objectKey, "/"); + if (_objectKey.length() == 0) { + _objectKey = "NameService"; } String query = url.getQuery(); if (query == null) { query = ""; } String props = StringUtil.removePrefix(query, "?").replace('&', ','); - properties = new NamedValueList(props).getProperties(); + _properties = new NamedValueList(props).getProperties(); } catch (Exception ex) { throw new SystemException(ex); } } + // public methods + public int getProtocol() { - return protocol; + return _protocol; } public String getHost() { - return host; + return _host; } public int getPort() { - return port; + return _port; } public String getObjectKey() { - return objectKey; + return _objectKey; } public PropertyMap getProperties() { - return properties; + return _properties; } public String toString() { - return Protocol.getName(protocol) + "://" + host + ":" + port + "/" + objectKey; + return Protocol.getName(_protocol) + "://" + _host + ":" + _port + "/" + _objectKey; } } Modified: geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/client/ValueInfo.java URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/client/ValueInfo.java?view=diff&r1=158861&r2=158862 ============================================================================== --- geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/client/ValueInfo.java (original) +++ geronimo/trunk/modules/interop/src/java/org/apache/geronimo/interop/rmi/iiop/client/ValueInfo.java Wed Mar 23 18:30:30 2005 @@ -18,30 +18,30 @@ package org.apache.geronimo.interop.rmi.iiop.client; public class ValueInfo { - public String nameToBeResolved = null; - public Object objectToBeBound = null; + public String _nameToBeResolved = null; + public Object _objectToBeBound = null; public ValueInfo(String nameToBeResolved) { - this.nameToBeResolved = nameToBeResolved; + _nameToBeResolved = nameToBeResolved; } public ValueInfo(Object objectToBeBound) { - this.objectToBeBound = objectToBeBound; + _objectToBeBound = objectToBeBound; } public void setNameToBeResolved(String name) { - nameToBeResolved = name; + _nameToBeResolved = name; } public String getNameToBeResolved() { - return nameToBeResolved; + return _nameToBeResolved; } public void setObjectToBeBound(Object object) { - objectToBeBound = object; + _objectToBeBound = object; } public Object getObjectToBeBound() { - return objectToBeBound; + return _objectToBeBound; } }