1 20 21 package org.jacorb.orb.giop; 22 23 import org.apache.avalon.framework.configuration.*; 24 import org.apache.avalon.framework.logger.Logger; 25 26 import java.io.*; 27 28 import org.jacorb.orb.iiop.*; 29 30 34 35 public class ServerGIOPConnection 36 extends GIOPConnection 37 { 38 private static final byte[] CLOSE_CONNECTION_MESSAGE = 39 new byte[] { 40 (byte )'G', (byte )'I', (byte )'O', (byte )'P', 1, 0, 0, 5, 0, 0, 0, 0 }; 48 49 private GIOPConnectionManager manager = null; 50 private Logger logger = null; 51 private boolean closeOnReadTimeout = false; 52 private boolean delayClose = false; 53 54 public ServerGIOPConnection( org.omg.ETF.Profile profile, 55 org.omg.ETF.Connection transport, 56 RequestListener request_listener, 57 ReplyListener reply_listener, 58 StatisticsProvider statistics_provider, 59 GIOPConnectionManager manager ) 60 { 61 super( profile, transport, request_listener, reply_listener, statistics_provider ); 62 this.manager = manager; 63 } 64 65 66 67 public void configure(Configuration configuration) 68 throws ConfigurationException 69 { 70 super.configure(configuration); 71 logger = ((org.jacorb.config.Configuration)configuration).getNamedLogger("jacorb.giop.conn"); 72 delayClose = 73 configuration.getAttribute("jacorb.connection.delay_close","off").equals("on"); 74 } 75 76 77 81 boolean tryClose() 82 { 83 if( tryDiscard() ) 84 { 85 sendCloseConnection(); 86 87 closeOnReadTimeout = true; 88 89 if( connection_listener != null ) 90 { 91 connection_listener.connectionClosed(); 92 } 93 94 return true; 95 } 96 else 97 { 98 return false; 99 } 100 } 101 102 103 110 private boolean tryDiscard() 111 { 112 if( ! hasPendingMessages() ) 113 { 114 synchronized( pendingUndecidedSync ) 115 { 116 discard_messages = true; 117 } 118 119 return true; 120 } 121 else 122 { 123 return false; 124 } 125 } 126 127 128 132 private void sendCloseConnection() 133 { 134 try 135 { 136 getWriteLock(); 137 138 write( CLOSE_CONNECTION_MESSAGE, 139 0, 140 CLOSE_CONNECTION_MESSAGE.length ); 141 142 transport.flush(); 143 144 if (statistics_provider != null) 145 { 146 statistics_provider.flushed(); 147 } 148 149 if( delayClose && transport instanceof IIOPConnection ) 150 { 151 ((IIOPConnection)transport).turnOnFinalTimeout(); 152 } 153 else 154 { 155 do_close = true; 158 159 transport.close(); 160 } 161 } 162 catch( org.omg.CORBA.COMM_FAILURE e ) 163 { 164 if (logger.isErrorEnabled()) 165 logger.error("COMM_FAILURE" , e ); 166 } 167 finally 168 { 169 releaseWriteLock(); 170 } 171 172 if( manager != null ) 173 { 174 manager.unregisterServerGIOPConnection( this ); 175 } 176 } 177 178 179 protected void readTimedOut() 180 { 181 if( closeOnReadTimeout ) 182 { 183 close(); 184 } 185 else 186 { 187 191 tryClose(); 192 } 193 } 194 195 199 protected void streamClosed() 200 { 201 close(); 202 } 203 204 207 public void close() 208 { 209 super.close(); 210 if( manager != null ) 211 { 212 manager.unregisterServerGIOPConnection( this ); 213 } 214 } 215 216 } | Popular Tags |