Source Code Cross Referenced for DocLitWrappedPortImpl.java in  » Web-Services-AXIS2 » jax-ws » org » apache » axis2 » jaxws » sample » parallelasync » server » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Web Services AXIS2 » jax ws » org.apache.axis2.jaxws.sample.parallelasync.server 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Licensed to the Apache Software Foundation (ASF) under one
003:         * or more contributor license agreements. See the NOTICE file
004:         * distributed with this work for additional information
005:         * regarding copyright ownership. The ASF licenses this file
006:         * to you under the Apache License, Version 2.0 (the
007:         * "License"); you may not use this file except in compliance
008:         * with the License. You may obtain a copy of the License at
009:         *
010:         * http://www.apache.org/licenses/LICENSE-2.0
011:         *
012:         * Unless required by applicable law or agreed to in writing,
013:         * software distributed under the License is distributed on an
014:         * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015:         * KIND, either express or implied. See the License for the
016:         * specific language governing permissions and limitations
017:         * under the License.
018:         */
019:
020:        package org.apache.axis2.jaxws.sample.parallelasync.server;
021:
022:        import java.util.concurrent.Future;
023:        import java.util.Hashtable;
024:
025:        import javax.jws.WebService;
026:        import javax.xml.ws.AsyncHandler;
027:        import javax.xml.ws.Holder;
028:        import javax.xml.ws.Response;
029:
030:        import org.apache.axis2.jaxws.sample.parallelasync.common.Constants;
031:        import org.apache.axis2.jaxws.TestLogger;
032:        import org.test.parallelasync.AnotherResponse;
033:        import org.test.parallelasync.CustomAsyncResponse;
034:        import org.test.parallelasync.InvokeAsyncResponse;
035:        import org.test.parallelasync.PingResponse;
036:        import org.test.parallelasync.SleepResponse;
037:
038:        /**
039:         * Async endpoint used for Async client side tests. Clients will invokeAsync
040:         * sleep method to force the server to block until wakeUp is called. The client
041:         * can call isAsleep to verify that sleep has been called by the async thread.
042:         */
043:        /*
044:         @WebService(
045:         serviceName="AsyncService",
046:         portName="AsyncPort",
047:         targetNamespace = "http://org/test/parallelasync",
048:         endpointInterface = "org.test.parallelasync.AsyncPort",
049:         wsdlLocation="WEB-INF/wsdl/async_doclitwr.wsdl")
050:         */
051:        @WebService(endpointInterface="org.apache.axis2.jaxws.sample.parallelasync.server.AsyncPort")
052:        public class DocLitWrappedPortImpl implements  AsyncPort {
053:
054:            private static final boolean DEBUG = false;
055:
056:            // in order to allow multiple sleeping requests to be held at the same time
057:            // use a table where 
058:            //       the key is the request string
059:            //       the value is the object used to block on
060:            //
061:            private static Hashtable sleepers = new Hashtable();
062:
063:            // intended to flag the need to cancel current requests being held (ie, sleeping)
064:            // does not stop new requests
065:            // not settable yet
066:            // need to determine when to reset it when dealing with multiple operations
067:            // currently reset when the sleepers table doesn't have any more requests
068:            private static boolean doCancell = false;
069:
070:            // strings used for logging
071:            private String myClassName = "DocLitWrappedPortImpl.";
072:
073:            /**
074:             * This operation takes the request and holds it in the web service until
075:             * <UL>
076:             * <LI>the client asks for it via wakeUp()
077:             * <LI>the operation times out
078:             * <LI>the operation is interrupted
079:             * </UL>
080:             * 
081:             * @param request The request identifier
082:             */
083:            public void sleep(Holder<String> request) {
084:
085:                boolean cancelRequested = false;
086:
087:                String key = new String(request.value);
088:                String msg = request.value;
089:
090:                String title = myClassName + "sleep(" + msg + "): ";
091:                String tid = " threadID [" + Thread.currentThread().getId()
092:                        + "] ";
093:                //if (DEBUG)
094:                //{
095:                //    System.out.println(title + tid + "Enter");
096:                //}
097:
098:                if (sleepers.get(key) != null) {
099:                    // already holding this request id
100:                    return;
101:                }
102:
103:                Thread myThread = Thread.currentThread();
104:                long threadID = myThread.getId();
105:
106:                // add this request to our list
107:                sleepers.put(key, myThread);
108:
109:                // set the timeout value
110:                long sec = Constants.SERVER_SLEEP_SEC;
111:
112:                try {
113:
114:                    //if (DEBUG)
115:                    //    System.out.println(title + "Starting to sleep on "
116:                    //            + " threadID ["+ threadID + "]" );
117:
118:                    // hold this request until
119:                    //  - the wait time expires
120:                    //  - the client explicits asks for this request via wakeUp()
121:                    //  - the wait is interrupted
122:                    //  - a cancel occurs
123:
124:                    while (sec > 0 && !doCancell) {
125:                        if (DEBUG)
126:                            TestLogger.logger.debug(title + "Sleeping on "
127:                                    + " threadID [" + threadID + "]"
128:                                    + " timeLeft=" + sec);
129:                        sec--;
130:
131:                        //msg.wait(500);
132:                        myThread.sleep(500);
133:                    }
134:
135:                } catch (InterruptedException e) {
136:
137:                    TestLogger.logger.debug(title + "Sleep interrupted on "
138:                            + " threadID [" + threadID + "]" + " timeLeft=["
139:                            + sec + "]");
140:
141:                } finally {
142:
143:                    if (DEBUG)
144:                        TestLogger.logger.debug(title + "final processing for "
145:                                + " threadID [" + threadID + "]");
146:
147:                    // remove this request from the list
148:                    sleepers.remove(key);
149:
150:                    // for now, reset the cancellation flag when the list of 
151:                    // waiting requests go to zero
152:                    if (sleepers.isEmpty()) {
153:                        doCancell = false;
154:                    }
155:                }
156:
157:            }
158:
159:            /**
160:             * Checks the specified request to determine whether
161:             * it is still being held by the web service.
162:             * 
163:             * @param request The request identifier to check
164:             * @return The String being used as a wait object if the
165:             *         request is still being held by the server
166:             *         or NULL if the request is not held by the server
167:             */
168:            public String isAsleep(String request) {
169:
170:                String title = myClassName + "isAsleep(" + request + "): ";
171:                String tid = " threadID [" + Thread.currentThread().getId()
172:                        + "] ";
173:
174:                if (sleepers.isEmpty()) {
175:                    if (DEBUG)
176:                        TestLogger.logger.debug(title + tid + " Not sleeping");
177:                    return null;
178:                }
179:
180:                Thread value = (Thread) sleepers.get(request);
181:
182:                if (value == null) {
183:                    if (DEBUG)
184:                        TestLogger.logger.debug(title + tid + " Not sleeping");
185:
186:                    return null;
187:                }
188:
189:                if (DEBUG)
190:                    TestLogger.logger.debug(title + tid + " sleeping on ["
191:                            + request + "]");
192:
193:                return request;
194:            }
195:
196:            public String wakeUp(String request) {
197:
198:                String title = myClassName + "wakeUp(): ";
199:                String tid = " threadID [" + Thread.currentThread().getId()
200:                        + "]";
201:
202:                if (sleepers.isEmpty()) {
203:                    if (DEBUG)
204:                        TestLogger.logger.debug(title + tid
205:                                + " No one to wake up");
206:
207:                    return null;
208:                }
209:
210:                Thread value = (Thread) sleepers.get(request);
211:
212:                if (value == null) {
213:                    if (DEBUG)
214:                        TestLogger.logger.debug(title + tid
215:                                + " Thread not available. No one to wake up.");
216:
217:                    return null;
218:                }
219:
220:                if (DEBUG)
221:                    TestLogger.logger.debug(title + tid + " Interrupting "
222:                            + " threadID [" + value.getId() + "]");
223:
224:                // interrupt the sleeper
225:                try {
226:                    value.interrupt();
227:                } catch (Exception e) {
228:                    if (DEBUG)
229:                        TestLogger.logger.debug(title + tid + " Interrupting "
230:                                + " threadID [" + value.getId()
231:                                + "]  got Exception [" + e.getClass().getName()
232:                                + "]   [" + e.getMessage() + "]");
233:                }
234:
235:                return request;
236:            }
237:
238:            /**
239:             * client side tests for remapping operation names, on the server side all
240:             * we need to do is roundtrip the message
241:             */
242:
243:            public String invokeAsync(String request) {
244:                String title = myClassName + "invokeAsync(" + request + ") : ";
245:                String tid = " threadID [" + Thread.currentThread().getId()
246:                        + "]";
247:                if (DEBUG)
248:                    TestLogger.logger.debug(title + "Enter" + tid);
249:
250:                return request;
251:            }
252:
253:            public String customAsync(String request) {
254:                String title = myClassName + "customeAsync(" + request + ") : ";
255:                String tid = " threadID [" + Thread.currentThread().getId()
256:                        + "]";
257:                if (DEBUG)
258:                    TestLogger.logger.debug(title + "Enter" + tid);
259:
260:                return request + "from customAsync method";
261:            }
262:
263:            public String another(String request) {
264:                String title = myClassName + "another(" + request + ") : ";
265:                String tid = " threadID [" + Thread.currentThread().getId()
266:                        + "]";
267:                if (DEBUG)
268:                    TestLogger.logger.debug(title + "Enter" + tid);
269:
270:                return request;
271:            }
272:
273:            public String ping(String request) {
274:                String title = myClassName + "ping(" + request + ") : ";
275:                String tid = " threadID [" + Thread.currentThread().getId()
276:                        + "]";
277:                if (DEBUG)
278:                    TestLogger.logger.debug(title + "Enter" + tid);
279:
280:                return request;
281:            }
282:
283:            public String remapped(String request) {
284:                // TODO Auto-generated method stub
285:                String title = myClassName + "remapped(" + request + ") : ";
286:                String tid = " threadID [" + Thread.currentThread().getId()
287:                        + "]";
288:                if (DEBUG)
289:                    TestLogger.logger.debug(title + "Enter" + tid);
290:
291:                return request;
292:            }
293:
294:            // NOT USED:
295:
296:            public String anotherAsync(String request) {
297:                // TODO Auto-generated method stub
298:                String title = myClassName + "anotherAsync(" + request + ") : ";
299:                String tid = " threadID [" + Thread.currentThread().getId()
300:                        + "]";
301:                if (DEBUG)
302:                    TestLogger.logger.debug(title + "Enter" + tid);
303:
304:                return null;
305:            }
306:
307:            public Future<?> anotherAsyncAsync(String request,
308:                    AsyncHandler<AnotherResponse> asyncHandler) {
309:                // TODO Auto-generated method stub
310:                String title = myClassName + " Future<?> anotherAsyncAsync("
311:                        + request + ") : ";
312:                String tid = " threadID [" + Thread.currentThread().getId()
313:                        + "]";
314:                if (DEBUG)
315:                    TestLogger.logger.debug(title + "Enter" + tid);
316:
317:                return null;
318:            }
319:
320:            public Response<AnotherResponse> anotherAsyncAsync(String request) {
321:                // TODO Auto-generated method stub
322:                String title = myClassName
323:                        + " Response<AnotherResponse> anotherAsyncAsync("
324:                        + request + ") : ";
325:                String tid = " threadID [" + Thread.currentThread().getId()
326:                        + "]";
327:                if (DEBUG)
328:                    TestLogger.logger.debug(title + "Enter" + tid);
329:
330:                return null;
331:            }
332:
333:            public Future<?> invokeAsyncAsync(String request,
334:                    AsyncHandler<InvokeAsyncResponse> asyncHandler) {
335:                // TODO Auto-generated method stub
336:                String title = myClassName + " Future<?> invokeAsyncAsync("
337:                        + request + ") : ";
338:                String tid = " threadID [" + Thread.currentThread().getId()
339:                        + "]";
340:                if (DEBUG)
341:                    TestLogger.logger.debug(title + "Enter" + tid);
342:
343:                return null;
344:            }
345:
346:            public Response<InvokeAsyncResponse> invokeAsyncAsync(String request) {
347:                // TODO Auto-generated method stub
348:                String title = myClassName
349:                        + " Response<InvokeAsyncResponse> invokeAsyncAsync("
350:                        + request + ") : ";
351:                String tid = " threadID [" + Thread.currentThread().getId()
352:                        + "]";
353:                if (DEBUG)
354:                    TestLogger.logger.debug(title + "Enter" + tid);
355:
356:                return null;
357:            }
358:
359:            public Future<?> pingAsync(String request,
360:                    AsyncHandler<PingResponse> asyncHandler) {
361:                // TODO Auto-generated method stub
362:                String title = myClassName + " Future<?> pingAsync(" + request
363:                        + ") : ";
364:                String tid = " threadID [" + Thread.currentThread().getId()
365:                        + "]";
366:                if (DEBUG)
367:                    TestLogger.logger.debug(title + "Enter" + tid);
368:
369:                return null;
370:            }
371:
372:            public Response<PingResponse> pingAsync(String request) {
373:                // TODO Auto-generated method stub
374:                String title = myClassName
375:                        + " Response<PingResponse> pingAsync(" + request
376:                        + ") : ";
377:                String tid = " threadID [" + Thread.currentThread().getId()
378:                        + "]";
379:                if (DEBUG)
380:                    TestLogger.logger.debug(title + "Enter" + tid);
381:
382:                return null;
383:            }
384:
385:            public Future<?> remappedAsync(String request,
386:                    AsyncHandler<CustomAsyncResponse> asyncHandler) {
387:                // TODO Auto-generated method stub
388:                String title = myClassName + " Future<?> remappedAsync("
389:                        + request + ") : ";
390:                String tid = " threadID [" + Thread.currentThread().getId()
391:                        + "]";
392:                if (DEBUG)
393:                    TestLogger.logger.debug(title + "Enter" + tid);
394:
395:                return null;
396:            }
397:
398:            public Response<CustomAsyncResponse> remappedAsync(String request) {
399:                // TODO Auto-generated method stub
400:                String title = myClassName
401:                        + " Response<CustomAsyncResponse> remappedAsync("
402:                        + request + ") : ";
403:                String tid = " threadID [" + Thread.currentThread().getId()
404:                        + "]";
405:                if (DEBUG)
406:                    TestLogger.logger.debug(title + "Enter" + tid);
407:
408:                return null;
409:            }
410:
411:            public Future<?> sleepAsync(String request,
412:                    AsyncHandler<SleepResponse> asyncHandler) {
413:                // TODO Auto-generated method stub
414:                String title = myClassName + " Future<?> sleepAsync(" + request
415:                        + ") : ";
416:                String tid = " threadID [" + Thread.currentThread().getId()
417:                        + "]";
418:                if (DEBUG)
419:                    TestLogger.logger.debug(title + "Enter" + tid);
420:
421:                return null;
422:            }
423:
424:            public Response<SleepResponse> sleepAsync(String request) {
425:                // TODO Auto-generated method stub
426:                String title = myClassName
427:                        + " Response<SleepResponse> sleepAsync(" + request
428:                        + ") : ";
429:                String tid = " threadID [" + Thread.currentThread().getId()
430:                        + "]";
431:                if (DEBUG)
432:                    TestLogger.logger.debug(title + "Enter" + tid);
433:
434:                return null;
435:            }
436:
437:        }
ww_w_.__j__a_va__2___s_.c___om___ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.