thread safety in xml parser lookup

git-svn-id: http://jclouds.googlecode.com/svn/trunk@2043 3d8758e0-26b5-11de-8745-db77d3ebf521
This commit is contained in:
adrian.f.cole 2009-11-04 01:58:46 +00:00
parent a2b17d5718
commit ce5e7017eb
4 changed files with 13 additions and 17 deletions

View File

@ -28,9 +28,7 @@ import java.net.InetAddress;
import java.net.UnknownHostException;
import javax.inject.Inject;
import javax.inject.Provider;
import javax.inject.Singleton;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
@ -38,7 +36,6 @@ import org.jclouds.http.functions.ParseSax;
import org.jclouds.http.functions.ParseSax.HandlerWithResult;
import org.jclouds.util.DateService;
import org.joda.time.DateTime;
import org.xml.sax.SAXException;
import org.xml.sax.XMLReader;
import com.google.gson.Gson;
@ -68,10 +65,18 @@ public class ParserModule extends AbstractModule {
private static class Factory implements ParseSax.Factory {
@Inject
private Provider<XMLReader> parser;
private SAXParserFactory factory;
public <T> ParseSax<T> create(HandlerWithResult<T> handler) {
return new ParseSax<T>(parser.get(), handler);
SAXParser saxParser;
try {
saxParser = factory.newSAXParser();
XMLReader parser = saxParser.getXMLReader();
return new ParseSax<T>(parser, handler);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
@ -92,14 +97,6 @@ public class ParserModule extends AbstractModule {
}
@Provides
XMLReader provideXMLReader(SAXParserFactory factory) throws ParserConfigurationException,
SAXException {
SAXParser saxParser = factory.newSAXParser();
XMLReader parser = saxParser.getXMLReader();
return parser;
}
@Provides
@Singleton
SAXParserFactory provideSAXParserFactory() {

View File

@ -113,7 +113,7 @@ public class PCSClientLiveTest {
validateMetadataItemNameEquals(containerURI, container);
connection.deleteContainer(containerURI).get(10, TimeUnit.SECONDS);
connection.deleteContainer(containerURI).get(30, TimeUnit.SECONDS);
}
}

View File

@ -60,7 +60,6 @@ public class ParseLoginResponseFromHeaders implements Function<HttpResponse, VCl
@Inject
private ParseLoginResponseFromHeaders(Factory factory,
Provider<OrgListToOrgUriHandler> orgHandlerProvider) {
super();
this.factory = factory;
this.orgHandlerProvider = orgHandlerProvider;
}

View File

@ -98,13 +98,13 @@
<priority value="DEBUG" />
<appender-ref ref="ASYNCWIRE" />
</category>
<!--
<category name="jclouds.http.wire">
<priority value="DEBUG" />
<appender-ref ref="ASYNCWIRE" />
</category>
<!-- ======================= -->
--><!-- ======================= -->
<!-- Setup the Root category -->
<!-- ======================= -->