You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by ma...@apache.org on 2010/08/12 10:25:39 UTC

svn commit: r984681 - in /myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal: application/StateManagerImpl.java renderkit/core/CoreResponseStateManager.java util/ObjectInputStreamResolveClass.java

Author: matzew
Date: Thu Aug 12 08:25:39 2010
New Revision: 984681

URL: http://svn.apache.org/viewvc?rev=984681&view=rev
Log:
TRINIDAD-1747 - zip page state to reduce live memory

changed original version of the custom ObjectInputStream to resolve primitives from a hashmap. The code for this 'mapper' has been taken from Apache Harmony's ObjectInputStream clazz

Added:
    myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/util/ObjectInputStreamResolveClass.java
Modified:
    myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/application/StateManagerImpl.java
    myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/CoreResponseStateManager.java

Modified: myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/application/StateManagerImpl.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/application/StateManagerImpl.java?rev=984681&r1=984680&r2=984681&view=diff
==============================================================================
--- myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/application/StateManagerImpl.java (original)
+++ myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/application/StateManagerImpl.java Thu Aug 12 08:25:39 2010
@@ -60,7 +60,7 @@ import org.apache.myfaces.trinidadintern
 import org.apache.myfaces.trinidadinternal.context.TrinidadPhaseListener;
 import org.apache.myfaces.trinidadinternal.util.SubKeyMap;
 import org.apache.myfaces.trinidadinternal.util.TokenCache;
-
+import org.apache.myfaces.trinidadinternal.util.ObjectInputStreamResolveClass;
 
 /**
  * StateManager that handles a hybrid client/server strategy:  the state
@@ -1359,7 +1359,7 @@ public class StateManagerImpl extends St
         }
 
         ByteArrayInputStream baos = new ByteArrayInputStream(bos.toByteArray());
-        ObjectInputStream ois = new ObjectInputStream(baos);
+        ObjectInputStream ois = new ObjectInputStreamResolveClass(baos);
         Object unzippedState = ois.readObject();
         ois.close();
         return unzippedState;

Modified: myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/CoreResponseStateManager.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/CoreResponseStateManager.java?rev=984681&r1=984680&r2=984681&view=diff
==============================================================================
--- myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/CoreResponseStateManager.java (original)
+++ myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/renderkit/core/CoreResponseStateManager.java Thu Aug 12 08:25:39 2010
@@ -45,7 +45,7 @@ import org.apache.myfaces.trinidad.util.
 import org.apache.myfaces.trinidad.util.Base64OutputStream;
 import org.apache.myfaces.trinidad.util.ClassLoaderUtils;
 import org.apache.myfaces.trinidadinternal.application.StateManagerImpl;
-
+import org.apache.myfaces.trinidadinternal.util.ObjectInputStreamResolveClass;
 
 /**
  * ResponseStateManager implementation for the Core RenderKit.
@@ -284,21 +284,7 @@ public class CoreResponseStateManager ex
         try
         {
           ObjectInputStream ois;
-          ois = new ObjectInputStream( new GZIPInputStream( b64_in,
-                                                            _BUFFER_SIZE ))
-            {
-              protected Class<?> resolveClass(ObjectStreamClass desc)
-                                       throws IOException,
-                                              ClassNotFoundException
-              {
-                // TRINIDAD-1062 It has been noticed that in OC4J and Weblogic that the
-                // classes being resolved are having problems by not finding
-                // them using the context class loader. Therefore, we are adding
-                // this work-around until the problem with these application
-                // servers can be better understood
-                return ClassLoaderUtils.loadClass(desc.getName());
-              }
-            };
+          ois = new ObjectInputStreamResolveClass( new GZIPInputStream( b64_in, _BUFFER_SIZE ));
 
           Object structure = ois.readObject();
           Object state = ois.readObject();

Added: myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/util/ObjectInputStreamResolveClass.java
URL: http://svn.apache.org/viewvc/myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/util/ObjectInputStreamResolveClass.java?rev=984681&view=auto
==============================================================================
--- myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/util/ObjectInputStreamResolveClass.java (added)
+++ myfaces/trinidad/trunk/trinidad-impl/src/main/java/org/apache/myfaces/trinidadinternal/util/ObjectInputStreamResolveClass.java Thu Aug 12 08:25:39 2010
@@ -0,0 +1,80 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+package org.apache.myfaces.trinidadinternal.util;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectStreamClass;
+import java.util.HashMap;
+
+import org.apache.myfaces.trinidad.util.ClassLoaderUtils;
+import org.apache.myfaces.trinidadinternal.util.ObjectInputStreamResolveClass;
+
+public class ObjectInputStreamResolveClass extends ObjectInputStream
+{
+  public ObjectInputStreamResolveClass()  throws IOException, SecurityException
+  {
+    super();
+  }
+
+  public ObjectInputStreamResolveClass(InputStream in) throws IOException 
+  {
+    super(in);
+  }
+  
+  protected Class<?> resolveClass(ObjectStreamClass desc)
+                           throws IOException,
+                                  ClassNotFoundException
+  {
+    Class<?> cls = null;
+    String className = desc.getName();
+
+    // if it is primitive class, for example, long.class
+    // we resolve them by getting them from the hashMaps
+    cls = _PRIMITIVE_CLASSES.get(className);
+
+    if (null == cls)
+    {
+      // TRINIDAD-1062 It has been noticed that in OC4J and Weblogic that the
+      // classes being resolved are having problems by not finding
+      // them using the context class loader. Therefore, we are adding
+      // this work-around until the problem with these application
+      // servers can be better understood
+      cls = ClassLoaderUtils.loadClass(desc.getName());
+    }
+    return cls;
+  }
+
+  // HashMap to map primitives to their clazzes
+  private static final HashMap<String, Class<?>> _PRIMITIVE_CLASSES = new HashMap<String, Class<?>>();
+
+  static
+  {
+    _PRIMITIVE_CLASSES.put("byte", byte.class);
+    _PRIMITIVE_CLASSES.put("short", short.class);
+    _PRIMITIVE_CLASSES.put("int", int.class);
+    _PRIMITIVE_CLASSES.put("long", long.class);
+    _PRIMITIVE_CLASSES.put("boolean", boolean.class);
+    _PRIMITIVE_CLASSES.put("char", char.class);
+    _PRIMITIVE_CLASSES.put("float", float.class);
+    _PRIMITIVE_CLASSES.put("double", double.class);
+    _PRIMITIVE_CLASSES.put("void", void.class);
+  }
+}