You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by di...@apache.org on 2001/08/29 19:26:41 UTC
cvs commit: xml-cocoon2/src/org/apache/cocoon/components/language/programming/java JavaLanguage.java
dims 01/08/29 10:26:41
Modified: src/org/apache/cocoon/components/language/generator
ProgramGeneratorImpl.java
src/org/apache/cocoon/components/language/programming/java
JavaLanguage.java
Log:
Patch for "xsp generation & multiple threads" from Marcus Crafter <cr...@fztig938.bank.dresdner.net>
Revision Changes Path
1.19 +78 -48 xml-cocoon2/src/org/apache/cocoon/components/language/generator/ProgramGeneratorImpl.java
Index: ProgramGeneratorImpl.java
===================================================================
RCS file: /home/cvs/xml-cocoon2/src/org/apache/cocoon/components/language/generator/ProgramGeneratorImpl.java,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -r1.18 -r1.19
--- ProgramGeneratorImpl.java 2001/08/22 03:51:05 1.18
+++ ProgramGeneratorImpl.java 2001/08/29 17:26:41 1.19
@@ -43,7 +43,7 @@
/**
* The default implementation of <code>ProgramGenerator</code>
* @author <a href="mailto:ricardo@apache.org">Ricardo Rocha</a>
- * @version CVS $Revision: 1.18 $ $Date: 2001/08/22 03:51:05 $
+ * @version CVS $Revision: 1.19 $ $Date: 2001/08/29 17:26:41 $
*/
public class ProgramGeneratorImpl extends AbstractLoggable
implements ProgramGenerator, Contextualizable, Composable, Configurable, ThreadSafe, Disposable {
@@ -101,8 +101,9 @@
}
/**
- * Set the global component manager. This metod also sets the
- * <code>ComponentSelector</code> used as language factory for both markup and programming languages.
+ * Set the global component manager. This method also sets the
+ * <code>ComponentSelector</code> used as language factory for both markup
+ * and programming languages.
* @param manager The global component manager
*/
public void compose(ComponentManager manager) throws ComponentException {
@@ -171,7 +172,7 @@
try {
programInstance = (CompiledComponent) select(normalizedName);
} catch (Exception e) {
- getLogger().debug("The instance was not accessible, creating it now.");
+ getLogger().debug("The instance was not accessible from the internal cache. Proceeding.");
}
if ((programInstance == null) && this.preload) {
@@ -187,32 +188,11 @@
}
if (programInstance == null) {
- MarkupLanguage markupLanguage = null;
- ProgrammingLanguage programmingLanguage = null;
- try {
- // Get markup and programming languages
- markupLanguage = (MarkupLanguage)this.markupSelector.select(markupLanguageName);
- programmingLanguage = (ProgrammingLanguage)this.languageSelector.select(programmingLanguageName);
- programmingLanguage.setLanguageName(programmingLanguageName);
- program = this.generateResource(newManager, fileName, normalizedName, markupLanguage, programmingLanguage, resolver);
- } catch (LanguageException le) {
- getLogger().debug("Language Exception", le);
- throw new ProcessingException("Language Exception", le);
- } finally {
- if (this.markupSelector != null) {
- this.markupSelector.release(markupLanguage);
- }
-
- if (this.languageSelector != null) {
- this.languageSelector.release(programmingLanguage);
- }
- }
-
- try {
- programInstance = (CompiledComponent) select(normalizedName);
- } catch (Exception cme) {
- getLogger().debug("Can't load ServerPage", cme);
- }
+ programInstance =
+ this.createResource(
+ newManager, fileName, normalizedName,
+ markupLanguageName, programmingLanguageName, resolver
+ );
}
if (this.autoReload == false) {
@@ -241,30 +221,80 @@
if (programInstance == null) {
if (program == null) {
- MarkupLanguage markupLanguage = null;
- ProgrammingLanguage programmingLanguage = null;
- try {
- // Get markup and programming languages
- markupLanguage = (MarkupLanguage)this.markupSelector.select(markupLanguageName);
- programmingLanguage = (ProgrammingLanguage)this.languageSelector.select(programmingLanguageName);
- programmingLanguage.setLanguageName(programmingLanguageName);
- program = this.generateResource(newManager, fileName, normalizedName, markupLanguage, programmingLanguage, resolver);
- } catch (LanguageException le) {
- getLogger().debug("Language Exception", le);
- throw new ProcessingException("Language Exception", le);
- } finally {
- this.markupSelector.release(markupLanguage);
- this.languageSelector.release(programmingLanguage);
- }
- }
- // Instantiate
- programInstance = (CompiledComponent) select(normalizedName);
+ programInstance =
+ this.createResource(
+ newManager, fileName, normalizedName,
+ markupLanguageName, programmingLanguageName,
+ resolver
+ );
+ } else
+ programInstance = (CompiledComponent) select(normalizedName);
}
return programInstance;
} finally {
source.recycle();
}
+ }
+
+ /**
+ * Helper method to create resources in a threadsafe manner.
+ */
+ private CompiledComponent createResource(
+ ComponentManager newManager,
+ String fileName,
+ String normalizedName,
+ String markupLanguageName,
+ String programmingLanguageName,
+ SourceResolver resolver
+ )
+ throws Exception {
+
+ CompiledComponent programInstance = null;
+ MarkupLanguage markupLanguage = null;
+ ProgrammingLanguage programmingLanguage = null;
+ Class program = null;
+
+ // prevent 2 requests from generating this resource simultaneously
+ synchronized (this) {
+ try {
+ programInstance = (CompiledComponent) select(normalizedName);
+ } catch (Exception e) {
+
+ getLogger().debug(
+ "Creating resource " +
+ normalizedName.replace(File.separatorChar, '.') +
+ ", using generator " + this
+ );
+
+ try {
+ // Get markup and programming languages
+ markupLanguage = (MarkupLanguage)this.markupSelector.select(markupLanguageName);
+ programmingLanguage = (ProgrammingLanguage)this.languageSelector.select(programmingLanguageName);
+ programmingLanguage.setLanguageName(programmingLanguageName);
+ program = this.generateResource(newManager, fileName, normalizedName, markupLanguage, programmingLanguage, resolver);
+ } catch (LanguageException le) {
+ getLogger().debug("Language Exception", le);
+ throw new ProcessingException("Language Exception", le);
+ } finally {
+ if (this.markupSelector != null) {
+ this.markupSelector.release(markupLanguage);
+ }
+
+ if (this.languageSelector != null) {
+ this.languageSelector.release(programmingLanguage);
+ }
+ }
+
+ try {
+ programInstance = (CompiledComponent) select(normalizedName);
+ } catch (Exception cme) {
+ getLogger().debug("Can't load ServerPage", cme);
+ }
+ }
+ }
+
+ return programInstance;
}
private Class generateResource(ComponentManager newManager,
1.7 +6 -5 xml-cocoon2/src/org/apache/cocoon/components/language/programming/java/JavaLanguage.java
Index: JavaLanguage.java
===================================================================
RCS file: /home/cvs/xml-cocoon2/src/org/apache/cocoon/components/language/programming/java/JavaLanguage.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- JavaLanguage.java 2001/08/21 17:59:52 1.6
+++ JavaLanguage.java 2001/08/29 17:26:41 1.7
@@ -31,7 +31,7 @@
* The Java programming language processor
*
* @author <a href="mailto:ricardo@apache.org">Ricardo Rocha</a>
- * @version CVS $Revision: 1.6 $ $Date: 2001/08/21 17:59:52 $
+ * @version CVS $Revision: 1.7 $ $Date: 2001/08/29 17:26:41 $
*/
public class JavaLanguage extends CompiledProgrammingLanguage implements ThreadSafe, Composable, Disposable {
@@ -149,11 +149,10 @@
String pathname =
baseDirectory.getCanonicalPath() + File.separator +
name.substring(0, pos).replace(File.separatorChar, '/');
+ String filename_abs =
+ pathname + File.separator + filename + "." + this.getSourceExtension();
- compiler.setFile(
- pathname + File.separator +
- filename + "." + this.getSourceExtension()
- );
+ compiler.setFile(filename_abs);
compiler.setSource(pathname);
@@ -179,6 +178,8 @@
if (encoding != null) {
compiler.setEncoding(encoding);
}
+
+ getLogger().debug("Compiling " + filename_abs);
if (!compiler.compile()) {
StringBuffer message = new StringBuffer("Error compiling ");
----------------------------------------------------------------------
In case of troubles, e-mail: webmaster@xml.apache.org
To unsubscribe, e-mail: cocoon-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: cocoon-cvs-help@xml.apache.org