Source Code Cross Referenced for DefaultMuleConnection.java in  » ESB » mule » org » mule » module » jca » 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 » ESB » mule » org.mule.module.jca 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * $Id: DefaultMuleConnection.java 11343 2008-03-13 10:58:26Z tcarlson $
003:         * --------------------------------------------------------------------------------------
004:         * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.com
005:         *
006:         * The software in this package is published under the terms of the CPAL v1.0
007:         * license, a copy of which has been included with this distribution in the
008:         * LICENSE.txt file.
009:         */
010:
011:        package org.mule.module.jca;
012:
013:        import org.mule.DefaultMuleEvent;
014:        import org.mule.DefaultMuleMessage;
015:        import org.mule.DefaultMuleSession;
016:        import org.mule.api.MuleContext;
017:        import org.mule.api.MuleEvent;
018:        import org.mule.api.MuleException;
019:        import org.mule.api.MuleMessage;
020:        import org.mule.api.MuleSession;
021:        import org.mule.api.config.MuleProperties;
022:        import org.mule.api.endpoint.ImmutableEndpoint;
023:        import org.mule.api.endpoint.InboundEndpoint;
024:        import org.mule.api.transport.DispatchException;
025:        import org.mule.api.transport.ReceiveException;
026:        import org.mule.config.i18n.CoreMessages;
027:        import org.mule.module.client.i18n.ClientMessages;
028:        import org.mule.module.jca.i18n.JcaMessages;
029:        import org.mule.security.MuleCredentials;
030:        import org.mule.transport.AbstractConnector;
031:
032:        import java.util.Map;
033:
034:        import javax.resource.ResourceException;
035:
036:        /**
037:         * <code>MuleConnection</code> TODO
038:         */
039:        public class DefaultMuleConnection implements  MuleConnection {
040:            private final MuleCredentials credentials;
041:            private final MuleContext muleContext;
042:            private MuleManagedConnection managedConnection;
043:
044:            public DefaultMuleConnection(
045:                    MuleManagedConnection managedConnection,
046:                    MuleContext muleContext, MuleCredentials credentials) {
047:                this .muleContext = muleContext;
048:                this .credentials = credentials;
049:                this .managedConnection = managedConnection;
050:            }
051:
052:            /**
053:             * Dispatches an event asynchronously to a endpointUri via a mule server. the Url
054:             * determines where to dispathc the event to, this can be in the form of
055:             * 
056:             * @param url the Mule url used to determine the destination and transport of the
057:             *            message
058:             * @param payload the object that is the payload of the event
059:             * @param messageProperties any properties to be associated with the payload. In
060:             *            the case of Jms you could set the JMSReplyTo property in these
061:             *            properties.
062:             * @throws org.mule.api.MuleException
063:             */
064:            public void dispatch(String url, Object payload,
065:                    Map messageProperties) throws MuleException {
066:                MuleMessage message = new DefaultMuleMessage(payload,
067:                        messageProperties);
068:                MuleEvent event = getEvent(message, url, false);
069:                try {
070:                    event.getSession().dispatchEvent(event);
071:                } catch (MuleException e) {
072:                    throw e;
073:                } catch (Exception e) {
074:                    throw new DispatchException(ClientMessages
075:                            .failedToDispatchClientEvent(), event.getMessage(),
076:                            event.getEndpoint(), e);
077:                }
078:            }
079:
080:            /**
081:             * Sends an object (payload) synchronous to the given url and returns a
082:             * MuleMessage response back.
083:             * 
084:             * @param url the Mule url used to determine the destination and transport of the
085:             *            message
086:             * @param payload the object that is the payload of the event
087:             * @param messageProperties any properties to be associated with the payload. In
088:             *            the case of Jms you could set the JMSReplyTo property in these
089:             *            properties.
090:             * @return a umomessage response.
091:             * @throws org.mule.api.MuleException
092:             */
093:            public MuleMessage send(String url, Object payload,
094:                    Map messageProperties) throws MuleException {
095:                MuleMessage message = new DefaultMuleMessage(payload,
096:                        messageProperties);
097:                MuleEvent event = getEvent(message, url, true);
098:
099:                MuleMessage response;
100:                try {
101:                    response = event.getSession().sendEvent(event);
102:                } catch (MuleException e) {
103:                    throw e;
104:                } catch (Exception e) {
105:                    throw new DispatchException(ClientMessages
106:                            .failedToDispatchClientEvent(), event.getMessage(),
107:                            event.getEndpoint(), e);
108:                }
109:                return response;
110:            }
111:
112:            /**
113:             * Will receive an event from an endpointUri determined by the url
114:             * 
115:             * @param url the Mule url used to determine the destination and transport of the
116:             *            message
117:             * @param timeout how long to block waiting to receive the event, if set to 0 the
118:             *            receive will not wait at all and if set to -1 the receive will wait
119:             *            forever
120:             * @return the message received or null if no message was received
121:             * @throws org.mule.api.MuleException
122:             */
123:            public MuleMessage request(String url, long timeout)
124:                    throws MuleException {
125:                InboundEndpoint endpoint = muleContext.getRegistry()
126:                        .lookupEndpointFactory().getInboundEndpoint(url);
127:
128:                try {
129:                    return endpoint.request(timeout);
130:                } catch (Exception e) {
131:                    throw new ReceiveException(endpoint, timeout, e);
132:                }
133:            }
134:
135:            /**
136:             * Packages a mule event for the current request
137:             * 
138:             * @param message the event payload
139:             * @param uri the destination endpointUri
140:             * @param synchronous whether the event will be synchronously processed
141:             * @return the MuleEvent
142:             * @throws MuleException in case of Mule error
143:             */
144:            protected MuleEvent getEvent(MuleMessage message, String uri,
145:                    boolean synchronous) throws MuleException {
146:                ImmutableEndpoint endpoint = muleContext.getRegistry()
147:                        .lookupEndpointFactory().getOutboundEndpoint(uri);
148:                //Connector connector = endpoint.getConnector();
149:
150:                //        if (!connector.isStarted() && manager.isStarted())
151:                //        {
152:                //            connector.start();
153:                //        }
154:
155:                try {
156:                    MuleSession session = new DefaultMuleSession(message,
157:                            ((AbstractConnector) endpoint.getConnector())
158:                                    .getSessionHandler(), muleContext);
159:
160:                    if (credentials != null) {
161:                        message.setProperty(MuleProperties.MULE_USER_PROPERTY,
162:                                "Plain " + credentials.getToken());
163:                    }
164:
165:                    return new DefaultMuleEvent(message, endpoint, session,
166:                            synchronous);
167:                } catch (Exception e) {
168:                    throw new DispatchException(CoreMessages
169:                            .failedToCreate("Client event"), message, endpoint,
170:                            e);
171:                }
172:            }
173:
174:            /**
175:             * Retrieves a ManagedConnection.
176:             * 
177:             * @return a ManagedConnection instance representing the physical connection to
178:             *         the EIS
179:             */
180:
181:            public MuleManagedConnection getManagedConnection() {
182:                return managedConnection;
183:            }
184:
185:            /**
186:             * Closes the connection.
187:             */
188:            public void close() throws ResourceException {
189:                if (managedConnection == null) {
190:                    return; // connection is already closed
191:                }
192:                managedConnection.removeConnection(this );
193:
194:                // Send a close event to the App Server
195:                managedConnection.fireCloseEvent(this );
196:                managedConnection = null;
197:            }
198:
199:            /**
200:             * Associates connection handle with new managed connection.
201:             * 
202:             * @param newMc new managed connection
203:             */
204:
205:            public void associateConnection(MuleManagedConnection newMc)
206:                    throws ResourceException {
207:                checkIfValid();
208:                // dissociate handle from current managed connection
209:                managedConnection.removeConnection(this );
210:                // associate handle with new managed connection
211:                newMc.addConnection(this );
212:                managedConnection = newMc;
213:            }
214:
215:            /**
216:             * Checks the validity of the physical connection to the EIS.
217:             * 
218:             * @throws javax.resource.ResourceException in case of any error
219:             */
220:
221:            void checkIfValid() throws ResourceException {
222:                if (managedConnection == null) {
223:                    throw new ResourceException(JcaMessages
224:                            .objectMarkedInvalid("muleManagedConnection")
225:                            .toString());
226:                }
227:            }
228:
229:            /**
230:             * Sets the physical connection to the EIS as invalid. The physical connection to
231:             * the EIS cannot be used any more.
232:             */
233:
234:            void invalidate() {
235:                managedConnection = null;
236:            }
237:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.