com/scalagent/kjoram/SessionDaemon.java

00001 /*
00002  * JORAM: Java(TM) Open Reliable Asynchronous Messaging
00003  * Copyright (C) 2001 - ScalAgent Distributed Technologies
00004  * Copyright (C) 1996 - Dyade
00005  *
00006  * This library is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Lesser General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2.1 of the License, or any later version.
00010  * 
00011  * This library is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Lesser General Public License for more details.
00015  * 
00016  * You should have received a copy of the GNU Lesser General Public
00017  * License along with this library; if not, write to the Free Software
00018  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
00019  * USA.
00020  *
00021  * Initial developer(s): Frederic Maistre (INRIA)
00022  * Contributor(s): Nicolas Tachker (ScalAgent)
00023  */
00024 package com.scalagent.kjoram;
00025 
00026 import com.scalagent.kjoram.jms.AbstractJmsReply;
00027 
00028 
00033 class SessionDaemon extends com.scalagent.kjoram.util.Daemon
00034 {
00036   private Session sess;
00037 
00043   public SessionDaemon(Session sess)
00044   {
00045     super(sess.toString());
00046     this.sess = sess;
00047     if (JoramTracing.dbgClient)
00048       JoramTracing.log(JoramTracing.DEBUG, "SessionDaemon: " + sess
00049                        + ": created.");
00050   }
00051 
00053   public void run()
00054   {
00055     AbstractJmsReply reply;
00056 
00057     try {
00058       while (running) {
00059         canStop = true; 
00060 
00061         // Expecting a reply:
00062         try {
00063           reply = (AbstractJmsReply) sess.repliesIn.get();
00064         }
00065         catch (Exception iE) {
00066           continue;
00067         }
00068         canStop = false;
00069 
00070         // Processing it through the session:
00071         sess.distribute(reply);
00072         sess.repliesIn.pop();
00073       }
00074     }
00075     finally {
00076       finish();
00077     }
00078   }
00079 
00081   public void shutdown()
00082   {
00083     if (JoramTracing.dbgClient)
00084       JoramTracing.log(JoramTracing.DEBUG, "SessionDaemon shut down.");
00085   }
00086 
00088   public void close()
00089   {
00090     if (JoramTracing.dbgClient)
00091       JoramTracing.log(JoramTracing.DEBUG, "SessionDaemon: finished."); 
00092   }
00093 }

Generated on Tue Sep 16 16:14:25 2008 for joram by  doxygen 1.5.0