source: trunk/src/main/java/omq/server/RemoteWrapper.java @ 49

Last change on this file since 49 was 49, checked in by stoda, 11 years ago

log4j added

File size: 2.0 KB
Line 
1package omq.server;
2
3import java.util.ArrayList;
4import java.util.concurrent.BlockingQueue;
5import java.util.concurrent.LinkedBlockingDeque;
6
7import org.apache.log4j.Logger;
8
9import com.rabbitmq.client.QueueingConsumer;
10import com.rabbitmq.client.QueueingConsumer.Delivery;
11
12/**
13 *
14 * @author Sergi Toda <sergi.toda@estudiants.urv.cat>
15 *
16 */
17public class RemoteWrapper {
18        private static final Logger logger = Logger.getLogger(RemoteWrapper.class.getName());
19
20        private RemoteObject obj;
21        private int numThreads;
22        private ArrayList<InvocationThread> invocationList;
23        private BlockingQueue<Delivery> deliveryQueue;
24
25        public RemoteWrapper(RemoteObject obj, int numThreads) {
26                this.obj = obj;
27                this.numThreads = numThreads;
28                invocationList = new ArrayList<InvocationThread>();
29                deliveryQueue = new LinkedBlockingDeque<QueueingConsumer.Delivery>();
30
31                logger.info("Object reference: " + obj.getRef() + ", numthreads listening = " + numThreads);
32
33                for (int i = 0; i < numThreads; i++) {
34                        InvocationThread thread = new InvocationThread(obj, deliveryQueue);
35                        invocationList.add(thread);
36                        thread.start();
37                }
38        }
39
40        public void notifyDelivery(Delivery delivery) throws Exception {
41                this.deliveryQueue.put(delivery);
42        }
43
44        public void stopRemoteWrapper() {
45                logger.warn("Stopping Invocation threads vinculed to " + obj.getRef());
46                for (InvocationThread thread : invocationList) {
47                        thread.interrupt();
48                }
49        }
50
51        public RemoteObject getObj() {
52                return obj;
53        }
54
55        public void setObj(RemoteObject obj) {
56                this.obj = obj;
57        }
58
59        public int getNumThreads() {
60                return numThreads;
61        }
62
63        public void setNumThreads(int numThreads) {
64                this.numThreads = numThreads;
65        }
66
67        public ArrayList<InvocationThread> getInvocationList() {
68                return invocationList;
69        }
70
71        public void setInvocationList(ArrayList<InvocationThread> invocationList) {
72                this.invocationList = invocationList;
73        }
74
75        public BlockingQueue<Delivery> getDeliveryQueue() {
76                return deliveryQueue;
77        }
78
79        public void setDeliveryQueue(BlockingQueue<Delivery> deliveryQueue) {
80                this.deliveryQueue = deliveryQueue;
81        }
82}
Note: See TracBrowser for help on using the repository browser.