-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathBTreeCluWorkerThread.java
More file actions
61 lines (57 loc) · 1.57 KB
/
BTreeCluWorkerThread.java
File metadata and controls
61 lines (57 loc) · 1.57 KB
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
/*
* Cluster B*-Tree implementation for the
* Concurrent Search Tree Project for
* Parallel Computing I
*
* Author: David C. Larsen <dcl9934@cs.rit.edu>
* Date: April. 12, 2011
*/
import edu.rit.pj.Comm;
import edu.rit.mp.*;
import edu.rit.mp.buf.*;
/**
* Thread responsible for sending data to a backend node, without blocking
* the main thread.
*/
public class BTreeCluWorkerThread extends Thread
{
Comm world;
int rank;
char command;
Integer key;
Integer value;
IntegerBuf response;
BTreeOperation<Integer, Integer> op;
BTreeCluWorkerThread( Comm world, int rank, BTreeOperation<Integer, Integer> operation )
{
this.world = world;
this.rank = rank;
this.command = operation.operation;
this.key = operation.key;
this.value = operation.value;
this.response = new IntegerItemBuf();
this.op = operation;
}
public void run()
{
try{
world.send( rank, CharacterBuf.buffer(command) );
switch( command )
{
case 'g':
world.send( rank, IntegerBuf.buffer(key) );
case 'p':
world.send( rank, IntegerBuf.buffer(key) );
world.send( rank, IntegerBuf.buffer(value) );
case 'q':
return;
}
response = new IntegerItemBuf();
world.receive( rank, response );
op.putResult( response.get(0) );
} catch( Exception ex )
{
System.err.println(ex);
}
}
}