dims 01/08/29 10:26:51
Modified: src/org/apache/cocoon/components/language/generator Tag:
cocoon_20_branch ProgramGeneratorImpl.java
src/org/apache/cocoon/components/language/programming/java
Tag: cocoon_20_branch JavaLanguage.java
Log:
Patch for "xsp generation & multiple threads" from Marcus Crafter
<[EMAIL PROTECTED]>
Revision Changes Path
No revision
No revision
1.5.2.15 +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.5.2.14
retrieving revision 1.5.2.15
diff -u -r1.5.2.14 -r1.5.2.15
--- ProgramGeneratorImpl.java 2001/08/22 03:57:58 1.5.2.14
+++ ProgramGeneratorImpl.java 2001/08/29 17:26:51 1.5.2.15
@@ -43,7 +43,7 @@
/**
* The default implementation of <code>ProgramGenerator</code>
* @author <a href="mailto:[EMAIL PROTECTED]">Ricardo Rocha</a>
- * @version CVS $Revision: 1.5.2.14 $ $Date: 2001/08/22 03:57:58 $
+ * @version CVS $Revision: 1.5.2.15 $ $Date: 2001/08/29 17:26:51 $
*/
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,
No revision
No revision
1.2.2.5 +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.2.2.4
retrieving revision 1.2.2.5
diff -u -r1.2.2.4 -r1.2.2.5
--- JavaLanguage.java 2001/08/21 18:00:01 1.2.2.4
+++ JavaLanguage.java 2001/08/29 17:26:51 1.2.2.5
@@ -31,7 +31,7 @@
* The Java programming language processor
*
* @author <a href="mailto:[EMAIL PROTECTED]">Ricardo Rocha</a>
- * @version CVS $Revision: 1.2.2.4 $ $Date: 2001/08/21 18:00:01 $
+ * @version CVS $Revision: 1.2.2.5 $ $Date: 2001/08/29 17:26:51 $
*/
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: [EMAIL PROTECTED]
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]