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


001:        /*
002:         * $Id: IdempotentReceiver.java 10529 2008-01-25 05:58:36Z dfeist $
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.routing.inbound;
012:
013:        import org.mule.api.MessagingException;
014:        import org.mule.api.MuleEvent;
015:        import org.mule.api.routing.IdempotentMessageIdStore;
016:        import org.mule.api.routing.RoutingException;
017:        import org.mule.config.i18n.CoreMessages;
018:
019:        /**
020:         * <code>IdempotentReceiver</code> ensures that only unique messages are received by a
021:         * service. It does this by checking the unique ID of the incoming message. Note that
022:         * the underlying endpoint must support unique message IDs for this to work, otherwise a
023:         * <code>UniqueIdNotSupportedException</code> is thrown.<br>
024:         * By default this implementation uses an instance of
025:         * {@link IdempotentInMemoryMessageIdStore}.
026:         */
027:        public class IdempotentReceiver extends SelectiveConsumer {
028:            protected volatile IdempotentMessageIdStore idStore;
029:            protected volatile String assignedComponentName;
030:
031:            // The maximum number of messages to keep in the store; exact interpretation of this
032:            // limit is up to the store implementation. By default the store is unbounded.
033:            protected volatile int maxMessages = -1;
034:
035:            // The number of seconds each message ID is kept in the store;
036:            // by default each entry is kept for 5 minutes
037:            protected volatile int messageTTL = (60 * 5);
038:
039:            // The number of seconds between expiration intervals;
040:            // by default we expire every minute
041:            protected volatile int expirationInterval = 60;
042:
043:            public IdempotentReceiver() {
044:                super ();
045:            }
046:
047:            public int getMaxMessages() {
048:                return maxMessages;
049:            }
050:
051:            public void setMaxMessages(int maxMessages) {
052:                this .maxMessages = maxMessages;
053:            }
054:
055:            public int getMessageTTL() {
056:                return messageTTL;
057:            }
058:
059:            public void setMessageTTL(int messageTTL) {
060:                this .messageTTL = messageTTL;
061:            }
062:
063:            public int getExpirationInterval() {
064:                return expirationInterval;
065:            }
066:
067:            public void setExpirationInterval(int expirationInterval) {
068:                if (expirationInterval <= 0) {
069:                    throw new IllegalArgumentException(CoreMessages
070:                            .propertyHasInvalidValue("expirationInterval",
071:                                    new Integer(expirationInterval)).toString());
072:                }
073:
074:                this .expirationInterval = expirationInterval;
075:            }
076:
077:            protected void initialize(MuleEvent event) throws RoutingException {
078:                if (assignedComponentName == null && idStore == null) {
079:                    this .assignedComponentName = event.getService().getName();
080:                    this .idStore = this .createMessageIdStore();
081:                }
082:            }
083:
084:            protected IdempotentMessageIdStore createMessageIdStore() {
085:                return new IdempotentInMemoryMessageIdStore(
086:                        assignedComponentName, maxMessages, messageTTL,
087:                        expirationInterval);
088:            }
089:
090:            // @Override
091:            public boolean isMatch(MuleEvent event) throws MessagingException {
092:                if (idStore == null) {
093:                    // we need to load this on the first request as we need the service name
094:                    synchronized (this ) {
095:                        this .initialize(event);
096:                    }
097:                }
098:
099:                try {
100:                    return !idStore.containsId(this .getIdForEvent(event));
101:                } catch (Exception ex) {
102:                    throw new RoutingException(event.getMessage(), event
103:                            .getEndpoint(), ex);
104:                }
105:            }
106:
107:            // @Override
108:            public MuleEvent[] process(MuleEvent event)
109:                    throws MessagingException {
110:                String eventComponentName = event.getService().getName();
111:                if (!assignedComponentName.equals(eventComponentName)) {
112:                    IllegalArgumentException iex = new IllegalArgumentException(
113:                            "This receiver is assigned to service: "
114:                                    + assignedComponentName
115:                                    + " but has received an event for service: "
116:                                    + eventComponentName
117:                                    + ". Please check your config to make sure each service"
118:                                    + "has its own instance of IdempotentReceiver.");
119:                    throw new RoutingException(event.getMessage(), event
120:                            .getEndpoint(), iex);
121:                }
122:
123:                Object id = this .getIdForEvent(event);
124:
125:                try {
126:                    if (idStore.storeId(id)) {
127:                        return new MuleEvent[] { event };
128:                    } else {
129:                        return null;
130:                    }
131:                } catch (Exception e) {
132:                    throw new RoutingException(CoreMessages
133:                            .failedToWriteMessageToStore(id,
134:                                    assignedComponentName), event.getMessage(),
135:                            event.getEndpoint(), e);
136:                }
137:            }
138:
139:            protected Object getIdForEvent(MuleEvent event)
140:                    throws MessagingException {
141:                return event.getMessage().getUniqueId();
142:            }
143:
144:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.