package omq.server.remote.request; import java.util.ArrayList; import java.util.concurrent.BlockingQueue; import java.util.concurrent.LinkedBlockingDeque; import com.rabbitmq.client.QueueingConsumer; import com.rabbitmq.client.QueueingConsumer.Delivery; /** * * @author Sergi Toda * */ public class RemoteWrapper { private RemoteObject obj; private int numThreads; private ArrayList invocationList; private BlockingQueue deliveryQueue; public RemoteWrapper(RemoteObject obj, int numThreads) { this.obj = obj; this.numThreads = numThreads; invocationList = new ArrayList(); deliveryQueue = new LinkedBlockingDeque(); System.out.println("RemoteWrapper -> Object: " + obj.getRef() + ", numthreads listening = " + numThreads); for (int i = 0; i < numThreads; i++) { InvocationThread thread = new InvocationThread(obj, deliveryQueue); invocationList.add(thread); thread.start(); } } public void notifyDelivery(Delivery delivery) throws Exception { this.deliveryQueue.put(delivery); } public void stopRemoteWrapper() { for (InvocationThread thread : invocationList) { thread.interrupt(); } } public RemoteObject getObj() { return obj; } public void setObj(RemoteObject obj) { this.obj = obj; } public int getNumThreads() { return numThreads; } public void setNumThreads(int numThreads) { this.numThreads = numThreads; } public ArrayList getInvocationList() { return invocationList; } public void setInvocationList(ArrayList invocationList) { this.invocationList = invocationList; } public BlockingQueue getDeliveryQueue() { return deliveryQueue; } public void setDeliveryQueue(BlockingQueue deliveryQueue) { this.deliveryQueue = deliveryQueue; } }