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