KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > scalagent > kjoram > SessionDaemon


1 /*
2  * JORAM: Java(TM) Open Reliable Asynchronous Messaging
3  * Copyright (C) 2001 - ScalAgent Distributed Technologies
4  * Copyright (C) 1996 - 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): Nicolas Tachker (ScalAgent)
23  */

24 package com.scalagent.kjoram;
25
26 import com.scalagent.kjoram.jms.AbstractJmsReply;
27
28
29 /**
30  * A <code>SessionDaemon</code> daemon is attached to a session for
31  * serializing the delivery of asynchronous replies to its consumers.
32  */

33 class SessionDaemon extends com.scalagent.kjoram.util.Daemon
34 {
35   /** The session the daemon is attached to. */
36   private Session sess;
37
38   /**
39    * Constructs a session daemon.
40    *
41    * @param sess The session the daemon belongs to.
42    */

43   public SessionDaemon(Session sess)
44   {
45     super(sess.toString());
46     this.sess = sess;
47     if (JoramTracing.dbgClient)
48       JoramTracing.log(JoramTracing.DEBUG, "SessionDaemon: " + sess
49                        + ": created.");
50   }
51
52   /** The daemon's loop. */
53   public void run()
54   {
55     AbstractJmsReply reply;
56
57     try {
58       while (running) {
59         canStop = true;
60
61         // Expecting a reply:
62
try {
63           reply = (AbstractJmsReply) sess.repliesIn.get();
64         }
65         catch (Exception JavaDoc iE) {
66           continue;
67         }
68         canStop = false;
69
70         // Processing it through the session:
71
sess.distribute(reply);
72         sess.repliesIn.pop();
73       }
74     }
75     finally {
76       finish();
77     }
78   }
79
80   /** Shuts the daemon down. */
81   public void shutdown()
82   {
83     if (JoramTracing.dbgClient)
84       JoramTracing.log(JoramTracing.DEBUG, "SessionDaemon shut down.");
85   }
86
87   /** Releases the daemon's resources. */
88   public void close()
89   {
90     if (JoramTracing.dbgClient)
91       JoramTracing.log(JoramTracing.DEBUG, "SessionDaemon: finished.");
92   }
93 }
94
Popular Tags