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


001:        // $Id: NakAckHeader.java,v 1.19 2006/04/05 05:37:34 belaban Exp $
002:
003:        package org.jgroups.protocols.pbcast;
004:
005:        import org.jgroups.Address;
006:        import org.jgroups.Global;
007:        import org.jgroups.Header;
008:        import org.jgroups.util.Range;
009:        import org.jgroups.util.Streamable;
010:        import org.jgroups.util.Util;
011:
012:        import java.io.*;
013:
014:        public class NakAckHeader extends Header implements  Streamable {
015:            public static final byte MSG = 1; // regular msg
016:            public static final byte XMIT_REQ = 2; // retransmit request
017:            public static final byte XMIT_RSP = 3; // retransmit response (contains one or more messages)
018:
019:            byte type = 0;
020:            long seqno = -1; // seqno of regular message (MSG)
021:            Range range = null; // range of msgs to be retransmitted (XMIT_REQ) or retransmitted (XMIT_RSP)
022:            Address sender; // the original sender of the message (for XMIT_REQ)
023:
024:            public NakAckHeader() {
025:            }
026:
027:            /**
028:             * Constructor for regular messages
029:             */
030:            public NakAckHeader(byte type, long seqno) {
031:                this .type = type;
032:                this .seqno = seqno;
033:            }
034:
035:            /**
036:             * Constructor for retransmit requests/responses (low and high define the range of msgs)
037:             */
038:            public NakAckHeader(byte type, long low, long high) {
039:                this .type = type;
040:                range = new Range(low, high);
041:            }
042:
043:            public NakAckHeader(byte type, long low, long high, Address sender) {
044:                this (type, low, high);
045:                this .sender = sender;
046:            }
047:
048:            public void writeExternal(ObjectOutput out) throws IOException {
049:                out.writeByte(type);
050:                out.writeLong(seqno);
051:                if (range != null) {
052:                    out.writeBoolean(true); // wasn't here before, bad bug !
053:                    range.writeExternal(out);
054:                } else
055:                    out.writeBoolean(false);
056:                out.writeObject(sender);
057:            }
058:
059:            public void readExternal(ObjectInput in) throws IOException,
060:                    ClassNotFoundException {
061:                boolean read_range;
062:                type = in.readByte();
063:                seqno = in.readLong();
064:                read_range = in.readBoolean();
065:                if (read_range) {
066:                    range = new Range();
067:                    range.readExternal(in);
068:                }
069:                sender = (Address) in.readObject();
070:            }
071:
072:            public void writeTo(DataOutputStream out) throws IOException {
073:                out.writeByte(type);
074:                if (type != XMIT_RSP)
075:                    out.writeLong(seqno);
076:                Util.writeStreamable(range, out);
077:                Util.writeAddress(sender, out);
078:            }
079:
080:            public void readFrom(DataInputStream in) throws IOException,
081:                    IllegalAccessException, InstantiationException {
082:                type = in.readByte();
083:                if (type != XMIT_RSP)
084:                    seqno = in.readLong();
085:                range = (Range) Util.readStreamable(Range.class, in);
086:                sender = Util.readAddress(in);
087:            }
088:
089:            public long size() {
090:                // type (1 byte) + seqno (8 bytes)
091:                int retval = Global.BYTE_SIZE;
092:
093:                if (type != XMIT_RSP) // we don't send the seqno if this is an XMIT_RSP
094:                    retval += Global.LONG_SIZE;
095:
096:                retval += Global.BYTE_SIZE; // presence for range
097:                if (range != null)
098:                    retval += 2 * Global.LONG_SIZE; // 2 times 8 bytes for seqno
099:                retval += Util.size(sender);
100:                return retval;
101:            }
102:
103:            public NakAckHeader copy() {
104:                NakAckHeader ret = new NakAckHeader(type, seqno);
105:                ret.range = range;
106:                ret.sender = sender;
107:                return ret;
108:            }
109:
110:            public static String type2Str(byte t) {
111:                switch (t) {
112:                case MSG:
113:                    return "MSG";
114:                case XMIT_REQ:
115:                    return "XMIT_REQ";
116:                case XMIT_RSP:
117:                    return "XMIT_RSP";
118:                default:
119:                    return "<undefined>";
120:                }
121:            }
122:
123:            public String toString() {
124:                StringBuffer ret = new StringBuffer();
125:                ret.append("[").append(type2Str(type));
126:                switch (type) {
127:                case MSG: // seqno and sender
128:                    ret.append(", seqno=").append(seqno);
129:                    break;
130:                case XMIT_REQ: // range and sender
131:                case XMIT_RSP: // range and sender
132:                    if (range != null)
133:                        ret.append(", range=").append(range);
134:                    break;
135:                }
136:
137:                if (sender != null)
138:                    ret.append(", sender=").append(sender);
139:                ret.append(']');
140:                return ret.toString();
141:            }
142:
143:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.