KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jacorb > orb > giop > ClientGIOPConnection


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
21 package org.jacorb.orb.giop;
22
23 import java.io.*;
24
25 import org.jacorb.orb.iiop.*;
26 import org.apache.avalon.framework.configuration.*;
27
28 /**
29  * @author Nicolas Noffke
30  * @version $Id: ClientGIOPConnection.java,v 1.13 2004/05/06 12:40:00 nicolas Exp $
31  */

32
33 public class ClientGIOPConnection
34     extends GIOPConnection
35     implements Configurable
36 {
37     private boolean ignore_pending_messages_on_timeout = false;
38
39     public ClientGIOPConnection( org.omg.ETF.Profile profile,
40                                  org.omg.ETF.Connection transport,
41                                  RequestListener request_listener,
42                                  ReplyListener reply_listener,
43                                  StatisticsProvider statistics_provider )
44     {
45         super( profile, transport, request_listener, reply_listener, statistics_provider );
46     }
47
48
49     public void configure(Configuration configuration)
50         throws ConfigurationException
51     {
52         super.configure(configuration);
53
54         ignore_pending_messages_on_timeout =
55             configuration.getAttribute("jacorb.connection.client.timeout_ignores_pending_messages","off").equals("on");
56     }
57
58
59     protected void readTimedOut()
60     {
61         synchronized( pendingUndecidedSync )
62         {
63             if (ignore_pending_messages_on_timeout)
64             {
65                 this.streamClosed();
66             }
67             else if (! hasPendingMessages())
68             {
69                 closeAllowReopen();
70             }
71         }
72     }
73
74     protected void streamClosed()
75     {
76         closeAllowReopen();
77
78         if( connection_listener != null )
79         {
80             connection_listener.streamClosed();
81         }
82     }
83
84     public void closeAllowReopen()
85     {
86         try
87         {
88             synchronized (connect_sync)
89             {
90                 getWriteLock();
91                 transport.close();
92                 // We expect that the same transport can be reconnected
93
// after a close, something that the ETF draft isn't
94
// particularly clear about.
95
}
96         }
97         finally
98         {
99             releaseWriteLock();
100         }
101     }
102
103 }// ClientGIOPConnection
104
Popular Tags