Author: dkulp
Date: Wed Jul 15 20:26:33 2009
New Revision: 794404
URL: http://svn.apache.org/viewvc?rev=794404&view=rev
Log:
Merged revisions 794396 via svnmerge from
https://svn.apache.org/repos/asf/cxf/trunk
........
r794396 | dkulp | 2009-07-15 16:17:11 -0400 (Wed, 15 Jul 2009) | 3 lines
[CXF-2342] Update to use pools of XMLInputFactory/XMLOutputFactory
objects
Modified patch from Kevin Conaway applied
........
Modified:
cxf/branches/2.2.x-fixes/ (props changed)
cxf/branches/2.2.x-fixes/common/common/src/main/java/org/apache/cxf/staxutils/StaxUtils.java
cxf/branches/2.2.x-fixes/common/common/src/test/java/org/apache/cxf/staxutils/DepthXMLStreamReaderTest.java
cxf/branches/2.2.x-fixes/common/common/src/test/java/org/apache/cxf/staxutils/FragmentStreamReaderTest.java
cxf/branches/2.2.x-fixes/rt/bindings/http/src/main/java/org/apache/cxf/binding/http/interceptor/URIParameterInInterceptor.java
cxf/branches/2.2.x-fixes/rt/core/src/main/java/org/apache/cxf/interceptor/StaxInInterceptor.java
cxf/branches/2.2.x-fixes/rt/core/src/main/java/org/apache/cxf/interceptor/StaxOutInterceptor.java
cxf/branches/2.2.x-fixes/systests/src/test/java/org/apache/cxf/systest/versioning/MediatorInInterceptor.java
Propchange: cxf/branches/2.2.x-fixes/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Wed Jul 15 20:26:33 2009
@@ -1 +1 @@
-/cxf/trunk:782728-782730,783097,783294,783396,784059,784181-784184,784893,784895,785279-785282,785468,785621,785624,785651,785734,785866,786142,786271-786272,786395,786512,786514,786582-786583,786638,786647,786850,787200,787269,787277-787279,787290-787291,787305,787323,787366,787849,788030,788060,788187,788444,788451,788703,788752,788774,788819-788820,789013,789371,789387,789420,789527-789530,789704-789705,789788,789811,789896-789901,790074,790094,790134,790188,790294,790553,790637-790644,790868,791301,791354,791538,791753,791947,792007,792096,792183,792261-792265,792271,792604,792683-792685,792975,792985,793059,793570,794297
+/cxf/trunk:782728-782730,783097,783294,783396,784059,784181-784184,784893,784895,785279-785282,785468,785621,785624,785651,785734,785866,786142,786271-786272,786395,786512,786514,786582-786583,786638,786647,786850,787200,787269,787277-787279,787290-787291,787305,787323,787366,787849,788030,788060,788187,788444,788451,788703,788752,788774,788819-788820,789013,789371,789387,789420,789527-789530,789704-789705,789788,789811,789896-789901,790074,790094,790134,790188,790294,790553,790637-790644,790868,791301,791354,791538,791753,791947,792007,792096,792183,792261-792265,792271,792604,792683-792685,792975,792985,793059,793570,794297,794396
Propchange: cxf/branches/2.2.x-fixes/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.
Modified:
cxf/branches/2.2.x-fixes/common/common/src/main/java/org/apache/cxf/staxutils/StaxUtils.java
URL:
http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/common/common/src/main/java/org/apache/cxf/staxutils/StaxUtils.java?rev=794404&r1=794403&r2=794404&view=diff
==============================================================================
---
cxf/branches/2.2.x-fixes/common/common/src/main/java/org/apache/cxf/staxutils/StaxUtils.java
(original)
+++
cxf/branches/2.2.x-fixes/common/common/src/main/java/org/apache/cxf/staxutils/StaxUtils.java
Wed Jul 15 20:26:33 2009
@@ -23,9 +23,9 @@
import java.io.OutputStream;
import java.io.Reader;
import java.io.Writer;
-//import java.util.HashMap;
-//import java.util.Map;
import java.util.Iterator;
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.LinkedBlockingQueue;
import java.util.logging.Logger;
import javax.xml.namespace.NamespaceContext;
@@ -75,23 +75,27 @@
private static final Logger LOG = LogUtils.getL7dLogger(StaxUtils.class);
- private static final XMLInputFactory XML_NS_AWARE_INPUT_FACTORY =
XMLInputFactory.newInstance();
- private static final XMLInputFactory XML_INPUT_FACTORY =
XMLInputFactory.newInstance();
- private static final XMLOutputFactory XML_OUTPUT_FACTORY =
XMLOutputFactory.newInstance();
+ private static final BlockingQueue<XMLInputFactory>
NS_AWARE_INPUT_FACTORY_POOL;
+ private static final BlockingQueue<XMLOutputFactory> OUTPUT_FACTORY_POOL;
private static final String XML_NS = "http://www.w3.org/2000/xmlns/";
static {
+ int i = 20;
+
try {
- XML_INPUT_FACTORY.setProperty(XMLInputFactory.IS_NAMESPACE_AWARE,
false);
- } catch (Exception e) {
- //ignore
+ String s = System.getProperty("org.apache.cxf.staxutils.pool-size",
+ "-1");
+ i = Integer.parseInt(s);
+ } catch (Throwable t) {
+ //ignore
+ i = 20;
}
- try {
-
XML_NS_AWARE_INPUT_FACTORY.setProperty(XMLInputFactory.IS_NAMESPACE_AWARE,
true);
- } catch (Exception ex) {
- //ignore
+ if (i <= 0) {
+ i = 20;
}
+ NS_AWARE_INPUT_FACTORY_POOL = new
LinkedBlockingQueue<XMLInputFactory>(i);
+ OUTPUT_FACTORY_POOL = new LinkedBlockingQueue<XMLOutputFactory>(i);
}
private StaxUtils() {
@@ -117,17 +121,29 @@
* Return a cached, namespace-aware, factory.
* @return
*/
- public static XMLInputFactory getXMLInputFactory() {
- return getXMLInputFactory(true);
+ private static XMLInputFactory getXMLInputFactory() {
+ XMLInputFactory f = NS_AWARE_INPUT_FACTORY_POOL.poll();
+ if (f == null) {
+ f = XMLInputFactory.newInstance();
+ f.setProperty(XMLInputFactory.IS_NAMESPACE_AWARE, true);
+ }
+ return f;
}
- /**
- * Return a cached factory.
- * @param nsAware
- * @return
- */
- public static XMLInputFactory getXMLInputFactory(boolean nsAware) {
- return nsAware ? XML_NS_AWARE_INPUT_FACTORY : XML_INPUT_FACTORY;
+ private static void returnXMLInputFactory(XMLInputFactory factory) {
+ NS_AWARE_INPUT_FACTORY_POOL.offer(factory);
+ }
+
+ private static XMLOutputFactory getXMLOutputFactory() {
+ XMLOutputFactory f = OUTPUT_FACTORY_POOL.poll();
+ if (f == null) {
+ f = XMLOutputFactory.newInstance();
+ }
+ return f;
+ }
+
+ private static void returnXMLOutputFactory(XMLOutputFactory factory) {
+ OUTPUT_FACTORY_POOL.offer(factory);
}
/**
@@ -141,18 +157,16 @@
return factory;
}
- public static XMLOutputFactory getXMLOutputFactory() {
- return XML_OUTPUT_FACTORY;
- }
+
public static XMLStreamWriter createXMLStreamWriter(Writer out) {
+ XMLOutputFactory factory = getXMLOutputFactory();
try {
- XMLOutputFactory factory = getXMLOutputFactory();
- synchronized (factory) {
- return factory.createXMLStreamWriter(out);
- }
+ return factory.createXMLStreamWriter(out);
} catch (XMLStreamException e) {
throw new RuntimeException("Cant' create XMLStreamWriter", e);
+ } finally {
+ returnXMLOutputFactory(factory);
}
}
@@ -164,36 +178,35 @@
if (encoding == null) {
encoding = "UTF-8";
}
-
+ XMLOutputFactory factory = getXMLOutputFactory();
try {
- XMLOutputFactory factory = getXMLOutputFactory();
- synchronized (factory) {
- return factory.createXMLStreamWriter(out, encoding);
- }
+ return factory.createXMLStreamWriter(out, encoding);
} catch (XMLStreamException e) {
throw new RuntimeException("Cant' create XMLStreamWriter", e);
+ } finally {
+ returnXMLOutputFactory(factory);
}
}
public static XMLStreamWriter createXMLStreamWriter(Result r) {
+ XMLOutputFactory factory = getXMLOutputFactory();
try {
- XMLOutputFactory factory = getXMLOutputFactory();
- synchronized (factory) {
- return factory.createXMLStreamWriter(r);
- }
+ return factory.createXMLStreamWriter(r);
} catch (XMLStreamException e) {
throw new RuntimeException("Cant' create XMLStreamWriter", e);
+ } finally {
+ returnXMLOutputFactory(factory);
}
}
public static XMLStreamReader createFilteredReader(XMLStreamReader reader,
StreamFilter filter) {
+ XMLInputFactory factory = getXMLInputFactory();
try {
- XMLInputFactory factory = getXMLInputFactory();
- synchronized (factory) {
- return factory.createFilteredReader(reader, filter);
- }
+ return factory.createFilteredReader(reader, filter);
} catch (XMLStreamException e) {
throw new RuntimeException("Cant' create XMLStreamReader", e);
+ } finally {
+ returnXMLInputFactory(factory);
}
}
@@ -857,13 +870,13 @@
encoding = "UTF-8";
}
+ XMLInputFactory factory = getXMLInputFactory();
try {
- XMLInputFactory factory = getXMLInputFactory();
- synchronized (factory) {
- return factory.createXMLStreamReader(in, encoding);
- }
+ return factory.createXMLStreamReader(in, encoding);
} catch (XMLStreamException e) {
throw new RuntimeException("Couldn't parse stream.", e);
+ } finally {
+ returnXMLInputFactory(factory);
}
}
@@ -872,23 +885,23 @@
* @return
*/
public static XMLStreamReader createXMLStreamReader(InputStream in) {
+ XMLInputFactory factory = getXMLInputFactory();
try {
- XMLInputFactory factory = getXMLInputFactory();
- synchronized (factory) {
- return factory.createXMLStreamReader(in);
- }
+ return factory.createXMLStreamReader(in);
} catch (XMLStreamException e) {
throw new RuntimeException("Couldn't parse stream.", e);
+ } finally {
+ returnXMLInputFactory(factory);
}
}
public static XMLStreamReader createXMLStreamReader(String systemId,
InputStream in) {
+ XMLInputFactory factory = getXMLInputFactory();
try {
- XMLInputFactory factory = getXMLInputFactory();
- synchronized (factory) {
- return factory.createXMLStreamReader(systemId, in);
- }
+ return factory.createXMLStreamReader(systemId, in);
} catch (XMLStreamException e) {
throw new RuntimeException("Couldn't parse stream.", e);
+ } finally {
+ returnXMLInputFactory(factory);
}
}
@@ -914,9 +927,12 @@
return new W3CDOMStreamReader(el);
}
}
+
XMLInputFactory factory = getXMLInputFactory();
- synchronized (factory) {
+ try {
return factory.createXMLStreamReader(source);
+ } finally {
+ returnXMLInputFactory(factory);
}
} catch (XMLStreamException e) {
throw new RuntimeException("Couldn't parse stream.", e);
@@ -928,14 +944,13 @@
* @return
*/
public static XMLStreamReader createXMLStreamReader(Reader reader) {
-
+ XMLInputFactory factory = getXMLInputFactory();
try {
- XMLInputFactory factory = getXMLInputFactory();
- synchronized (factory) {
- return factory.createXMLStreamReader(reader);
- }
+ return factory.createXMLStreamReader(reader);
} catch (XMLStreamException e) {
throw new RuntimeException("Couldn't parse stream.", e);
+ } finally {
+ returnXMLInputFactory(factory);
}
}
Modified:
cxf/branches/2.2.x-fixes/common/common/src/test/java/org/apache/cxf/staxutils/DepthXMLStreamReaderTest.java
URL:
http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/common/common/src/test/java/org/apache/cxf/staxutils/DepthXMLStreamReaderTest.java?rev=794404&r1=794403&r2=794404&view=diff
==============================================================================
---
cxf/branches/2.2.x-fixes/common/common/src/test/java/org/apache/cxf/staxutils/DepthXMLStreamReaderTest.java
(original)
+++
cxf/branches/2.2.x-fixes/common/common/src/test/java/org/apache/cxf/staxutils/DepthXMLStreamReaderTest.java
Wed Jul 15 20:26:33 2009
@@ -19,7 +19,6 @@
package org.apache.cxf.staxutils;
-import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamReader;
import org.junit.Assert;
@@ -29,9 +28,8 @@
@Test
public void testReader() throws Exception {
- XMLInputFactory ifactory = StaxUtils.getXMLInputFactory();
XMLStreamReader reader =
-
ifactory.createXMLStreamReader(getClass().getResourceAsStream("./resources/amazon.xml"));
+
StaxUtils.createXMLStreamReader(getClass().getResourceAsStream("./resources/amazon.xml"));
DepthXMLStreamReader dr = new DepthXMLStreamReader(reader);
Modified:
cxf/branches/2.2.x-fixes/common/common/src/test/java/org/apache/cxf/staxutils/FragmentStreamReaderTest.java
URL:
http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/common/common/src/test/java/org/apache/cxf/staxutils/FragmentStreamReaderTest.java?rev=794404&r1=794403&r2=794404&view=diff
==============================================================================
---
cxf/branches/2.2.x-fixes/common/common/src/test/java/org/apache/cxf/staxutils/FragmentStreamReaderTest.java
(original)
+++
cxf/branches/2.2.x-fixes/common/common/src/test/java/org/apache/cxf/staxutils/FragmentStreamReaderTest.java
Wed Jul 15 20:26:33 2009
@@ -19,7 +19,6 @@
package org.apache.cxf.staxutils;
-import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamReader;
import org.junit.Assert;
@@ -29,9 +28,8 @@
@Test
public void testReader() throws Exception {
- XMLInputFactory ifactory = StaxUtils.getXMLInputFactory();
XMLStreamReader reader =
-
ifactory.createXMLStreamReader(getClass().getResourceAsStream("./resources/amazon.xml"));
+
StaxUtils.createXMLStreamReader(getClass().getResourceAsStream("./resources/amazon.xml"));
DepthXMLStreamReader dr = new DepthXMLStreamReader(reader);
Modified:
cxf/branches/2.2.x-fixes/rt/bindings/http/src/main/java/org/apache/cxf/binding/http/interceptor/URIParameterInInterceptor.java
URL:
http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/rt/bindings/http/src/main/java/org/apache/cxf/binding/http/interceptor/URIParameterInInterceptor.java?rev=794404&r1=794403&r2=794404&view=diff
==============================================================================
---
cxf/branches/2.2.x-fixes/rt/bindings/http/src/main/java/org/apache/cxf/binding/http/interceptor/URIParameterInInterceptor.java
(original)
+++
cxf/branches/2.2.x-fixes/rt/bindings/http/src/main/java/org/apache/cxf/binding/http/interceptor/URIParameterInInterceptor.java
Wed Jul 15 20:26:33 2009
@@ -114,8 +114,12 @@
XMLInputFactory inputFactory =
StaxInInterceptor.getXMLInputFactory(message);
try {
XMLStreamReader reader;
- synchronized (inputFactory) {
- reader =
inputFactory.createXMLStreamReader(message.getContent(InputStream.class));
+ if (inputFactory == null) {
+ reader =
StaxUtils.createXMLStreamReader(message.getContent(InputStream.class));
+ } else {
+ synchronized (inputFactory) {
+ reader =
inputFactory.createXMLStreamReader(message.getContent(InputStream.class));
+ }
}
doc = StaxUtils.read(reader);
} catch (XMLStreamException e) {
Modified:
cxf/branches/2.2.x-fixes/rt/core/src/main/java/org/apache/cxf/interceptor/StaxInInterceptor.java
URL:
http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/rt/core/src/main/java/org/apache/cxf/interceptor/StaxInInterceptor.java?rev=794404&r1=794403&r2=794404&view=diff
==============================================================================
---
cxf/branches/2.2.x-fixes/rt/core/src/main/java/org/apache/cxf/interceptor/StaxInInterceptor.java
(original)
+++
cxf/branches/2.2.x-fixes/rt/core/src/main/java/org/apache/cxf/interceptor/StaxInInterceptor.java
Wed Jul 15 20:26:33 2009
@@ -79,8 +79,12 @@
XMLStreamReader reader;
try {
XMLInputFactory factory = getXMLInputFactory(message);
- synchronized (factory) {
- reader = factory.createXMLStreamReader(is, encoding);
+ if (factory == null) {
+ reader = StaxUtils.createXMLStreamReader(is, encoding);
+ } else {
+ synchronized (factory) {
+ reader = factory.createXMLStreamReader(is, encoding);
+ }
}
} catch (XMLStreamException e) {
throw new Fault(new
org.apache.cxf.common.i18n.Message("STREAM_CREATE_EXC",
@@ -123,8 +127,7 @@
}
}
return xif;
- } else {
- return StaxUtils.getXMLInputFactory();
- }
+ }
+ return null;
}
}
Modified:
cxf/branches/2.2.x-fixes/rt/core/src/main/java/org/apache/cxf/interceptor/StaxOutInterceptor.java
URL:
http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/rt/core/src/main/java/org/apache/cxf/interceptor/StaxOutInterceptor.java?rev=794404&r1=794403&r2=794404&view=diff
==============================================================================
---
cxf/branches/2.2.x-fixes/rt/core/src/main/java/org/apache/cxf/interceptor/StaxOutInterceptor.java
(original)
+++
cxf/branches/2.2.x-fixes/rt/core/src/main/java/org/apache/cxf/interceptor/StaxOutInterceptor.java
Wed Jul 15 20:26:33 2009
@@ -65,8 +65,12 @@
try {
XMLOutputFactory factory = getXMLOutputFactory(message);
- synchronized (factory) {
- writer = factory.createXMLStreamWriter(os, encoding);
+ if (factory == null) {
+ writer = StaxUtils.createXMLStreamWriter(os, encoding);
+ } else {
+ synchronized (factory) {
+ writer = factory.createXMLStreamWriter(os, encoding);
+ }
}
if
(Boolean.TRUE.equals(message.getContextualProperty(FORCE_START_DOCUMENT))) {
writer.writeStartDocument(encoding, "1.0");
@@ -142,9 +146,8 @@
Boolean.TRUE);
m.put(FORCE_START_DOCUMENT, Boolean.TRUE);
return xif;
- } else {
- return StaxUtils.getXMLOutputFactory();
}
+ return null;
}
public class StaxOutEndingInterceptor extends
AbstractPhaseInterceptor<Message> {
Modified:
cxf/branches/2.2.x-fixes/systests/src/test/java/org/apache/cxf/systest/versioning/MediatorInInterceptor.java
URL:
http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/systests/src/test/java/org/apache/cxf/systest/versioning/MediatorInInterceptor.java?rev=794404&r1=794403&r2=794404&view=diff
==============================================================================
---
cxf/branches/2.2.x-fixes/systests/src/test/java/org/apache/cxf/systest/versioning/MediatorInInterceptor.java
(original)
+++
cxf/branches/2.2.x-fixes/systests/src/test/java/org/apache/cxf/systest/versioning/MediatorInInterceptor.java
Wed Jul 15 20:26:33 2009
@@ -36,6 +36,7 @@
import org.apache.cxf.io.CachedOutputStream;
import org.apache.cxf.message.Message;
import org.apache.cxf.phase.Phase;
+import org.apache.cxf.staxutils.StaxUtils;
public class MediatorInInterceptor extends
AbstractEndpointSelectionInterceptor {
@@ -64,8 +65,12 @@
XMLStreamReader xsr;
XMLInputFactory factory =
StaxInInterceptor.getXMLInputFactory(message);
- synchronized (factory) {
- xsr = factory.createXMLStreamReader(bos.getInputStream(),
encoding);
+ if (factory == null) {
+ xsr = StaxUtils.createXMLStreamReader(bos.getInputStream(),
encoding);
+ } else {
+ synchronized (factory) {
+ xsr = factory.createXMLStreamReader(bos.getInputStream(),
encoding);
+ }
}
// move to the soap body