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


001:        // $Id: RspList.java,v 1.7 2006/05/13 08:48:38 belaban Exp $
002:
003:        package org.jgroups.util;
004:
005:        import org.jgroups.Address;
006:
007:        import java.util.*;
008:
009:        /**
010:         * Contains responses from all members. Marks faulty members.
011:         * A RspList is a response list used in peer-to-peer protocols.
012:         */
013:        public class RspList implements  Map {
014:
015:            /** Map<Address, Rsp> */
016:            final Map rsps = new HashMap();
017:
018:            public RspList() {
019:
020:            }
021:
022:            /** Adds a lkist of responses
023:             * @param responses Collection<Rsp>
024:             */
025:            public RspList(Collection responses) {
026:                if (responses != null) {
027:                    for (Iterator it = responses.iterator(); it.hasNext();) {
028:                        Rsp rsp = (Rsp) it.next();
029:                        rsps.put(rsp.getSender(), rsp);
030:                    }
031:                }
032:            }
033:
034:            public boolean isEmpty() {
035:                return rsps.isEmpty();
036:            }
037:
038:            public boolean containsKey(Object key) {
039:                return rsps.containsKey(key);
040:            }
041:
042:            public boolean containsValue(Object value) {
043:                return rsps.containsValue(value);
044:            }
045:
046:            /**
047:             * Returns the Rsp associated with address key
048:             * @param key Address (key)
049:             * @return Rsp
050:             */
051:            public Object get(Object key) {
052:                return rsps.get(key);
053:            }
054:
055:            /**
056:             * Returns the value associated with address key
057:             * @param key
058:             * @return Object value
059:             */
060:            public Object getValue(Object key) {
061:                Rsp rsp = (Rsp) get(key);
062:                return rsp != null ? rsp.getValue() : null;
063:            }
064:
065:            public Object put(Object key, Object value) {
066:                return rsps.put(key, value);
067:            }
068:
069:            public Object remove(Object key) {
070:                return rsps.remove(key);
071:            }
072:
073:            public void putAll(Map m) {
074:                rsps.putAll(m);
075:            }
076:
077:            public void clear() {
078:                rsps.clear();
079:            }
080:
081:            public Set keySet() {
082:                return rsps.keySet();
083:            }
084:
085:            public Collection values() {
086:                return rsps.values();
087:            }
088:
089:            public Set entrySet() {
090:                return rsps.entrySet();
091:            }
092:
093:            /**
094:             * Clears the response list
095:             * @deprecated Use {@link #clear()} instead
096:             */
097:            public void reset() {
098:                clear();
099:            }
100:
101:            public void addRsp(Address sender, Object retval) {
102:                Rsp rsp = (Rsp) get(sender);
103:                if (rsp != null) {
104:                    rsp.sender = sender;
105:                    rsp.retval = retval;
106:                    rsp.received = true;
107:                    rsp.suspected = false;
108:                    return;
109:                }
110:                rsps.put(sender, new Rsp(sender, retval));
111:            }
112:
113:            public void addNotReceived(Address sender) {
114:                Rsp rsp = (Rsp) get(sender);
115:                if (rsp == null)
116:                    rsps.put(sender, new Rsp(sender));
117:            }
118:
119:            public void addSuspect(Address sender) {
120:                Rsp rsp = (Rsp) get(sender);
121:                if (rsp != null) {
122:                    rsp.sender = sender;
123:                    rsp.retval = null;
124:                    rsp.received = false;
125:                    rsp.suspected = true;
126:                    return;
127:                }
128:                rsps.put(sender, new Rsp(sender, true));
129:            }
130:
131:            public boolean isReceived(Address sender) {
132:                Rsp rsp = (Rsp) get(sender);
133:                if (rsp == null)
134:                    return false;
135:                return rsp.received;
136:            }
137:
138:            public int numSuspectedMembers() {
139:                int num = 0;
140:                Rsp rsp;
141:                Collection values = values();
142:                for (Iterator it = values.iterator(); it.hasNext();) {
143:                    rsp = (Rsp) it.next();
144:                    if (rsp.wasSuspected())
145:                        num++;
146:                }
147:                return num;
148:            }
149:
150:            /** Returns the first value in the response set. This is random, but we try to return a non-null value first */
151:            public Object getFirst() {
152:                Collection values = values();
153:                for (Iterator it = values.iterator(); it.hasNext();) {
154:                    Rsp rsp = (Rsp) it.next();
155:                    if (rsp.getValue() != null)
156:                        return rsp.getValue();
157:                }
158:                return null;
159:            }
160:
161:            /**
162:             * Returns the results from non-suspected members that are not null.
163:             */
164:            public Vector getResults() {
165:                Vector ret = new Vector();
166:                Rsp rsp;
167:                Object val;
168:
169:                for (Iterator it = values().iterator(); it.hasNext();) {
170:                    rsp = (Rsp) it.next();
171:                    if (rsp.wasReceived() && (val = rsp.getValue()) != null)
172:                        ret.addElement(val);
173:                }
174:                return ret;
175:            }
176:
177:            public Vector getSuspectedMembers() {
178:                Vector retval = new Vector();
179:                Rsp rsp;
180:
181:                for (Iterator it = values().iterator(); it.hasNext();) {
182:                    rsp = (Rsp) it.next();
183:                    if (rsp.wasSuspected())
184:                        retval.addElement(rsp.getSender());
185:                }
186:                return retval;
187:            }
188:
189:            public boolean isSuspected(Address sender) {
190:                Rsp rsp = (Rsp) get(sender);
191:                if (rsp == null)
192:                    return false;
193:                return rsp.suspected;
194:            }
195:
196:            public int size() {
197:                return rsps.size();
198:            }
199:
200:            /**
201:             * Returns the Rsp at index i
202:             * @param i The index
203:             * @return a Rsp
204:             * @throws ArrayIndexOutOfBoundsException
205:             * @deprecated Use {@link #entrySet()} or {@link #values()} instead
206:             */
207:            public Object elementAt(int i)
208:                    throws ArrayIndexOutOfBoundsException {
209:                Set keys = new TreeSet(keySet());
210:                if (keys == null)
211:                    return null;
212:                Object[] keys_array = keys.toArray();
213:                Object key = keys_array[i];
214:                return get(key);
215:            }
216:
217:            public String toString() {
218:                StringBuffer ret = new StringBuffer();
219:                Rsp rsp;
220:
221:                for (Iterator it = values().iterator(); it.hasNext();) {
222:                    rsp = (Rsp) it.next();
223:                    ret.append("[" + rsp + "]\n");
224:                }
225:                return ret.toString();
226:            }
227:
228:            boolean contains(Address sender) {
229:                return containsKey(sender);
230:            }
231:
232:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.