Source Code Cross Referenced for AsynchronousCall.java in  » Web-Services » xins » org » xins » client » async » 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 » xins » org.xins.client.async 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * $Id: AsynchronousCall.java,v 1.13 2007/09/18 08:45:07 agoubard Exp $
003:         *
004:         * Copyright 2003-2007 Orange Nederland Breedband B.V.
005:         * See the COPYRIGHT file for redistribution and use restrictions.
006:         */
007:        package org.xins.client.async;
008:
009:        import java.util.ArrayList;
010:        import java.util.Collections;
011:        import java.util.Iterator;
012:        import java.util.List;
013:        import org.xins.client.AbstractCAPI;
014:        import org.xins.client.AbstractCAPICallRequest;
015:
016:        /**
017:         * Class used to register the {@link CallListener}s and to call the API
018:         * asynchronously.
019:         *
020:         * @version $Revision: 1.13 $ $Date: 2007/09/18 08:45:07 $
021:         * @author <a href="mailto:anthony.goubard@japplis.com">Anthony Goubard</a>
022:         *
023:         * @since XINS 1.4.0
024:         */
025:        public class AsynchronousCall {
026:
027:            /**
028:             * List containing the registered {@link CallListener}.
029:             */
030:            private List _listeners = new ArrayList();
031:
032:            /**
033:             * Adds a new listener for the call.
034:             *
035:             * @param listener
036:             *    the listener that will be notified of the result of the call.
037:             */
038:            public void addCallListener(CallListener listener) {
039:                _listeners.add(listener);
040:            }
041:
042:            /**
043:             * Removes a listener for the call. If the listener was not previously added
044:             * nothing happens.
045:             *
046:             * @param listener
047:             *    the listener that will be notified of the result of the call.
048:             */
049:            public void removeCallListener(CallListener listener) {
050:                _listeners.remove(listener);
051:            }
052:
053:            /**
054:             * Calls a function asynchronously. This function does not return anything as
055:             * the result and exception will be received by the registered {@link CallListener}.
056:             *
057:             * @param capi
058:             *    the CAPI to use to call the function.
059:             *
060:             * @param request
061:             *    the input parameters for this call.
062:             */
063:            public void call(AbstractCAPI capi, AbstractCAPICallRequest request) {
064:                CallNotifyThread thread = new CallNotifyThread(capi, request,
065:                        _listeners);
066:                thread.start();
067:            }
068:
069:            /**
070:             * Thread that executes the call to the function.
071:             *
072:             * @version $Revision: 1.13 $ $Date: 2007/09/18 08:45:07 $
073:             * @author <a href="mailto:anthony.goubard@japplis.com">Anthony Goubard</a>
074:             */
075:            private static class CallNotifyThread extends CallCAPIThread {
076:
077:                /**
078:                 * The listeners to notify.
079:                 */
080:                private final List _listeners;
081:
082:                /**
083:                 * Calls a CAPI function on a separate thread and notifies the listeners
084:                 * of the result.
085:                 *
086:                 * @param capi
087:                 *    the CAPI to use to call the function.
088:                 *
089:                 * @param request
090:                 *    the input parameters for this call.
091:                 *
092:                 * @param listeners
093:                 *    the listeners to notify of the result of the call.
094:                 */
095:                CallNotifyThread(AbstractCAPI capi,
096:                        AbstractCAPICallRequest request, List listeners) {
097:                    super (capi, request);
098:
099:                    // Notify the listeners registered at the moment of the call and not
100:                    // when the result is received.
101:                    _listeners = Collections.unmodifiableList(listeners);
102:                }
103:
104:                public void run() {
105:
106:                    // Call the API
107:                    super .run();
108:
109:                    // Get the result and notify the listeners
110:                    if (getException() == null) {
111:                        CallSucceededEvent event = new CallSucceededEvent(
112:                                getCAPI(), getRequest(), getDuration(),
113:                                getResult());
114:                        Iterator itListeners = _listeners.iterator();
115:                        while (itListeners.hasNext()) {
116:                            CallListener listener = (CallListener) itListeners
117:                                    .next();
118:                            listener.callSucceeded(event);
119:                        }
120:                    } else {
121:                        CallFailedEvent event = new CallFailedEvent(getCAPI(),
122:                                getRequest(), getDuration(), getException());
123:                        Iterator itListeners = _listeners.iterator();
124:                        while (itListeners.hasNext()) {
125:                            CallListener listener = (CallListener) itListeners
126:                                    .next();
127:                            listener.callFailed(event);
128:                        }
129:                    }
130:                }
131:            }
132:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.