[typica-svn] [typica] r325 committed - performance improvements

1 view
Skip to first unread message

typ...@googlecode.com

unread,
May 5, 2010, 2:14:31 PM5/5/10
to typic...@googlegroups.com
Revision: 325
Author: dkavanagh
Date: Wed May 5 11:14:03 2010
Log: performance improvements

http://code.google.com/p/typica/source/detail?r=325

Modified:
/trunk/java/com/xerox/amazonws/common/AWSQueryConnection.java
/trunk/java/com/xerox/amazonws/common/JAXBuddy.java

=======================================
--- /trunk/java/com/xerox/amazonws/common/AWSQueryConnection.java Mon Apr
12 05:56:46 2010
+++ /trunk/java/com/xerox/amazonws/common/AWSQueryConnection.java Wed May
5 11:14:03 2010
@@ -87,10 +87,10 @@
*/
public class AWSQueryConnection extends AWSConnection {
private static final Log log =
LogFactory.getLog(AWSQueryConnection.class);
+ private static String userAgent = "typica/";

// this is the number of automatic retries
private int maxRetries = 5;
- private String userAgent = "typica/";
private HttpClient hc = null;
private int maxConnections = 100;
private String proxyHost = null;
@@ -103,6 +103,22 @@
private int connectionTimeout = 0;
private TimeZone serverTimeZone = TimeZone.getTimeZone("GMT");

+ static {
+ String version = "?";
+ try {
+ Properties props = new Properties();
+ InputStream verStream =
ClassLoader.getSystemResourceAsStream("version.properties");
+ try {
+ props.load(verStream);
+ } finally {
+ verStream.close();
+
+ }
+ version = props.getProperty("version");
+ } catch (Exception ex) { }
+ userAgent = userAgent + version + " ("+ System.getProperty("os.arch")
+ "; " + System.getProperty("os.name") + ")";
+ }
+
/**
* Initializes the queue service with your AWS login information.
*
@@ -115,19 +131,6 @@
public AWSQueryConnection(String awsAccessId, String awsSecretKey,
boolean isSecure,
String server, int port) {
super(awsAccessId, awsSecretKey, isSecure, server, port);
- String version = "?";
- try {
- Properties props = new Properties();
- InputStream verStream =
this.getClass().getClassLoader().getResourceAsStream("version.properties");
- try {
- props.load(verStream);
- } finally {
- close(verStream);
-
- }
- version = props.getProperty("version");
- } catch (Exception ex) { }
- userAgent = userAgent + version + " ("+ System.getProperty("os.arch")
+ "; " + System.getProperty("os.name") + ")";
}

/**
@@ -504,7 +507,9 @@
throw new HttpException("Number of retries exceeded : "+action,
error);
}
doRetry = false;
- try { Thread.sleep((int)Math.pow(2.0, retries)*1000); } catch
(InterruptedException ex) {}
+ try {
+ Thread.sleep((long)(Math.random() * (Math.pow(4, (retries-1))*100L)));
+ } catch (InterruptedException ex) {}
}
} while (!done);
return (T)response;
=======================================
--- /trunk/java/com/xerox/amazonws/common/JAXBuddy.java Wed Apr 9 14:53:06
2008
+++ /trunk/java/com/xerox/amazonws/common/JAXBuddy.java Wed May 5 11:14:03
2010
@@ -27,6 +27,12 @@
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Node;
+import org.xml.sax.SAXException;

/**
* This class implements some helpful methods to marshal and unmarshal xml.
@@ -36,6 +42,35 @@
*/
public class JAXBuddy {
public final static Hashtable<String, JAXBContext> contextCache = new
Hashtable<String, JAXBContext>();
+
+ private static final DocumentBuilderFactory domFactory =
+ DocumentBuilderFactory.newInstance();
+
+ private static ThreadLocal<DocumentBuilder> builder = null;
+
+ public static DocumentBuilder createDocumentBuilder() throws Exception
+ {
+ return domFactory.newDocumentBuilder() ;
+ }
+
+ /** Initialize DocumentBuilder **/
+ static {
+ builder = new ThreadLocal<DocumentBuilder>() {
+ @Override
+ protected synchronized DocumentBuilder initialValue() {
+ DocumentBuilder b = null;
+ try {
+ domFactory.setNamespaceAware(true);
+ b= createDocumentBuilder();
+ } catch(JAXBException e) {
+ throw new ExceptionInInitializerError(e);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ return b;
+ }
+ };
+ }

/**
* A convenience method to turn an object into a stream of XML.
@@ -75,9 +110,16 @@
* @param is the stream to read the XMl from
* @return an object representing the data from the stream
*/
- public static <T> T deserializeXMLStream(Class<T> c, InputStream is)
throws JAXBException {
+ public static <T> T deserializeXMLStream(Class<T> c, InputStream is)
+ throws JAXBException, IOException, SAXException {
Unmarshaller u = getUnmarshaller(c);
- T result = c.cast(u.unmarshal(is));
+ //T result = c.cast(u.unmarshal(is));
+ Document doc = builder.get().parse(is);
+ if (doc == null) {
+ throw new IOException("XML parser returned no document");
+ }
+ Node root = doc.getDocumentElement();
+ T result = c.cast(u.unmarshal(doc));
return result;
}

--
You received this message because you are subscribed to the Google Groups "typica-svn" group.
To post to this group, send email to typic...@googlegroups.com.
To unsubscribe from this group, send email to typica-svn+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/typica-svn?hl=en.

Reply all
Reply to author
Forward
0 new messages