Source Code Cross Referenced for EjbHaClusterFactory.java in  » J2EE » JOnAS-4.8.6 » org » objectweb » jonas » management » cluster » 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 » J2EE » JOnAS 4.8.6 » org.objectweb.jonas.management.cluster 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * JOnAS: Java(TM) Open Application Server
003:         * Copyright (C) 2006 Bull S.A.
004:         * Contact: jonas-team@objectweb.org
005:         *
006:         * This library is free software; you can redistribute it and/or
007:         * modify it under the terms of the GNU Lesser General Public
008:         * License as published by the Free Software Foundation; either
009:         * version 2.1 of the License, or any later version.
010:         *
011:         * This library is distributed in the hope that it will be useful,
012:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
013:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014:         * Lesser General Public License for more details.
015:         *
016:         * You should have received a copy of the GNU Lesser General Public
017:         * License along with this library; if not, write to the Free Software
018:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
019:         * USA
020:         *
021:         * --------------------------------------------------------------------------
022:         * $Id: EjbHaClusterFactory.java 9758 2006-10-18 06:28:50Z durieuxp $
023:         * --------------------------------------------------------------------------
024:         */package org.objectweb.jonas.management.cluster;
025:
026:        import java.util.Collection;
027:        import java.util.HashMap;
028:        import java.util.Iterator;
029:        import java.util.Set;
030:        import java.util.StringTokenizer;
031:
032:        import javax.management.JMException;
033:        import javax.management.MalformedObjectNameException;
034:        import javax.management.ObjectName;
035:
036:        import org.objectweb.jonas.management.monitoring.DomainMonitor;
037:        import org.objectweb.jonas.management.monitoring.ServerProxy;
038:
039:        import org.objectweb.util.monolog.api.BasicLevel;
040:
041:        /**
042:         * Factory for HA clusters
043:         * These Clusters are built dynamically, when a new server is discovered
044:         * as being part of a cluster of this type.
045:         * @author durieuxp
046:         */
047:        public class EjbHaClusterFactory extends ClusterFactory {
048:
049:            /**
050:             * List of TomcatCluster objects
051:             * There may be more than 1 TomcatCluster in the domain.
052:             * key = clusterName, value = TomcatCluster
053:             */
054:            private HashMap myclusters = new HashMap();
055:
056:            /**
057:             * Constructor
058:             */
059:            public EjbHaClusterFactory(DomainMonitor dm) {
060:                super (dm);
061:            }
062:
063:            /**
064:             * Look for a cluster by its name
065:             * @param name fo the cluster
066:             * @return cluster or null if not found
067:             */
068:            public BaseCluster getCluster(String name) {
069:                return (BaseCluster) myclusters.get(name);
070:            }
071:
072:            /**
073:             * A new server has been discovered.
074:             * In case this server is recognized, it is added in a Cluster.
075:             * If not, nothing is done.
076:             * @param proxy The new ServerProxy
077:             * @return True if recognized as a tomcat server.
078:             */
079:            public boolean notifyServer(ServerProxy proxy) {
080:
081:                String serverName = proxy.getServerName();
082:                logger.log(BasicLevel.DEBUG, serverName);
083:
084:                // Determine if a HA Cluster MBean exists in the server
085:                // referenced by this proxy.
086:                ObjectName ons;
087:                try {
088:                    ons = ObjectName.getInstance(domainName
089:                            + ":type=CMI,name=JGroupsHA,*");
090:                } catch (MalformedObjectNameException e1) {
091:                    logger
092:                            .log(BasicLevel.ERROR,
093:                                    "MalformedObjectNameException");
094:                    return false;
095:                }
096:                Set set = proxy.queryNames(ons);
097:                if (set == null) {
098:                    logger.log(BasicLevel.DEBUG, "Cannot reach " + serverName);
099:                    return false;
100:                }
101:                if (set.isEmpty()) {
102:                    logger.log(BasicLevel.DEBUG,
103:                            "No CMI Cluster with name=JGroupsHA declared");
104:                    return false;
105:                }
106:                // ObjectName = "<domain>:type=CMI,J2EEServer=<server>,name=JGroupsHA,channel=<ch>,protocol="UDP"
107:                ObjectName on = null;
108:                String protocol = null;
109:                for (Iterator it = set.iterator(); it.hasNext();) {
110:                    on = (ObjectName) it.next();
111:                    protocol = on.getKeyProperty("protocol");
112:                    if ("UDP".equals(protocol) || "TCP".equals(protocol)) {
113:                        break;
114:                    }
115:                }
116:
117:                // Found an MBean: Get information about this cluster
118:                logger.log(BasicLevel.DEBUG, "Found EjbHaCluster protocol="
119:                        + protocol);
120:                String clusterName = on.getKeyProperty("channel");
121:
122:                // Retrieve the EjbHaCluster. Create it if necessary.
123:                EjbHaCluster cluster = (EjbHaCluster) myclusters
124:                        .get(clusterName);
125:                if (cluster == null) {
126:                    ObjectName clon = null;
127:                    try {
128:                        cluster = new EjbHaCluster(this );
129:                        clon = cluster.setName(clusterName);
130:                    } catch (JMException e) {
131:                        logger.log(BasicLevel.ERROR,
132:                                "Cannot create EJbHa Cluster:" + e);
133:                        return false;
134:                    }
135:
136:                    // Get additional info
137:                    String strprop = (String) proxy.getAttribute(on,
138:                            "PropertiesAsString");
139:                    StringTokenizer stk = new StringTokenizer(strprop, "{},");
140:                    int nb = stk.countTokens();
141:                    for (int i = 0; i < nb; i++) {
142:                        String str = stk.nextToken();
143:                        int ind = str.indexOf('=', 0);
144:                        if (ind <= 0) {
145:                            logger
146:                                    .log(BasicLevel.ERROR, "Bad property: "
147:                                            + str);
148:                        }
149:                        String key = str.substring(0, ind).trim();
150:                        String value = str.substring(ind + 1).trim();
151:                        logger.log(BasicLevel.DEBUG, key + "=" + value);
152:                        if (key.equals("mcast_port")) {
153:                            int mcastPort = (new Integer(value)).intValue();
154:                            cluster.setMcastPort(mcastPort);
155:                        }
156:                        if (key.equals("mcast_addr")) {
157:                            cluster.setMcastAddr(value);
158:                        }
159:                        // TODO Add other parameters 
160:                    }
161:
162:                    // Register the MBean if not done
163:                    if (!mbeanServer.isRegistered(clon)) {
164:                        try {
165:                            // A MBean is registered for each Cluster
166:                            mbeanServer.registerMBean(cluster, clon);
167:                        } catch (Exception e) {
168:                            logger.log(BasicLevel.ERROR,
169:                                    "Cannot register cluster:" + e);
170:                            return false;
171:                        }
172:                    }
173:                    myclusters.put(clusterName, cluster);
174:                }
175:
176:                // add a server to the cluster
177:                return cluster.addHaServer(serverName, proxy);
178:            }
179:
180:            public Collection getClusterList() {
181:                return myclusters.values();
182:            }
183:
184:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.