You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by gi...@apache.org on 2004/11/07 15:35:16 UTC
svn commit: rev 56850 - cocoon/trunk/src/java/org/apache/cocoon/transformation/helpers
Author: giacomo
Date: Sun Nov 7 06:35:15 2004
New Revision: 56850
Modified:
cocoon/trunk/src/java/org/apache/cocoon/transformation/helpers/DefaultIncludeCacheManager.java
Log:
migrated to the RunnableManager package part 2
Modified: cocoon/trunk/src/java/org/apache/cocoon/transformation/helpers/DefaultIncludeCacheManager.java
==============================================================================
--- cocoon/trunk/src/java/org/apache/cocoon/transformation/helpers/DefaultIncludeCacheManager.java (original)
+++ cocoon/trunk/src/java/org/apache/cocoon/transformation/helpers/DefaultIncludeCacheManager.java Sun Nov 7 06:35:15 2004
@@ -41,6 +41,7 @@
import org.apache.excalibur.source.SourceValidity;
import org.apache.excalibur.store.Store;
import org.xml.sax.SAXException;
+import EDU.oswego.cs.dl.util.concurrent.CountDown;
/**
* Default implementation of a {@link IncludeCacheManager}.
@@ -180,14 +181,15 @@
Source source = session.resolveURI(uri, this.resolver);
LoaderThread loader = new LoaderThread(source, serializer, this.manager);
- Thread thread = new Thread(loader);
+ final RunnableManager runnableManager = (RunnableManager)this.manager.lookup( RunnableManager.ROLE );
session.add(uri, loader);
- thread.start();
+ runnableManager.execute( loader );
+ this.manager.release( runnableManager );
if (this.getLogger().isDebugEnabled()) {
this.getLogger().debug("Thread started for " + uri);
}
} catch (ServiceException ce) {
- throw new SourceException("Unable to lookup thread pool or xml serializer.", ce);
+ throw new SourceException("Unable to lookup thread pool, RunnableManager, or xml serializer.", ce);
} catch (Exception e) {
throw new SourceException("Unable to get pooled thread.", e);
}
@@ -227,13 +229,8 @@
this.getLogger().debug("Waiting for pooled thread to finish loading.");
}
- // wait
- while (!loader.finished) {
- try {
- Thread.sleep(10);
- } catch (InterruptedException e) {
- }
- }
+ // wait for it
+ loader.join();
if (this.getLogger().isDebugEnabled()) {
this.getLogger().debug("Pooled thread finished loading.");
@@ -419,55 +416,61 @@
}
this.defaultCacheStorage = new StoreIncludeCacheStorageProxy(this.store, this.getLogger());
}
-
-}
-
-final class LoaderThread implements Runnable {
-
- private Source source;
- private XMLSerializer serializer;
- boolean finished;
- Exception exception;
- byte[] content;
- ServiceManager manager;
-
- public LoaderThread(Source source,
- XMLSerializer serializer,
- ServiceManager manager) {
- this.source = source;
- this.serializer = serializer;
- this.finished = false;
- this.manager = manager;
- }
- public void run() {
- try {
- SourceUtil.toSAX(this.source, this.serializer);
- this.content = (byte[])this.serializer.getSAXFragment();
- } catch (Exception local) {
- this.exception = local;
- } finally {
- this.manager.release( this.serializer );
- this.finished = true;
+ final private static class LoaderThread implements Runnable {
+
+ private final Source source;
+ private final XMLSerializer serializer;
+ private final CountDown finished;
+ Exception exception;
+ byte[] content;
+ final private ServiceManager manager;
+
+ public LoaderThread(Source source,
+ XMLSerializer serializer,
+ ServiceManager manager) {
+ this.source = source;
+ this.serializer = serializer;
+ this.finished = new CountDown( 1 );
+ this.manager = manager;
+ }
+
+ public void run() {
+ try {
+ SourceUtil.toSAX(this.source, this.serializer);
+ this.content = (byte[])this.serializer.getSAXFragment();
+ } catch (Exception local) {
+ this.exception = local;
+ } finally {
+ this.manager.release( this.serializer );
+ this.finished.release();
+ }
+ }
+
+ void join() {
+ try {
+ this.finished.acquire();
+ } catch ( final InterruptedException ie) {
+ // ignore
+ }
}
}
-}
-
-final class PreemptiveBooter implements Runnable {
-
- private final String uri;
-
- public PreemptiveBooter( final String uri )
- {
- this.uri = uri;
- }
+ final private static class PreemptiveBooter implements Runnable {
- public void run() {
- try {
- URL url = new URL(this.uri);
- url.getContent();
- } catch (Exception ignore) {
+ private final String uri;
+
+ public PreemptiveBooter( final String uri )
+ {
+ this.uri = uri;
+ }
+
+ public void run() {
+ try {
+ URL url = new URL(this.uri);
+ url.getContent();
+ } catch (Exception ignore) {
+ }
}
}
-}
\ No newline at end of file
+}