KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jacorb > orb > etf > ConnectionBase


1 /*
2  * JacORB - a free Java ORB
3  *
4  * Copyright (C) 1997-2004 Gerald Brose.
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) 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  * Library General Public License for more details.
15  *
16  * You should have received a copy of the GNU Library General Public
17  * License along with this library; if not, write to the Free
18  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19  */

20 package org.jacorb.orb.etf;
21
22 import java.io.*;
23
24 import org.apache.avalon.framework.logger.Logger;
25 import org.apache.avalon.framework.configuration.*;
26
27 /**
28  * This an abstract base implementation of the ETF::Connection interface.
29  *
30  *
31  *
32  * @author Nicolas Noffke / Andre Spiegel
33  * @version $Id: ConnectionBase.java,v 1.1 2004/08/25 09:31:41 simon.mcqueen Exp $
34  */

35
36 public abstract class ConnectionBase
37     extends org.omg.ETF._ConnectionLocalBase
38     implements Configurable
39 {
40     protected boolean connected = false;
41     
42     /**
43     * Optionally initialised to be used in the dumping of messages.
44     * See property <code>jacorb.debug.dump_outgoing_messages</code>.
45     * Default is off.
46     */

47     protected ByteArrayOutputStream b_out = null;
48     
49     /**
50     * Time out after a close connection has been received.
51     * See property <code>jacorb.connection.timeout_after_closeconnection</code>.
52     * Default 20000 milliseconds.
53     */

54     protected int finalTimeout = 20000;
55     
56     /**
57     * The Profile of the target / server side of the connection.
58     */

59     protected ProfileBase profile = null;
60
61     /** shared with sub classes */
62     protected Logger logger;
63     protected org.jacorb.config.Configuration configuration;
64     protected String JavaDoc connection_info;
65     
66     protected ConnectionBase()
67     {
68     }
69     
70     /**
71     * Initialise this instance as a copy of another. Intended for use within subclass
72     * constructors.
73     */

74     protected ConnectionBase(ConnectionBase other)
75     {
76         this.b_out = other.b_out;
77         this.connection_info = other.connection_info;
78         this.finalTimeout = other.finalTimeout;
79         this.profile = other.profile;
80     }
81     
82     public void configure(Configuration configuration)
83         throws ConfigurationException
84     {
85         this.configuration = (org.jacorb.config.Configuration)configuration;
86         logger = this.configuration.getNamedLogger(
87                  this.configuration.getLoggerName(this.getClass()));
88
89         if( configuration.getAttribute("jacorb.debug.dump_outgoing_messages","off").equals("on"))
90         {
91             b_out = new ByteArrayOutputStream();
92         }
93
94         finalTimeout =
95             configuration.getAttributeAsInteger("jacorb.connection.timeout_after_closeconnection",
96                                                 20000 );
97     }
98     
99     protected abstract void setTimeout(int timeout);
100     
101     protected abstract int getTimeout();
102     
103     public org.omg.ETF.Profile get_server_profile()
104     {
105         return profile;
106     }
107     
108     public synchronized boolean is_connected()
109     {
110         return connected;
111     }
112
113     /**
114      * This is used to tell the transport that a CloseConnection has
115      * been sent, and that it should set a timeout in case the client
116      * doesn't close its side of the connection right away.
117      *
118      * This should only be called on the thread that listens on the
119      * socket because timeouts are not applied until read() is called
120      * the next time.
121      */

122     public void turnOnFinalTimeout()
123     {
124         setTimeout( finalTimeout );
125     }
126
127     protected org.omg.CORBA.COMM_FAILURE JavaDoc to_COMM_FAILURE (IOException ex)
128     {
129         return new org.omg.CORBA.COMM_FAILURE JavaDoc("IOException: "
130                                                + ex.toString());
131     }
132
133     /**
134      * Wait for the given time_out period for incoming data on this
135      * connection. It shall return false if this call times out and
136      * no data is available. It may not throw a TIMEOUT exception.
137      * If data can already be read or arrives before the end of the
138      * time out, this function shall return true, immediately.
139      */

140     public boolean wait_next_data (long time_out)
141     {
142         throw new org.omg.CORBA.NO_IMPLEMENT JavaDoc();
143     }
144
145
146     /**
147      * A boolean flag describing whether this connection supports the
148      * Bidirectional GIOP mechanism as described by GIOP-1.2 in CORBA 2.3.1
149      * (OMG Document: formal/99-10-07). It shall return true if it does,
150      * and false if it does not.
151      */

152     public boolean supports_callback()
153     {
154         return true;
155     }
156
157     /**
158      * A flag directing the ORB to use either the Handle class to perform
159      * data queries with a time_out, or the transport layer (through this
160      * connection). The instance shall return true, if the Handle should
161      * signal time outs for read operations. Then the ORB may not call
162      * wait_next_data. Otherwise, a false shall be returned, and the
163      * function wait_next_data shall be implemented by this class.
164      */

165     public boolean use_handle_time_out()
166     {
167         // We have neither mechanism in JacORB.
168
// I wonder if we should. AS.
169
return false;
170     }
171 }
172
173
Popular Tags