KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > joram > mom > dest > Topic


1 /*
2  * JORAM: Java(TM) Open Reliable Asynchronous Messaging
3  * Copyright (C) 2001 - 2007 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): Frederic Maistre (INRIA)
22  * Contributor(s): ScalAgent Distributed Technologies
23  */

24 package org.objectweb.joram.mom.dest;
25
26 import java.util.Properties JavaDoc;
27
28 import org.objectweb.joram.mom.notifications.AbstractRequest;
29 import org.objectweb.joram.mom.notifications.ClusterRequest;
30 import org.objectweb.joram.mom.notifications.DestinationAdminRequestNot;
31 import org.objectweb.joram.mom.notifications.ExceptionReply;
32 import org.objectweb.joram.mom.notifications.Monit_GetCluster;
33 import org.objectweb.joram.mom.notifications.Monit_GetFather;
34 import org.objectweb.joram.mom.notifications.Monit_GetSubscriptions;
35 import org.objectweb.joram.mom.notifications.SetFatherRequest;
36 import org.objectweb.joram.mom.notifications.SubscribeRequest;
37 import org.objectweb.joram.mom.notifications.UnclusterRequest;
38 import org.objectweb.joram.mom.notifications.UnsetFatherRequest;
39 import org.objectweb.joram.mom.notifications.UnsubscribeRequest;
40 import org.objectweb.joram.shared.JoramTracing;
41 import org.objectweb.joram.shared.excepts.MomException;
42 import org.objectweb.util.monolog.api.BasicLevel;
43
44 import fr.dyade.aaa.agent.AgentId;
45 import fr.dyade.aaa.agent.Channel;
46 import fr.dyade.aaa.agent.Notification;
47
48 /**
49  * A <code>Topic</code> agent is an agent hosting a MOM topic, and which
50  * behaviour is provided by a <code>TopicImpl</code> instance.
51  *
52  * @see TopicImpl
53  */

54 public class Topic extends Destination {
55   
56   public static final String JavaDoc TOPIC_TYPE = "topic";
57   
58   public static String JavaDoc getDestinationType() {
59     return TOPIC_TYPE;
60   }
61
62   /**
63    * Empty constructor for newInstance().
64    */

65   public Topic() {}
66
67   /**
68    * Constructor with parameters for fixing the topic and specifying its
69    * identifier.
70    * It is uniquely used by the AdminTopic agent.
71    */

72   protected Topic(String JavaDoc name, boolean fixed, int stamp) {
73     super(name, fixed, stamp);
74   }
75
76   /**
77    * Creates the <tt>TopicImpl</tt>.
78    *
79    * @param adminId Identifier of the topic administrator.
80    * @param prop The initial set of properties.
81    */

82   public DestinationImpl createsImpl(AgentId adminId, Properties JavaDoc prop) {
83     return new TopicImpl(getId(), adminId, prop);
84   }
85   
86   /**
87    * Distributes the received notifications to the appropriate reactions.
88    * @throws Exception
89    */

90   public void react(AgentId from, Notification not) throws Exception JavaDoc {
91     ((TopicImpl)destImpl).setAlreadySentLocally(false);
92     int reqId = -1;
93     if (not instanceof AbstractRequest)
94       reqId = ((AbstractRequest) not).getRequestId();
95
96     if (JoramTracing.dbgDestination.isLoggable(BasicLevel.DEBUG))
97       JoramTracing.dbgDestination.log(BasicLevel.DEBUG, "--- " + this
98                                     + ": got " + not.getClass().getName()
99                                     + " with id: " + reqId
100                                     + " from: " + from.toString());
101     try {
102       if (not instanceof ClusterRequest)
103         ((TopicImpl)destImpl).clusterRequest(from, (ClusterRequest) not);
104       else if (not instanceof ClusterTest)
105         ((TopicImpl)destImpl).clusterTest(from, (ClusterTest) not);
106       else if (not instanceof ClusterAck)
107         ((TopicImpl)destImpl).clusterAck(from, (ClusterAck) not);
108       else if (not instanceof ClusterNot)
109         ((TopicImpl)destImpl).clusterNot(from, (ClusterNot) not);
110       else if (not instanceof UnclusterRequest)
111         ((TopicImpl)destImpl).unclusterRequest(from, (UnclusterRequest) not);
112       else if (not instanceof UnclusterNot)
113         ((TopicImpl)destImpl).unclusterNot(from, (UnclusterNot) not);
114       else if (not instanceof SetFatherRequest)
115         ((TopicImpl)destImpl).setFatherRequest(from, (SetFatherRequest) not);
116       else if (not instanceof FatherTest)
117         ((TopicImpl)destImpl).fatherTest(from, (FatherTest) not);
118       else if (not instanceof FatherAck)
119         ((TopicImpl)destImpl).fatherAck(from, (FatherAck) not);
120       else if (not instanceof UnsetFatherRequest)
121         ((TopicImpl)destImpl).unsetFatherRequest(from, (UnsetFatherRequest) not);
122       else if (not instanceof Monit_GetSubscriptions)
123         ((TopicImpl)destImpl).monitGetSubscriptions(from, (Monit_GetSubscriptions) not);
124       else if (not instanceof Monit_GetFather)
125         ((TopicImpl)destImpl).monitGetFather(from, (Monit_GetFather) not);
126       else if (not instanceof Monit_GetCluster)
127         ((TopicImpl)destImpl).monitGetCluster(from, (Monit_GetCluster) not);
128       else if (not instanceof SubscribeRequest)
129         ((TopicImpl)destImpl).subscribeRequest(from, (SubscribeRequest) not);
130       else if (not instanceof UnsubscribeRequest)
131         ((TopicImpl)destImpl).unsubscribeRequest(from, (UnsubscribeRequest) not);
132       else if (not instanceof TopicForwardNot)
133         ((TopicImpl)destImpl).topicForwardNot(from, (TopicForwardNot) not);
134       else if (not instanceof DestinationAdminRequestNot)
135         ((TopicImpl)destImpl).destinationAdminRequestNot(from, (DestinationAdminRequestNot) not);
136       else
137         super.react(from, not);
138     } catch (MomException exc) {
139       // MOM exceptions are sent to the requester.
140
if (logger.isLoggable(BasicLevel.WARN))
141         logger.log(BasicLevel.WARN, exc);
142
143       AbstractRequest req = (AbstractRequest) not;
144       Channel.sendTo(from, new ExceptionReply(req, exc));
145     }
146   }
147
148 }
149
Popular Tags