KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > axis > client > async > AsyncResult


1 /*
2  * Copyright 2001-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.apache.axis.client.async;
18
19 import javax.xml.namespace.QName JavaDoc;
20
21 /**
22  * Access the results of the Async call
23  *
24  * @author Davanum Srinivas (dims@yahoo.com)
25  */

26 public class AsyncResult implements IAsyncResult, Runnable JavaDoc {
27
28     /**
29      * Field thread
30      */

31     private Thread JavaDoc thread = null;
32
33     /**
34      * Field response
35      */

36     private Object JavaDoc response = null;
37
38     /**
39      * Field exception
40      */

41     private Throwable JavaDoc exception = null;
42
43     /**
44      * Field ac
45      */

46     private AsyncCall ac = null;
47
48     /**
49      * Field opName
50      */

51     private QName JavaDoc opName = null;
52
53     /**
54      * Field params
55      */

56     private Object JavaDoc[] params = null;
57
58     /**
59      * Field status
60      */

61     private Status status = Status.NONE;
62
63     /**
64      * Constructor AsyncResult
65      *
66      * @param ac
67      * @param opName
68      * @param params
69      */

70     public AsyncResult(AsyncCall ac, QName JavaDoc opName, Object JavaDoc[] params) {
71         this.ac = ac;
72         this.opName = opName;
73         this.params = params;
74
75         if (opName == null) {
76             this.opName = ac.getCall().getOperationName();
77         }
78
79         thread = new Thread JavaDoc(this);
80         thread.setDaemon(true);
81         thread.start();
82     }
83
84     /**
85      * Method abort
86      */

87     public void abort() {
88         thread.interrupt();
89         status = Status.INTERRUPTED;
90     }
91
92     /**
93      * Method getStatus
94      *
95      * @return
96      */

97     public Status getStatus() {
98         return status;
99     }
100
101     /**
102      * Method waitFor
103      *
104      * @param timeout
105      * @throws InterruptedException
106      */

107     public void waitFor(long timeout) throws InterruptedException JavaDoc {
108         thread.wait(timeout);
109     }
110
111     /**
112      * Method getResponse
113      *
114      * @return
115      */

116     public Object JavaDoc getResponse() {
117         return response;
118     }
119
120     /**
121      * Method getException
122      *
123      * @return
124      */

125     public Throwable JavaDoc getException() {
126         return exception;
127     }
128
129     /**
130      * Method run
131      */

132     public void run() {
133         try {
134             response = ac.getCall().invoke(opName, params);
135             status = Status.COMPLETED;
136         } catch (Throwable JavaDoc e) {
137             exception = e;
138             status = Status.EXCEPTION;
139         } finally {
140             IAsyncCallback callback = ac.getCallback();
141             if (callback != null) {
142                 callback.onCompletion(this);
143             }
144         }
145     }
146 }
147
Popular Tags