KickJava   Java API By Example, From Geeks To Geeks.

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


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.io.IOException JavaDoc;
27 import java.util.Calendar JavaDoc;
28 import java.util.Enumeration JavaDoc;
29 import java.util.Hashtable JavaDoc;
30 import java.util.Properties JavaDoc;
31 import java.util.Vector JavaDoc;
32
33 import org.objectweb.joram.mom.notifications.AdminReply;
34 import org.objectweb.joram.mom.notifications.ClientMessages;
35 import org.objectweb.joram.mom.notifications.Monit_FreeAccess;
36 import org.objectweb.joram.mom.notifications.Monit_FreeAccessRep;
37 import org.objectweb.joram.mom.notifications.Monit_GetDMQSettings;
38 import org.objectweb.joram.mom.notifications.Monit_GetDMQSettingsRep;
39 import org.objectweb.joram.mom.notifications.Monit_GetReaders;
40 import org.objectweb.joram.mom.notifications.Monit_GetStat;
41 import org.objectweb.joram.mom.notifications.Monit_GetStatRep;
42 import org.objectweb.joram.mom.notifications.Monit_GetUsersRep;
43 import org.objectweb.joram.mom.notifications.Monit_GetWriters;
44 import org.objectweb.joram.mom.notifications.RequestGroupNot;
45 import org.objectweb.joram.mom.notifications.SetDMQRequest;
46 import org.objectweb.joram.mom.notifications.SetRightRequest;
47 import org.objectweb.joram.mom.notifications.SpecialAdminRequest;
48 import org.objectweb.joram.mom.proxies.SendRepliesNot;
49 import org.objectweb.joram.mom.proxies.SendReplyNot;
50 import org.objectweb.joram.shared.excepts.AccessException;
51 import org.objectweb.joram.shared.excepts.RequestException;
52 import org.objectweb.joram.shared.messages.Message;
53 import org.objectweb.util.monolog.api.BasicLevel;
54 import org.objectweb.util.monolog.api.Logger;
55
56 import fr.dyade.aaa.agent.AgentId;
57 import fr.dyade.aaa.agent.Channel;
58 import fr.dyade.aaa.agent.DeleteNot;
59 import fr.dyade.aaa.agent.Notification;
60 import fr.dyade.aaa.agent.UnknownAgent;
61 import fr.dyade.aaa.util.Debug;
62
63 /**
64  * The <code>DestinationImpl</code> class implements the common behaviour of
65  * MOM destinations.
66  */

67 public abstract class DestinationImpl implements java.io.Serializable JavaDoc, DestinationImplMBean {
68   public static Logger logger = Debug.getLogger(DestinationImpl.class.getName());
69   
70   /**
71    * <code>true</code> if the destination successfully processed a deletion
72    * request.
73    */

74   private boolean deletable = false;
75
76   /** Identifier of the destination's administrator. */
77   private AgentId adminId;
78   /** Identifier of the agent hosting the destination. */
79   protected AgentId destId;
80
81   /** <code>true</code> if the READ access is granted to everybody. */
82   protected boolean freeReading = false;
83   /** <code>true</code> if the WRITE access is granted to everybody. */
84   protected boolean freeWriting = false;
85   /** Table of the destination readers and writers. */
86   protected Hashtable JavaDoc clients;
87
88   /** READ access value. */
89   public static int READ = 1;
90   /** WRITE access value. */
91   public static int WRITE = 2;
92   /** READ and WRITE access value. */
93   public static int READWRITE = 3;
94
95   /**
96    * Identifier of the dead message queue this destination must send its
97    * dead messages to, if any.
98    */

99   protected AgentId dmqId = null;
100
101   /**
102    * Transient <code>StringBuffer</code> used to build message, this buffer
103    * is created during agent <tt>AdminTopicinitialization</tt>, then reused
104    * during the topic life.
105    */

106   transient StringBuffer JavaDoc strbuf;
107
108   private Destination agent;
109
110   /**
111    * date of creation.
112    */

113   public long creationDate = -1;
114
115   protected long nbMsgsReceiveSinceCreation = 0;
116   protected long nbMsgsDeliverSinceCreation = 0;
117   protected long nbMsgsSendToDMQSinceCreation = 0;
118
119   /**
120    * Constructs a <code>DestinationImpl</code>.
121    *
122    * @param destId Identifier of the agent hosting the destination.
123    * @param adminId Identifier of the administrator of the destination.
124    * @param prop The initial set of properties.
125    */

126   public DestinationImpl(AgentId destId, AgentId adminId, Properties JavaDoc prop) {
127     this.destId = destId;
128     this.adminId = adminId;
129     clients = new Hashtable JavaDoc();
130     strbuf = new StringBuffer JavaDoc();
131
132     if (creationDate == -1)
133       creationDate = System.currentTimeMillis();
134
135     if (logger.isLoggable(BasicLevel.DEBUG))
136       logger.log(BasicLevel.DEBUG, this + ", created.");
137   }
138
139   void setNoSave() {
140     if (agent != null) {
141       if (logger.isLoggable(BasicLevel.DEBUG))
142         logger.log(BasicLevel.DEBUG, this + ".setNoSave().");
143       agent.setNoSave();
144     }
145   }
146
147   void setSave() {
148     if (agent != null) {
149       if (logger.isLoggable(BasicLevel.DEBUG))
150         logger.log(BasicLevel.DEBUG, this + ".setSave().");
151       agent.setSave();
152     }
153   }
154
155   public void setAgent(Destination agent) {
156     // state change, so save.
157
setSave();
158     this.agent = agent;
159   }
160
161   protected boolean isLocal(AgentId id) {
162     return (destId.getTo() == id.getTo());
163   }
164
165   /** Returns <code>true</code> if the destination might be deleted. */
166   public boolean canBeDeleted() {
167     return deletable;
168   }
169
170   /**
171    * Method implementing the reaction to a <code>SetRightRequest</code>
172    * notification requesting rights to be set for a user.
173    *
174    * @exception AccessException If the requester is not the administrator.
175    */

176   public void setRightRequest(AgentId from, SetRightRequest not) throws AccessException {
177     if (! isAdministrator(from))
178       throw new AccessException("ADMIN right not granted");
179
180     AgentId user = not.getClient();
181     int right = not.getRight();
182     String JavaDoc info;
183
184     try {
185       processSetRight(user,right);
186       doRightRequest(not);
187       info = strbuf.append("Request [")
188         .append(not.getClass().getName())
189         .append("], sent to Destination [")
190         .append(destId)
191         .append("], successful [true]: user [")
192         .append(user)
193         .append("] set with right [" + right +"]").toString();
194       strbuf.setLength(0);
195       forward(from, new AdminReply(not, true, info));
196     } catch (RequestException exc) {
197       info = strbuf.append("Request [")
198         .append(not.getClass().getName())
199         .append("], sent to Destination [")
200         .append(destId)
201         .append("], successful [false]: ")
202         .append(exc.getMessage()).toString();
203       strbuf.setLength(0);
204       forward(from, new AdminReply(not, false, info));
205     }
206
207     if (logger.isLoggable(BasicLevel.DEBUG))
208       logger.log(BasicLevel.DEBUG, info);
209   }
210
211   /** set user right. */
212   protected void processSetRight(AgentId user, int right)
213     throws RequestException {
214     // state change, so save.
215
setSave();
216
217     // Setting "all" users rights:
218
if (user == null) {
219       if (right == READ)
220         freeReading = true;
221       else if (right == WRITE)
222         freeWriting = true;
223       else if (right == -READ)
224         freeReading = false;
225       else if (right == -WRITE)
226         freeWriting = false;
227       else
228         throw new RequestException("Invalid right value: " + right);
229     } else {
230       // Setting a specific user right:
231
Integer JavaDoc currentRight = (Integer JavaDoc) clients.get(user);
232       if (right == READ) {
233         if (currentRight != null && currentRight.intValue() == WRITE)
234           clients.put(user, new Integer JavaDoc(READWRITE));
235         else
236           clients.put(user, new Integer JavaDoc(READ));
237       } else if (right == WRITE) {
238         if (currentRight != null && currentRight.intValue() == READ)
239           clients.put(user, new Integer JavaDoc(READWRITE));
240         else
241           clients.put(user, new Integer JavaDoc(WRITE));
242       } else if (right == -READ) {
243         if (currentRight != null && currentRight.intValue() == READWRITE)
244           clients.put(user, new Integer JavaDoc(WRITE));
245         else if (currentRight != null && currentRight.intValue() == READ)
246           clients.remove(user);
247       } else if (right == -WRITE) {
248         if (currentRight != null && currentRight.intValue() == READWRITE)
249           clients.put(user, new Integer JavaDoc(READ));
250         else if (currentRight != null && currentRight.intValue() == WRITE)
251           clients.remove(user);
252       } else
253         throw new RequestException("Invalid right value: " + right);
254     }
255   }
256     
257   /**
258    * Method implementing the reaction to a <code>SetDMQRequest</code>
259    * notification setting the dead message queue identifier for this
260    * destination.
261    *
262    * @exception AccessException If the requester is not the administrator.
263    */

264   public void setDMQRequest(AgentId from, SetDMQRequest not) throws AccessException {
265     if (! isAdministrator(from))
266       throw new AccessException("ADMIN right not granted");
267
268     // state change, so save.
269
setSave();
270
271     dmqId = not.getDmqId();
272     
273     String JavaDoc info = strbuf.append("Request [")
274       .append(not.getClass().getName())
275       .append("], sent to Destination [")
276       .append(destId)
277       .append("], successful [true]: dmq [")
278       .append(dmqId)
279       .append("] set").toString();
280     strbuf.setLength(0);
281     forward(from, new AdminReply(not, true, info));
282     
283     if (logger.isLoggable(BasicLevel.DEBUG))
284       logger.log(BasicLevel.DEBUG, info);
285   }
286
287   /**
288    * Method implementing the reaction to a <code>Monit_GetReaders</code>
289    * notification requesting the identifiers of the destination's readers.
290    *
291    * @exception AccessException If the requester is not the administrator.
292    */

293   public void monitGetReaders(AgentId from, Monit_GetReaders not) throws AccessException {
294     if (! isAdministrator(from))
295       throw new AccessException("ADMIN right not granted");
296
297     AgentId key;
298     int right;
299     Vector JavaDoc readers = new Vector JavaDoc();
300     for (Enumeration JavaDoc keys = clients.keys(); keys.hasMoreElements();) {
301       key = (AgentId) keys.nextElement();
302       right = ((Integer JavaDoc) clients.get(key)).intValue();
303
304       if (right == READ || right == READWRITE)
305         readers.add(key);
306     }
307     forward(from, new Monit_GetUsersRep(not, readers));
308   }
309
310   /**
311    * Method implementing the reaction to a <code>Monit_GetWriters</code>
312    * notification requesting the identifiers of the destination's writers.
313    *
314    * @exception AccessException If the requester is not the administrator.
315    */

316   public void monitGetWriters(AgentId from, Monit_GetWriters not) throws AccessException {
317     if (! isAdministrator(from))
318       throw new AccessException("ADMIN right not granted");
319
320     AgentId key;
321     int right;
322     Vector JavaDoc writers = new Vector JavaDoc();
323     for (Enumeration JavaDoc keys = clients.keys(); keys.hasMoreElements();) {
324       key = (AgentId) keys.nextElement();
325       right = ((Integer JavaDoc) clients.get(key)).intValue();
326
327       if (right == WRITE || right == READWRITE)
328         writers.add(key);
329     }
330     forward(from, new Monit_GetUsersRep(not, writers));
331   }
332
333   public static String JavaDoc[] _rights = {":R;", ";W;", ":RW;"};
334
335   /**
336    * Returns a string representation of the rights set on this destination.
337    *
338    * @return the rights set on this destination.
339    */

340   public String JavaDoc[] getRights() {
341     String JavaDoc rigths[] = new String JavaDoc[clients.size()];
342
343     AgentId key;
344     int right;
345
346     int i=0;
347     for (Enumeration JavaDoc keys = clients.keys(); keys.hasMoreElements();) {
348       key = (AgentId) keys.nextElement();
349       right = ((Integer JavaDoc) clients.get(key)).intValue();
350       rigths[i] = key.toString() + _rights[right -1];
351     }
352
353     return rigths;
354   }
355
356   /**
357    * Returns a string representation of rights set on this destination for a
358    * particular user. The user is pointed out by its unique identifier.
359    *
360    * @param userid The user's unique identifier.
361    * @return the rights set on this destination.
362    */

363   public String JavaDoc getRight(String JavaDoc userid) {
364     AgentId key = AgentId.fromString(userid);
365     if (key == null) return userid + ":bad user;";
366     Integer JavaDoc right = (Integer JavaDoc) clients.get(key);
367     if (right == null) return userid + ":unknown;";
368
369     return userid + _rights[right.intValue() -1];
370   }
371
372 // public void setRight(String userid, String right) {
373
// AgentId key = AgentId.fromString(userid);
374

375 // // To be continued
376
// }
377

378   /**
379    * Method implementing the reaction to a <code>Monit_FreeAccess</code>
380    * notification requesting the free access status of this destination.
381    *
382    * @exception AccessException If the requester is not the administrator.
383    */

384   public void monitFreeAccess(AgentId from, Monit_FreeAccess not) throws AccessException {
385     if (! isAdministrator(from))
386       throw new AccessException("ADMIN right not granted");
387
388     forward(from, new Monit_FreeAccessRep(not, freeReading, freeWriting));
389   }
390
391   /**
392    * Method implementing the reaction to a <code>Monit_GetDMQSettings</code>
393    * notification requesting the destination's DMQ settings.
394    *
395    * @exception AccessException If the requester is not the administrator.
396    */

397   public void monitGetDMQSettings(AgentId from, Monit_GetDMQSettings not) throws AccessException {
398     if (! isAdministrator(from))
399       throw new AccessException("ADMIN right not granted");
400
401     String JavaDoc id = null;
402     if (dmqId != null)
403       id = dmqId.toString();
404
405     forward(from, new Monit_GetDMQSettingsRep(not, id, null));
406   }
407
408   /**
409    * Method implementing the reaction to a <code>Monit_GetStat</code>
410    * notification requesting to get statistic of this destination.
411    *
412    * @exception AccessException If the requester is not the administrator.
413    */

414   public void monitGetStat(AgentId from, Monit_GetStat not) throws AccessException {
415     if (! isAdministrator(from))
416       throw new AccessException("ADMIN right not granted");
417
418     Hashtable JavaDoc stats = new Hashtable JavaDoc();
419     stats.put("nbMsgsReceiveSinceCreation", new Long JavaDoc(nbMsgsReceiveSinceCreation));
420     stats.put("nbMsgsDeliverSinceCreation", new Long JavaDoc(nbMsgsDeliverSinceCreation));
421     stats.put("nbMsgsSendToDMQSinceCreation", new Long JavaDoc(nbMsgsSendToDMQSinceCreation));
422     stats.put("creationDate", new Long JavaDoc(creationDate));
423
424     forward(from, new Monit_GetStatRep(not, stats));
425   }
426
427   /**
428    * Method implementing the reaction to a <code>ClientMessages</code>
429    * notification holding messages sent by a client.
430    * <p>
431    * If the sender is not a writer on the destination the messages are
432    * sent to the DMQ and an exception is thrown. Otherwise, the processing of
433    * the received messages is performed in subclasses.
434    *
435    * @exception AccessException If the sender is not a WRITER on the
436    * destination.
437    */

438   protected void clientMessages(AgentId from, ClientMessages not) throws AccessException {
439     if (logger.isLoggable(BasicLevel.DEBUG))
440       logger.log(BasicLevel.DEBUG,
441                  "DestinationImpl.clientMessages(" + from + ',' + not + ')');
442
443     // If sender is not a writer, sending the messages to the DMQ, and
444
// throwing an exception:
445
if (! isWriter(from)) {
446       ClientMessages deadM;
447       deadM = new ClientMessages(not.getClientContext(), not.getRequestId());
448
449       Message msg;
450       for (Enumeration JavaDoc msgs = not.getMessages().elements();
451            msgs.hasMoreElements();) {
452         msg = (Message) msgs.nextElement();
453         msg.notWriteable = true;
454         deadM.addMessage(msg);
455       }
456       sendToDMQ(deadM, not.getDMQId());
457       throw new AccessException("WRITE right not granted");
458     }
459
460     doClientMessages(from, not);
461
462     // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
463
// for topic performance : must send reply after process ClientMessage
464
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
465

466     if (! not.getPersistent() && !not.getAsyncSend()) {
467       forward(from, new SendReplyNot(not.getClientContext(), not.getRequestId()));
468     }
469   }
470
471   /**
472    * Method implementing the reaction to an <code>UnknownAgent</code>
473    * notification.
474    * <p>
475    * If the unknown agent is the DMQ, its identifier is set to null. If it
476    * is a client of the destination, it is removed. Specific processing is
477    * also done in subclasses.
478    */

479   public void unknownAgent(AgentId from, UnknownAgent not) {
480     if (isAdministrator(not.agent)) {
481       if (logger.isLoggable(BasicLevel.ERROR))
482             logger.log(BasicLevel.ERROR,
483                        "Admin of dest " + destId + " does not exist anymore.");
484     } else if (not.agent.equals(dmqId)) {
485       // state change, so save.
486
setSave();
487       dmqId = null;
488     } else {
489       // state change, so save.
490
setSave();
491       clients.remove(from);
492       doUnknownAgent(not);
493     }
494   }
495
496   /**
497    * Method implementing the reaction to a <code>DeleteNot</code>
498    * notification requesting the deletion of the destination.
499    * <p>
500    * The processing is done in subclasses if the sender is an administrator.
501    */

502   public void deleteNot(AgentId from, DeleteNot not) {
503     if (! isAdministrator(from)) {
504       if (logger.isLoggable(BasicLevel.WARN))
505         logger.log(BasicLevel.WARN,
506                    "Unauthorized deletion request from " + from);
507     } else {
508       doDeleteNot(not);
509       // state change, so save.
510
setSave();
511       deletable = true;
512     }
513   }
514
515   /**
516    * Method implementing the reaction to a <code>SpecialAdminRequest</code>
517    * notification requesting the special administration of the destination.
518    * <p>
519    */

520   public void specialAdminRequest(AgentId from, SpecialAdminRequest not) {
521     String JavaDoc info;
522     Object JavaDoc obj = null;
523
524     // state change, so save.
525
setSave();
526
527     try {
528       if (!isAdministrator(from)) {
529         if (logger.isLoggable(BasicLevel.WARN))
530           logger.log(BasicLevel.WARN,
531                      "Unauthorized SpecialAdminRequest request from " + from);
532         throw new RequestException("ADMIN right not granted");
533       }
534       obj = specialAdminProcess(not);
535       info = strbuf.append("Request [")
536         .append(not.getClass().getName())
537         .append("], sent to Destination [")
538         .append(destId)
539         .append("], successful [true] ").toString();
540       strbuf.setLength(0);
541       forward(from, new AdminReply(not, true, info, obj));
542     } catch (RequestException exc) {
543       info = strbuf.append("Request [")
544         .append(not.getClass().getName())
545         .append("], sent to Destination [")
546         .append(destId)
547         .append("], successful [false]: ")
548         .append(exc.getMessage()).toString();
549       strbuf.setLength(0);
550       forward(from, new AdminReply(not, false, info, obj));
551     }
552     if (logger.isLoggable(BasicLevel.DEBUG))
553       logger.log(BasicLevel.DEBUG, info);
554   }
555   
556   public void requestGroupNot(AgentId from, RequestGroupNot not) {
557     Enumeration JavaDoc en = not.getClientMessages();
558     ClientMessages theCM = (ClientMessages) en.nextElement();
559     Vector JavaDoc replies = new Vector JavaDoc();
560     replies.addElement(new SendReplyNot(
561         theCM.getClientContext(),
562         theCM.getRequestId()));
563     while (en.hasMoreElements()) {
564       ClientMessages cm = (ClientMessages) en.nextElement();
565       Vector JavaDoc msgs = cm.getMessages();
566       for (int i = 0; i < msgs.size(); i++) {
567         theCM.addMessage((Message) msgs.elementAt(i));
568       }
569       if (! cm.getAsyncSend()) {
570         replies.addElement(new SendReplyNot(
571             cm.getClientContext(),
572             cm.getRequestId()));
573       }
574     }
575     
576     doClientMessages(from, theCM);
577
578     // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
579
// for topic performance : must send reply after process ClientMessage
580
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
581
if (! not.getPersistent() && replies.size() > 0) {
582       forward(from, new SendRepliesNot(replies));
583     }
584   }
585   
586   protected Object JavaDoc specialAdminProcess(SpecialAdminRequest not)
587     throws RequestException {
588     return null;
589   }
590
591   /**
592    * Checks the reading permission of a given client agent.
593    *
594    * @param client AgentId of the client requesting a reading permission.
595    */

596   protected boolean isReader(AgentId client) {
597     if (isAdministrator(client) || freeReading)
598       return true;
599
600     Integer JavaDoc clientRight = (Integer JavaDoc) clients.get(client);
601     if (clientRight == null)
602       return false;
603     else
604       return ((clientRight.intValue() == READ) ||
605               (clientRight.intValue() == READWRITE));
606   }
607
608   /**
609    * Checks the writing permission of a given client agent.
610    *
611    * @param client AgentId of the client requesting a writing permission.
612    */

613   protected boolean isWriter(AgentId client) {
614     if (isAdministrator(client) || freeWriting)
615       return true;
616
617     Integer JavaDoc clientRight = (Integer JavaDoc) clients.get(client);
618     if (clientRight == null)
619       return false;
620     else
621       return ((clientRight.intValue() == WRITE) ||
622               (clientRight.intValue() == READWRITE));
623   }
624
625   /**
626    * Checks the administering permission of a given client agent.
627    *
628    * @param client AgentId of the client requesting an admin permission.
629    */

630   protected boolean isAdministrator(AgentId client) {
631     return client.equals(adminId) ||
632       client.equals(AdminTopic.getDefault());
633   }
634
635   /**
636    * Sends dead messages to the appropriate dead message queue.
637    *
638    * @param deadMessages The dead messages.
639    * @param dmqId Identifier of the dead message queue to use,
640    * <code>null</code> if not provided.
641    */

642   protected void sendToDMQ(ClientMessages deadMessages, AgentId dmqId) {
643     Vector JavaDoc messages = deadMessages.getMessages();
644     nbMsgsSendToDMQSinceCreation = nbMsgsSendToDMQSinceCreation + messages.size();
645
646     AgentId destDmqId = null;
647     if (dmqId != null) {
648       // Sending the dead messages to the provided DMQ
649
destDmqId = dmqId;
650     } else if (this.dmqId != null) {
651       // Sending the dead messages to the destination's DMQ
652
destDmqId = this.dmqId;
653     } else if (DeadMQueueImpl.id != null) {
654       // Sending the dead messages to the server's default DMQ
655
destDmqId = DeadMQueueImpl.id;
656     }
657
658     if (destDmqId != null &&
659         ! destDmqId.equals(destId)) {
660       forward(destDmqId, deadMessages);
661     }
662     // Else it means that the dead message queue is
663
// the queue itself: drop the messages.
664
}
665
666   abstract protected void doRightRequest(SetRightRequest not);
667   abstract protected void doClientMessages(AgentId from, ClientMessages not);
668   abstract protected void doUnknownAgent(UnknownAgent not);
669   abstract protected void doDeleteNot(DeleteNot not);
670   
671   public SetRightRequest preProcess(SetRightRequest req) {
672     // nothing to do
673
return req;
674   }
675   
676   public void postProcess(SetRightRequest req) {
677     // nothing to do
678
}
679   
680   public ClientMessages preProcess(AgentId from, ClientMessages msgs) {
681     // nothing to do.
682
return msgs;
683   }
684   
685   public void postProcess(ClientMessages msgs) {
686     // nothing to do.
687
}
688   
689   private void writeObject(java.io.ObjectOutputStream JavaDoc out)
690     throws IOException JavaDoc {
691     out.writeBoolean(deletable);
692     out.writeObject(adminId);
693     out.writeObject(destId);
694     out.writeBoolean(freeReading);
695     out.writeBoolean(freeWriting);
696     out.writeObject(clients);
697     out.writeObject(dmqId);
698     out.writeLong(creationDate);
699     out.writeLong(nbMsgsReceiveSinceCreation);
700     out.writeLong(nbMsgsDeliverSinceCreation);
701     out.writeLong(nbMsgsSendToDMQSinceCreation);
702     out.writeObject(agent);
703   }
704
705   private void readObject(java.io.ObjectInputStream JavaDoc in)
706     throws IOException JavaDoc, ClassNotFoundException JavaDoc {
707     deletable = in.readBoolean();
708     adminId = (AgentId)in.readObject();
709     destId = (AgentId)in.readObject();
710     freeReading = in.readBoolean();
711     freeWriting = in.readBoolean();
712     clients = (Hashtable JavaDoc)in.readObject();
713     dmqId = (AgentId)in.readObject();
714     strbuf = new StringBuffer JavaDoc();
715     creationDate = in.readLong();
716     nbMsgsReceiveSinceCreation = in.readLong();
717     nbMsgsDeliverSinceCreation = in.readLong();
718     nbMsgsSendToDMQSinceCreation = in.readLong();
719     agent = (Destination)in.readObject();
720   }
721
722   // DestinationMBean interface
723

724   /**
725    * Returns the unique identifier of the destination.
726    *
727    * @return the unique identifier of the destination.
728    */

729   public final String JavaDoc getDestinationId() {
730     return destId.toString();
731   }
732
733   /**
734    * Tests if this destination is free for reading.
735    *
736    * @return true if anyone can receive messages from this destination;
737    * false otherwise.
738    */

739   public boolean isFreeReading() {
740     return freeReading;
741   }
742
743   /**
744    * Sets the <code>FreeReading</code> attribute for this destination.
745    *
746    * @param on if true anyone can receive message from this destination.
747    */

748   public void setFreeReading(boolean on) {
749     // state change, so save.
750
setSave();
751     freeReading = on;
752   }
753
754   /**
755    * Tests if this destination is free for writing.
756    *
757    * @return true if anyone can send messages to this destination;
758    * false otherwise.
759    */

760   public boolean isFreeWriting() {
761     return freeWriting;
762   }
763
764   /**
765    * Sets the <code>FreeWriting</code> attribute for this destination.
766    *
767    * @param on if true anyone can send message to this destination.
768    */

769   public void setFreeWriting(boolean on) {
770     // state change, so save.
771
setSave();
772     freeWriting = on;
773   }
774
775   /**
776    * Return the unique identifier of DMQ set for this destnation if any.
777    *
778    * @return the unique identifier of DMQ set for this destnation if any;
779    * null otherwise.
780    */

781   public String JavaDoc getDMQId() {
782     if (dmqId != null)
783       return dmqId.toString();
784     return null;
785   }
786
787   /**
788    * Returns this destination creation time as a long.
789    *
790    * @return the destination creation time as UTC milliseconds from the epoch.
791    */

792   public long getCreationTimeInMillis() {
793     return creationDate;
794   }
795
796   /**
797    * Returns this destination creation time through a <code>String</code> of
798    * the form: <code>dow mon dd hh:mm:ss zzz yyyy</code>.
799    *
800    * @return the destination creation time.
801    */

802   public String JavaDoc getCreationDate() {
803     Calendar JavaDoc cal = Calendar.getInstance();
804     cal.setTimeInMillis(creationDate);
805     return cal.getTime().toString();
806   }
807
808   /**
809    * Returns the number of messages received since creation time of this
810    * destination.
811    *
812    * @return the number of messages received since creation time.
813    */

814   public long getNbMsgsReceiveSinceCreation() {
815     return nbMsgsReceiveSinceCreation;
816   }
817   /**
818    * Returns the number of messages delivered since creation time of this
819    * destination. It includes messages all delivered messages to a consumer,
820    * already acknowledged or not.
821    *
822    * @return the number of messages delivered since creation time.
823    */

824   public long getNbMsgsDeliverSinceCreation() {
825     return nbMsgsDeliverSinceCreation;
826   }
827
828   /**
829    * Returns the number of erroneous messages forwarded to the DMQ since
830    * creation time of this destination..
831    *
832    * @return the number of erroneous messages forwarded to the DMQ.
833    */

834   public long getNbMsgsSendToDMQSinceCreation() {
835     return nbMsgsSendToDMQSinceCreation;
836   }
837
838   protected void replyToTopic(
839     org.objectweb.joram.shared.admin.AdminReply reply,
840     AgentId replyTo,
841     String JavaDoc requestMsgId,
842     String JavaDoc replyMsgId) {
843     Message message = new Message();
844     message.correlationId = requestMsgId;
845     message.timestamp = System.currentTimeMillis();
846     message.setDestination(replyTo.toString(), Topic.TOPIC_TYPE);
847     message.id = replyMsgId;;
848     try {
849       message.setObject(reply);
850       ClientMessages clientMessages = new ClientMessages(-1, -1, message);
851       forward(replyTo, clientMessages);
852     } catch (Exception JavaDoc exc) {
853       if (logger.isLoggable(BasicLevel.ERROR))
854         logger.log(BasicLevel.ERROR, "", exc);
855       throw new Error JavaDoc(exc.getMessage());
856     }
857   }
858   
859   public final void forward(AgentId to, Notification not) {
860     Channel.sendTo(to, not);
861   }
862 }
863
Popular Tags