axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sc...@apache.org
Subject cvs commit: xml-axis/java/src/org/apache/axis/transport/http SimpleAxisWorker.java
Date Wed, 28 Aug 2002 01:26:54 GMT
scheu       2002/08/27 18:26:54

  Modified:    java/src/org/apache/axis SOAPPart.java
               java/src/org/apache/axis/transport/http
                        SimpleAxisWorker.java
  Log:
  Changes to SOAPPart to speed-up processing of getAsBytes and getAsString.
  If a FORM_STRING message is processed via getAsBytes(), the
  String message is saved away in the new cache variable currentMessageAsString.
  If a subsequent call to getAsString() is performed, the currentMessageAsString
  value is returned instead of doing the reverse translation.
  
  The same changes are made to getAsString().
  
  Testing revealed that the getAsString() cache is hit in each of our tests
  (usually many times per test).
  
  In my own tests SOAPPart.writeTo() performance improved from 16% of the total
  time to 10% of the total time.
  
  I also wrapped each "complicated" log.debug() message in a log.isDebugEnabled()
  if statement.  I did not change the debug messages that simply passed a constant
  String.  Should these be changed too ?
  
  Revision  Changes    Path
  1.43      +56 -16    xml-axis/java/src/org/apache/axis/SOAPPart.java
  
  Index: SOAPPart.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/SOAPPart.java,v
  retrieving revision 1.42
  retrieving revision 1.43
  diff -u -r1.42 -r1.43
  --- SOAPPart.java	27 Aug 2002 20:47:01 -0000	1.42
  +++ SOAPPart.java	28 Aug 2002 01:26:54 -0000	1.43
  @@ -128,6 +128,10 @@
        */
       private Object currentMessage ;
   
  +    // These two fields are used for caching in getAsString and getAsBytes
  +    private String currentMessageAsString = null;
  +    private byte[] currentMessageAsBytes = null;
  +
       /**
        * Message object this part is tied to. Used for serialization settings.
        */
  @@ -310,7 +314,7 @@
        * array.  This will force buffering of the message.
        */
       public byte[] getAsBytes() throws AxisFault {
  -	    log.debug("Enter: SOAPPart::getAsBytes");
  +        log.debug("Enter: SOAPPart::getAsBytes");
           if ( currentForm == FORM_BYTES ) {
               log.debug("Exit: SOAPPart::getAsBytes");
               return (byte[])currentMessage;
  @@ -321,7 +325,7 @@
                   getAsSOAPEnvelope();
               } catch (Exception e) {
                   log.fatal(JavaUtils.getMessage("makeEnvFail00"), e);
  -	            log.debug("Exit: SOAPPart::getAsBytes");
  +                log.debug("Exit: SOAPPart::getAsBytes");
                   return null;
               }
           }
  @@ -371,6 +375,18 @@
           }
   
           if ( currentForm == FORM_STRING ) {
  +            // If the current message was already converted from
  +            // a byte[] to String, return the byte[] representation
  +            // (this is done to avoid unnecessary conversions)
  +            if (currentMessage == currentMessageAsString &&
  +                currentMessageAsBytes != null) {
  +                if (log.isDebugEnabled()) {
  +                    log.debug("Exit: SOAPPart::getAsBytes()");
  +                }
  +                return currentMessageAsBytes;
  +            }
  +            // Save this message in case it is requested later in getAsString
  +            currentMessageAsString = (String) currentMessage;
               try{
                   setCurrentMessage( ((String)currentMessage).getBytes("UTF-8"),
                  FORM_BYTES );
  @@ -378,6 +394,8 @@
                  setCurrentMessage( ((String)currentMessage).getBytes(),
                                  FORM_BYTES );
               }
  +            currentMessageAsBytes = (byte[]) currentMessage;
  +
               log.debug("Exit: SOAPPart::getAsBytes");
               return (byte[])currentMessage;
           }
  @@ -395,7 +413,9 @@
       public String getAsString() throws AxisFault {
           log.debug("Enter: SOAPPart::getAsString");
           if ( currentForm == FORM_STRING ) {
  -            log.debug("Exit: SOAPPart::getAsString(): " + currentMessage);
  +            if (log.isDebugEnabled()) {
  +                log.debug("Exit: SOAPPart::getAsString(): " + currentMessage);
  +            }
               return (String)currentMessage;
           }
   
  @@ -406,14 +426,29 @@
           }
   
           if ( currentForm == FORM_BYTES ) {
  -                        try{
  -                                setCurrentMessage( new String((byte[]) currentMessage,"UTF-8"),
  -                               FORM_STRING );
  -                        }catch(UnsupportedEncodingException ue){
  -            setCurrentMessage( new String((byte[]) currentMessage),
  -                               FORM_STRING );
  -                        }
  -            log.debug("Exit: SOAPPart::getAsString(): " + currentMessage);
  +            // If the current message was already converted from
  +            // a String to byte[], return the String representation
  +            // (this is done to avoid unnecessary conversions)
  +            if (currentMessage == currentMessageAsBytes &&
  +                currentMessageAsString != null) {
  +                if (log.isDebugEnabled()) {
  +                    log.debug("Exit: SOAPPart::getAsString(): " + currentMessageAsString);
  +                } 
  +                return currentMessageAsString;
  +            }
  +            // Save this message in case it is requested later in getAsBytes
  +            currentMessageAsBytes = (byte[]) currentMessage;
  +            try{
  +                setCurrentMessage( new String((byte[]) currentMessage,"UTF-8"),
  +                                   FORM_STRING );
  +            }catch(UnsupportedEncodingException ue){
  +                setCurrentMessage( new String((byte[]) currentMessage),
  +                                   FORM_STRING );
  +            }
  +            currentMessageAsString = (String) currentMessage;
  +            if (log.isDebugEnabled()) {
  +                log.debug("Exit: SOAPPart::getAsString(): " + currentMessage);
  +            }
               return (String)currentMessage;
           }
   
  @@ -427,7 +462,9 @@
                   return null;
               }
               setCurrentMessage(writer.getBuffer().toString(), FORM_STRING);
  -            log.debug("Exit: SOAPPart::getAsString(): " + currentMessage);
  +            if (log.isDebugEnabled()) {
  +                log.debug("Exit: SOAPPart::getAsString(): " + currentMessage);
  +            }
               return (String)currentMessage;
           }
   
  @@ -440,7 +477,9 @@
                   throw AxisFault.makeFault(e);
               }
               setCurrentMessage(writer.getBuffer().toString(), FORM_STRING);
  -            log.debug("Exit: SOAPPart::getAsString(): " + currentMessage);
  +            if (log.isDebugEnabled()) {
  +                log.debug("Exit: SOAPPart::getAsString(): " + currentMessage);
  +            }
               return (String)currentMessage;
           }
   
  @@ -458,9 +497,10 @@
       public SOAPEnvelope getAsSOAPEnvelope()
           throws AxisFault
       {
  -        log.debug("Enter: SOAPPart::getAsSOAPEnvelope()");
  -        log.debug(JavaUtils.getMessage("currForm", formNames[currentForm]));
  -
  +        if (log.isDebugEnabled()) {
  +            log.debug("Enter: SOAPPart::getAsSOAPEnvelope()");
  +            log.debug(JavaUtils.getMessage("currForm", formNames[currentForm]));
  +        }
           if ( currentForm == FORM_SOAPENVELOPE )
               return (SOAPEnvelope)currentMessage;
   
  
  
  
  1.16      +1 -0      xml-axis/java/src/org/apache/axis/transport/http/SimpleAxisWorker.java
  
  Index: SimpleAxisWorker.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/transport/http/SimpleAxisWorker.java,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- SimpleAxisWorker.java	23 Aug 2002 19:07:19 -0000	1.15
  +++ SimpleAxisWorker.java	28 Aug 2002 01:26:54 -0000	1.16
  @@ -486,6 +486,7 @@
               } catch (Exception e) {
               }
           }
  +
       }
   
       /**
  
  
  

Mime
View raw message