01: /* Copyright 2001 The JA-SIG Collaborative. All rights reserved.
02: * See license distributed with this file and
03: * available online at http://www.uportal.org/license.html
04: */
05:
06: package org.jasig.portal.utils;
07:
08: /**
09: * A receipt that provides some information/control
10: * about a job that's being processed on the ThreadPool
11: * @author Peter Kharchenko {@link <a href="mailto:pkharchenko@interactivebusiness.com">pkharchenko@interactivebusiness.com</a>}
12: */
13:
14: public class ThreadPoolReceipt {
15: protected ThreadPoolWorker worker;
16: protected boolean jobdone;
17: protected boolean jobsuccessful;
18: protected Throwable thrownException;
19:
20: public ThreadPoolReceipt(ThreadPoolWorker w) {
21: this .worker = w;
22: jobdone = false;
23: jobsuccessful = false;
24: thrownException = null;
25: }
26:
27: public String toString() {
28: String s = new String("done=" + jobdone + ", successful="
29: + jobsuccessful);
30: if (thrownException != null) {
31: s += "\n" + thrownException;
32: }
33: return s;
34: }
35:
36: public synchronized void updateStatus(
37: ThreadPoolWorker currentWorker, boolean isdone,
38: boolean issuccessful, Throwable ex) {
39: this .worker = currentWorker;
40: this .jobdone = isdone;
41: this .jobsuccessful = issuccessful;
42: this .thrownException = ex;
43: notifyAll();
44: }
45:
46: /**
47: * Signals to the thread that it should abandon all hopes
48: * and kill the job as soon as possible.
49: */
50: public synchronized void killJob() {
51: if (!jobdone && worker != null) {
52: worker.killRequest();
53: }
54: }
55:
56: public synchronized void releaseWorker() {
57: if (!jobdone && worker != null) {
58: worker.completeRequest();
59: }
60: }
61:
62: public Throwable getThrownException() {
63: return thrownException;
64: }
65:
66: public boolean isJobsuccessful() {
67: return jobsuccessful;
68: }
69:
70: public synchronized boolean isJobdone() {
71: return jobdone;
72: }
73: }
|