Fri, 04 Apr 2014 14:58:04 +0400
8029073: (corba) New connection reclaimed when number of connection is greater than highwatermark
Reviewed-by: coffeys
duke@1 | 1 | /* |
coffeys@478 | 2 | * Copyright (c) 2001, 2013, Oracle and/or its affiliates. All rights reserved. |
duke@1 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
duke@1 | 4 | * |
duke@1 | 5 | * This code is free software; you can redistribute it and/or modify it |
duke@1 | 6 | * under the terms of the GNU General Public License version 2 only, as |
ohair@158 | 7 | * published by the Free Software Foundation. Oracle designates this |
duke@1 | 8 | * particular file as subject to the "Classpath" exception as provided |
ohair@158 | 9 | * by Oracle in the LICENSE file that accompanied this code. |
duke@1 | 10 | * |
duke@1 | 11 | * This code is distributed in the hope that it will be useful, but WITHOUT |
duke@1 | 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
duke@1 | 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
duke@1 | 14 | * version 2 for more details (a copy is included in the LICENSE file that |
duke@1 | 15 | * accompanied this code). |
duke@1 | 16 | * |
duke@1 | 17 | * You should have received a copy of the GNU General Public License version |
duke@1 | 18 | * 2 along with this work; if not, write to the Free Software Foundation, |
duke@1 | 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
duke@1 | 20 | * |
ohair@158 | 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
ohair@158 | 22 | * or visit www.oracle.com if you need additional information or have any |
ohair@158 | 23 | * questions. |
duke@1 | 24 | */ |
duke@1 | 25 | |
duke@1 | 26 | package com.sun.corba.se.impl.transport; |
duke@1 | 27 | |
duke@1 | 28 | import java.io.IOException; |
duke@1 | 29 | import java.net.InetSocketAddress; |
duke@1 | 30 | import java.net.ServerSocket; |
duke@1 | 31 | import java.net.Socket; |
duke@1 | 32 | import java.nio.channels.SelectableChannel; |
duke@1 | 33 | import java.nio.channels.SelectionKey; |
duke@1 | 34 | import java.nio.channels.ServerSocketChannel; |
duke@1 | 35 | import java.nio.channels.SocketChannel; |
duke@1 | 36 | import java.util.Iterator; |
duke@1 | 37 | |
duke@1 | 38 | import com.sun.corba.se.pept.broker.Broker; |
duke@1 | 39 | import com.sun.corba.se.pept.encoding.InputObject; |
duke@1 | 40 | import com.sun.corba.se.pept.encoding.OutputObject; |
duke@1 | 41 | import com.sun.corba.se.pept.protocol.MessageMediator; |
duke@1 | 42 | import com.sun.corba.se.pept.transport.Acceptor; |
duke@1 | 43 | import com.sun.corba.se.pept.transport.Connection; |
duke@1 | 44 | import com.sun.corba.se.pept.transport.ContactInfo; |
duke@1 | 45 | import com.sun.corba.se.pept.transport.EventHandler; |
duke@1 | 46 | import com.sun.corba.se.pept.transport.InboundConnectionCache; |
duke@1 | 47 | import com.sun.corba.se.pept.transport.Selector; |
duke@1 | 48 | |
duke@1 | 49 | import com.sun.corba.se.spi.extension.RequestPartitioningPolicy; |
duke@1 | 50 | import com.sun.corba.se.spi.ior.IORTemplate; |
duke@1 | 51 | import com.sun.corba.se.spi.ior.TaggedProfileTemplate; |
duke@1 | 52 | import com.sun.corba.se.spi.ior.iiop.IIOPAddress ; |
duke@1 | 53 | import com.sun.corba.se.spi.ior.iiop.IIOPFactories; |
duke@1 | 54 | import com.sun.corba.se.spi.ior.iiop.IIOPProfileTemplate ; |
duke@1 | 55 | import com.sun.corba.se.spi.ior.iiop.GIOPVersion ; |
duke@1 | 56 | import com.sun.corba.se.spi.ior.iiop.AlternateIIOPAddressComponent; |
duke@1 | 57 | import com.sun.corba.se.spi.logging.CORBALogDomains; |
duke@1 | 58 | import com.sun.corba.se.spi.orb.ORB; |
duke@1 | 59 | import com.sun.corba.se.spi.orbutil.threadpool.Work; |
duke@1 | 60 | import com.sun.corba.se.spi.protocol.CorbaMessageMediator; |
duke@1 | 61 | import com.sun.corba.se.spi.transport.CorbaAcceptor; |
duke@1 | 62 | import com.sun.corba.se.spi.transport.CorbaConnection; |
duke@1 | 63 | import com.sun.corba.se.spi.transport.SocketInfo; |
duke@1 | 64 | import com.sun.corba.se.spi.transport.SocketOrChannelAcceptor; |
duke@1 | 65 | |
duke@1 | 66 | import com.sun.corba.se.impl.encoding.CDRInputObject; |
duke@1 | 67 | import com.sun.corba.se.impl.encoding.CDROutputObject; |
duke@1 | 68 | import com.sun.corba.se.impl.logging.ORBUtilSystemException; |
duke@1 | 69 | import com.sun.corba.se.impl.oa.poa.Policies; // REVISIT impl/poa specific |
duke@1 | 70 | import com.sun.corba.se.impl.orbutil.ORBConstants; |
duke@1 | 71 | import com.sun.corba.se.impl.orbutil.ORBUtility; |
duke@1 | 72 | |
duke@1 | 73 | // BEGIN Legacy support. |
duke@1 | 74 | import com.sun.corba.se.spi.legacy.connection.LegacyServerSocketEndPointInfo; |
duke@1 | 75 | // END Legacy support. |
duke@1 | 76 | |
duke@1 | 77 | /** |
duke@1 | 78 | * @author Harold Carr |
duke@1 | 79 | */ |
duke@1 | 80 | public class SocketOrChannelAcceptorImpl |
duke@1 | 81 | extends |
duke@1 | 82 | EventHandlerBase |
duke@1 | 83 | implements |
duke@1 | 84 | CorbaAcceptor, |
duke@1 | 85 | SocketOrChannelAcceptor, |
duke@1 | 86 | Work, |
duke@1 | 87 | // BEGIN Legacy |
duke@1 | 88 | SocketInfo, |
duke@1 | 89 | LegacyServerSocketEndPointInfo |
duke@1 | 90 | // END Legacy |
duke@1 | 91 | { |
duke@1 | 92 | protected ServerSocketChannel serverSocketChannel; |
duke@1 | 93 | protected ServerSocket serverSocket; |
duke@1 | 94 | protected int port; |
duke@1 | 95 | protected long enqueueTime; |
duke@1 | 96 | protected boolean initialized; |
duke@1 | 97 | protected ORBUtilSystemException wrapper ; |
duke@1 | 98 | protected InboundConnectionCache connectionCache; |
duke@1 | 99 | |
duke@1 | 100 | // BEGIN Legacy |
duke@1 | 101 | protected String type = ""; |
duke@1 | 102 | protected String name = ""; |
duke@1 | 103 | protected String hostname; |
duke@1 | 104 | protected int locatorPort; |
duke@1 | 105 | // END Legacy |
duke@1 | 106 | |
duke@1 | 107 | public SocketOrChannelAcceptorImpl(ORB orb) |
duke@1 | 108 | { |
duke@1 | 109 | this.orb = orb; |
duke@1 | 110 | wrapper = ORBUtilSystemException.get( orb, |
duke@1 | 111 | CORBALogDomains.RPC_TRANSPORT ) ; |
duke@1 | 112 | |
duke@1 | 113 | setWork(this); |
duke@1 | 114 | initialized = false; |
duke@1 | 115 | |
duke@1 | 116 | // BEGIN Legacy support. |
duke@1 | 117 | this.hostname = orb.getORBData().getORBServerHost(); |
duke@1 | 118 | this.name = LegacyServerSocketEndPointInfo.NO_NAME; |
duke@1 | 119 | this.locatorPort = -1; |
duke@1 | 120 | // END Legacy support. |
duke@1 | 121 | } |
duke@1 | 122 | |
duke@1 | 123 | public SocketOrChannelAcceptorImpl(ORB orb, int port) |
duke@1 | 124 | { |
duke@1 | 125 | this(orb); |
duke@1 | 126 | this.port = port; |
duke@1 | 127 | } |
duke@1 | 128 | |
duke@1 | 129 | // BEGIN Legacy support. |
duke@1 | 130 | public SocketOrChannelAcceptorImpl(ORB orb, int port, |
duke@1 | 131 | String name, String type) |
duke@1 | 132 | { |
duke@1 | 133 | this(orb, port); |
duke@1 | 134 | this.name = name; |
duke@1 | 135 | this.type = type; |
duke@1 | 136 | } |
duke@1 | 137 | // END Legacy support. |
duke@1 | 138 | |
duke@1 | 139 | //////////////////////////////////////////////////// |
duke@1 | 140 | // |
duke@1 | 141 | // pept.transport.Acceptor |
duke@1 | 142 | // |
duke@1 | 143 | |
duke@1 | 144 | public boolean initialize() |
duke@1 | 145 | { |
duke@1 | 146 | if (initialized) { |
duke@1 | 147 | return false; |
duke@1 | 148 | } |
duke@1 | 149 | if (orb.transportDebugFlag) { |
duke@1 | 150 | dprint(".initialize: " + this); |
duke@1 | 151 | } |
duke@1 | 152 | InetSocketAddress inetSocketAddress = null; |
duke@1 | 153 | try { |
duke@1 | 154 | if (orb.getORBData().getListenOnAllInterfaces().equals(ORBConstants.LISTEN_ON_ALL_INTERFACES)) { |
duke@1 | 155 | inetSocketAddress = new InetSocketAddress(port); |
duke@1 | 156 | } else { |
duke@1 | 157 | String host = orb.getORBData().getORBServerHost(); |
duke@1 | 158 | inetSocketAddress = new InetSocketAddress(host, port); |
duke@1 | 159 | } |
duke@1 | 160 | serverSocket = orb.getORBData().getSocketFactory() |
duke@1 | 161 | .createServerSocket(type, inetSocketAddress); |
duke@1 | 162 | internalInitialize(); |
duke@1 | 163 | } catch (Throwable t) { |
duke@1 | 164 | throw wrapper.createListenerFailed( t, Integer.toString(port) ) ; |
duke@1 | 165 | } |
duke@1 | 166 | initialized = true; |
duke@1 | 167 | return true; |
duke@1 | 168 | } |
duke@1 | 169 | |
duke@1 | 170 | protected void internalInitialize() |
duke@1 | 171 | throws Exception |
duke@1 | 172 | { |
duke@1 | 173 | // Determine the listening port (for the IOR). |
duke@1 | 174 | // This is important when using emphemeral ports (i.e., |
duke@1 | 175 | // when the port value to the constructor is 0). |
duke@1 | 176 | |
duke@1 | 177 | port = serverSocket.getLocalPort(); |
duke@1 | 178 | |
duke@1 | 179 | // Register with transport (also sets up monitoring). |
duke@1 | 180 | |
duke@1 | 181 | orb.getCorbaTransportManager().getInboundConnectionCache(this); |
duke@1 | 182 | |
duke@1 | 183 | // Finish configuation. |
duke@1 | 184 | |
duke@1 | 185 | serverSocketChannel = serverSocket.getChannel(); |
duke@1 | 186 | |
duke@1 | 187 | if (serverSocketChannel != null) { |
duke@1 | 188 | setUseSelectThreadToWait( |
duke@1 | 189 | orb.getORBData().acceptorSocketUseSelectThreadToWait()); |
duke@1 | 190 | serverSocketChannel.configureBlocking( |
duke@1 | 191 | ! orb.getORBData().acceptorSocketUseSelectThreadToWait()); |
duke@1 | 192 | } else { |
duke@1 | 193 | // Configure to use listener and reader threads. |
duke@1 | 194 | setUseSelectThreadToWait(false); |
duke@1 | 195 | } |
duke@1 | 196 | setUseWorkerThreadForEvent( |
duke@1 | 197 | orb.getORBData().acceptorSocketUseWorkerThreadForEvent()); |
duke@1 | 198 | |
duke@1 | 199 | } |
duke@1 | 200 | |
duke@1 | 201 | public boolean initialized() |
duke@1 | 202 | { |
duke@1 | 203 | return initialized; |
duke@1 | 204 | } |
duke@1 | 205 | |
duke@1 | 206 | public String getConnectionCacheType() |
duke@1 | 207 | { |
duke@1 | 208 | return this.getClass().toString(); |
duke@1 | 209 | } |
duke@1 | 210 | |
duke@1 | 211 | public void setConnectionCache(InboundConnectionCache connectionCache) |
duke@1 | 212 | { |
duke@1 | 213 | this.connectionCache = connectionCache; |
duke@1 | 214 | } |
duke@1 | 215 | |
duke@1 | 216 | public InboundConnectionCache getConnectionCache() |
duke@1 | 217 | { |
duke@1 | 218 | return connectionCache; |
duke@1 | 219 | } |
duke@1 | 220 | |
duke@1 | 221 | public boolean shouldRegisterAcceptEvent() |
duke@1 | 222 | { |
duke@1 | 223 | return true; |
duke@1 | 224 | } |
duke@1 | 225 | |
duke@1 | 226 | public void accept() |
duke@1 | 227 | { |
duke@1 | 228 | try { |
duke@1 | 229 | SocketChannel socketChannel = null; |
duke@1 | 230 | Socket socket = null; |
duke@1 | 231 | if (serverSocketChannel == null) { |
duke@1 | 232 | socket = serverSocket.accept(); |
duke@1 | 233 | } else { |
duke@1 | 234 | socketChannel = serverSocketChannel.accept(); |
duke@1 | 235 | socket = socketChannel.socket(); |
duke@1 | 236 | } |
duke@1 | 237 | orb.getORBData().getSocketFactory() |
duke@1 | 238 | .setAcceptedSocketOptions(this, serverSocket, socket); |
duke@1 | 239 | if (orb.transportDebugFlag) { |
duke@1 | 240 | dprint(".accept: " + |
duke@1 | 241 | (serverSocketChannel == null |
duke@1 | 242 | ? serverSocket.toString() |
duke@1 | 243 | : serverSocketChannel.toString())); |
duke@1 | 244 | } |
duke@1 | 245 | |
duke@1 | 246 | CorbaConnection connection = |
duke@1 | 247 | new SocketOrChannelConnectionImpl(orb, this, socket); |
duke@1 | 248 | if (orb.transportDebugFlag) { |
duke@1 | 249 | dprint(".accept: new: " + connection); |
duke@1 | 250 | } |
duke@1 | 251 | |
duke@1 | 252 | // NOTE: The connection MUST be put in the cache BEFORE being |
duke@1 | 253 | // registered with the selector. Otherwise if the bytes |
duke@1 | 254 | // are read on the connection it will attempt a time stamp |
duke@1 | 255 | // but the cache will be null, resulting in NPE. |
aefimov@645 | 256 | |
aefimov@645 | 257 | // A connection needs to be timestamped before putting to the cache. |
aefimov@645 | 258 | // Otherwise the newly created connection (with 0 timestamp) could be |
aefimov@645 | 259 | // incorrectly reclaimed by concurrent reclaim() call OR if there |
aefimov@645 | 260 | // will be no events on this connection then it could be reclaimed |
aefimov@645 | 261 | // by upcoming reclaim() call. |
aefimov@645 | 262 | getConnectionCache().stampTime(connection); |
duke@1 | 263 | getConnectionCache().put(this, connection); |
duke@1 | 264 | |
duke@1 | 265 | if (connection.shouldRegisterServerReadEvent()) { |
duke@1 | 266 | Selector selector = orb.getTransportManager().getSelector(0); |
duke@1 | 267 | selector.registerForEvent(connection.getEventHandler()); |
duke@1 | 268 | } |
duke@1 | 269 | |
duke@1 | 270 | getConnectionCache().reclaim(); |
duke@1 | 271 | |
duke@1 | 272 | } catch (IOException e) { |
duke@1 | 273 | if (orb.transportDebugFlag) { |
duke@1 | 274 | dprint(".accept:", e); |
duke@1 | 275 | } |
duke@1 | 276 | orb.getTransportManager().getSelector(0).unregisterForEvent(this); |
duke@1 | 277 | // REVISIT - need to close - recreate - then register new one. |
duke@1 | 278 | orb.getTransportManager().getSelector(0).registerForEvent(this); |
duke@1 | 279 | // NOTE: if register cycling we do not want to shut down ORB |
duke@1 | 280 | // since local beans will still work. Instead one will see |
duke@1 | 281 | // a growing log file to alert admin of problem. |
duke@1 | 282 | } |
duke@1 | 283 | } |
duke@1 | 284 | |
duke@1 | 285 | public void close () |
duke@1 | 286 | { |
duke@1 | 287 | try { |
duke@1 | 288 | if (orb.transportDebugFlag) { |
duke@1 | 289 | dprint(".close->:"); |
duke@1 | 290 | } |
duke@1 | 291 | Selector selector = orb.getTransportManager().getSelector(0); |
duke@1 | 292 | selector.unregisterForEvent(this); |
duke@1 | 293 | if (serverSocketChannel != null) { |
duke@1 | 294 | serverSocketChannel.close(); |
duke@1 | 295 | } |
duke@1 | 296 | if (serverSocket != null) { |
duke@1 | 297 | serverSocket.close(); |
duke@1 | 298 | } |
duke@1 | 299 | } catch (IOException e) { |
duke@1 | 300 | if (orb.transportDebugFlag) { |
duke@1 | 301 | dprint(".close:", e); |
duke@1 | 302 | } |
duke@1 | 303 | } finally { |
duke@1 | 304 | if (orb.transportDebugFlag) { |
duke@1 | 305 | dprint(".close<-:"); |
duke@1 | 306 | } |
duke@1 | 307 | } |
duke@1 | 308 | } |
duke@1 | 309 | |
duke@1 | 310 | public EventHandler getEventHandler() |
duke@1 | 311 | { |
duke@1 | 312 | return this; |
duke@1 | 313 | } |
duke@1 | 314 | |
duke@1 | 315 | //////////////////////////////////////////////////// |
duke@1 | 316 | // |
duke@1 | 317 | // CorbaAcceptor |
duke@1 | 318 | // |
duke@1 | 319 | |
duke@1 | 320 | public String getObjectAdapterId() |
duke@1 | 321 | { |
duke@1 | 322 | return null; |
duke@1 | 323 | } |
duke@1 | 324 | |
duke@1 | 325 | public String getObjectAdapterManagerId() |
duke@1 | 326 | { |
duke@1 | 327 | return null; |
duke@1 | 328 | } |
duke@1 | 329 | |
duke@1 | 330 | public void addToIORTemplate(IORTemplate iorTemplate, |
duke@1 | 331 | Policies policies, |
duke@1 | 332 | String codebase) |
duke@1 | 333 | { |
duke@1 | 334 | Iterator iterator = iorTemplate.iteratorById( |
duke@1 | 335 | org.omg.IOP.TAG_INTERNET_IOP.value); |
duke@1 | 336 | |
duke@1 | 337 | String hostname = orb.getORBData().getORBServerHost(); |
duke@1 | 338 | |
duke@1 | 339 | if (iterator.hasNext()) { |
duke@1 | 340 | // REVISIT - how does this play with legacy ORBD port exchange? |
duke@1 | 341 | IIOPAddress iiopAddress = |
duke@1 | 342 | IIOPFactories.makeIIOPAddress(orb, hostname, port); |
duke@1 | 343 | AlternateIIOPAddressComponent iiopAddressComponent = |
duke@1 | 344 | IIOPFactories.makeAlternateIIOPAddressComponent(iiopAddress); |
duke@1 | 345 | |
duke@1 | 346 | while (iterator.hasNext()) { |
duke@1 | 347 | TaggedProfileTemplate taggedProfileTemplate = |
duke@1 | 348 | (TaggedProfileTemplate) iterator.next(); |
duke@1 | 349 | taggedProfileTemplate.add(iiopAddressComponent); |
duke@1 | 350 | } |
duke@1 | 351 | } else { |
duke@1 | 352 | GIOPVersion version = orb.getORBData().getGIOPVersion(); |
duke@1 | 353 | int templatePort; |
duke@1 | 354 | if (policies.forceZeroPort()) { |
duke@1 | 355 | templatePort = 0; |
duke@1 | 356 | } else if (policies.isTransient()) { |
duke@1 | 357 | templatePort = port; |
duke@1 | 358 | } else { |
duke@1 | 359 | templatePort = orb.getLegacyServerSocketManager() |
duke@1 | 360 | .legacyGetPersistentServerPort(SocketInfo.IIOP_CLEAR_TEXT); |
duke@1 | 361 | } |
duke@1 | 362 | IIOPAddress addr = |
duke@1 | 363 | IIOPFactories.makeIIOPAddress(orb, hostname, templatePort); |
duke@1 | 364 | IIOPProfileTemplate iiopProfile = |
duke@1 | 365 | IIOPFactories.makeIIOPProfileTemplate(orb, version, addr); |
duke@1 | 366 | if (version.supportsIORIIOPProfileComponents()) { |
duke@1 | 367 | iiopProfile.add(IIOPFactories.makeCodeSetsComponent(orb)); |
duke@1 | 368 | iiopProfile.add(IIOPFactories.makeMaxStreamFormatVersionComponent()); |
duke@1 | 369 | RequestPartitioningPolicy rpPolicy = (RequestPartitioningPolicy) |
duke@1 | 370 | policies.get_effective_policy( |
duke@1 | 371 | ORBConstants.REQUEST_PARTITIONING_POLICY); |
duke@1 | 372 | if (rpPolicy != null) { |
duke@1 | 373 | iiopProfile.add( |
duke@1 | 374 | IIOPFactories.makeRequestPartitioningComponent( |
duke@1 | 375 | rpPolicy.getValue())); |
duke@1 | 376 | } |
duke@1 | 377 | if (codebase != null && codebase != "") { |
duke@1 | 378 | iiopProfile.add(IIOPFactories. makeJavaCodebaseComponent(codebase)); |
duke@1 | 379 | } |
duke@1 | 380 | if (orb.getORBData().isJavaSerializationEnabled()) { |
duke@1 | 381 | iiopProfile.add( |
duke@1 | 382 | IIOPFactories.makeJavaSerializationComponent()); |
duke@1 | 383 | } |
duke@1 | 384 | } |
duke@1 | 385 | iorTemplate.add(iiopProfile); |
duke@1 | 386 | } |
duke@1 | 387 | } |
duke@1 | 388 | |
duke@1 | 389 | public String getMonitoringName() |
duke@1 | 390 | { |
duke@1 | 391 | return "AcceptedConnections"; |
duke@1 | 392 | } |
duke@1 | 393 | |
duke@1 | 394 | //////////////////////////////////////////////////// |
duke@1 | 395 | // |
duke@1 | 396 | // EventHandler methods |
duke@1 | 397 | // |
duke@1 | 398 | |
duke@1 | 399 | public SelectableChannel getChannel() |
duke@1 | 400 | { |
duke@1 | 401 | return serverSocketChannel; |
duke@1 | 402 | } |
duke@1 | 403 | |
duke@1 | 404 | public int getInterestOps() |
duke@1 | 405 | { |
duke@1 | 406 | return SelectionKey.OP_ACCEPT; |
duke@1 | 407 | } |
duke@1 | 408 | |
duke@1 | 409 | public Acceptor getAcceptor() |
duke@1 | 410 | { |
duke@1 | 411 | return this; |
duke@1 | 412 | } |
duke@1 | 413 | |
duke@1 | 414 | public Connection getConnection() |
duke@1 | 415 | { |
duke@1 | 416 | throw new RuntimeException("Should not happen."); |
duke@1 | 417 | } |
duke@1 | 418 | |
duke@1 | 419 | //////////////////////////////////////////////////// |
duke@1 | 420 | // |
duke@1 | 421 | // Work methods. |
duke@1 | 422 | // |
duke@1 | 423 | |
duke@1 | 424 | /* CONFLICT: with legacy below. |
duke@1 | 425 | public String getName() |
duke@1 | 426 | { |
duke@1 | 427 | return this.toString(); |
duke@1 | 428 | } |
duke@1 | 429 | */ |
duke@1 | 430 | |
duke@1 | 431 | public void doWork() |
duke@1 | 432 | { |
duke@1 | 433 | try { |
duke@1 | 434 | if (orb.transportDebugFlag) { |
duke@1 | 435 | dprint(".doWork->: " + this); |
duke@1 | 436 | } |
duke@1 | 437 | if (selectionKey.isAcceptable()) { |
duke@1 | 438 | accept(); |
duke@1 | 439 | } else { |
duke@1 | 440 | if (orb.transportDebugFlag) { |
duke@1 | 441 | dprint(".doWork: ! selectionKey.isAcceptable: " + this); |
duke@1 | 442 | } |
duke@1 | 443 | } |
duke@1 | 444 | } catch (SecurityException se) { |
duke@1 | 445 | if (orb.transportDebugFlag) { |
duke@1 | 446 | dprint(".doWork: ignoring SecurityException: " |
duke@1 | 447 | + se |
duke@1 | 448 | + " " + this); |
duke@1 | 449 | } |
duke@1 | 450 | String permissionStr = ORBUtility.getClassSecurityInfo(getClass()); |
duke@1 | 451 | wrapper.securityExceptionInAccept(se, permissionStr); |
duke@1 | 452 | } catch (Exception ex) { |
duke@1 | 453 | if (orb.transportDebugFlag) { |
duke@1 | 454 | dprint(".doWork: ignoring Exception: " |
duke@1 | 455 | + ex |
duke@1 | 456 | + " " + this); |
duke@1 | 457 | } |
duke@1 | 458 | wrapper.exceptionInAccept(ex); |
duke@1 | 459 | } catch (Throwable t) { |
duke@1 | 460 | if (orb.transportDebugFlag) { |
duke@1 | 461 | dprint(".doWork: ignoring Throwable: " |
duke@1 | 462 | + t |
duke@1 | 463 | + " " + this); |
duke@1 | 464 | } |
duke@1 | 465 | } finally { |
duke@1 | 466 | |
duke@1 | 467 | // IMPORTANT: To avoid bug (4953599), we force the |
duke@1 | 468 | // Thread that does the NIO select to also do the |
duke@1 | 469 | // enable/disable of Ops using SelectionKey.interestOps(). |
duke@1 | 470 | // Otherwise, the SelectionKey.interestOps() may block |
duke@1 | 471 | // indefinitely. |
duke@1 | 472 | // NOTE: If "acceptorSocketUseWorkerThreadForEvent" is |
duke@1 | 473 | // set to to false in ParserTable.java, then this method, |
duke@1 | 474 | // doWork(), will get executed by the same thread |
duke@1 | 475 | // (SelectorThread) that does the NIO select. |
duke@1 | 476 | // If "acceptorSocketUseWorkerThreadForEvent" is set |
duke@1 | 477 | // to true, a WorkerThread will execute this method, |
duke@1 | 478 | // doWork(). Hence, the registering of the enabling of |
duke@1 | 479 | // the SelectionKey's interestOps is done here instead |
duke@1 | 480 | // of calling SelectionKey.interestOps(<interest op>). |
duke@1 | 481 | |
duke@1 | 482 | Selector selector = orb.getTransportManager().getSelector(0); |
duke@1 | 483 | selector.registerInterestOps(this); |
duke@1 | 484 | |
duke@1 | 485 | if (orb.transportDebugFlag) { |
duke@1 | 486 | dprint(".doWork<-:" + this); |
duke@1 | 487 | } |
duke@1 | 488 | } |
duke@1 | 489 | } |
duke@1 | 490 | |
duke@1 | 491 | public void setEnqueueTime(long timeInMillis) |
duke@1 | 492 | { |
duke@1 | 493 | enqueueTime = timeInMillis; |
duke@1 | 494 | } |
duke@1 | 495 | |
duke@1 | 496 | public long getEnqueueTime() |
duke@1 | 497 | { |
duke@1 | 498 | return enqueueTime; |
duke@1 | 499 | } |
duke@1 | 500 | |
duke@1 | 501 | |
duke@1 | 502 | // |
duke@1 | 503 | // Factory methods. |
duke@1 | 504 | // |
duke@1 | 505 | |
duke@1 | 506 | // REVISIT: refactor into common base or delegate. |
duke@1 | 507 | public MessageMediator createMessageMediator(Broker broker, |
duke@1 | 508 | Connection connection) |
duke@1 | 509 | { |
duke@1 | 510 | // REVISIT - no factoring so cheat to avoid code dup right now. |
duke@1 | 511 | // REVISIT **** COUPLING !!!! |
duke@1 | 512 | ContactInfo contactInfo = new SocketOrChannelContactInfoImpl(); |
duke@1 | 513 | return contactInfo.createMessageMediator(broker, connection); |
duke@1 | 514 | } |
duke@1 | 515 | |
duke@1 | 516 | // REVISIT: refactor into common base or delegate. |
duke@1 | 517 | public MessageMediator finishCreatingMessageMediator(Broker broker, |
duke@1 | 518 | Connection connection, |
duke@1 | 519 | MessageMediator messageMediator) |
duke@1 | 520 | { |
duke@1 | 521 | // REVISIT - no factoring so cheat to avoid code dup right now. |
duke@1 | 522 | // REVISIT **** COUPLING !!!! |
duke@1 | 523 | ContactInfo contactInfo = new SocketOrChannelContactInfoImpl(); |
duke@1 | 524 | return contactInfo.finishCreatingMessageMediator(broker, |
duke@1 | 525 | connection, messageMediator); |
duke@1 | 526 | } |
duke@1 | 527 | |
duke@1 | 528 | public InputObject createInputObject(Broker broker, |
duke@1 | 529 | MessageMediator messageMediator) |
duke@1 | 530 | { |
duke@1 | 531 | CorbaMessageMediator corbaMessageMediator = (CorbaMessageMediator) |
duke@1 | 532 | messageMediator; |
duke@1 | 533 | return new CDRInputObject((ORB)broker, |
duke@1 | 534 | (CorbaConnection)messageMediator.getConnection(), |
duke@1 | 535 | corbaMessageMediator.getDispatchBuffer(), |
duke@1 | 536 | corbaMessageMediator.getDispatchHeader()); |
duke@1 | 537 | } |
duke@1 | 538 | |
duke@1 | 539 | public OutputObject createOutputObject(Broker broker, |
duke@1 | 540 | MessageMediator messageMediator) |
duke@1 | 541 | { |
duke@1 | 542 | CorbaMessageMediator corbaMessageMediator = (CorbaMessageMediator) |
duke@1 | 543 | messageMediator; |
coffeys@478 | 544 | return sun.corba.OutputStreamFactory.newCDROutputObject((ORB) broker, |
coffeys@478 | 545 | corbaMessageMediator, corbaMessageMediator.getReplyHeader(), |
coffeys@478 | 546 | corbaMessageMediator.getStreamFormatVersion()); |
duke@1 | 547 | } |
duke@1 | 548 | |
duke@1 | 549 | //////////////////////////////////////////////////// |
duke@1 | 550 | // |
duke@1 | 551 | // SocketOrChannelAcceptor |
duke@1 | 552 | // |
duke@1 | 553 | |
duke@1 | 554 | public ServerSocket getServerSocket() |
duke@1 | 555 | { |
duke@1 | 556 | return serverSocket; |
duke@1 | 557 | } |
duke@1 | 558 | |
duke@1 | 559 | //////////////////////////////////////////////////// |
duke@1 | 560 | // |
duke@1 | 561 | // Implementation. |
duke@1 | 562 | // |
duke@1 | 563 | |
duke@1 | 564 | public String toString() |
duke@1 | 565 | { |
duke@1 | 566 | String sock; |
duke@1 | 567 | if (serverSocketChannel == null) { |
duke@1 | 568 | if (serverSocket == null) { |
duke@1 | 569 | sock = "(not initialized)"; |
duke@1 | 570 | } else { |
duke@1 | 571 | sock = serverSocket.toString(); |
duke@1 | 572 | } |
duke@1 | 573 | } else { |
duke@1 | 574 | sock = serverSocketChannel.toString(); |
duke@1 | 575 | } |
duke@1 | 576 | |
duke@1 | 577 | return |
duke@1 | 578 | toStringName() + |
duke@1 | 579 | "[" |
duke@1 | 580 | + sock + " " |
duke@1 | 581 | + type + " " |
duke@1 | 582 | + shouldUseSelectThreadToWait() + " " |
duke@1 | 583 | + shouldUseWorkerThreadForEvent() |
duke@1 | 584 | + "]" ; |
duke@1 | 585 | } |
duke@1 | 586 | |
duke@1 | 587 | protected String toStringName() |
duke@1 | 588 | { |
duke@1 | 589 | return "SocketOrChannelAcceptorImpl"; |
duke@1 | 590 | } |
duke@1 | 591 | |
duke@1 | 592 | protected void dprint(String msg) |
duke@1 | 593 | { |
duke@1 | 594 | ORBUtility.dprint(toStringName(), msg); |
duke@1 | 595 | } |
duke@1 | 596 | |
duke@1 | 597 | protected void dprint(String msg, Throwable t) |
duke@1 | 598 | { |
duke@1 | 599 | dprint(msg); |
duke@1 | 600 | t.printStackTrace(System.out); |
duke@1 | 601 | } |
duke@1 | 602 | |
duke@1 | 603 | // BEGIN Legacy support |
duke@1 | 604 | //////////////////////////////////////////////////// |
duke@1 | 605 | // |
duke@1 | 606 | // LegacyServerSocketEndPointInfo and EndPointInfo |
duke@1 | 607 | // |
duke@1 | 608 | |
duke@1 | 609 | public String getType() |
duke@1 | 610 | { |
duke@1 | 611 | return type; |
duke@1 | 612 | } |
duke@1 | 613 | |
duke@1 | 614 | public String getHostName() |
duke@1 | 615 | { |
duke@1 | 616 | return hostname; |
duke@1 | 617 | } |
duke@1 | 618 | |
duke@1 | 619 | public String getHost() |
duke@1 | 620 | { |
duke@1 | 621 | return hostname; |
duke@1 | 622 | } |
duke@1 | 623 | |
duke@1 | 624 | public int getPort() |
duke@1 | 625 | { |
duke@1 | 626 | return port; |
duke@1 | 627 | } |
duke@1 | 628 | |
duke@1 | 629 | public int getLocatorPort() |
duke@1 | 630 | { |
duke@1 | 631 | return locatorPort; |
duke@1 | 632 | } |
duke@1 | 633 | |
duke@1 | 634 | public void setLocatorPort (int port) |
duke@1 | 635 | { |
duke@1 | 636 | locatorPort = port; |
duke@1 | 637 | } |
duke@1 | 638 | |
duke@1 | 639 | public String getName() |
duke@1 | 640 | { |
duke@1 | 641 | // Kluge alert: |
duke@1 | 642 | // Work and Legacy both define getName. |
duke@1 | 643 | // Try to make this behave best for most cases. |
duke@1 | 644 | String result = |
duke@1 | 645 | name.equals(LegacyServerSocketEndPointInfo.NO_NAME) ? |
duke@1 | 646 | this.toString() : name; |
duke@1 | 647 | return result; |
duke@1 | 648 | } |
duke@1 | 649 | // END Legacy support |
duke@1 | 650 | } |
duke@1 | 651 | |
duke@1 | 652 | // End of file. |