Line | |
---|
1 | package omq.server.remote.request; |
---|
2 | |
---|
3 | import java.util.concurrent.BlockingQueue; |
---|
4 | |
---|
5 | import omq.Remote; |
---|
6 | import omq.common.message.request.Request; |
---|
7 | import omq.common.util.Serializer; |
---|
8 | |
---|
9 | |
---|
10 | import com.rabbitmq.client.QueueingConsumer.Delivery; |
---|
11 | |
---|
12 | /** |
---|
13 | * |
---|
14 | * @author Sergi Toda <sergi.toda@estudiants.urv.cat> |
---|
15 | * |
---|
16 | */ |
---|
17 | public class InvocationThread extends Thread { |
---|
18 | private Remote obj; |
---|
19 | private BlockingQueue<Delivery> deliveryQueue; |
---|
20 | private boolean killed = false; |
---|
21 | |
---|
22 | public InvocationThread(Remote obj, BlockingQueue<Delivery> deliveryQueue) { |
---|
23 | this.obj = obj; |
---|
24 | this.deliveryQueue = deliveryQueue; |
---|
25 | } |
---|
26 | |
---|
27 | @Override |
---|
28 | public void run() { |
---|
29 | while (!killed) { |
---|
30 | try { |
---|
31 | // Get the delivery |
---|
32 | Delivery delivery = deliveryQueue.take(); |
---|
33 | |
---|
34 | // Get the request |
---|
35 | Request req = (Request) Serializer.deserialize(delivery.getBody()); |
---|
36 | |
---|
37 | // Invoke the method requested |
---|
38 | req.invokeRequest(obj, delivery.getProperties()); |
---|
39 | } catch (InterruptedException i) { |
---|
40 | killed = true; |
---|
41 | } catch (Exception e) { |
---|
42 | System.out.println("Error a l'Invocation Thread \nException: " + e); |
---|
43 | } |
---|
44 | |
---|
45 | } |
---|
46 | } |
---|
47 | |
---|
48 | public Remote getObj() { |
---|
49 | return obj; |
---|
50 | } |
---|
51 | |
---|
52 | public void setObj(Remote obj) { |
---|
53 | this.obj = obj; |
---|
54 | } |
---|
55 | |
---|
56 | public BlockingQueue<Delivery> getDeliveryQueue() { |
---|
57 | return deliveryQueue; |
---|
58 | } |
---|
59 | |
---|
60 | public void setDeliveryQueue(BlockingQueue<Delivery> deliveryQueue) { |
---|
61 | this.deliveryQueue = deliveryQueue; |
---|
62 | } |
---|
63 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.