I'm creating a program in Java in which a client can send read/write operations to a node which sends a read/write request to a supernode. The supernode is using a Thrift HaHs server. There are multiple nodes and thus should be able to handle concurrent operations. Writing is no proble, but I'm having a problem with reading.
Each time a node connects to the server, a thread will take its read/write request and put it in a queue (LinkedBlockingQueue since this is a critical section that needs to be locked). The server has a separate pool of worker threads that will process each request in the queue concurrently.
My problem is that after I get a specific file, I need to pass it back to the connecting node (using the same Thrift connection). However, I'm not sure how to do that since the requests are handled by separate worker threads. Here's the order of steps.
// node calls this supernode method (via Thrift RPC)
Request connect(Request req) {
queue.put(req)
return req;
}
// Inside Worker Thread class (which is inside supernode)
public void run() {
try {
while ( true ) {
Request req = queue.take();
processRequest(req);
}
}
catch ( InterruptedException ie ) {
// just terminate
}
}
Basically, I'm trying to figure out how I can send something back to the same Thrift socket inside processRequest
Any help would be much appreciated!