1 26 package org.objectweb.joram.mom.proxies; 27 28 import java.util.Enumeration ; 29 import java.util.Hashtable ; 30 31 import org.objectweb.joram.mom.notifications.ClientMessages; 32 import org.objectweb.joram.mom.notifications.RequestGroupNot; 33 import org.objectweb.joram.shared.client.ProducerMessages; 34 35 import fr.dyade.aaa.agent.AgentId; 36 37 40 public class RequestBuffer { 41 42 private ProxyAgentItf proxyAgent; 43 44 private Hashtable nots = new Hashtable (); 45 46 public RequestBuffer(ProxyAgentItf proxy) { 47 proxyAgent = proxy; 48 } 49 50 public void put(int key, ProducerMessages req) { 51 AgentId to = AgentId.fromString(req.getTarget()); 52 RequestGroupNot not = (RequestGroupNot) nots.get(to); 53 if (not == null) { 54 not = new RequestGroupNot(); 55 nots.put(to, not); 56 } 57 ClientMessages cm = new ClientMessages(key, req.getRequestId(), req 58 .getMessages()); 59 if (to.getTo() == proxyAgent.getId().getTo()) { 60 cm.setPersistent(false); 61 } 62 if (req.getAsyncSend()) { 63 cm.setAsyncSend(true); 64 } 65 not.addClientMessages(cm); 66 } 67 68 public void flush() { 69 if (nots.size() > 0) { 70 Enumeration ids = nots.keys(); 71 Enumeration notifs = nots.elements(); 72 while (notifs.hasMoreElements()) { 73 AgentId to = (AgentId) ids.nextElement(); 74 RequestGroupNot not = (RequestGroupNot) notifs.nextElement(); 75 if (to.getTo() == proxyAgent.getId().getTo()) { 76 not.setPersistent(false); 77 proxyAgent.sendNot(to, not); 78 } else { 79 proxyAgent.sendNot(to, not); 80 } 81 } 82 nots.clear(); 83 } 84 } 85 } 86 | Popular Tags |