KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > resource > spi > work > WorkEvent


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 package javax.resource.spi.work;
25
26 import java.lang.Object JavaDoc;
27 import java.lang.Runnable JavaDoc;
28 import java.lang.Exception JavaDoc;
29 import java.lang.Throwable JavaDoc;
30 import java.util.EventObject JavaDoc;
31
32 /**
33  * This class models the various events that occur during the processing of
34  * a <code>Work</code> instance.
35  *
36  * @version 1.0
37  * @author Ram Jeyaraman
38  */

39 public class WorkEvent extends EventObject JavaDoc {
40
41     /**
42      * Indicates <code>Work</code> instance has been accepted.
43      */

44     public static final int WORK_ACCEPTED = 1;
45
46     /**
47      * Indicates <code>Work</code> instance has been rejected.
48      */

49     public static final int WORK_REJECTED = 2;
50
51     /**
52      * Indicates <code>Work</code> instance has started execution.
53      */

54     public static final int WORK_STARTED = 3;
55
56     /**
57      * Indicates <code>Work</code> instance has completed execution.
58      */

59     public static final int WORK_COMPLETED = 4;
60
61     /**
62      * The event type.
63      */

64     private int type;
65
66     /**
67      * The <code>Work</code> object on which the event occured.
68      */

69     private Work JavaDoc work;
70
71     /**
72      * The exception that occured during <code>Work</code> processing.
73      */

74     private WorkException JavaDoc exc;
75
76     /**
77      * The start delay duration (in milliseconds).
78      */

79     private long startDuration = WorkManager.UNKNOWN;
80
81     /**
82      * Constructor.
83      *
84      * @param source The object on which the event initially
85      * occurred.
86      *
87      * @param type The event type.
88      *
89      * @param work The <code>Work</code> object on which
90      * the event occured.
91      *
92      * @param exc The exception that occured during
93      * <code>Work</code> processing.
94
95     */

96     public WorkEvent(Object JavaDoc source, int type, Work JavaDoc work, WorkException JavaDoc exc) {
97     super(source);
98     this.type = type;
99     this.work = work;
100     this.exc = exc;
101     }
102
103     /**
104      * Constructor.
105      *
106      * @param source The object on which the event initially
107      * occurred.
108      *
109      * @param type The event type.
110      *
111      * @param work The <code>Work</code> object on which
112      * the event occured.
113      *
114      * @param exc The exception that occured during
115      * <code>Work</code> processing.
116      *
117      * @param startDuration The start delay duration
118      * (in milliseconds).
119      */

120     public WorkEvent(Object JavaDoc source, int type, Work JavaDoc work, WorkException JavaDoc exc,
121             long startDuration) {
122     this(source, type, work, exc);
123     this.startDuration = startDuration;
124     }
125
126     /**
127      * Return the type of this event.
128      *
129      * @return the event type.
130      */

131     public int getType() { return this.type; }
132
133     /**
134      * Return the <code>Work</code> instance which is the cause of the event.
135      *
136      * @return the <code>Work</code> instance.
137      */

138     public Work JavaDoc getWork() { return this.work; }
139
140     /**
141      * Return the start interval duration.
142      *
143      * @return the time elapsed (in milliseconds) since the <code>Work</code>
144      * was accepted, until the <code>Work</code> execution started. Note,
145      * this does not offer real-time guarantees. It is valid to return -1, if
146      * the actual start interval duration is unknown.
147      */

148     public long getStartDuration() { return this.startDuration; }
149
150     /**
151      * Return the <code>WorkException</code>. The actual
152      * <code>WorkException</code> subtype returned depends on the type of the
153      * event.
154      *
155      * @return a <code>WorkRejectedException</code> or a
156      * <code>WorkCompletedException</code>, if any.
157      */

158     public WorkException JavaDoc getException() { return this.exc; }
159 }
160
Popular Tags