File: recThread.java

package info (click to toggle)
spread 3.17.3-5
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 1,748 kB
  • ctags: 2,313
  • sloc: ansic: 15,627; sh: 2,591; java: 2,290; perl: 556; yacc: 523; makefile: 240; lex: 204; xml: 77
file content (192 lines) | stat: -rw-r--r-- 5,785 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
/*
 * The Spread Toolkit.
 *     
 * The contents of this file are subject to the Spread Open-Source
 * License, Version 1.0 (the ``License''); you may not use
 * this file except in compliance with the License.  You may obtain a
 * copy of the License at:
 *
 * http://www.spread.org/license/
 *
 * or in the file ``license.txt'' found in this distribution.
 *
 * Software distributed under the License is distributed on an AS IS basis, 
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 
 * for the specific language governing rights and limitations under the 
 * License.
 *
 * The Creators of Spread are:
 *  Yair Amir, Michal Miskin-Amir, Jonathan Stanton.
 *
 *  Copyright (C) 1993-2004 Spread Concepts LLC <spread@spreadconcepts.com>
 *
 *  All Rights Reserved.
 *
 * Major Contributor(s):
 * ---------------
 *    Cristina Nita-Rotaru crisn@cs.purdue.edu - group communication security.
 *    Theo Schlossnagle    jesus@omniti.com - Perl, skiplists, autoconf.
 *    Dan Schoenblum       dansch@cnds.jhu.edu - Java interface.
 *    John Schultz         jschultz@cnds.jhu.edu - contribution to process group membership.
 *
 */


import spread.*;

public class recThread extends Thread implements Runnable {
	private SpreadConnection connection;
        public  boolean threadSuspended;

	public recThread(SpreadConnection aConn) {
		connection=aConn;
	}
	private void DisplayMessage(SpreadMessage msg)
	{
		try
		{
   		        System.out.println("*****************RECTHREAD Received Message************");
			if(msg.isRegular())
			{
				System.out.print("Received a ");
				if(msg.isUnreliable())
					System.out.print("UNRELIABLE");
				else if(msg.isReliable())
					System.out.print("RELIABLE");
				else if(msg.isFifo())
					System.out.print("FIFO");
				else if(msg.isCausal())
					System.out.print("CAUSAL");
				else if(msg.isAgreed())
					System.out.print("AGREED");
				else if(msg.isSafe())
					System.out.print("SAFE");
				System.out.println(" message.");
				
				System.out.println("Sent by  " + msg.getSender() + ".");
				
				System.out.println("Type is " + msg.getType() + ".");
				
				if(msg.getEndianMismatch() == true)
					System.out.println("There is an endian mismatch.");
				else
					System.out.println("There is no endian mismatch.");
				
				SpreadGroup groups[] = msg.getGroups();
				System.out.println("To " + groups.length + " groups.");
				
				byte data[] = msg.getData();
				System.out.println("The data is " + data.length + " bytes.");
				
				System.out.println("The message is: " + new String(data));
			}
			else if ( msg.isMembership() )
			{
				MembershipInfo info = msg.getMembershipInfo();
				
				if(info.isRegularMembership())
				{
					SpreadGroup groups[] = msg.getGroups();
				
					System.out.println("Received a REGULAR membership.");
					System.out.println("For group " + info.getGroup() + ".");
					System.out.println("With " + groups.length + " members.");
					System.out.println("I am member " + msg.getType() + ".");
					for(int i = 0 ; i < groups.length ; i++)
						System.out.println("  " + groups[i]);
				
					System.out.println("Group ID is " + info.getGroupID());
				
					System.out.print("Due to ");
					if(info.isCausedByJoin())
					{
						System.out.println("the JOIN of " + info.getJoined() + ".");
					}
					else if(info.isCausedByLeave())
					{
						System.out.println("the LEAVE of " + info.getLeft() + ".");
					}
					else if(info.isCausedByDisconnect())
					{
						System.out.println("the DISCONNECT of " + info.getDisconnected() + ".");
					}
					else if(info.isCausedByNetwork())
					{
						SpreadGroup stayed[] = info.getStayed();
						System.out.println("NETWORK change.");
						System.out.println("VS set has " + stayed.length + " members:");
						for(int i = 0 ; i < stayed.length ; i++)
							System.out.println("  " + stayed[i]);
					}
				}
				else if(info.isTransition())
				{
					System.out.println("Received a TRANSITIONAL membership for group " + info.getGroup());
				}
				else if(info.isSelfLeave())
				{
					System.out.println("Received a SELF-LEAVE message for group " + info.getGroup());
				}
			} else if ( msg.isReject() )
			{
			        // Received a Reject message 
				System.out.print("Received a ");
				if(msg.isUnreliable())
					System.out.print("UNRELIABLE");
				else if(msg.isReliable())
					System.out.print("RELIABLE");
				else if(msg.isFifo())
					System.out.print("FIFO");
				else if(msg.isCausal())
					System.out.print("CAUSAL");
				else if(msg.isAgreed())
					System.out.print("AGREED");
				else if(msg.isSafe())
					System.out.print("SAFE");
				System.out.println(" REJECTED message.");
				
				System.out.println("Sent by  " + msg.getSender() + ".");
				
				System.out.println("Type is " + msg.getType() + ".");
				
				if(msg.getEndianMismatch() == true)
					System.out.println("There is an endian mismatch.");
				else
					System.out.println("There is no endian mismatch.");
				
				SpreadGroup groups[] = msg.getGroups();
				System.out.println("To " + groups.length + " groups.");
				
				byte data[] = msg.getData();
				System.out.println("The data is " + data.length + " bytes.");
				
				System.out.println("The message is: " + new String(data));
			} else {
			    System.out.println("Message is of unknown type: " + msg.getServiceType() );
			}
		}
		catch(Exception e)
		{
			e.printStackTrace();
			System.exit(1);
		}
	}
	
	public void run() {
	  while(true) {
            try {
	      DisplayMessage(connection.receive());

	      if (threadSuspended) {
                synchronized(this) {
                    while (threadSuspended) {
                        wait();
		    }
                }
	      }
	    } catch(Exception e) {

	    }
	  }
        }
}