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


001:        /*
002:         * $Id: GenericLifecycleManager.java 11149 2008-03-03 19:41:55Z acooke $
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:        package org.mule.lifecycle;
011:
012:        import org.mule.api.MuleException;
013:        import org.mule.api.MuleContext;
014:        import org.mule.api.lifecycle.LifecycleManager;
015:        import org.mule.api.lifecycle.LifecyclePhase;
016:        import org.mule.api.lifecycle.LifecycleTransitionResult;
017:        import org.mule.lifecycle.phases.NotInLifecyclePhase;
018:        import org.mule.util.StringMessageUtils;
019:
020:        import java.util.HashMap;
021:        import java.util.HashSet;
022:        import java.util.Iterator;
023:        import java.util.Map;
024:        import java.util.Set;
025:
026:        import org.apache.commons.collections.set.ListOrderedSet;
027:        import org.apache.commons.logging.Log;
028:        import org.apache.commons.logging.LogFactory;
029:
030:        public class GenericLifecycleManager implements  LifecycleManager {
031:            /**
032:             * logger used by this class
033:             */
034:            protected transient final Log logger = LogFactory
035:                    .getLog(GenericLifecycleManager.class);
036:            protected static NotInLifecyclePhase notInLifecyclePhase = new NotInLifecyclePhase();
037:            protected String currentPhase = notInLifecyclePhase.getName();
038:            protected String executingPhase = null;
039:            protected ListOrderedSet lifecycles = new ListOrderedSet();
040:            protected Map index = new HashMap(6);
041:            protected Set completedPhases = new HashSet(6);
042:
043:            public Set getLifecycles() {
044:                return lifecycles;
045:            }
046:
047:            public void setLifecycles(Set lifecycles) {
048:                for (Iterator iterator = lifecycles.iterator(); iterator
049:                        .hasNext();) {
050:                    LifecyclePhase phase = (LifecyclePhase) iterator.next();
051:                    registerLifecycle(phase);
052:                }
053:
054:            }
055:
056:            public void registerLifecycle(LifecyclePhase lci) {
057:                index.put(lci.getName(), new Integer(lifecycles.size()));
058:                lifecycles.add(lci);
059:            }
060:
061:            public void firePhase(MuleContext muleContext, String phase)
062:                    throws MuleException {
063:                if (currentPhase.equalsIgnoreCase(phase)) {
064:                    logger.debug("Already in lifecycle phase: " + phase);
065:                    return;
066:                }
067:                Integer phaseIndex = (Integer) index.get(phase);
068:                if (phaseIndex == null) {
069:                    throw new IllegalArgumentException(
070:                            "No lifeccycle phase registered with name: "
071:                                    + phase);
072:                }
073:                try {
074:                    setExecutingPhase(phase);
075:                    LifecyclePhase li = (LifecyclePhase) lifecycles
076:                            .get(phaseIndex.intValue());
077:                    li.fireLifecycle(muleContext, currentPhase);
078:                    setCurrentPhase(li);
079:                } finally {
080:                    setExecutingPhase(null);
081:                }
082:            }
083:
084:            public String getCurrentPhase() {
085:                return currentPhase;
086:            }
087:
088:            /**
089:             * Returns the name of the currently executing phase or null if there is not current phase
090:             *
091:             * @return
092:             */
093:            public String getExecutingPhase() {
094:                return executingPhase;
095:            }
096:
097:            protected synchronized void setCurrentPhase(LifecyclePhase phase) {
098:                completedPhases.add(phase.getName());
099:                completedPhases.remove(phase.getOppositeLifecyclePhase());
100:                this .currentPhase = phase.getName();
101:            }
102:
103:            protected synchronized void setExecutingPhase(String phase) {
104:                this .executingPhase = phase;
105:            }
106:
107:            public void reset() {
108:                setExecutingPhase(null);
109:                completedPhases.clear();
110:                setCurrentPhase(notInLifecyclePhase);
111:            }
112:
113:            public boolean isPhaseComplete(String phaseName) {
114:                return completedPhases.contains(phaseName);
115:            }
116:
117:            public void applyLifecycle(MuleContext muleContext, Object object)
118:                    throws MuleException {
119:                logger.debug("applying lifecycle to " + object);
120:                LifecyclePhase lcp;
121:                String phase;
122:                Integer phaseIndex;
123:                for (Iterator iterator = completedPhases.iterator(); iterator
124:                        .hasNext();) {
125:                    phase = (String) iterator.next();
126:                    phaseIndex = (Integer) index.get(phase);
127:                    lcp = (LifecyclePhase) lifecycles
128:                            .get(phaseIndex.intValue());
129:                    logger.debug("phase: " + lcp);
130:                    LifecycleTransitionResult result = lcp
131:                            .applyLifecycle(object);
132:                    if (!LifecycleTransitionResult.isOk(result)) {
133:                        throw result.nestedRetryLifecycleException();
134:                    }
135:                }
136:                //If we're currently in a phase, fire that too
137:                if (getExecutingPhase() != null) {
138:                    phaseIndex = (Integer) index.get(getExecutingPhase());
139:                    lcp = (LifecyclePhase) lifecycles
140:                            .get(phaseIndex.intValue());
141:                    logger.debug("and executing: " + lcp);
142:                    LifecycleTransitionResult result = lcp
143:                            .applyLifecycle(object);
144:                    if (!LifecycleTransitionResult.isOk(result)) {
145:                        throw result.nestedRetryLifecycleException();
146:                    }
147:                }
148:            }
149:
150:            public void checkPhase(String name) throws IllegalStateException {
151:                if (completedPhases.contains(name)) {
152:                    throw new IllegalStateException("Phase '" + name
153:                            + "' has already been executed");
154:                }
155:
156:                if (name.equalsIgnoreCase(executingPhase)) {
157:                    throw new IllegalStateException("Phase '" + name
158:                            + "' is already currently being executed");
159:                }
160:
161:                if (executingPhase != null) {
162:                    throw new IllegalStateException(
163:                            "Currently executing lifecycle phase: "
164:                                    + executingPhase);
165:                }
166:
167:                Integer phaseIndex = (Integer) index.get(name);
168:                if (phaseIndex == null) {
169:                    throw new IllegalStateException("Phase does not exist: "
170:                            + name);
171:                }
172:                if (NotInLifecyclePhase.PHASE_NAME.equals(currentPhase)) {
173:                    if (phaseIndex.intValue() > 0) {
174:                        throw new IllegalStateException(
175:                                "The first lifecycle phase has to be called before the '"
176:                                        + name + "' phase");
177:                    }
178:                } else {
179:                    LifecyclePhase phase = (LifecyclePhase) lifecycles
180:                            .get(phaseIndex.intValue());
181:                    if (!phase.isPhaseSupported(currentPhase)) {
182:                        throw new IllegalStateException("Lifecycle phase: "
183:                                + currentPhase
184:                                + " does not support current phase: "
185:                                + name
186:                                + ". Phases supported are: "
187:                                + StringMessageUtils.toString(phase
188:                                        .getSupportedPhases()));
189:                    }
190:                }
191:            }
192:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.