Source code: com/virtuosotechnologies/lib/asyncjob/AbstractAsyncJob.java
1 /*
2 ================================================================================
3
4 FILE: AbstractAsyncJob.java
5
6 PROJECT:
7
8 Virtuoso Utilities
9
10 CONTENTS:
11
12 Abstract base implementation of AsyncJob
13
14 PROGRAMMERS:
15
16 Daniel Azuma (DA) <dazuma@kagi.com>
17
18 COPYRIGHT:
19
20 Copyright (C) 2003 Daniel Azuma (dazuma@kagi.com)
21
22 This program is free software; you can redistribute it and/or
23 modify it under the terms of the GNU General Public License as
24 published by the Free Software Foundation; either version 2
25 of the License, or (at your option) any later version.
26
27 This program is distributed in the hope that it will be useful,
28 but WITHOUT ANY WARRANTY; without even the implied warranty of
29 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30 GNU General Public License for more details.
31
32 You should have received a copy of the GNU General Public
33 License along with this program; if not, write to
34 Free Software Foundation, Inc.
35 59 Temple Place, Suite 330
36 Boston, MA 02111-1307 USA
37
38 ================================================================================
39 */
40
41
42 package com.virtuosotechnologies.lib.asyncjob;
43
44 import com.virtuosotechnologies.lib.propertyset.PropertySet;
45 import com.virtuosotechnologies.lib.propertyset.BasicPropertySet;
46
47
48 /**
49 * Abstract base implementation of AsyncJob
50 */
51 public abstract class AbstractAsyncJob
52 extends BasicPropertySet
53 implements AsyncJob
54 {
55 /**
56 * Constructor
57 */
58 protected AbstractAsyncJob(
59 PropertySet defaultProperties,
60 String jobName,
61 boolean canCancel,
62 float initialFractionDone,
63 String initialProgressString)
64 {
65 super(defaultProperties);
66 putValue(JOB_NAME_PROPERTY, jobName);
67 putValue(CAN_CANCEL_PROPERTY, canCancel ? Boolean.TRUE : Boolean.FALSE);
68 putValue(INITIAL_FRACTION_DONE_PROPERTY, new Float(initialFractionDone));
69 putValue(INITIAL_PROGRESS_STRING_PROPERTY, initialProgressString);
70 }
71
72
73 /**
74 * Constructor
75 */
76 protected AbstractAsyncJob(
77 String jobName,
78 boolean canCancel,
79 float initialFractionDone,
80 String initialProgressString)
81 {
82 this(null, jobName, canCancel, initialFractionDone, initialProgressString);
83 }
84
85
86 /**
87 * Constructor
88 */
89 protected AbstractAsyncJob(
90 PropertySet defaultProperties,
91 String jobName,
92 boolean canCancel)
93 {
94 this(defaultProperties, jobName, canCancel, 0.0f, null);
95 }
96
97
98 /**
99 * Constructor
100 */
101 protected AbstractAsyncJob(
102 String jobName,
103 boolean canCancel)
104 {
105 this(null, jobName, canCancel, 0.0f, null);
106 }
107
108
109 /**
110 * Constructor
111 */
112 protected AbstractAsyncJob(
113 PropertySet defaultProperties)
114 {
115 super(defaultProperties);
116 }
117
118
119 /**
120 * Constructor
121 */
122 protected AbstractAsyncJob()
123 {
124 this(null);
125 }
126
127
128 /**
129 * Interrupt the job if it is currently running. The implementation
130 * should respond by throwing the given AsyncJobException out of run.
131 * If no custom exception is specified, the job should throw a new
132 * AsyncJobInterruptedException.
133 * <p>
134 * This default implementation returns false to indicate that the job
135 * cannot be interrupted.
136 *
137 * @param exception custom exception to throw
138 * @return true if the job was interrupted. Return false if the job was
139 * not running or cannot be interrupted.
140 */
141 public boolean interrupt(
142 AsyncJobException exception)
143 {
144 return false;
145 }
146 }