Source Code Cross Referenced for ParticipantGmsImpl.java in  » Net » JGroups-2.4.1-sp3 » org » jgroups » protocols » 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 » Net » JGroups 2.4.1 sp3 » org.jgroups.protocols 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        // $Id: ParticipantGmsImpl.java,v 1.9.10.1 2007/04/27 08:03:51 belaban Exp $
002:
003:        package org.jgroups.protocols;
004:
005:        import org.jgroups.Address;
006:        import org.jgroups.View;
007:        import org.jgroups.ViewId;
008:        import org.jgroups.blocks.GroupRequest;
009:        import org.jgroups.blocks.MethodCall;
010:
011:        import java.util.Vector;
012:
013:        public class ParticipantGmsImpl extends GmsImpl {
014:            boolean leaving = false;
015:            boolean received_final_view = false;
016:            final Object leave_mutex = new Object();
017:            final Vector suspected_mbrs = new Vector(5);
018:            final Vector new_mbrs = new Vector(11);
019:
020:            public ParticipantGmsImpl(GMS g) {
021:                gms = g;
022:                init();
023:            }
024:
025:            final public void init() {
026:                leaving = false;
027:                received_final_view = false;
028:                suspected_mbrs.removeAllElements();
029:                new_mbrs.removeAllElements();
030:                if (gms.mbrs != null)
031:                    for (int i = 0; i < gms.mbrs.size(); i++)
032:                        new_mbrs.addElement(gms.mbrs.elementAt(i));
033:            }
034:
035:            public void join(Address mbr) {
036:                wrongMethod("join");
037:            }
038:
039:            /**
040:             Loop: determine coord. If coord is me --> handleLeave(). Else send handleLeave() to coord until
041:             success.
042:             */
043:            public void leave(Address mbr) {
044:                Address coord;
045:
046:                if (mbr.equals(gms.local_addr))
047:                    leaving = true;
048:
049:                while ((coord = gms.determineCoordinator()) != null
050:                        && !received_final_view) {
051:                    synchronized (leave_mutex) {
052:                        if (gms.local_addr.equals(coord)) { // I'm the coordinator
053:                            gms.becomeCoordinator();
054:                            gms.handleLeave(mbr, false); // regular leave
055:                        } else {
056:                            try {
057:
058:                                if (log.isInfoEnabled())
059:                                    log.info("sending LEAVE request to "
060:                                            + coord);
061:                                MethodCall call = new MethodCall("handleLeave",
062:                                        new Object[] { mbr, Boolean.FALSE },
063:                                        new String[] { Address.class.getName(),
064:                                                boolean.class.getName() });
065:                                gms.callRemoteMethod(coord, call,
066:                                        GroupRequest.GET_NONE, 0); // asynchronous
067:                            } catch (Exception e) {
068:                            }
069:                        }
070:
071:                        try {
072:                            leave_mutex.wait(gms.leave_timeout);
073:                        } catch (Exception e) {
074:                        }
075:                    }
076:                }
077:                gms.becomeClient();
078:            }
079:
080:            public void suspect(Address mbr) {
081:                handleSuspect(mbr);
082:            }
083:
084:            public void merge(Vector other_coords) {
085:                wrongMethod("merge");
086:            }
087:
088:            public boolean handleJoin(Address mbr) {
089:                wrongMethod("handleJoin");
090:                return false;
091:            }
092:
093:            public void handleLeave(Address mbr, boolean suspected) {
094:                wrongMethod("handleLeave");
095:            }
096:
097:            /**
098:             If we are leaving, we have to wait for the view change (last msg in the current view) that
099:             excludes us before we can leave.
100:             */
101:            public void handleViewChange(ViewId new_view, Vector mbrs) {
102:                if (log.isInfoEnabled())
103:                    log.info("mbrs are " + mbrs);
104:
105:                suspected_mbrs.removeAllElements();
106:                new_mbrs.removeAllElements();
107:                if (mbrs != null)
108:                    for (int i = 0; i < mbrs.size(); i++)
109:                        new_mbrs.addElement(mbrs.elementAt(i));
110:
111:                if (leaving) {
112:                    if (mbrs != null && mbrs.contains(gms.local_addr)) {
113:                        if (log.isWarnEnabled())
114:                            log
115:                                    .warn("received view in which I'm still a member, cannot quit yet");
116:                        gms.installView(new_view, mbrs);
117:                    } else {
118:                        synchronized (leave_mutex) {
119:                            received_final_view = true;
120:                            leave_mutex.notifyAll();
121:                        }
122:                    }
123:                    return;
124:                }
125:                gms.installView(new_view, mbrs);
126:            }
127:
128:            // Only coordinators Handle Merge requests.
129:            public View handleMerge(ViewId other_view, Vector other_members) {
130:                wrongMethod("handleMerge");
131:                return null;
132:            }
133:
134:            public void handleSuspect(Address mbr) {
135:                Vector suspects;
136:
137:                if (mbr == null)
138:                    return;
139:                if (!suspected_mbrs.contains(mbr))
140:                    suspected_mbrs.addElement(mbr);
141:                new_mbrs.removeElement(mbr);
142:
143:                if (log.isInfoEnabled())
144:                    log.info("suspected mbr=" + mbr + "\nsuspected_mbrs="
145:                            + suspected_mbrs + "\nnew_mbrs=" + new_mbrs);
146:
147:                if (new_mbrs.size() > 0
148:                        && new_mbrs.elementAt(0).equals(gms.local_addr)) {
149:
150:                    if (log.isInfoEnabled())
151:                        log.info("suspected mbr=" + mbr + ", members are "
152:                                + gms.mbrs + ", coord=" + gms.local_addr
153:                                + ": I'm the new coord !");
154:
155:                    suspects = (Vector) suspected_mbrs.clone();
156:                    suspected_mbrs.removeAllElements();
157:                    new_mbrs.removeAllElements();
158:                    gms.becomeCoordinator();
159:                    gms.castViewChange(null, null, suspects);
160:                }
161:            }
162:
163:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.