diff options
-rw-r--r-- | cs/src/Ice/BasicStream.cs | 97 | ||||
-rw-r--r-- | java/src/IceInternal/BasicStream.java | 138 |
2 files changed, 69 insertions, 166 deletions
diff --git a/cs/src/Ice/BasicStream.cs b/cs/src/Ice/BasicStream.cs index a6fc455b381..acab362e947 100644 --- a/cs/src/Ice/BasicStream.cs +++ b/cs/src/Ice/BasicStream.cs @@ -3472,35 +3472,9 @@ namespace IceInternal _buf.expand(n); } - private sealed class DynamicObjectFactory : Ice.ObjectFactory + private Ice.Object createObject(string id) { - internal DynamicObjectFactory(Type c) - { - _class = c; - } - - public Ice.Object create(string type) - { - try - { - return (Ice.Object)AssemblyUtil.createInstance(_class); - } - catch(Exception ex) - { - throw new Ice.SyscallException(ex); - } - } - - public void destroy() - { - } - - private Type _class; - } - - private Ice.ObjectFactory loadObjectFactory(string id) - { - Ice.ObjectFactory factory = null; + Ice.Object obj = null; try { @@ -3510,7 +3484,7 @@ namespace IceInternal // if(c != null && !c.IsAbstract && !c.IsInterface) { - factory = new DynamicObjectFactory(c); + obj = (Ice.Object)AssemblyUtil.createInstance(c); } } catch(Exception ex) @@ -3520,7 +3494,7 @@ namespace IceInternal throw e; } - return factory; + return obj; } private sealed class DynamicUserExceptionFactory : UserExceptionFactory @@ -3553,9 +3527,9 @@ namespace IceInternal private Type _class; } - private UserExceptionFactory getUserExceptionFactory(string id) + private Ice.UserException createUserException(string id) { - UserExceptionFactory factory = null; + Ice.UserException userEx = null; try { @@ -3566,15 +3540,15 @@ namespace IceInternal // Ensure the class is instantiable. // Debug.Assert(!c.IsAbstract && !c.IsInterface); - factory = new DynamicUserExceptionFactory(c); + userEx = (Ice.UserException)AssemblyUtil.createInstance(c); } } catch(Exception ex) { - throw new Ice.UnknownUserException(id.Substring(2), ex); + throw new Ice.MarshalException(ex); } - return factory; + return userEx; } private static string typeToClass(string id) @@ -3700,41 +3674,42 @@ namespace IceInternal // startSlice(); string mostDerivedId = _typeId; - UserExceptionFactory exceptionFactory = factory; while(true) { - // - // Look for a factory for this ID. - // - if(exceptionFactory == null) - { - exceptionFactory = _stream.getUserExceptionFactory(_typeId); - } + Ice.UserException userEx = null; // - // We found a factory, we get out of this loop. + // Use a factory if one was provided. // - if(exceptionFactory != null) + if(factory != null) { - // - // Got factory -- ask the factory to instantiate the - // exception, initialize the exception members, and throw - // the exception. - // try { - exceptionFactory.createAndThrow(_typeId); + factory.createAndThrow(_typeId); } catch(Ice.UserException ex) { - ex.read__(_stream); - readPendingObjects(); - throw ex; - - // Never reached. + userEx = ex; } } + if(userEx == null) + { + userEx = _stream.createUserException(_typeId); + } + + // + // We found the exception. + // + if(userEx != null) + { + userEx.read__(_stream); + readPendingObjects(); + throw userEx; + + // Never reached. + } + // // Performance sensitive, so we use lazy initialization for // tracing. @@ -4186,17 +4161,11 @@ namespace IceInternal } // - // Last chance: check the table of static factories (i.e., - // automatically generated factories for concrete classes). + // Last chance: try to instantiate the class dynamically. // if(v == null) { - userFactory = _stream.loadObjectFactory(_typeId); - if(userFactory != null) - { - v = userFactory.create(_typeId); - Debug.Assert(v != null); - } + v = _stream.createObject(_typeId); } // diff --git a/java/src/IceInternal/BasicStream.java b/java/src/IceInternal/BasicStream.java index 5d0006dcb07..7e686517e0f 100644 --- a/java/src/IceInternal/BasicStream.java +++ b/java/src/IceInternal/BasicStream.java @@ -2524,86 +2524,25 @@ public class BasicStream _buf.expand(n); } - private static final class DynamicObjectFactory implements Ice.ObjectFactory + private Ice.Object + createObject(String id) { - DynamicObjectFactory(Class<?> c) - { - _class = c; - } - - public Ice.Object - create(String type) - { - try - { - return (Ice.Object)_class.newInstance(); - } - catch(java.lang.Exception ex) - { - throw new Ice.SyscallException(ex); - } - } - - public void - destroy() - { - } - - private Class<?> _class; - } - - private Ice.ObjectFactory - loadObjectFactory(String id) - { - Ice.ObjectFactory factory = null; + Ice.Object obj = null; try { Class<?> c = findClass(id); if(c != null) { - factory = new DynamicObjectFactory(c); - /* - * TODO: See ICE-3635 regarding caching of factories. - * Perhaps we should store these dynamic factories in a - * per-communicator map and check this map prior to - * calling findClass above. - * - Ice.ObjectFactory dynamicFactory = new DynamicObjectFactory(c); - // - // We will try to install the dynamic factory, but - // another thread may install a factory first. - // - while(factory == null) - { - try - { - _instance.servantFactoryManager().add(dynamicFactory, id); - factory = dynamicFactory; - } - catch(Ice.AlreadyRegisteredException ex) - { - // - // Another thread already installed the - // factory, so try to obtain it. It's possible - // (but unlikely) that the factory will have - // already been removed, in which case the - // return value will be null and the while - // loop will attempt to install the dynamic - // factory again. - // - factory = _instance.servantFactoryManager().find(id); - } - } - */ + obj = (Ice.Object)c.newInstance(); } } - catch(LinkageError ex) + catch(java.lang.Exception ex) { throw new Ice.NoObjectFactoryException("no object factory", id, ex); } - return factory; + return obj; } private static final class DynamicUserExceptionFactory @@ -2640,25 +2579,25 @@ public class BasicStream private Class<?> _class; } - private UserExceptionFactory - getUserExceptionFactory(String id) + private Ice.UserException + createUserException(String id) { - UserExceptionFactory factory = null; + Ice.UserException userEx = null; try { Class<?> c = findClass(id); if(c != null) { - factory = new DynamicUserExceptionFactory(c); + userEx = (Ice.UserException)c.newInstance(); } } - catch(LinkageError ex) + catch(java.lang.Exception ex) { throw new Ice.MarshalException(ex); } - return factory; + return userEx; } private Class<?> @@ -2916,41 +2855,42 @@ public class BasicStream // startSlice(); final String mostDerivedId = _typeId; - UserExceptionFactory exceptionFactory = factory; while(true) { - // - // Look for a factory for this ID. - // - if(exceptionFactory == null) - { - exceptionFactory = _stream.getUserExceptionFactory(_typeId); - } + Ice.UserException userEx = null; // - // We found a factory, we get out of this loop. + // Use a factory if one was provided. // - if(exceptionFactory != null) + if(factory != null) { - // - // Got factory -- ask the factory to instantiate the - // exception, initialize the exception members, and throw - // the exception. - // try { - exceptionFactory.createAndThrow(_typeId); + factory.createAndThrow(_typeId); } catch(Ice.UserException ex) { - ex.__read(_stream); - readPendingObjects(); - throw ex; - - // Never reached. + userEx = ex; } } + if(userEx == null) + { + userEx = _stream.createUserException(_typeId); + } + + // + // We found the exception. + // + if(userEx != null) + { + userEx.__read(_stream); + readPendingObjects(); + throw userEx; + + // Never reached. + } + // // Performance sensitive, so we use lazy initialization for // tracing. @@ -3403,17 +3343,11 @@ public class BasicStream } // - // Last chance: check the table of static factories (i.e., - // automatically generated factories for concrete classes). + // Last chance: try to instantiate the class dynamically. // if(v == null) { - userFactory = _stream.loadObjectFactory(_typeId); - if(userFactory != null) - { - v = userFactory.create(_typeId); - assert(v != null); - } + v = _stream.createObject(_typeId); } // |