haul 2002/12/17 06:53:17
Modified: src/java/org/apache/cocoon/components/modules/input
AbstractMetaModule.java ChainMetaModule.java
DateMetaInputModule.java DigestMetaModule.java
JXPathMetaModule.java MapMetaModule.java
SimpleMappingMetaModule.java XMLFileModule.java
XMLMetaModule.java
Log:
<action dev="CH" type="update">
Make all "meta" modules ThreadSafe
</action>
Revision Changes Path
1.7 +27 -27
xml-cocoon2/src/java/org/apache/cocoon/components/modules/input/AbstractMetaModule.java
Index: AbstractMetaModule.java
===================================================================
RCS file:
/home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/modules/input/AbstractMetaModule.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- AbstractMetaModule.java 16 Dec 2002 14:55:05 -0000 1.6
+++ AbstractMetaModule.java 17 Dec 2002 14:53:16 -0000 1.7
@@ -73,7 +73,7 @@
* @version CVS $Id$
*/
public abstract class AbstractMetaModule extends AbstractInputModule
- implements Initializable, Composable, Disposable {
+ implements Composable, Disposable {
/** The component manager instance */
protected ComponentManager manager;
@@ -92,7 +92,7 @@
// during configure() so why bother
here...
/** Is this instance initialized? */
- protected Boolean initialized = new Boolean(false);
+ protected boolean initialized = false;
/* Constants */
@@ -116,28 +116,34 @@
/**
* Initialize the meta module with exactly one other input
- * module. Override this method and dispose() to keep references
- * to more than one module.
+ * module. Since "meta" modules require references to components
+ * of the same role, initialization cannot be done in initialize()
+ * when also implementing ThreadSafe since at that point the
+ * component selector is not yet initialized it would trigger the
+ * creation of a new one resulting in an endless loop of
+ * initializations. Therefore, every module needs to call this
+ * method when it first requires access to another module if the
+ * module itself has not been initialized. Override this method
+ * and dispose() to keep references to more than one module.
*/
- public void initialize() {
+ public synchronized void lazy_initialize() {
try {
// obtain input modules
- synchronized (this.initialized) {
- if (!this.initialized.booleanValue())
- this.inputSelector=(ComponentSelector)
this.manager.lookup(INPUT_MODULE_SELECTOR);
- if (this.inputSelector != null && this.inputSelector instanceof
ThreadSafe) {
-
- if (this.defaultInput != null) {
- this.input = obtainModule(this.defaultInput);
- }
-
+ if (!this.initialized) {
+ this.inputSelector=(ComponentSelector)
this.manager.lookup(INPUT_MODULE_SELECTOR);
+ if (this.inputSelector != null && this.inputSelector instanceof
ThreadSafe) {
+
+ if (this.defaultInput != null) {
+ this.input = obtainModule(this.defaultInput);
+ }
+
} else if (!(this.inputSelector instanceof ThreadSafe) ) {
this.manager.release(this.inputSelector);
this.inputSelector = null;
}
-
- this.initialized = new Boolean(true);
+
+ this.initialized = true;
}
} catch (Exception e) {
if (getLogger().isWarnEnabled())
@@ -152,16 +158,10 @@
*/
public void dispose() {
- if (!this.initialized.booleanValue()) {
- if (getLogger().isErrorEnabled()) {
- getLogger().error("Uninitialized Component! FAILING");
- }
- } else {
- if (this.inputSelector != null) {
- if (this.input != null)
- this.inputSelector.release(this.input);
- this.manager.release(this.inputSelector);
- }
+ if (this.inputSelector != null) {
+ if (this.input != null)
+ this.inputSelector.release(this.input);
+ this.manager.release(this.inputSelector);
}
}
1.6 +27 -39
xml-cocoon2/src/java/org/apache/cocoon/components/modules/input/ChainMetaModule.java
Index: ChainMetaModule.java
===================================================================
RCS file:
/home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/modules/input/ChainMetaModule.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- ChainMetaModule.java 16 Dec 2002 14:55:05 -0000 1.5
+++ ChainMetaModule.java 17 Dec 2002 14:53:16 -0000 1.6
@@ -96,7 +96,7 @@
* @author <a href="mailto:[EMAIL PROTECTED]">Christian Haul</a>
* @version CVS $Id$
*/
-public class ChainMetaModule extends AbstractMetaModule {
+public class ChainMetaModule extends AbstractMetaModule implements ThreadSafe {
class ModuleHolder {
public String name = null;
@@ -135,26 +135,25 @@
}
- public void initialize() {
+ public synchronized void lazy_initialize() {
try {
// obtain input modules
- synchronized (this.initialized) {
- if (!this.initialized.booleanValue())
- this.inputSelector=(ComponentSelector)
this.manager.lookup(INPUT_MODULE_SELECTOR);
- if (this.inputSelector != null && this.inputSelector instanceof
ThreadSafe) {
-
- for (int i=0; i<this.inputs.length; i++) {
- if (this.inputs[i].name != null)
- this.inputs[i].input =
obtainModule(this.inputs[i].name);
- }
-
- } else if (!(this.inputSelector instanceof ThreadSafe) ) {
- this.manager.release(this.inputSelector);
- this.inputSelector = null;
+ if (!this.initialized) {
+ this.inputSelector=(ComponentSelector)
this.manager.lookup(INPUT_MODULE_SELECTOR);
+ if (this.inputSelector != null && this.inputSelector instanceof
ThreadSafe) {
+
+ for (int i=0; i<this.inputs.length; i++) {
+ if (this.inputs[i].name != null)
+ this.inputs[i].input =
obtainModule(this.inputs[i].name);
}
- this.initialized = new Boolean(true);
+ } else if (!(this.inputSelector instanceof ThreadSafe) ) {
+ this.manager.release(this.inputSelector);
+ this.inputSelector = null;
+ }
+
+ this.initialized = true;
}
} catch (Exception e) {
if (getLogger().isWarnEnabled())
@@ -165,20 +164,14 @@
public void dispose() {
- if (!this.initialized.booleanValue()) {
- if (getLogger().isErrorEnabled()) {
- getLogger().error("Uninitialized Component! dispose() FAILING");
- }
- } else {
- if (this.inputSelector != null) {
-
- for (int i=0; i<this.inputs.length; i++) {
- if (this.inputs[i].input != null)
- this.inputSelector.release(this.inputs[i].input);
- }
-
- this.manager.release(this.inputSelector);
+ if (this.inputSelector != null) {
+
+ for (int i=0; i<this.inputs.length; i++) {
+ if (this.inputs[i].input != null)
+ this.inputSelector.release(this.inputs[i].input);
}
+
+ this.manager.release(this.inputSelector);
}
}
@@ -186,10 +179,8 @@
public Object[] getAttributeValues( String attr, Configuration modeConf, Map
objectModel )
throws ConfigurationException {
- if (!this.initialized.booleanValue()) {
- if (getLogger().isErrorEnabled())
- getLogger().error("Uninitialized Component! getAttributeValues()
FAILING");
- return null;
+ if (!this.initialized) {
+ this.lazy_initialize();
}
// obtain correct configuration objects
@@ -252,11 +243,8 @@
public Iterator getAttributeNames( Configuration modeConf, Map objectModel )
throws ConfigurationException {
-
- if (!this.initialized.booleanValue()) {
- if (getLogger().isErrorEnabled())
- getLogger().error("Uninitialized Component! getAttributeNames()
FAILING");
- return null;
+ if (!this.initialized) {
+ this.lazy_initialize();
}
// obtain correct configuration objects
1.5 +7 -10
xml-cocoon2/src/java/org/apache/cocoon/components/modules/input/DateMetaInputModule.java
Index: DateMetaInputModule.java
===================================================================
RCS file:
/home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/modules/input/DateMetaInputModule.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- DateMetaInputModule.java 5 Dec 2002 10:01:05 -0000 1.4
+++ DateMetaInputModule.java 17 Dec 2002 14:53:16 -0000 1.5
@@ -53,6 +53,7 @@
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;
+import org.apache.avalon.framework.thread.ThreadSafe;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
@@ -69,7 +70,7 @@
* @author <a href="mailto:[EMAIL PROTECTED]">Christian Haul</a>
* @version CVS $Id$
*/
-public class DateMetaInputModule extends AbstractMetaModule {
+public class DateMetaInputModule extends AbstractMetaModule implements ThreadSafe {
private String defaultFormat = "yyyy-MM-dd";
private DateFormat defaultFormatter = null;
@@ -89,10 +90,8 @@
public Object[] getAttributeValues( String name, Configuration modeConf, Map
objectModel )
throws ConfigurationException {
- if (!this.initialized.booleanValue()) {
- if (getLogger().isErrorEnabled())
- getLogger().error("Uninitialized Component! FAILING");
- return null;
+ if (!this.initialized) {
+ this.lazy_initialize();
}
if (this.defaultInput == null) {
if (getLogger().isWarnEnabled())
@@ -144,10 +143,8 @@
public Iterator getAttributeNames( Configuration modeConf, Map objectModel )
throws ConfigurationException {
- if (!this.initialized.booleanValue()) {
- if (getLogger().isErrorEnabled())
- getLogger().error("Uninitialized Component! FAILING");
- return null;
+ if (!this.initialized) {
+ this.lazy_initialize();
}
if (this.defaultInput == null) {
if (getLogger().isWarnEnabled())
1.9 +9 -14
xml-cocoon2/src/java/org/apache/cocoon/components/modules/input/DigestMetaModule.java
Index: DigestMetaModule.java
===================================================================
RCS file:
/home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/modules/input/DigestMetaModule.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- DigestMetaModule.java 5 Dec 2002 10:01:04 -0000 1.8
+++ DigestMetaModule.java 17 Dec 2002 14:53:16 -0000 1.9
@@ -52,6 +52,7 @@
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;
+import org.apache.avalon.framework.thread.ThreadSafe;
import java.net.URLEncoder;
import java.security.MessageDigest;
@@ -71,7 +72,7 @@
* @author <a href="mailto:[EMAIL PROTECTED]">Christian Haul</a>
* @version CVS $Id$
*/
-public class DigestMetaModule extends AbstractMetaModule {
+public class DigestMetaModule extends AbstractMetaModule implements ThreadSafe {
private String defaultAlgorithm = "SHA";
private String defaultProvider = null;
@@ -92,10 +93,8 @@
public Object getAttribute( String name, Configuration modeConf, Map
objectModel )
throws ConfigurationException {
- if (!this.initialized.booleanValue()) {
- if (getLogger().isErrorEnabled())
- getLogger().error("Uninitialized Component! FAILING");
- return null;
+ if (!this.initialized) {
+ this.lazy_initialize();
}
if (this.defaultInput == null) {
if (getLogger().isWarnEnabled())
@@ -157,10 +156,8 @@
public Iterator getAttributeNames( Configuration modeConf, Map objectModel )
throws ConfigurationException {
- if (!this.initialized.booleanValue()) {
- if (getLogger().isErrorEnabled())
- getLogger().error("Uninitialized Component! FAILING");
- return null;
+ if (!this.initialized) {
+ this.lazy_initialize();
}
if (this.defaultInput == null) {
if (getLogger().isWarnEnabled())
@@ -193,10 +190,8 @@
public Object[] getAttributeValues( String name, Configuration modeConf, Map
objectModel )
throws ConfigurationException {
- if (!this.initialized.booleanValue()) {
- if (getLogger().isErrorEnabled())
- getLogger().error("Uninitialized Component! FAILING");
- return null;
+ if (!this.initialized) {
+ this.lazy_initialize();
}
if (this.defaultInput == null) {
if (getLogger().isWarnEnabled())
1.5 +11 -3
xml-cocoon2/src/java/org/apache/cocoon/components/modules/input/JXPathMetaModule.java
Index: JXPathMetaModule.java
===================================================================
RCS file:
/home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/modules/input/JXPathMetaModule.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- JXPathMetaModule.java 16 Dec 2002 10:37:33 -0000 1.4
+++ JXPathMetaModule.java 17 Dec 2002 14:53:16 -0000 1.5
@@ -54,6 +54,7 @@
import org.apache.avalon.framework.configuration.Configurable;
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;
+import org.apache.avalon.framework.thread.ThreadSafe;
import org.apache.commons.jxpath.*;
import java.util.Iterator;
@@ -95,7 +96,7 @@
* @author <a href="mailto:[EMAIL PROTECTED]">Christian Haul</a>
* @version $Id$
*/
-public class JXPathMetaModule extends AbstractMetaModule implements Configurable {
+public class JXPathMetaModule extends AbstractMetaModule implements Configurable,
ThreadSafe {
/**
* Contains all globally registered extension classes and
@@ -313,6 +314,10 @@
*/
protected Object getContextObject(Configuration modeConf, Map objectModel) {
+ if (!this.initialized) {
+ this.lazy_initialize();
+ }
+
Configuration mConf = null;
String inputName=null;
String parameter = this.parameter;
@@ -323,7 +328,10 @@
}
if (getLogger().isDebugEnabled())
- getLogger().debug("modeConf is "+modeConf+" this.inputConf is
"+this.inputConf+" mConf is "+mConf+" this.input is "+this.input+" this.defaultInput
is "+this.defaultInput+" inputName is "+inputName+" parameter is "+parameter);
+ getLogger().debug("modeConf is "+modeConf+" this.inputConf is
"+this.inputConf
+ +" mConf is "+mConf+" this.input is "+this.input
+ +" this.defaultInput is "+this.defaultInput
+ +" inputName is "+inputName+" parameter is
"+parameter);
Object obj = this.getValue(parameter, objectModel,
this.input, this.defaultInput, this.inputConf,
1.7 +7 -10
xml-cocoon2/src/java/org/apache/cocoon/components/modules/input/MapMetaModule.java
Index: MapMetaModule.java
===================================================================
RCS file:
/home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/modules/input/MapMetaModule.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- MapMetaModule.java 5 Dec 2002 10:01:05 -0000 1.6
+++ MapMetaModule.java 17 Dec 2002 14:53:16 -0000 1.7
@@ -52,6 +52,7 @@
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;
+import org.apache.avalon.framework.thread.ThreadSafe;
import java.util.Iterator;
import java.util.Map;
@@ -67,7 +68,7 @@
* @author <a href="mailto:[EMAIL PROTECTED]">Christian Haul</a>
* @version CVS $Id$
*/
-public class MapMetaModule extends AbstractMetaModule {
+public class MapMetaModule extends AbstractMetaModule implements ThreadSafe {
protected String objectName = null;
protected String parameter = null;
@@ -84,10 +85,8 @@
public Object getAttribute( String name, Configuration modeConf, Map
objectModel )
throws ConfigurationException {
- if (!this.initialized.booleanValue()) {
- if (getLogger().isErrorEnabled())
- getLogger().error("Uninitialized Component! FAILING");
- return null;
+ if (!this.initialized) {
+ this.lazy_initialize();
}
if (this.defaultInput == null) {
if (getLogger().isWarnEnabled())
@@ -127,10 +126,8 @@
public Iterator getAttributeNames( Configuration modeConf, Map objectModel )
throws ConfigurationException {
- if (!this.initialized.booleanValue()) {
- if (getLogger().isErrorEnabled())
- getLogger().error("Uninitialized Component! FAILING");
- return null;
+ if (!this.initialized) {
+ this.lazy_initialize();
}
if (this.defaultInput == null) {
if (getLogger().isWarnEnabled())
1.5 +9 -14
xml-cocoon2/src/java/org/apache/cocoon/components/modules/input/SimpleMappingMetaModule.java
Index: SimpleMappingMetaModule.java
===================================================================
RCS file:
/home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/modules/input/SimpleMappingMetaModule.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- SimpleMappingMetaModule.java 16 Dec 2002 09:57:05 -0000 1.4
+++ SimpleMappingMetaModule.java 17 Dec 2002 14:53:16 -0000 1.5
@@ -52,6 +52,7 @@
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;
+import org.apache.avalon.framework.thread.ThreadSafe;
import java.util.HashMap;
import java.util.HashSet;
@@ -84,7 +85,7 @@
* @author <a href="mailto:[EMAIL PROTECTED]">Christian Haul</a>
* @version CVS $Id$
*/
-public class SimpleMappingMetaModule extends AbstractMetaModule {
+public class SimpleMappingMetaModule extends AbstractMetaModule implements
ThreadSafe {
String prefix = null;
String suffix = null;
@@ -154,10 +155,8 @@
public Object getAttribute( String name, Configuration modeConf, Map
objectModel )
throws ConfigurationException {
- if (!this.initialized.booleanValue()) {
- if (getLogger().isErrorEnabled())
- getLogger().error("Uninitialized Component! FAILING");
- return null;
+ if (!this.initialized) {
+ this.lazy_initialize();
}
if (this.defaultInput == null) {
if (getLogger().isWarnEnabled())
@@ -217,10 +216,8 @@
public Object[] getAttributeValues( String name, Configuration modeConf, Map
objectModel )
throws ConfigurationException {
- if (!this.initialized.booleanValue()) {
- if (getLogger().isErrorEnabled())
- getLogger().error("Uninitialized Component! FAILING");
- return null;
+ if (!this.initialized) {
+ this.lazy_initialize();
}
if (this.defaultInput == null) {
if (getLogger().isWarnEnabled())
@@ -277,10 +274,8 @@
public Iterator getAttributeNames( Configuration modeConf, Map objectModel )
throws ConfigurationException {
- if (!this.initialized.booleanValue()) {
- if (getLogger().isErrorEnabled())
- getLogger().error("Uninitialized Component! FAILING");
- return null;
+ if (!this.initialized) {
+ this.lazy_initialize();
}
if (this.defaultInput == null) {
if (getLogger().isWarnEnabled())
1.3 +4 -2
xml-cocoon2/src/java/org/apache/cocoon/components/modules/input/XMLFileModule.java
Index: XMLFileModule.java
===================================================================
RCS file:
/home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/modules/input/XMLFileModule.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- XMLFileModule.java 5 Dec 2002 10:01:05 -0000 1.2
+++ XMLFileModule.java 17 Dec 2002 14:53:16 -0000 1.3
@@ -140,7 +140,9 @@
* @return a <code>Document</code> value
* @exception Exception if an error occurs
*/
- public Document getDocument(ComponentManager manager, SourceResolver
resolver, Logger logger) throws Exception {
+ public synchronized Document getDocument(ComponentManager manager,
+ SourceResolver resolver,
+ Logger logger) throws Exception {
Source src = null;
SourceValidity valid = null;
1.8 +9 -14
xml-cocoon2/src/java/org/apache/cocoon/components/modules/input/XMLMetaModule.java
Index: XMLMetaModule.java
===================================================================
RCS file:
/home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/modules/input/XMLMetaModule.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- XMLMetaModule.java 16 Dec 2002 10:05:51 -0000 1.7
+++ XMLMetaModule.java 17 Dec 2002 14:53:16 -0000 1.8
@@ -60,6 +60,7 @@
import org.apache.avalon.framework.component.Component;
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;
+import org.apache.avalon.framework.thread.ThreadSafe;
import org.apache.cocoon.xml.dom.DOMUtil;
import org.apache.cocoon.xml.dom.DocumentWrapper;
@@ -115,7 +116,7 @@
* @author <a href="mailto:[EMAIL PROTECTED]">Christian Haul</a>
* @version CVS $Id$
*/
-public class XMLMetaModule extends AbstractMetaModule {
+public class XMLMetaModule extends AbstractMetaModule implements ThreadSafe {
protected String rootName = "root";
protected String ignore = null;
@@ -150,10 +151,8 @@
public Object getAttribute( String name, Configuration modeConf, Map
objectModel )
throws ConfigurationException {
- if (!this.initialized.booleanValue()) {
- if (getLogger().isErrorEnabled())
- getLogger().error("Uninitialized Component! FAILING");
- return null;
+ if (!this.initialized) {
+ this.lazy_initialize();
}
if (this.defaultInput == null) {
if (getLogger().isWarnEnabled())
@@ -298,10 +297,8 @@
public Iterator getAttributeNames( Configuration modeConf, Map objectModel )
throws ConfigurationException {
- if (!this.initialized.booleanValue()) {
- if (getLogger().isErrorEnabled())
- getLogger().error("Uninitialized Component! FAILING");
- return null;
+ if (!this.initialized) {
+ this.lazy_initialize();
}
if (this.defaultInput == null) {
if (getLogger().isWarnEnabled())
@@ -318,10 +315,8 @@
public Object[] getAttributeValues( String name, Configuration modeConf, Map
objectModel )
throws ConfigurationException {
- if (!this.initialized.booleanValue()) {
- if (getLogger().isErrorEnabled())
- getLogger().error("Uninitialized Component! FAILING");
- return null;
+ if (!this.initialized) {
+ this.lazy_initialize();
}
if (this.defaultInput == null) {
if (getLogger().isWarnEnabled())
----------------------------------------------------------------------
In case of troubles, e-mail: [EMAIL PROTECTED]
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]