KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > aspects > asynchronous > aspects > AsynchronousFacadeImpl


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2005, JBoss Inc., and individual contributors as indicated
4   * by the @authors tag. See the copyright.txt in the distribution for a
5   * full listing of individual contributors.
6   *
7   * This is free software; you can redistribute it and/or modify it
8   * under the terms of the GNU Lesser General Public License as
9   * published by the Free Software Foundation; either version 2.1 of
10   * the License, or (at your option) any later version.
11   *
12   * This software is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15   * Lesser General Public License for more details.
16   *
17   * You should have received a copy of the GNU Lesser General Public
18   * License along with this software; if not, write to the Free
19   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21   */

22
23 package org.jboss.aspects.asynchronous.aspects;
24
25 import org.jboss.aspects.asynchronous.AsynchronousConstants;
26 import org.jboss.aspects.asynchronous.AsynchronousResponse;
27 import org.jboss.aspects.asynchronous.AsynchronousTask;
28 import org.jboss.aspects.asynchronous.ThreadManagerResponse;
29
30 /**
31  * @author <a HREF="mailto:chussenet@yahoo.com">{Claude Hussenet Independent Consultant}</a>.
32  * @version <tt>$Revision: 37406 $</tt>
33  */

34
35 public class AsynchronousFacadeImpl
36
37 implements AsynchronousFacade, AsynchronousConstants
38 {
39
40    private AsynchronousFacadeFields asynchronousFacadeFields = null;
41
42    public AsynchronousFacadeImpl()
43    {
44
45       asynchronousFacadeFields =
46
47       new AsynchronousFacadeFieldsThreadLocalImpl();
48
49    }
50
51    private AsynchronousFacadeFields getAsynchronousFacadeFields()
52    {
53
54       return asynchronousFacadeFields;
55
56    }
57
58    public AsynchronousTask getAsynchronousTask()
59    {
60
61       return getAsynchronousFacadeFields().getAsynchronousTask();
62
63    }
64
65    public void setTimeout(long timeout)
66    {
67
68       getAsynchronousFacadeFields().setTimeout(timeout);
69
70    }
71
72    public long getTimeout()
73    {
74
75       return getAsynchronousFacadeFields().getTimeout();
76
77    }
78
79    public void setAsynchronousTask(AsynchronousTask asynchronousTask)
80    {
81
82       getAsynchronousFacadeFields().setAsynchronousTask(asynchronousTask);
83
84    }
85
86    public void setId(String JavaDoc id)
87    {
88
89       getAsynchronousFacadeFields().setId(id);
90
91    }
92
93    public String JavaDoc getId()
94    {
95
96       return getAsynchronousFacadeFields().getId();
97
98    }
99
100    public ThreadManagerResponse getThreadManagerResponse()
101    {
102
103       return getAsynchronousTask().getResponse();
104
105    }
106
107    public AsynchronousResponse waitForResponse()
108    {
109
110       return waitForResponse(getAsynchronousTask());
111
112    }
113
114    public Object JavaDoc getReturnValue()
115    {
116
117       return getReturnValue(getAsynchronousTask());
118
119    }
120
121    public boolean isDone()
122    {
123
124       return isDone(getAsynchronousTask());
125
126    }
127
128    public int getResponseCode()
129    {
130
131       return getResponseCode(getAsynchronousTask());
132
133    }
134
135    public AsynchronousResponse waitForResponse(AsynchronousTask asynchronousTask)
136    {
137
138       if (asynchronousTask.getResponse().getResponseCode()
139
140       == AsynchronousConstants.OK)
141       {
142
143          AsynchronousResponse atask =
144
145          (AsynchronousResponse) asynchronousTask
146
147          .getResponse()
148
149          .getResult();
150
151          return atask;
152
153       }
154
155       return asynchronousTask.getResponse();
156
157    }
158
159    public Object JavaDoc getReturnValue(AsynchronousTask asynchronousTask)
160    {
161
162       if (asynchronousTask == null)
163
164          return null;
165
166       AsynchronousResponse asynchronousResponse =
167
168       waitForResponse(asynchronousTask);
169
170       if (asynchronousResponse.getResponseCode() == OK)
171
172          return asynchronousResponse.getResult();
173
174       else
175
176          return null;
177
178    }
179
180    public boolean isDone(AsynchronousTask synchronousTask)
181    {
182
183       if (synchronousTask == null)
184
185          return false;
186
187       else
188
189          return synchronousTask.isDone();
190
191    }
192
193    public int getResponseCode(AsynchronousTask synchronousTask)
194    {
195
196       return (waitForResponse(synchronousTask).getResponseCode());
197
198    }
199
200 }
201
202
Popular Tags