KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > fr > dyade > aaa > jndi2 > ha > HARequestContext


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

22 package fr.dyade.aaa.jndi2.ha;
23
24 import fr.dyade.aaa.jndi2.msg.*;
25 import fr.dyade.aaa.jndi2.server.*;
26
27 import java.net.*;
28 import java.io.*;
29
30 import org.objectweb.util.monolog.api.BasicLevel;
31 import org.objectweb.util.monolog.api.Logger;
32
33 public class HARequestContext extends RequestContext {
34
35   private transient IOControl ioCtrl;
36
37   private JndiRequest request;
38
39   private JndiReply reply;
40
41   private int id;
42
43   private transient HARequestManager manager;
44
45   HARequestContext(IOControl ioCtrl,
46                    int id) throws Exception JavaDoc {
47     this.ioCtrl = ioCtrl;
48     this.id = id;
49     request = (JndiRequest)ioCtrl.readObject();
50   }
51
52   public final int getId() {
53     return id;
54   }
55
56   void recover(HARequestContext ctx) {
57     ioCtrl = ctx.ioCtrl;
58   }
59
60   final JndiReply getReply() {
61     return reply;
62   }
63
64 // final Socket getSocket() {
65
// return ioCtrl.getSocket();
66
// }
67

68   public final JndiRequest getRequest() {
69     return request;
70   }
71
72   public void reply(JndiReply reply) {
73     this.reply = reply;
74     if (ioCtrl != null) {
75       try {
76         ioCtrl.writeObject(reply);
77       } catch (Exception JavaDoc exc) {
78         Trace.logger.log(BasicLevel.ERROR, "", exc);
79       } finally {
80         ioCtrl.close();
81       }
82     }
83   }
84
85   private void close() {
86     // Closes the connection
87
ioCtrl.close();
88     if (manager != null)
89       manager.removeContext(id);
90   }
91   
92   public String JavaDoc toString() {
93     return '(' + super.toString() +
94       ",request=" + request + ')';
95   }
96 }
97
Popular Tags