Author: lindner
Date: Fri Dec 5 02:54:27 2008
New Revision: 723705
URL: http://svn.apache.org/viewvc?rev=723705&view=rev
Log:
Performance Patch from hi5
- errorMessage was being created for every getter json serialization
- on a heavily loaded server GC overhead went from 10% to 2%
Modified:
incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/core/util/BeanJsonConverter.java
Modified:
incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/core/util/BeanJsonConverter.java
URL:
http://svn.apache.org/viewvc/incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/core/util/BeanJsonConverter.java?rev=723705&r1=723704&r2=723705&view=diff
==============================================================================
---
incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/core/util/BeanJsonConverter.java
(original)
+++
incubator/shindig/trunk/java/social-api/src/main/java/org/apache/shindig/social/core/util/BeanJsonConverter.java
Fri Dec 5 02:54:27 2008
@@ -78,7 +78,7 @@
* @param pojo The object to convert
* @return An object whos toString method will return json
*/
- public String convertToString(Object pojo) {
+ public String convertToString(final Object pojo) {
return convertToJson(pojo).toString();
}
@@ -88,7 +88,7 @@
* @param pojo The object to convert
* @return An object whos toString method will return json
*/
- public Object convertToJson(Object pojo) {
+ public Object convertToJson(final Object pojo) {
try {
return translateObjectToJson(pojo);
} catch (JSONException e) {
@@ -96,7 +96,7 @@
}
}
- private Object translateObjectToJson(Object val) throws JSONException {
+ private Object translateObjectToJson(final Object val) throws JSONException {
if (val instanceof Object[]) {
JSONArray array = new JSONArray();
for (Object asd : (Object[]) val) {
@@ -143,7 +143,7 @@
* @param pojo The object to convert
* @return A JSONObject representing this pojo
*/
- private JSONObject convertMethodsToJson(Object pojo) {
+ private JSONObject convertMethodsToJson(final Object pojo) {
List<MethodPair> availableGetters;
availableGetters = GETTER_METHODS.get(pojo.getClass());
@@ -154,31 +154,34 @@
JSONObject toReturn = new JSONObject();
for (MethodPair getter : availableGetters) {
- String errorMessage = "Could not encode the " + getter.method + " method
on "
- + pojo.getClass().getName();
try {
Object val = getter.method.invoke(pojo, EMPTY_OBJECT);
if (val != null) {
toReturn.put(getter.fieldName, translateObjectToJson(val));
}
} catch (JSONException e) {
- throw new RuntimeException(errorMessage, e);
+ throw new RuntimeException(errorMessage(pojo, getter), e);
} catch (IllegalAccessException e) {
- throw new RuntimeException(errorMessage, e);
+ throw new RuntimeException(errorMessage(pojo, getter), e);
} catch (InvocationTargetException e) {
- throw new RuntimeException(errorMessage, e);
+ throw new RuntimeException(errorMessage(pojo, getter), e);
} catch (IllegalArgumentException e) {
- throw new RuntimeException(errorMessage, e);
+ throw new RuntimeException(errorMessage(pojo, getter), e);
}
}
return toReturn;
}
- private static class MethodPair {
+ private static String errorMessage(Object pojo, MethodPair getter) {
+ return "Could not encode the " + getter.method + " method on "
+ + pojo.getClass().getName();
+ }
+
+ private static final class MethodPair {
public Method method;
public String fieldName;
- private MethodPair(Method method, String fieldName) {
+ private MethodPair(final Method method, final String fieldName) {
this.method = method;
this.fieldName = fieldName;
}