You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by mo...@apache.org on 2003/01/26 09:26:58 UTC
cvs commit: jakarta-commons-sandbox/jelly/jelly-tags/threads/src/java/org/apache/commons/jelly/tags/threads GroupTag.java InterruptTag.java JoinTag.java MutexTag.java NotifyTag.java SleepTag.java SynchronizeTag.java ThreadTag.java UseMutexTag.java UseThreadTag.java WaitForTag.java WaitTag.java
morgand 2003/01/26 00:26:58
Modified: jelly/jelly-tags/threads/src/java/org/apache/commons/jelly/tags/threads
GroupTag.java InterruptTag.java JoinTag.java
MutexTag.java NotifyTag.java SleepTag.java
SynchronizeTag.java ThreadTag.java UseMutexTag.java
UseThreadTag.java WaitForTag.java WaitTag.java
Log:
converted threads taglib from Exception to JellyTagException
Revision Changes Path
1.2 +2 -1 jakarta-commons-sandbox/jelly/jelly-tags/threads/src/java/org/apache/commons/jelly/tags/threads/GroupTag.java
Index: GroupTag.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/jelly/jelly-tags/threads/src/java/org/apache/commons/jelly/tags/threads/GroupTag.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- GroupTag.java 30 Oct 2002 19:13:01 -0000 1.1
+++ GroupTag.java 26 Jan 2003 08:26:58 -0000 1.2
@@ -57,6 +57,7 @@
package org.apache.commons.jelly.tags.threads;
+import org.apache.commons.jelly.JellyTagException;
import org.apache.commons.jelly.TagSupport;
import org.apache.commons.jelly.XMLOutput;
@@ -79,7 +80,7 @@
private List threads = new ArrayList();
/** Child threads will add themselves and will then all be started together */
- public void doTag(XMLOutput output) throws Exception {
+ public void doTag(XMLOutput output) throws JellyTagException {
invokeBody(output);
// store the group in a jelly variable
1.2 +2 -2 jakarta-commons-sandbox/jelly/jelly-tags/threads/src/java/org/apache/commons/jelly/tags/threads/InterruptTag.java
Index: InterruptTag.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/jelly/jelly-tags/threads/src/java/org/apache/commons/jelly/tags/threads/InterruptTag.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- InterruptTag.java 30 Oct 2002 19:13:01 -0000 1.1
+++ InterruptTag.java 26 Jan 2003 08:26:58 -0000 1.2
@@ -69,12 +69,12 @@
public class InterruptTag extends UseThreadTag {
/** Interrupt one thread */
- protected void useThread(Thread thread, XMLOutput output) throws Exception {
+ protected void useThread(Thread thread, XMLOutput output) {
thread.interrupt();
}
/** Interrupt all of the threads in a group */
- protected void useThreadGroup(List threadGroup, XMLOutput output) throws Exception {
+ protected void useThreadGroup(List threadGroup, XMLOutput output) {
for (int i = 0; i < threadGroup.size(); i++) {
((Thread) threadGroup.get(i)).interrupt();
}
1.2 +2 -2 jakarta-commons-sandbox/jelly/jelly-tags/threads/src/java/org/apache/commons/jelly/tags/threads/JoinTag.java
Index: JoinTag.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/jelly/jelly-tags/threads/src/java/org/apache/commons/jelly/tags/threads/JoinTag.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- JoinTag.java 30 Oct 2002 19:13:01 -0000 1.1
+++ JoinTag.java 26 Jan 2003 08:26:58 -0000 1.2
@@ -71,12 +71,12 @@
private long timeout = -1;
/** Perform the thread join */
- protected void useThread(Thread thread, XMLOutput output) throws Exception {
+ protected void useThread(Thread thread, XMLOutput output) throws InterruptedException {
joinThread(thread);
}
/** Join all of the threads in a thread group */
- protected void useThreadGroup(List threadGroup, XMLOutput output) throws Exception {
+ protected void useThreadGroup(List threadGroup, XMLOutput output) throws InterruptedException {
for (int i = 0; i < threadGroup.size(); i++) {
joinThread((Thread) threadGroup.get(i));
}
1.2 +3 -3 jakarta-commons-sandbox/jelly/jelly-tags/threads/src/java/org/apache/commons/jelly/tags/threads/MutexTag.java
Index: MutexTag.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/jelly/jelly-tags/threads/src/java/org/apache/commons/jelly/tags/threads/MutexTag.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- MutexTag.java 30 Oct 2002 19:13:01 -0000 1.1
+++ MutexTag.java 26 Jan 2003 08:26:58 -0000 1.2
@@ -57,7 +57,7 @@
package org.apache.commons.jelly.tags.threads;
-import org.apache.commons.jelly.JellyException;
+import org.apache.commons.jelly.JellyTagException;
import org.apache.commons.jelly.TagSupport;
import org.apache.commons.jelly.XMLOutput;
@@ -72,9 +72,9 @@
private String var = null;
/** Create and set the mutex */
- public void doTag(XMLOutput output) throws Exception {
+ public void doTag(XMLOutput output) throws JellyTagException {
if (var == null) {
- throw new JellyException("mutexes require a var attribute");
+ throw new JellyTagException("mutexes require a var attribute");
}
context.setVariable(var, this);
1.2 +1 -1 jakarta-commons-sandbox/jelly/jelly-tags/threads/src/java/org/apache/commons/jelly/tags/threads/NotifyTag.java
Index: NotifyTag.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/jelly/jelly-tags/threads/src/java/org/apache/commons/jelly/tags/threads/NotifyTag.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- NotifyTag.java 30 Oct 2002 19:13:01 -0000 1.1
+++ NotifyTag.java 26 Jan 2003 08:26:58 -0000 1.2
@@ -71,7 +71,7 @@
private boolean notifyAll = false;
/** Perform the notify */
- public void useMutex(Object mutex, XMLOutput output) throws Exception {
+ public void useMutex(Object mutex, XMLOutput output) {
if (notifyAll) {
mutex.notifyAll();
} else {
1.2 +8 -2 jakarta-commons-sandbox/jelly/jelly-tags/threads/src/java/org/apache/commons/jelly/tags/threads/SleepTag.java
Index: SleepTag.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/jelly/jelly-tags/threads/src/java/org/apache/commons/jelly/tags/threads/SleepTag.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- SleepTag.java 30 Oct 2002 19:13:01 -0000 1.1
+++ SleepTag.java 26 Jan 2003 08:26:58 -0000 1.2
@@ -56,6 +56,7 @@
*/
package org.apache.commons.jelly.tags.threads;
+import org.apache.commons.jelly.JellyTagException;
import org.apache.commons.jelly.TagSupport;
import org.apache.commons.jelly.XMLOutput;
@@ -70,8 +71,13 @@
private long howLong = 0;
/** Put the thread to sleep */
- public void doTag(XMLOutput output) throws Exception {
- Thread.sleep(howLong);
+ public void doTag(XMLOutput output) throws JellyTagException {
+ try {
+ Thread.sleep(howLong);
+ }
+ catch (InterruptedException e) {
+ throw new JellyTagException(e);
+ }
}
/**
1.2 +2 -1 jakarta-commons-sandbox/jelly/jelly-tags/threads/src/java/org/apache/commons/jelly/tags/threads/SynchronizeTag.java
Index: SynchronizeTag.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/jelly/jelly-tags/threads/src/java/org/apache/commons/jelly/tags/threads/SynchronizeTag.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- SynchronizeTag.java 30 Oct 2002 19:13:01 -0000 1.1
+++ SynchronizeTag.java 26 Jan 2003 08:26:58 -0000 1.2
@@ -57,6 +57,7 @@
package org.apache.commons.jelly.tags.threads;
+import org.apache.commons.jelly.JellyTagException;
import org.apache.commons.jelly.XMLOutput;
/**
@@ -69,7 +70,7 @@
public class SynchronizeTag extends UseMutexTag {
/** Synchronize on the mutex */
- protected void useMutex(Object mutex, XMLOutput output) throws Exception {
+ protected void useMutex(Object mutex, XMLOutput output) throws JellyTagException {
synchronized (mutex) {
invokeBody(output);
}
1.2 +10 -4 jakarta-commons-sandbox/jelly/jelly-tags/threads/src/java/org/apache/commons/jelly/tags/threads/ThreadTag.java
Index: ThreadTag.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/jelly/jelly-tags/threads/src/java/org/apache/commons/jelly/tags/threads/ThreadTag.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ThreadTag.java 30 Oct 2002 19:13:01 -0000 1.1
+++ ThreadTag.java 26 Jan 2003 08:26:58 -0000 1.2
@@ -57,7 +57,7 @@
package org.apache.commons.jelly.tags.threads;
import org.apache.commons.jelly.JellyContext;
-import org.apache.commons.jelly.JellyException;
+import org.apache.commons.jelly.JellyTagException;
import org.apache.commons.jelly.TagSupport;
import org.apache.commons.jelly.XMLOutput;
import org.apache.commons.jelly.util.NestedRuntimeException;
@@ -67,6 +67,7 @@
import java.io.FileOutputStream;
import java.io.IOException;
+import java.io.UnsupportedEncodingException;
/**
* A tag that spawns the contained script in a separate thread. A thread
@@ -109,10 +110,15 @@
// Tag interface
//-------------------------------------------------------------------------
- public void doTag(final XMLOutput output) throws Exception {
+ public void doTag(final XMLOutput output) throws JellyTagException {
if (xmlOutput == null) {
// lets default to system.out
- xmlOutput = XMLOutput.createXMLOutput(System.out);
+ try {
+ xmlOutput = XMLOutput.createXMLOutput(System.out);
+ }
+ catch (UnsupportedEncodingException e) {
+ throw new JellyTagException(e);
+ }
}
// lets create a child context
@@ -130,7 +136,7 @@
xmlOutput.flush();
}
}
- catch (JellyException e) {
+ catch (JellyTagException e) {
// jelly wraps the exceptions thrown
Throwable subException = e.getCause();
if (subException != null) {
1.2 +4 -4 jakarta-commons-sandbox/jelly/jelly-tags/threads/src/java/org/apache/commons/jelly/tags/threads/UseMutexTag.java
Index: UseMutexTag.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/jelly/jelly-tags/threads/src/java/org/apache/commons/jelly/tags/threads/UseMutexTag.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- UseMutexTag.java 30 Oct 2002 19:13:01 -0000 1.1
+++ UseMutexTag.java 26 Jan 2003 08:26:58 -0000 1.2
@@ -57,7 +57,7 @@
package org.apache.commons.jelly.tags.threads;
-import org.apache.commons.jelly.JellyException;
+import org.apache.commons.jelly.JellyTagException;
import org.apache.commons.jelly.TagSupport;
import org.apache.commons.jelly.XMLOutput;
@@ -72,17 +72,17 @@
private Object mutex = null;
/** Calls useMutex after checking to make sure that <i>setMutex</i> was called */
- public void doTag(XMLOutput output) throws Exception {
+ public void doTag(XMLOutput output) throws JellyTagException {
// either use the set thread or search for a parent thread to use
if (mutex == null) {
- throw new JellyException("no mutex set");
+ throw new JellyTagException("no mutex set");
}
useMutex(mutex, output);
}
/** Implement this method to do something with the mutex */
- protected abstract void useMutex(Object mutex, XMLOutput output) throws Exception;
+ protected abstract void useMutex(Object mutex, XMLOutput output) throws JellyTagException;
/** Get the mutex */
public Object getMutex() {
1.2 +31 -25 jakarta-commons-sandbox/jelly/jelly-tags/threads/src/java/org/apache/commons/jelly/tags/threads/UseThreadTag.java
Index: UseThreadTag.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/jelly/jelly-tags/threads/src/java/org/apache/commons/jelly/tags/threads/UseThreadTag.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- UseThreadTag.java 30 Oct 2002 19:13:01 -0000 1.1
+++ UseThreadTag.java 26 Jan 2003 08:26:58 -0000 1.2
@@ -57,7 +57,7 @@
package org.apache.commons.jelly.tags.threads;
-import org.apache.commons.jelly.JellyException;
+import org.apache.commons.jelly.JellyTagException;
import org.apache.commons.jelly.TagSupport;
import org.apache.commons.jelly.XMLOutput;
@@ -81,40 +81,46 @@
* The default behavior is to either use the set thread or to
* search for a parent thread to use.
*/
- public void doTag(XMLOutput output) throws Exception {
- // either use the set thread or search for a parent thread to use
- if (thread != null) {
- useThread(thread, output);
- } else if (threadGroup != null) {
- useThreadGroup(threadGroup, output);
- } else {
- // check if this tag is nested inside a thread. if so
- // use the parent thread.
- if (searchForParent) {
- // first look for parent threads
- ThreadTag tt = (ThreadTag) findAncestorWithClass(ThreadTag.class);
- if (tt != null) {
- useThread(tt.getThread(), output);
- } else {
- // then look for parent thread groups
- GroupTag gt = (GroupTag) findAncestorWithClass(GroupTag.class);
- if (gt != null) {
- useThreadGroup(gt.getThreads(), output);
+ public void doTag(XMLOutput output) throws JellyTagException {
+ try {
+ // either use the set thread or search for a parent thread to use
+ if (thread != null) {
+ useThread(thread, output);
+ } else if (threadGroup != null) {
+ useThreadGroup(threadGroup, output);
+ } else {
+ // check if this tag is nested inside a thread. if so
+ // use the parent thread.
+ if (searchForParent) {
+ // first look for parent threads
+ ThreadTag tt = (ThreadTag) findAncestorWithClass(ThreadTag.class);
+
+ if (tt != null) {
+ useThread(tt.getThread(), output);
} else {
- throw new JellyException("no thread or thread group found");
+ // then look for parent thread groups
+ GroupTag gt = (GroupTag) findAncestorWithClass(GroupTag.class);
+ if (gt != null) {
+ useThreadGroup(gt.getThreads(), output);
+ } else {
+ throw new JellyTagException("no thread or thread group found");
+ }
}
+ } else {
+ throw new JellyTagException("no thread or thread group found");
}
- } else {
- throw new JellyException("no thread or thread group found");
}
}
+ catch (InterruptedException e) {
+ throw new JellyTagException(e);
+ }
}
/** Implement this method to do something with the thread */
- protected abstract void useThread(Thread thread, XMLOutput output) throws Exception;
+ protected abstract void useThread(Thread thread, XMLOutput output) throws InterruptedException ;
/** Implement this method to do something with the threadGroup */
- protected abstract void useThreadGroup(List threadGroup, XMLOutput output) throws Exception;
+ protected abstract void useThreadGroup(List threadGroup, XMLOutput output) throws InterruptedException ;
/**
* Set the thread to use in some way.
1.2 +3 -3 jakarta-commons-sandbox/jelly/jelly-tags/threads/src/java/org/apache/commons/jelly/tags/threads/WaitForTag.java
Index: WaitForTag.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/jelly/jelly-tags/threads/src/java/org/apache/commons/jelly/tags/threads/WaitForTag.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- WaitForTag.java 30 Oct 2002 19:13:01 -0000 1.1
+++ WaitForTag.java 26 Jan 2003 08:26:58 -0000 1.2
@@ -57,7 +57,7 @@
package org.apache.commons.jelly.tags.threads;
-import org.apache.commons.jelly.JellyException;
+import org.apache.commons.jelly.JellyTagException;
import org.apache.commons.jelly.TagSupport;
import org.apache.commons.jelly.XMLOutput;
@@ -113,9 +113,9 @@
* @throws TimeoutException If the call to waitUntilDone(onlyWait) times out
* @throws RequirementException If a threads status doesn't match the setStatus() value
*/
- public void doTag(XMLOutput output) throws TimeoutException, RequirementException, Exception {
+ public void doTag(XMLOutput output) throws TimeoutException, RequirementException, JellyTagException {
if (thread == null && group == null) {
- throw new JellyException("This tag requires that you set the thread or group attribute");
+ throw new JellyTagException("This tag requires that you set the thread or group attribute");
}
// wait on the thread
1.2 +11 -5 jakarta-commons-sandbox/jelly/jelly-tags/threads/src/java/org/apache/commons/jelly/tags/threads/WaitTag.java
Index: WaitTag.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/jelly/jelly-tags/threads/src/java/org/apache/commons/jelly/tags/threads/WaitTag.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- WaitTag.java 30 Oct 2002 19:13:01 -0000 1.1
+++ WaitTag.java 26 Jan 2003 08:26:58 -0000 1.2
@@ -57,6 +57,7 @@
package org.apache.commons.jelly.tags.threads;
+import org.apache.commons.jelly.JellyTagException;
import org.apache.commons.jelly.XMLOutput;
/**
@@ -70,11 +71,16 @@
private long timeout = -1;
/** Start waiting */
- public void useMutex(Object mutex, XMLOutput output) throws Exception {
- if (timeout > 0) {
- mutex.wait(timeout);
- } else {
- mutex.wait();
+ public void useMutex(Object mutex, XMLOutput output) throws JellyTagException {
+ try {
+ if (timeout > 0) {
+ mutex.wait(timeout);
+ } else {
+ mutex.wait();
+ }
+ }
+ catch (InterruptedException e) {
+ throw new JellyTagException(e);
}
}
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>