KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > joram > mom > proxies > RequestBuffer


1 /*
2  * JORAM: Java(TM) Open Reliable Asynchronous Messaging
3  * Copyright (C) 2001 - 2006 ScalAgent Distributed Technologies
4  * Copyright (C) 1996 - 2000 Dyade
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA.
20  *
21  * Initial developer(s): ScalAgent Distributed Technologies
22  *
23  * Created on 16 mai 2006
24  *
25  */

26 package org.objectweb.joram.mom.proxies;
27
28 import java.util.Enumeration JavaDoc;
29 import java.util.Hashtable JavaDoc;
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 /**
38  *
39  */

40 public class RequestBuffer {
41   
42   private ProxyAgentItf proxyAgent;
43   
44   private Hashtable JavaDoc nots = new Hashtable JavaDoc();
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 JavaDoc ids = nots.keys();
71       Enumeration JavaDoc 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