Source Code Cross Referenced for HASingletonInvoker.java in  » Portal » jboss-portal-2.6.4 » org » jboss » portal » jems » ha » 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 » Portal » jboss portal 2.6.4 » org.jboss.portal.jems.ha 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /******************************************************************************
002:         * JBoss, a division of Red Hat                                               *
003:         * Copyright 2006, Red Hat Middleware, LLC, and individual                    *
004:         * contributors as indicated by the @authors tag. See the                     *
005:         * copyright.txt in the distribution for a full listing of                    *
006:         * individual contributors.                                                   *
007:         *                                                                            *
008:         * This is free software; you can redistribute it and/or modify it            *
009:         * under the terms of the GNU Lesser General Public License as                *
010:         * published by the Free Software Foundation; either version 2.1 of           *
011:         * the License, or (at your option) any later version.                        *
012:         *                                                                            *
013:         * This software is distributed in the hope that it will be useful,           *
014:         * but WITHOUT ANY WARRANTY; without even the implied warranty of             *
015:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU           *
016:         * Lesser General Public License for more details.                            *
017:         *                                                                            *
018:         * You should have received a copy of the GNU Lesser General Public           *
019:         * License along with this software; if not, write to the Free                *
020:         * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA         *
021:         * 02110-1301 USA, or see the FSF site: http://www.fsf.org.                   *
022:         ******************************************************************************/package org.jboss.portal.jems.ha;
023:
024:        import org.jboss.ha.singleton.HASingletonSupport;
025:        import org.jboss.invocation.Invocation;
026:        import org.jboss.naming.Util;
027:
028:        import javax.management.ObjectName;
029:        import javax.naming.InitialContext;
030:        import javax.naming.NamingException;
031:        import java.lang.reflect.Method;
032:        import java.util.Properties;
033:
034:        /**
035:         * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
036:         * @version $Revision: 8784 $
037:         */
038:        public class HASingletonInvoker extends HASingletonSupport implements 
039:                HASingletonInvokerMBean {
040:            /** The proxy factory. */
041:            private ObjectName proxyFactory;
042:
043:            /** The cached proxy. */
044:            private Proxy proxy;
045:
046:            /** Where is bound the ha proxy. */
047:            private String jndiName;
048:
049:            /** The callback service which this service depends on. */
050:            private Callback callback;
051:
052:            /** The JNDI properties. */
053:            private Properties jndiProperties;
054:
055:            /** How many time we retry on fail over. */
056:            private int maxRetries;
057:
058:            /** How long we wait before trying a jndi lookup during fail over. */
059:            private long retryWaitingTimeMS;
060:
061:            public long getRetryWaitingTimeMS() {
062:                return retryWaitingTimeMS;
063:            }
064:
065:            public void setRetryWaitingTimeMS(long retryWaitingTimeMS) {
066:                this .retryWaitingTimeMS = retryWaitingTimeMS;
067:            }
068:
069:            public int getMaxRetries() {
070:                return maxRetries;
071:            }
072:
073:            public void setMaxRetries(int maxRetries) {
074:                this .maxRetries = maxRetries;
075:            }
076:
077:            public Properties getJNDIProperties() {
078:                return jndiProperties;
079:            }
080:
081:            public void setJNDIProperties(Properties jndiProperties) {
082:                this .jndiProperties = jndiProperties;
083:            }
084:
085:            public ObjectName getProxyFactory() {
086:                return proxyFactory;
087:            }
088:
089:            public void setProxyFactory(ObjectName proxyFactory) {
090:                this .proxyFactory = proxyFactory;
091:            }
092:
093:            public Callback getCallback() {
094:                return callback;
095:            }
096:
097:            public void setCallback(Callback callback) {
098:                this .callback = callback;
099:            }
100:
101:            public String getJNDIName() {
102:                return jndiName;
103:            }
104:
105:            public void setJNDIName(String jndiName) {
106:                this .jndiName = jndiName;
107:            }
108:
109:            public Proxy lookupProxy() {
110:                if (proxy == null) {
111:                    try {
112:                        InitialContext ctx = new InitialContext(jndiProperties);
113:                        proxy = (Proxy) ctx.lookup(jndiName);
114:                    } catch (NamingException e) {
115:                        log.error("Proxy " + jndiName + " not bound");
116:                    }
117:                }
118:                return proxy;
119:            }
120:
121:            public Object invoke(String methodName, Class[] types, Object[] args)
122:                    throws Exception {
123:                int retries = maxRetries;
124:                while (retries-- > 0) {
125:                    try {
126:                        Proxy proxy = lookupProxy();
127:                        return proxy.invoke(methodName, types, args);
128:                    } catch (Throwable t) {
129:                        if (!(t instanceof  Error)) {
130:                            proxy = null;
131:                            if (retries > 0) {
132:                                log.error("Cannot invoke proxy will retry "
133:                                        + retries + " times", t);
134:                                try {
135:                                    log.debug("Sleeping for "
136:                                            + retryWaitingTimeMS
137:                                            + " before trying to fail over");
138:                                    Thread.sleep(retryWaitingTimeMS);
139:                                } catch (InterruptedException ignore) {
140:                                    // Get out of the loop
141:                                    retries = 0;
142:                                }
143:                            } else {
144:                                log
145:                                        .error(
146:                                                "Cannot invoke proxy will no more retry",
147:                                                t);
148:                            }
149:                        } else {
150:                            throw (Error) t;
151:                        }
152:                    }
153:                }
154:                // Todo : throw exception
155:                return null;
156:            }
157:
158:            protected void startService() throws Exception {
159:                callback.setInvoker(this );
160:
161:                //
162:                super .startService();
163:            }
164:
165:            protected void stopService() throws Exception {
166:                super .stopService();
167:
168:                //
169:                callback.setInvoker(null);
170:            }
171:
172:            public void startSingleton() {
173:                String name = callback.getDisplayName();
174:
175:                //
176:                try {
177:
178:                    // Start the service.
179:                    log.debug("Starting singleton " + name);
180:                    callback.startSingleton();
181:                    log.debug("Singleton " + name + " started");
182:
183:                    //
184:                    log.debug("Binding singleton proxy " + name);
185:                    Object proxy = server.getAttribute(proxyFactory, "Proxy");
186:                    Util.bind(new InitialContext(), jndiName, proxy);
187:                    log.debug("Singleton proxy " + name + " bound");
188:                } catch (Exception e) {
189:                    log.error("Not able to start singleton " + name + " bound",
190:                            e);
191:                }
192:            }
193:
194:            public void stopSingleton() {
195:                // Stop the singleton
196:                if (callback != null) {
197:                    //
198:                    String name = callback.getDisplayName();
199:
200:                    //
201:                    log.debug("Stopping singleton proxy " + name);
202:                    callback.stopSingleton();
203:                    log.debug("Singleton " + name + " stopped");
204:                }
205:            }
206:
207:            public Object invoke(Invocation mi) throws Exception {
208:                Method m = mi.getMethod();
209:                Object[] args = mi.getArguments();
210:                return callback
211:                        .invoke(m.getName(), m.getParameterTypes(), args);
212:            }
213:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.