1 /*
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3 *
4 * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
5 *
6 * The contents of this file are subject to the terms of either the GNU
7 * General Public License Version 2 only ("GPL") or the Common Development
8 * and Distribution License("CDDL") (collectively, the "License"). You
9 * may not use this file except in compliance with the License. You can obtain
10 * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
11 * or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
12 * language governing permissions and limitations under the License.
13 *
14 * When distributing the software, include this License Header Notice in each
15 * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
16 * Sun designates this particular file as subject to the "Classpath" exception
17 * as provided by Sun in the GPL Version 2 section of the License file that
18 * accompanied this code. If applicable, add the following below the License
19 * Header, with the fields enclosed by brackets [] replaced by your own
20 * identifying information: "Portions Copyrighted [year]
21 * [name of copyright owner]"
22 *
23 * Contributor(s):
24 *
25 * If you wish your version of this file to be governed by only the CDDL or
26 * only the GPL Version 2, indicate your decision by adding "[Contributor]
27 * elects to include this software in this distribution under the [CDDL or GPL
28 * Version 2] license." If you don't indicate a single choice of license, a
29 * recipient has the option to distribute your version of this file under
30 * either the CDDL, the GPL Version 2 or to extend the choice of license to
31 * its licensees as provided above. However, if you add GPL Version 2 code
32 * and therefore, elected the GPL Version 2 license, then the option applies
33 * only if the new code is made subject to such option by the copyright
34 * holder.
35 */
36
37 package javax.resource.spi.work;
38
39 import java.lang.Object;
40 import java.lang.Runnable;
41 import java.lang.Exception;
42 import java.lang.Throwable;
43 import java.util.EventObject;
44
45 /**
46 * This class models the various events that occur during the processing of
47 * a <code>Work</code> instance.
48 *
49 * @version 1.0
50 * @author Ram Jeyaraman
51 */
52 public class WorkEvent extends EventObject {
53
54 /**
55 * Indicates <code>Work</code> instance has been accepted.
56 */
57 public static final int WORK_ACCEPTED = 1;
58
59 /**
60 * Indicates <code>Work</code> instance has been rejected.
61 */
62 public static final int WORK_REJECTED = 2;
63
64 /**
65 * Indicates <code>Work</code> instance has started execution.
66 */
67 public static final int WORK_STARTED = 3;
68
69 /**
70 * Indicates <code>Work</code> instance has completed execution.
71 */
72 public static final int WORK_COMPLETED = 4;
73
74 /**
75 * The event type.
76 */
77 private int type;
78
79 /**
80 * The <code>Work</code> object on which the event occured.
81 */
82 private Work work;
83
84 /**
85 * The exception that occured during <code>Work</code> processing.
86 */
87 private WorkException exc;
88
89 /**
90 * The start delay duration (in milliseconds).
91 */
92 private long startDuration = WorkManager.UNKNOWN;
93
94 /**
95 * Constructor.
96 *
97 * @param source The object on which the event initially
98 * occurred.
99 *
100 * @param type The event type.
101 *
102 * @param work The <code>Work</code> object on which
103 * the event occured.
104 *
105 * @param exc The exception that occured during
106 * <code>Work</code> processing.
107
108 */
109 public WorkEvent(Object source, int type, Work work, WorkException exc) {
110 super(source);
111 this.type = type;
112 this.work = work;
113 this.exc = exc;
114 }
115
116 /**
117 * Constructor.
118 *
119 * @param source The object on which the event initially
120 * occurred.
121 *
122 * @param type The event type.
123 *
124 * @param work The <code>Work</code> object on which
125 * the event occured.
126 *
127 * @param exc The exception that occured during
128 * <code>Work</code> processing.
129 *
130 * @param startDuration The start delay duration
131 * (in milliseconds).
132 */
133 public WorkEvent(Object source, int type, Work work, WorkException exc,
134 long startDuration) {
135 this(source, type, work, exc);
136 this.startDuration = startDuration;
137 }
138
139 /**
140 * Return the type of this event.
141 *
142 * @return the event type.
143 */
144 public int getType() { return this.type; }
145
146 /**
147 * Return the <code>Work</code> instance which is the cause of the event.
148 *
149 * @return the <code>Work</code> instance.
150 */
151 public Work getWork() { return this.work; }
152
153 /**
154 * Return the start interval duration.
155 *
156 * @return the time elapsed (in milliseconds) since the <code>Work</code>
157 * was accepted, until the <code>Work</code> execution started. Note,
158 * this does not offer real-time guarantees. It is valid to return -1, if
159 * the actual start interval duration is unknown.
160 */
161 public long getStartDuration() { return this.startDuration; }
162
163 /**
164 * Return the <code>WorkException</code>. The actual
165 * <code>WorkException</code> subtype returned depends on the type of the
166 * event.
167 *
168 * @return a <code>WorkRejectedException</code> or a
169 * <code>WorkCompletedException</code>, if any.
170 */
171 public WorkException getException() { return this.exc; }
172 }