openamf/src/java/org/openamf/io AMFDeserializer.java,1.33,1.34 AMFSerializer.java,1.39,1.40

[email protected] Tue, 19 Aug 2003 17:45:41 -0700
Newsgroups gmane.comp.java.openamf.cvs
Message-ID <[email protected]>
Update of /cvsroot/openamf/openamf/src/java/org/openamf/io
In directory sc8-pr-cvs1:/tmp/cvs-serv23177/src/java/org/openamf/io

Modified Files:
	AMFDeserializer.java AMFSerializer.java 
Log Message:
checking log level before calling debug improves performance

Index: AMFDeserializer.java
===================================================================
RCS file: /cvsroot/openamf/openamf/src/java/org/openamf/io/AMFDeserializer.java,v
retrieving revision 1.33
retrieving revision 1.34
diff -C2 -d -r1.33 -r1.34
*** AMFDeserializer.java	16 Aug 2003 13:11:16 -0000	1.33
--- AMFDeserializer.java	20 Aug 2003 00:45:38 -0000	1.34
***************
*** 73,87 ****
       */
      public AMFDeserializer(DataInputStream inputStream) throws IOException {
!         if (!log.isDebugEnabled()) {
!             log.info("Deserializing Message, for more info turn on debug level");
!         }
          // Save the input stream for this object
          this.inputStream = inputStream;
          // Read the binary header
          readHeaders();
!         log.debug("readHeader");
          // Read the binary body
          readBodies();
!         log.debug("readBody");
      }
  
--- 73,86 ----
       */
      public AMFDeserializer(DataInputStream inputStream) throws IOException {
!         if (log.isInfoEnabled()) log.info("Deserializing Message, for more info turn on debug level");
! 
          // Save the input stream for this object
          this.inputStream = inputStream;
          // Read the binary header
          readHeaders();
!         if (log.isDebugEnabled()) log.debug("readHeader");
          // Read the binary body
          readBodies();
!         if (log.isDebugEnabled()) log.debug("readBody");
      }
  
***************
*** 100,104 ****
          // Find total number of header elements
          headerCount = inputStream.readUnsignedShort();
!         log.debug("headerCount = " + headerCount);
          // Loop over all the header elements
          for (int i = 0; i < headerCount; i++) {
--- 99,103 ----
          // Find total number of header elements
          headerCount = inputStream.readUnsignedShort();
!         if (log.isDebugEnabled()) log.debug("headerCount = " + headerCount);
          // Loop over all the header elements
          for (int i = 0; i < headerCount; i++) {
***************
*** 127,131 ****
          // Find the total number of body elements
          bodyCount = inputStream.readUnsignedShort();
!         log.debug("bodyCount = " + bodyCount);
  
          // Loop over all the body elements
--- 126,130 ----
          // Find the total number of body elements
          bodyCount = inputStream.readUnsignedShort();
!         if (log.isDebugEnabled()) log.debug("bodyCount = " + bodyCount);
  
          // Loop over all the body elements
***************
*** 141,145 ****
              // Grab the type of the element
              byte type = inputStream.readByte();
!             log.debug("type = " + type);
              // Turn the argument elements into real data
              Object data = readData(type);
--- 140,144 ----
              // Grab the type of the element
              byte type = inputStream.readByte();
!             if (log.isDebugEnabled()) log.debug("type = " + type);
              // Turn the argument elements into real data
              Object data = readData(type);
***************
*** 158,162 ****
          // Grab the explicit type - somehow it works
          String type = inputStream.readUTF();
!         log.debug("Reading Custom Class: " + type);
          String mappedJavaClass = OpenAMFConfig.getInstance().getJavaClassName(type);
          if (mappedJavaClass != null) {
--- 157,161 ----
          // Grab the explicit type - somehow it works
          String type = inputStream.readUTF();
!         if (log.isDebugEnabled()) log.debug("Reading Custom Class: " + type);
          String mappedJavaClass = OpenAMFConfig.getInstance().getJavaClassName(type);
          if (mappedJavaClass != null) {
***************
*** 183,187 ****
          storeObject(aso);
          // Init the array
!         log.debug("reading object");
          // Grab the key
          String key = inputStream.readUTF();
--- 182,186 ----
          storeObject(aso);
          // Init the array
!         if (log.isDebugEnabled()) log.debug("reading object");
          // Grab the key
          String key = inputStream.readUTF();
***************
*** 196,205 ****
              } else {
                  aso.put(key, value);
!                 log.debug(" adding {key=" + key + ", value=" + value + ", type=" + type + "}");
              }
              // Get the next name
              key = inputStream.readUTF();
          }
!         log.debug("finished reading object");
          // Return the map
          return aso;
--- 195,204 ----
              } else {
                  aso.put(key, value);
!                 if (log.isDebugEnabled()) log.debug(" adding {key=" + key + ", value=" + value + ", type=" + type + "}");
              }
              // Get the next name
              key = inputStream.readUTF();
          }
!         if (log.isDebugEnabled()) log.debug("finished reading object");
          // Return the map
          return aso;
***************
*** 216,223 ****
          List array = new ArrayList();
          storeObject(array);
!         log.debug("Reading array");
          // Grab the length of the array
          long length = inputStream.readInt();
!         log.debug("array length = " + length);
          // Loop over all the elements in the data
          for (long i = 0; i < length; i++) {
--- 215,222 ----
          List array = new ArrayList();
          storeObject(array);
!         if (log.isDebugEnabled()) log.debug("Reading array");
          // Grab the length of the array
          long length = inputStream.readInt();
!         if (log.isDebugEnabled()) log.debug("array length = " + length);
          // Loop over all the elements in the data
          for (long i = 0; i < length; i++) {
***************
*** 239,243 ****
      private void storeObject(Object o) {
          storedObjects.add(o);
!         log.debug("storedObjects.size: " + storedObjects.size());
      }
  
--- 238,242 ----
      private void storeObject(Object o) {
          storedObjects.add(o);
!         if (log.isDebugEnabled()) log.debug("storedObjects.size: " + storedObjects.size());
      }
  
***************
*** 268,272 ****
      protected Object readFlushedSO() throws IOException {
          int index = inputStream.readUnsignedShort();
!         log.debug("Object Index: " + index);
          return storedObjects.get(index);
      }
--- 267,271 ----
      protected Object readFlushedSO() throws IOException {
          int index = inputStream.readUnsignedShort();
!         if (log.isDebugEnabled()) log.debug("Object Index: " + index);
          return storedObjects.get(index);
      }
***************
*** 289,293 ****
       */
      protected Object readData(byte type) throws IOException {
!         log.debug("Reading data of type " + AMFBody.getObjectTypeDescription(type));
          switch (type) {
              case AMFBody.DATA_TYPE_NUMBER: // 0
--- 288,292 ----
       */
      protected Object readData(byte type) throws IOException {
!         if (log.isDebugEnabled()) log.debug("Reading data of type " + AMFBody.getObjectTypeDescription(type));
          switch (type) {
              case AMFBody.DATA_TYPE_NUMBER: // 0

Index: AMFSerializer.java
===================================================================
RCS file: /cvsroot/openamf/openamf/src/java/org/openamf/io/AMFSerializer.java,v
retrieving revision 1.39
retrieving revision 1.40
diff -C2 -d -r1.39 -r1.40
*** AMFSerializer.java	19 Aug 2003 23:07:21 -0000	1.39
--- AMFSerializer.java	20 Aug 2003 00:45:38 -0000	1.40
***************
*** 70,76 ****
  	 */
  	public void serializeMessage(AMFMessage message) throws IOException {
! 		if (log.isInfoEnabled()) {
! 			log.info("Serializing Message, for more info turn on debug level");
! 		}
      clearStoredObjects();
  		outputStream.writeShort(message.getVersion());
--- 70,75 ----
  	 */
  	public void serializeMessage(AMFMessage message) throws IOException {
! 		if (log.isInfoEnabled()) log.info("Serializing Message, for more info turn on debug level");
! 
      clearStoredObjects();
  		outputStream.writeShort(message.getVersion());
***************
*** 198,206 ****
  	 */
  	protected void writeObject(Object object) throws IOException {
! 		log.debug("Writing Object");
  		String customClassName =
  			OpenAMFConfig.getInstance().getCustomClassName(
  				object.getClass().getName());
! 		log.debug("customClassName :" + customClassName);
  		if (customClassName == null) {
  			outputStream.writeByte(AMFBody.DATA_TYPE_OBJECT);
--- 197,205 ----
  	 */
  	protected void writeObject(Object object) throws IOException {
! 		if (log.isDebugEnabled()) log.debug("Writing Object");
  		String customClassName =
  			OpenAMFConfig.getInstance().getCustomClassName(
  				object.getClass().getName());
! 		if (log.isDebugEnabled()) log.debug("customClassName :" + customClassName);
  		if (customClassName == null) {
  			outputStream.writeByte(AMFBody.DATA_TYPE_OBJECT);
***************
*** 288,296 ****
  	protected void writeMap(Map map) throws IOException {
  		if (map instanceof ASObject && ((ASObject) map).getType() != null) {
! 			log.debug("Writing Custom Class: " + ((ASObject) map).getType());
  			outputStream.writeByte(AMFBody.DATA_TYPE_CUSTOM_CLASS);
  			outputStream.writeUTF(((ASObject) map).getType());
  		} else {
! 			log.debug("Writing Map");
  			outputStream.writeByte(AMFBody.DATA_TYPE_OBJECT);
  		}
--- 287,295 ----
  	protected void writeMap(Map map) throws IOException {
  		if (map instanceof ASObject && ((ASObject) map).getType() != null) {
! 			if (log.isDebugEnabled()) log.debug("Writing Custom Class: " + ((ASObject) map).getType());
  			outputStream.writeByte(AMFBody.DATA_TYPE_CUSTOM_CLASS);
  			outputStream.writeUTF(((ASObject) map).getType());
  		} else {
! 			if (log.isDebugEnabled()) log.debug("Writing Map");
  			outputStream.writeByte(AMFBody.DATA_TYPE_OBJECT);
  		}
***************
*** 315,321 ****
  		Element docElement = document.getDocumentElement();
  		String xmlData = XMLUtils.convertDOMToString(docElement);
! 		if (log.isDebugEnabled()) {
! 			log.debug("Writing xmlData: \n" + xmlData);
! 		}
  		ByteArrayOutputStream baOutputStream = new ByteArrayOutputStream();
  		baOutputStream.write(xmlData.getBytes());
--- 314,318 ----
  		Element docElement = document.getDocumentElement();
  		String xmlData = XMLUtils.convertDOMToString(docElement);
! 		if (log.isDebugEnabled()) log.debug("Writing xmlData: \n" + xmlData);
  		ByteArrayOutputStream baOutputStream = new ByteArrayOutputStream();
  		baOutputStream.write(xmlData.getBytes());
***************
*** 325,340 ****
  
    private void writeStoredObject(Object obj) throws IOException {
!     log.debug("Writing object reference for " + obj);
      outputStream.write(AMFBody.DATA_TYPE_REFERENCE_OBJECT);
      outputStream.writeShort(((Integer) storedObjects.get(obj)).intValue());
    }
  
!   private void storeObject(Object obj)
!   {
      storedObjects.put(obj, new Integer(storedObjectCount++));
    }
  
!   private void clearStoredObjects()
!   {
      storedObjects.clear();
    }
--- 322,335 ----
  
    private void writeStoredObject(Object obj) throws IOException {
!     if (log.isDebugEnabled()) log.debug("Writing object reference for " + obj);
      outputStream.write(AMFBody.DATA_TYPE_REFERENCE_OBJECT);
      outputStream.writeShort(((Integer) storedObjects.get(obj)).intValue());
    }
  
!   private void storeObject(Object obj) {
      storedObjects.put(obj, new Integer(storedObjectCount++));
    }
  
!   private void clearStoredObjects() {
      storedObjects.clear();
    }




-------------------------------------------------------
This SF.net email is sponsored by Dice.com.
Did you know that Dice has over 25,000 tech jobs available today? From
careers in IT to Engineering to Tech Sales, Dice has tech jobs from the
best hiring companies. http://www.dice.com/index.epl?rel_code=104