cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r627772 - in /incubator/cxf/trunk/rt/bindings/corba/src: main/java/org/apache/cxf/binding/corba/ main/java/org/apache/cxf/binding/corba/runtime/ main/java/org/apache/cxf/binding/corba/types/ main/java/org/apache/cxf/binding/corba/utils/ tes...
Date Thu, 14 Feb 2008 15:04:17 GMT
Author: dkulp
Date: Thu Feb 14 07:04:12 2008
New Revision: 627772

URL: http://svn.apache.org/viewvc?rev=627772&view=rev
Log:
Performance update to corba stuff to reduce calls to string_to_object

Modified:
    incubator/cxf/trunk/rt/bindings/corba/src/main/java/org/apache/cxf/binding/corba/CorbaDestination.java
    incubator/cxf/trunk/rt/bindings/corba/src/main/java/org/apache/cxf/binding/corba/CorbaServerConduit.java
    incubator/cxf/trunk/rt/bindings/corba/src/main/java/org/apache/cxf/binding/corba/runtime/CorbaObjectReader.java
    incubator/cxf/trunk/rt/bindings/corba/src/main/java/org/apache/cxf/binding/corba/types/CorbaPrimitiveHandler.java
    incubator/cxf/trunk/rt/bindings/corba/src/main/java/org/apache/cxf/binding/corba/utils/CorbaUtils.java
    incubator/cxf/trunk/rt/bindings/corba/src/test/java/org/apache/cxf/binding/corba/CorbaBindingFactoryTest.java
    incubator/cxf/trunk/rt/bindings/corba/src/test/java/org/apache/cxf/binding/corba/CorbaServerConduitTest.java
    incubator/cxf/trunk/rt/bindings/corba/src/test/java/org/apache/cxf/binding/corba/utils/CorbaUtilsTest.java

Modified: incubator/cxf/trunk/rt/bindings/corba/src/main/java/org/apache/cxf/binding/corba/CorbaDestination.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/bindings/corba/src/main/java/org/apache/cxf/binding/corba/CorbaDestination.java?rev=627772&r1=627771&r2=627772&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/bindings/corba/src/main/java/org/apache/cxf/binding/corba/CorbaDestination.java
(original)
+++ incubator/cxf/trunk/rt/bindings/corba/src/main/java/org/apache/cxf/binding/corba/CorbaDestination.java
Thu Feb 14 07:04:12 2008
@@ -21,6 +21,8 @@
 
 import java.io.IOException;
 import java.lang.reflect.Method;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
@@ -29,9 +31,11 @@
 import org.apache.cxf.binding.corba.utils.CorbaUtils;
 import org.apache.cxf.binding.corba.utils.OrbConfig;
 import org.apache.cxf.binding.corba.wsdl.AddressType;
+import org.apache.cxf.binding.corba.wsdl.OperationType;
 import org.apache.cxf.common.logging.LogUtils;
 import org.apache.cxf.message.Message;
 import org.apache.cxf.service.model.BindingInfo;
+import org.apache.cxf.service.model.BindingOperationInfo;
 import org.apache.cxf.service.model.EndpointInfo;
 import org.apache.cxf.transport.Conduit;
 import org.apache.cxf.transport.Destination;
@@ -46,6 +50,26 @@
 
 public class CorbaDestination implements Destination {
     
+    public static final class OpInfoEntry {
+
+        private BindingOperationInfo boInfo;
+        private OperationType opType;
+
+        public OpInfoEntry(BindingOperationInfo bopInfo, OperationType extensor) {
+            this.boInfo = bopInfo;
+            this.opType = extensor;
+        }
+
+        public BindingOperationInfo getBoInfo() {
+            return boInfo;
+        }
+
+        public OperationType getOpType() {
+            return opType;
+        }
+
+    }
+
     private static final Logger LOG = LogUtils.getL7dLogger(CorbaDestination.class);
     private AddressType address;
     private EndpointReferenceType reference;
@@ -57,6 +81,8 @@
     private CorbaTypeMap typeMap;
     private byte[] objectId;
     private POA bindingPOA;
+    private org.omg.CORBA.Object obj;
+    private Map<String, OpInfoEntry> opInfoCache = new ConcurrentHashMap<String,
OpInfoEntry>();
 
     public CorbaDestination(EndpointInfo ei, OrbConfig config) {
         this(ei, config, null);    
@@ -86,7 +112,7 @@
                                   Message partialResponse,
                                   EndpointReferenceType ref)
         throws IOException {
-        return  new CorbaServerConduit(endpointInfo, reference, orbConfig, typeMap);
+        return  new CorbaServerConduit(endpointInfo, reference, obj, orbConfig, typeMap);
     }
 
     public BindingInfo getBindingInfo() {
@@ -150,7 +176,6 @@
         // Need to indicate that this ORB can't be destroyed while we are using it
         CorbaBindingHelper.keepORBAlive(location);
         
-        org.omg.CORBA.Object obj = null;
         try {
             POA rootPOA = POAHelper.narrow(orb.resolve_initial_references("RootPOA"));
             POAManager poaManager = rootPOA.the_POAManager();
@@ -269,7 +294,7 @@
         }
     }
 
-    private void addKeyToBootManager(String location, org.omg.CORBA.Object obj) {
+    private void addKeyToBootManager(String location, org.omg.CORBA.Object value) {
         int keyIndex = location.indexOf('/');
         String key = location.substring(keyIndex + 1);
         try {
@@ -280,7 +305,7 @@
             Object bootMgr = narrowMethod.invoke(null, orb.resolve_initial_references("BootManager"));
             Method addBindingMethod = 
                 bootMgrClass.getMethod("add_binding", byte[].class, org.omg.CORBA.Object.class);
-            addBindingMethod.invoke(bootMgr, key.getBytes(), obj);
+            addBindingMethod.invoke(bootMgr, key.getBytes(), value);
             LOG.info("Added key " + key + " to bootmanager");
         } catch (ClassNotFoundException ex) {
             //Not supported by the orb. skip it.
@@ -289,5 +314,18 @@
         } catch (Exception ex) {
             throw new CorbaBindingException(ex);
         }
+    }
+
+    public OpInfoEntry getBindingOpInfo(String opName) {
+        if (!opInfoCache .containsKey(opName)) {
+            for (BindingOperationInfo bopInfo : binding.getOperations()) {
+                if (bopInfo.getName().getLocalPart().equals(opName)) {
+                    opInfoCache.put(opName, new OpInfoEntry(bopInfo,
+                            bopInfo.getExtensor(OperationType.class)));
+                    break;
+                }
+            }
+        }
+        return opInfoCache.get(opName);
     }
 }

Modified: incubator/cxf/trunk/rt/bindings/corba/src/main/java/org/apache/cxf/binding/corba/CorbaServerConduit.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/bindings/corba/src/main/java/org/apache/cxf/binding/corba/CorbaServerConduit.java?rev=627772&r1=627771&r2=627772&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/bindings/corba/src/main/java/org/apache/cxf/binding/corba/CorbaServerConduit.java
(original)
+++ incubator/cxf/trunk/rt/bindings/corba/src/main/java/org/apache/cxf/binding/corba/CorbaServerConduit.java
Thu Feb 14 07:04:12 2008
@@ -21,15 +21,10 @@
 
 import java.io.IOException;
 import java.io.OutputStream;
-import java.util.logging.Level;
-import java.util.logging.Logger;
 
 import org.apache.cxf.binding.corba.utils.CorbaBindingHelper;
-import org.apache.cxf.binding.corba.utils.CorbaUtils;
 import org.apache.cxf.binding.corba.utils.OrbConfig;
-import org.apache.cxf.binding.corba.wsdl.AddressType;
 import org.apache.cxf.binding.corba.wsdl.CorbaConstants;
-import org.apache.cxf.common.logging.LogUtils;
 import org.apache.cxf.io.CachedOutputStream;
 import org.apache.cxf.message.Exchange;
 import org.apache.cxf.message.Message;
@@ -45,45 +40,30 @@
 import org.omg.CORBA.ServerRequest;
 
 public class CorbaServerConduit implements Conduit {
-    private static final Logger LOG = LogUtils.getL7dLogger(CorbaServerConduit.class);
 
     private EndpointInfo endpointInfo;
     private EndpointReferenceType target;
     private ORB orb;
     private CorbaTypeMap typeMap;
+    private org.omg.CORBA.Object targetObject;
 
     public CorbaServerConduit(EndpointInfo ei,
                               EndpointReferenceType ref,
+                              org.omg.CORBA.Object targetObj, 
                               OrbConfig config,
                               CorbaTypeMap map) {
         endpointInfo = ei;
         target = getTargetReference(ref);
         orb = CorbaBindingHelper.getDefaultORB(config);
         typeMap = map;
+        targetObject = targetObj;
     }
 
     public void prepare(Message message) throws IOException {
-        try {
-            String location = endpointInfo.getAddress();
-            if (location == null) {
-                AddressType address = endpointInfo.getExtensor(AddressType.class);
-
-                if (address == null) {
-                    LOG.log(Level.SEVERE, "Unable to locate a valid CORBA address");
-                    throw new CorbaBindingException("Unable to locate a valid CORBA address");
-                }
-                location = address.getLocation();
-            }
-            org.omg.CORBA.Object targetObject = CorbaUtils.importObjectReference(orb, location);
-            message.put(CorbaConstants.ORB, orb);
-            message.put(CorbaConstants.CORBA_ENDPOINT_OBJECT, targetObject);
-            message.setContent(OutputStream.class,
-                               new CorbaOutputStream(message));
-            ((CorbaMessage) message).setCorbaTypeMap(typeMap);
-        } catch (java.lang.Exception ex) {
-            LOG.log(Level.SEVERE, "Could not resolve target object");
-            throw new CorbaBindingException(ex);
-        }
+        message.put(CorbaConstants.ORB, orb);
+        message.put(CorbaConstants.CORBA_ENDPOINT_OBJECT, targetObject);
+        message.setContent(OutputStream.class, new CorbaOutputStream(message));
+        ((CorbaMessage) message).setCorbaTypeMap(typeMap);
     }
 
     public void close(Message message) throws IOException {        
@@ -103,7 +83,6 @@
     }
 
     public void setMessageObserver(MessageObserver observer) {
-        //NOTHING
     }
 
     public final EndpointReferenceType getTargetReference(EndpointReferenceType t) {

Modified: incubator/cxf/trunk/rt/bindings/corba/src/main/java/org/apache/cxf/binding/corba/runtime/CorbaObjectReader.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/bindings/corba/src/main/java/org/apache/cxf/binding/corba/runtime/CorbaObjectReader.java?rev=627772&r1=627771&r2=627772&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/bindings/corba/src/main/java/org/apache/cxf/binding/corba/runtime/CorbaObjectReader.java
(original)
+++ incubator/cxf/trunk/rt/bindings/corba/src/main/java/org/apache/cxf/binding/corba/runtime/CorbaObjectReader.java
Thu Feb 14 07:04:12 2008
@@ -399,7 +399,6 @@
             CorbaSequenceHandler sequenceObj = (CorbaSequenceHandler)obj;
             List<CorbaObjectHandler> seqElements = sequenceObj.getElements();
             int length = stream.read_ulong();
-
             List<CorbaObjectHandler> elements = new ArrayList<CorbaObjectHandler>(length);
             
             // Simply checking the bound won't handle our recursive types.  We need to check
for the

Modified: incubator/cxf/trunk/rt/bindings/corba/src/main/java/org/apache/cxf/binding/corba/types/CorbaPrimitiveHandler.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/bindings/corba/src/main/java/org/apache/cxf/binding/corba/types/CorbaPrimitiveHandler.java?rev=627772&r1=627771&r2=627772&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/bindings/corba/src/main/java/org/apache/cxf/binding/corba/types/CorbaPrimitiveHandler.java
(original)
+++ incubator/cxf/trunk/rt/bindings/corba/src/main/java/org/apache/cxf/binding/corba/types/CorbaPrimitiveHandler.java
Thu Feb 14 07:04:12 2008
@@ -25,6 +25,7 @@
 
 public class CorbaPrimitiveHandler extends CorbaObjectHandler {
 
+    private static final int UNSIGNED_MAX = 256; 
     private Object value;
     
     public CorbaPrimitiveHandler(QName primName, QName primIdlType, TypeCode primTC, Object
primType) {
@@ -50,8 +51,10 @@
             break;
         case TCKind._tk_char:
             char charValue = ((Character)value).charValue();
-            // value + (-128)
-            data = Byte.toString((byte)(charValue + Byte.MIN_VALUE));
+            // outside the normal range it will -256
+            data = Byte.toString((byte)(charValue > Byte.MAX_VALUE 
+                                                    ? charValue - UNSIGNED_MAX 
+                                                    : charValue));
             break;
         case TCKind._tk_wchar:
             data = ((Character)value).toString();
@@ -101,8 +104,12 @@
         case TCKind._tk_char:
             // A char is mapped to a byte, we need it as a character
             Byte byteValue = new Byte(data);
-            // value - (-128)
-            value = new Character((char)(byteValue.byteValue() - Byte.MIN_VALUE));
+            // for values < 0 + 256 
+            // This means that we can directly write out the chars in the normal
+            // range 0-127 even when using UTF-8
+            value = new Character((char)(byteValue.byteValue() < 0 
+                                         ? byteValue.byteValue() + UNSIGNED_MAX
+                                         : byteValue.byteValue()));
             break;
         case TCKind._tk_wchar:
             // A wide char is mapped to a string, we need it as a character

Modified: incubator/cxf/trunk/rt/bindings/corba/src/main/java/org/apache/cxf/binding/corba/utils/CorbaUtils.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/bindings/corba/src/main/java/org/apache/cxf/binding/corba/utils/CorbaUtils.java?rev=627772&r1=627771&r2=627772&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/bindings/corba/src/main/java/org/apache/cxf/binding/corba/utils/CorbaUtils.java
(original)
+++ incubator/cxf/trunk/rt/bindings/corba/src/main/java/org/apache/cxf/binding/corba/utils/CorbaUtils.java
Thu Feb 14 07:04:12 2008
@@ -32,6 +32,7 @@
 import javax.xml.namespace.QName;
 
 import org.apache.cxf.binding.corba.CorbaBindingException;
+import org.apache.cxf.binding.corba.CorbaStreamable;
 import org.apache.cxf.binding.corba.CorbaTypeMap;
 import org.apache.cxf.binding.corba.wsdl.Alias;
 import org.apache.cxf.binding.corba.wsdl.Anonarray;
@@ -63,6 +64,8 @@
 import org.apache.ws.commons.schema.XmlSchemaExternal;
 import org.apache.ws.commons.schema.XmlSchemaForm;
 import org.apache.ws.commons.schema.XmlSchemaType;
+import org.omg.CORBA.Any;
+import org.omg.CORBA.NVList;
 import org.omg.CORBA.ORB;
 import org.omg.CORBA.StructMember;
 import org.omg.CORBA.TCKind;
@@ -75,11 +78,27 @@
     static final Map<QName, TCKind> PRIMITIVE_TYPECODES = new HashMap<QName, TCKind>();
 
     private static final Logger LOG = LogUtils.getL7dLogger(CorbaUtils.class);
-    
+    private static final class LastExport {
+        private final String ior;
+        private final org.omg.CORBA.Object ref;
+        LastExport(String iors, org.omg.CORBA.Object oref) {
+            ior = iors;
+            ref = oref;
+        }
+        String getIor() {
+            return ior;
+        }
+        org.omg.CORBA.Object getRef() {
+            return ref;
+        }
+    }
+    private static final ThreadLocal<LastExport> LAST_EXPORT_CACHE = 
+        new ThreadLocal<LastExport>();
+
     private CorbaUtils() {
         //utility class
     }
-
+    
     
     public static QName getEmptyQName() {
         return EMPTY_QNAME;
@@ -447,6 +466,13 @@
         file.close();
     }
 
+
+    public static String exportObjectReference(org.omg.CORBA.Object obj, ORB orb) {
+        String ior = orb.object_to_string(obj);
+        LAST_EXPORT_CACHE.set(new LastExport(ior, obj));
+        return ior;
+    }
+
     public static org.omg.CORBA.Object importObjectReference(ORB orb,
                                                              String url) {
         org.omg.CORBA.Object result;
@@ -456,9 +482,15 @@
         } else if ("IOR:".equalsIgnoreCase(url)) {
             throw new RuntimeException("Proxy not initialized. URL contains a invalid ior");
         }
-        
+    
+        String trimmedUrl = url.trim();
+        LastExport last = LAST_EXPORT_CACHE.get();
+        if (last != null
+            && trimmedUrl.equals(last.getIor())) {
+            return last.getRef();
+        }
         try {
-            result = orb.string_to_object(url.trim());
+            result = orb.string_to_object(trimmedUrl);
         } catch (java.lang.Exception ex) {
             throw new RuntimeException(ex);
         }
@@ -572,6 +604,22 @@
         }
         return result;
     }
+
+    public static NVList nvListFromStreamables(ORB orb, CorbaStreamable[] streamables) {
+        NVList list = null;
+        if (streamables != null && streamables.length > 0) {
+            list = orb.create_list(streamables.length);
+            for (int i = 0; i < streamables.length; ++i) {
+                Any value = orb.create_any();
+                value.insert_Streamable(streamables[i]);
+                list.add_value(streamables[i].getName(), value, streamables[i].getMode());
+            }
+        } else {
+            list = orb.create_list(0);
+        }
+        return list; 
+    }
+             
 
     static {
         PRIMITIVE_TYPECODES.put(CorbaConstants.NT_CORBA_BOOLEAN, TCKind.from_int(TCKind._tk_boolean));

Modified: incubator/cxf/trunk/rt/bindings/corba/src/test/java/org/apache/cxf/binding/corba/CorbaBindingFactoryTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/bindings/corba/src/test/java/org/apache/cxf/binding/corba/CorbaBindingFactoryTest.java?rev=627772&r1=627771&r2=627772&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/bindings/corba/src/test/java/org/apache/cxf/binding/corba/CorbaBindingFactoryTest.java
(original)
+++ incubator/cxf/trunk/rt/bindings/corba/src/test/java/org/apache/cxf/binding/corba/CorbaBindingFactoryTest.java
Thu Feb 14 07:04:12 2008
@@ -106,6 +106,8 @@
                          "SimpleCORBAPort");
         
         Conduit conduit = factory.getConduit(endpointInfo);
+        assertNotNull(conduit);   
+        conduit = factory.getConduit(endpointInfo, null);
         assertNotNull(conduit);
         target = EasyMock.createMock(EndpointReferenceType.class);
         conduit = factory.getConduit(endpointInfo, target);

Modified: incubator/cxf/trunk/rt/bindings/corba/src/test/java/org/apache/cxf/binding/corba/CorbaServerConduitTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/bindings/corba/src/test/java/org/apache/cxf/binding/corba/CorbaServerConduitTest.java?rev=627772&r1=627771&r2=627772&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/bindings/corba/src/test/java/org/apache/cxf/binding/corba/CorbaServerConduitTest.java
(original)
+++ incubator/cxf/trunk/rt/bindings/corba/src/test/java/org/apache/cxf/binding/corba/CorbaServerConduitTest.java
Thu Feb 14 07:04:12 2008
@@ -64,6 +64,7 @@
     TestUtils testUtils;
     OrbConfig orbConfig;
     CorbaTypeMap corbaTypeMap;
+    private org.omg.CORBA.Object targetObject;
 
 
     @Before
@@ -78,6 +79,7 @@
         props.put("yoko.orb.id", "CXF-CORBA-Server-Binding");
         orb = ORB.init(new String[0], props);
         orbConfig = new OrbConfig();
+        targetObject = EasyMock.createMock(org.omg.CORBA.Object.class);
     }
     
     @After
@@ -106,6 +108,7 @@
         CorbaDestination destination = new CorbaDestination(endpointInfo, orbConfig);
         CorbaServerConduit conduit = new CorbaServerConduit(endpointInfo,
                                                             destination.getAddress(),
+                                                            targetObject,
                                                             orbConfig,
                                                             corbaTypeMap);
         CorbaMessage message = new CorbaMessage(new MessageImpl());
@@ -120,6 +123,10 @@
         assertTrue("Orb should not be null", orb2 != null);
         Object obj = message.get("endpoint");
         assertTrue("EndpointReferenceType should not be null", obj != null);
+        
+        assertTrue("passed in targetObject is used",  
+                targetObject.equals(message.get(CorbaConstants.CORBA_ENDPOINT_OBJECT)));
+        
         destination.shutdown();
     }
        
@@ -133,6 +140,7 @@
         CorbaDestination destination = new CorbaDestination(endpointInfo, orbConfig);
         CorbaServerConduit conduit = new CorbaServerConduit(endpointInfo,
                                                             destination.getAddress(),
+                                                            targetObject,
                                                             orbConfig,
                                                             corbaTypeMap);
         
@@ -152,6 +160,7 @@
         endpointInfo.setAddress("corbaloc::localhost:40000/Simple");
         CorbaServerConduit conduit = new CorbaServerConduit(endpointInfo,
                                                             destination.getAddress(),
+                                                            targetObject,
                                                             orbConfig,
                                                             corbaTypeMap);
         String address = conduit.getAddress();
@@ -287,7 +296,7 @@
         target = EasyMock.createMock(EndpointReferenceType.class);                   
         endpointInfo = EasyMock.createMock(EndpointInfo.class);
         CorbaServerConduit corbaServerConduit = 
-            new CorbaServerConduit(endpointInfo, target, orbConfig, corbaTypeMap);
+            new CorbaServerConduit(endpointInfo, target, targetObject, orbConfig, corbaTypeMap);
         
         if (send) {
             // setMessageObserver

Modified: incubator/cxf/trunk/rt/bindings/corba/src/test/java/org/apache/cxf/binding/corba/utils/CorbaUtilsTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/bindings/corba/src/test/java/org/apache/cxf/binding/corba/utils/CorbaUtilsTest.java?rev=627772&r1=627771&r2=627772&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/bindings/corba/src/test/java/org/apache/cxf/binding/corba/utils/CorbaUtilsTest.java
(original)
+++ incubator/cxf/trunk/rt/bindings/corba/src/test/java/org/apache/cxf/binding/corba/utils/CorbaUtilsTest.java
Thu Feb 14 07:04:12 2008
@@ -213,5 +213,5 @@
         }
 
     }
-        
+
 }



Mime
View raw message