corba/src/share/classes/com/sun/corba/se/impl/transport/SocketOrChannelAcceptorImpl.java
author skoppar
Fri, 24 Sep 2010 22:42:14 -0700
changeset 7059 79caba0caf4f
parent 5555 b2b5ed3f0d0d
child 18307 8bf60b58675b
permissions -rw-r--r--
6891766: Vulnerabilities in use of reflection in CORBA Reviewed-by: hawtin
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4
02bb8761fcce Initial load
duke
parents:
diff changeset
     1
/*
7059
79caba0caf4f 6891766: Vulnerabilities in use of reflection in CORBA
skoppar
parents: 5555
diff changeset
     2
 * Copyright (c) 2001, 2010, 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.
02bb8761fcce Initial load
duke
parents:
diff changeset
   256
            getConnectionCache().put(this, connection);
02bb8761fcce Initial load
duke
parents:
diff changeset
   257
02bb8761fcce Initial load
duke
parents:
diff changeset
   258
            if (connection.shouldRegisterServerReadEvent()) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   259
                Selector selector = orb.getTransportManager().getSelector(0);
02bb8761fcce Initial load
duke
parents:
diff changeset
   260
                selector.registerForEvent(connection.getEventHandler());
02bb8761fcce Initial load
duke
parents:
diff changeset
   261
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   262
02bb8761fcce Initial load
duke
parents:
diff changeset
   263
            getConnectionCache().reclaim();
02bb8761fcce Initial load
duke
parents:
diff changeset
   264
02bb8761fcce Initial load
duke
parents:
diff changeset
   265
        } catch (IOException e) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   266
            if (orb.transportDebugFlag) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   267
                dprint(".accept:", e);
02bb8761fcce Initial load
duke
parents:
diff changeset
   268
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   269
            orb.getTransportManager().getSelector(0).unregisterForEvent(this);
02bb8761fcce Initial load
duke
parents:
diff changeset
   270
            // REVISIT - need to close - recreate - then register new one.
02bb8761fcce Initial load
duke
parents:
diff changeset
   271
            orb.getTransportManager().getSelector(0).registerForEvent(this);
02bb8761fcce Initial load
duke
parents:
diff changeset
   272
            // NOTE: if register cycling we do not want to shut down ORB
02bb8761fcce Initial load
duke
parents:
diff changeset
   273
            // since local beans will still work.  Instead one will see
02bb8761fcce Initial load
duke
parents:
diff changeset
   274
            // a growing log file to alert admin of problem.
02bb8761fcce Initial load
duke
parents:
diff changeset
   275
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   276
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   277
02bb8761fcce Initial load
duke
parents:
diff changeset
   278
    public void close ()
02bb8761fcce Initial load
duke
parents:
diff changeset
   279
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   280
        try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   281
            if (orb.transportDebugFlag) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   282
                dprint(".close->:");
02bb8761fcce Initial load
duke
parents:
diff changeset
   283
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   284
            Selector selector = orb.getTransportManager().getSelector(0);
02bb8761fcce Initial load
duke
parents:
diff changeset
   285
            selector.unregisterForEvent(this);
02bb8761fcce Initial load
duke
parents:
diff changeset
   286
            if (serverSocketChannel != null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   287
                serverSocketChannel.close();
02bb8761fcce Initial load
duke
parents:
diff changeset
   288
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   289
            if (serverSocket != null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   290
                serverSocket.close();
02bb8761fcce Initial load
duke
parents:
diff changeset
   291
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   292
        } catch (IOException e) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   293
            if (orb.transportDebugFlag) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   294
                dprint(".close:", e);
02bb8761fcce Initial load
duke
parents:
diff changeset
   295
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   296
        } finally {
02bb8761fcce Initial load
duke
parents:
diff changeset
   297
            if (orb.transportDebugFlag) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   298
                dprint(".close<-:");
02bb8761fcce Initial load
duke
parents:
diff changeset
   299
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   300
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   301
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   302
02bb8761fcce Initial load
duke
parents:
diff changeset
   303
    public EventHandler getEventHandler()
02bb8761fcce Initial load
duke
parents:
diff changeset
   304
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   305
        return this;
02bb8761fcce Initial load
duke
parents:
diff changeset
   306
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   307
02bb8761fcce Initial load
duke
parents:
diff changeset
   308
    ////////////////////////////////////////////////////
02bb8761fcce Initial load
duke
parents:
diff changeset
   309
    //
02bb8761fcce Initial load
duke
parents:
diff changeset
   310
    // CorbaAcceptor
02bb8761fcce Initial load
duke
parents:
diff changeset
   311
    //
02bb8761fcce Initial load
duke
parents:
diff changeset
   312
02bb8761fcce Initial load
duke
parents:
diff changeset
   313
    public String getObjectAdapterId()
02bb8761fcce Initial load
duke
parents:
diff changeset
   314
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   315
        return null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   316
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   317
02bb8761fcce Initial load
duke
parents:
diff changeset
   318
    public String getObjectAdapterManagerId()
02bb8761fcce Initial load
duke
parents:
diff changeset
   319
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   320
        return null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   321
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   322
02bb8761fcce Initial load
duke
parents:
diff changeset
   323
    public void addToIORTemplate(IORTemplate iorTemplate,
02bb8761fcce Initial load
duke
parents:
diff changeset
   324
                                 Policies policies,
02bb8761fcce Initial load
duke
parents:
diff changeset
   325
                                 String codebase)
02bb8761fcce Initial load
duke
parents:
diff changeset
   326
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   327
        Iterator iterator = iorTemplate.iteratorById(
02bb8761fcce Initial load
duke
parents:
diff changeset
   328
            org.omg.IOP.TAG_INTERNET_IOP.value);
02bb8761fcce Initial load
duke
parents:
diff changeset
   329
02bb8761fcce Initial load
duke
parents:
diff changeset
   330
        String hostname = orb.getORBData().getORBServerHost();
02bb8761fcce Initial load
duke
parents:
diff changeset
   331
02bb8761fcce Initial load
duke
parents:
diff changeset
   332
        if (iterator.hasNext()) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   333
            // REVISIT - how does this play with legacy ORBD port exchange?
02bb8761fcce Initial load
duke
parents:
diff changeset
   334
            IIOPAddress iiopAddress =
02bb8761fcce Initial load
duke
parents:
diff changeset
   335
                IIOPFactories.makeIIOPAddress(orb, hostname, port);
02bb8761fcce Initial load
duke
parents:
diff changeset
   336
            AlternateIIOPAddressComponent iiopAddressComponent =
02bb8761fcce Initial load
duke
parents:
diff changeset
   337
                IIOPFactories.makeAlternateIIOPAddressComponent(iiopAddress);
02bb8761fcce Initial load
duke
parents:
diff changeset
   338
02bb8761fcce Initial load
duke
parents:
diff changeset
   339
            while (iterator.hasNext()) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   340
                TaggedProfileTemplate taggedProfileTemplate =
02bb8761fcce Initial load
duke
parents:
diff changeset
   341
                    (TaggedProfileTemplate) iterator.next();
02bb8761fcce Initial load
duke
parents:
diff changeset
   342
                taggedProfileTemplate.add(iiopAddressComponent);
02bb8761fcce Initial load
duke
parents:
diff changeset
   343
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   344
        } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   345
            GIOPVersion version = orb.getORBData().getGIOPVersion();
02bb8761fcce Initial load
duke
parents:
diff changeset
   346
            int templatePort;
02bb8761fcce Initial load
duke
parents:
diff changeset
   347
            if (policies.forceZeroPort()) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   348
                templatePort = 0;
02bb8761fcce Initial load
duke
parents:
diff changeset
   349
            } else if (policies.isTransient()) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   350
                templatePort = port;
02bb8761fcce Initial load
duke
parents:
diff changeset
   351
            } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   352
                templatePort = orb.getLegacyServerSocketManager()
02bb8761fcce Initial load
duke
parents:
diff changeset
   353
                   .legacyGetPersistentServerPort(SocketInfo.IIOP_CLEAR_TEXT);
02bb8761fcce Initial load
duke
parents:
diff changeset
   354
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   355
            IIOPAddress addr =
02bb8761fcce Initial load
duke
parents:
diff changeset
   356
                IIOPFactories.makeIIOPAddress(orb, hostname, templatePort);
02bb8761fcce Initial load
duke
parents:
diff changeset
   357
            IIOPProfileTemplate iiopProfile =
02bb8761fcce Initial load
duke
parents:
diff changeset
   358
                IIOPFactories.makeIIOPProfileTemplate(orb, version, addr);
02bb8761fcce Initial load
duke
parents:
diff changeset
   359
            if (version.supportsIORIIOPProfileComponents()) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   360
                iiopProfile.add(IIOPFactories.makeCodeSetsComponent(orb));
02bb8761fcce Initial load
duke
parents:
diff changeset
   361
                iiopProfile.add(IIOPFactories.makeMaxStreamFormatVersionComponent());
02bb8761fcce Initial load
duke
parents:
diff changeset
   362
                RequestPartitioningPolicy rpPolicy = (RequestPartitioningPolicy)
02bb8761fcce Initial load
duke
parents:
diff changeset
   363
                    policies.get_effective_policy(
02bb8761fcce Initial load
duke
parents:
diff changeset
   364
                                      ORBConstants.REQUEST_PARTITIONING_POLICY);
02bb8761fcce Initial load
duke
parents:
diff changeset
   365
                if (rpPolicy != null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   366
                    iiopProfile.add(
02bb8761fcce Initial load
duke
parents:
diff changeset
   367
                         IIOPFactories.makeRequestPartitioningComponent(
02bb8761fcce Initial load
duke
parents:
diff changeset
   368
                             rpPolicy.getValue()));
02bb8761fcce Initial load
duke
parents:
diff changeset
   369
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
   370
                if (codebase != null && codebase != "") {
02bb8761fcce Initial load
duke
parents:
diff changeset
   371
                    iiopProfile.add(IIOPFactories. makeJavaCodebaseComponent(codebase));
02bb8761fcce Initial load
duke
parents:
diff changeset
   372
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
   373
                if (orb.getORBData().isJavaSerializationEnabled()) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   374
                    iiopProfile.add(
02bb8761fcce Initial load
duke
parents:
diff changeset
   375
                           IIOPFactories.makeJavaSerializationComponent());
02bb8761fcce Initial load
duke
parents:
diff changeset
   376
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
   377
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   378
            iorTemplate.add(iiopProfile);
02bb8761fcce Initial load
duke
parents:
diff changeset
   379
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   380
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   381
02bb8761fcce Initial load
duke
parents:
diff changeset
   382
    public String getMonitoringName()
02bb8761fcce Initial load
duke
parents:
diff changeset
   383
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   384
        return "AcceptedConnections";
02bb8761fcce Initial load
duke
parents:
diff changeset
   385
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   386
02bb8761fcce Initial load
duke
parents:
diff changeset
   387
    ////////////////////////////////////////////////////
02bb8761fcce Initial load
duke
parents:
diff changeset
   388
    //
02bb8761fcce Initial load
duke
parents:
diff changeset
   389
    // EventHandler methods
02bb8761fcce Initial load
duke
parents:
diff changeset
   390
    //
02bb8761fcce Initial load
duke
parents:
diff changeset
   391
02bb8761fcce Initial load
duke
parents:
diff changeset
   392
    public SelectableChannel getChannel()
02bb8761fcce Initial load
duke
parents:
diff changeset
   393
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   394
        return serverSocketChannel;
02bb8761fcce Initial load
duke
parents:
diff changeset
   395
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   396
02bb8761fcce Initial load
duke
parents:
diff changeset
   397
    public int getInterestOps()
02bb8761fcce Initial load
duke
parents:
diff changeset
   398
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   399
        return SelectionKey.OP_ACCEPT;
02bb8761fcce Initial load
duke
parents:
diff changeset
   400
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   401
02bb8761fcce Initial load
duke
parents:
diff changeset
   402
    public Acceptor getAcceptor()
02bb8761fcce Initial load
duke
parents:
diff changeset
   403
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   404
        return this;
02bb8761fcce Initial load
duke
parents:
diff changeset
   405
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   406
02bb8761fcce Initial load
duke
parents:
diff changeset
   407
    public Connection getConnection()
02bb8761fcce Initial load
duke
parents:
diff changeset
   408
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   409
        throw new RuntimeException("Should not happen.");
02bb8761fcce Initial load
duke
parents:
diff changeset
   410
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   411
02bb8761fcce Initial load
duke
parents:
diff changeset
   412
    ////////////////////////////////////////////////////
02bb8761fcce Initial load
duke
parents:
diff changeset
   413
    //
02bb8761fcce Initial load
duke
parents:
diff changeset
   414
    // Work methods.
02bb8761fcce Initial load
duke
parents:
diff changeset
   415
    //
02bb8761fcce Initial load
duke
parents:
diff changeset
   416
02bb8761fcce Initial load
duke
parents:
diff changeset
   417
    /* CONFLICT: with legacy below.
02bb8761fcce Initial load
duke
parents:
diff changeset
   418
    public String getName()
02bb8761fcce Initial load
duke
parents:
diff changeset
   419
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   420
        return this.toString();
02bb8761fcce Initial load
duke
parents:
diff changeset
   421
    }
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 void doWork()
02bb8761fcce Initial load
duke
parents:
diff changeset
   425
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   426
        try {
02bb8761fcce Initial load
duke
parents:
diff changeset
   427
            if (orb.transportDebugFlag) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   428
                dprint(".doWork->: " + this);
02bb8761fcce Initial load
duke
parents:
diff changeset
   429
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   430
            if (selectionKey.isAcceptable()) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   431
                        accept();
02bb8761fcce Initial load
duke
parents:
diff changeset
   432
            } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   433
                if (orb.transportDebugFlag) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   434
                    dprint(".doWork: ! selectionKey.isAcceptable: " + this);
02bb8761fcce Initial load
duke
parents:
diff changeset
   435
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
   436
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   437
        } catch (SecurityException se) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   438
            if (orb.transportDebugFlag) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   439
                dprint(".doWork: ignoring SecurityException: "
02bb8761fcce Initial load
duke
parents:
diff changeset
   440
                       + se
02bb8761fcce Initial load
duke
parents:
diff changeset
   441
                       + " " + this);
02bb8761fcce Initial load
duke
parents:
diff changeset
   442
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   443
            String permissionStr = ORBUtility.getClassSecurityInfo(getClass());
02bb8761fcce Initial load
duke
parents:
diff changeset
   444
            wrapper.securityExceptionInAccept(se, permissionStr);
02bb8761fcce Initial load
duke
parents:
diff changeset
   445
        } catch (Exception ex) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   446
            if (orb.transportDebugFlag) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   447
                dprint(".doWork: ignoring Exception: "
02bb8761fcce Initial load
duke
parents:
diff changeset
   448
                       + ex
02bb8761fcce Initial load
duke
parents:
diff changeset
   449
                       + " " + this);
02bb8761fcce Initial load
duke
parents:
diff changeset
   450
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   451
            wrapper.exceptionInAccept(ex);
02bb8761fcce Initial load
duke
parents:
diff changeset
   452
        } catch (Throwable t) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   453
            if (orb.transportDebugFlag) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   454
                dprint(".doWork: ignoring Throwable: "
02bb8761fcce Initial load
duke
parents:
diff changeset
   455
                       + t
02bb8761fcce Initial load
duke
parents:
diff changeset
   456
                       + " " + this);
02bb8761fcce Initial load
duke
parents:
diff changeset
   457
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   458
        } finally {
02bb8761fcce Initial load
duke
parents:
diff changeset
   459
02bb8761fcce Initial load
duke
parents:
diff changeset
   460
            // IMPORTANT: To avoid bug (4953599), we force the
02bb8761fcce Initial load
duke
parents:
diff changeset
   461
            // Thread that does the NIO select to also do the
02bb8761fcce Initial load
duke
parents:
diff changeset
   462
            // enable/disable of Ops using SelectionKey.interestOps().
02bb8761fcce Initial load
duke
parents:
diff changeset
   463
            // Otherwise, the SelectionKey.interestOps() may block
02bb8761fcce Initial load
duke
parents:
diff changeset
   464
            // indefinitely.
02bb8761fcce Initial load
duke
parents:
diff changeset
   465
            // NOTE: If "acceptorSocketUseWorkerThreadForEvent" is
02bb8761fcce Initial load
duke
parents:
diff changeset
   466
            // set to to false in ParserTable.java, then this method,
02bb8761fcce Initial load
duke
parents:
diff changeset
   467
            // doWork(), will get executed by the same thread
02bb8761fcce Initial load
duke
parents:
diff changeset
   468
            // (SelectorThread) that does the NIO select.
02bb8761fcce Initial load
duke
parents:
diff changeset
   469
            // If "acceptorSocketUseWorkerThreadForEvent" is set
02bb8761fcce Initial load
duke
parents:
diff changeset
   470
            // to true, a WorkerThread will execute this method,
02bb8761fcce Initial load
duke
parents:
diff changeset
   471
            // doWork(). Hence, the registering of the enabling of
02bb8761fcce Initial load
duke
parents:
diff changeset
   472
            // the SelectionKey's interestOps is done here instead
02bb8761fcce Initial load
duke
parents:
diff changeset
   473
            // of calling SelectionKey.interestOps(<interest op>).
02bb8761fcce Initial load
duke
parents:
diff changeset
   474
02bb8761fcce Initial load
duke
parents:
diff changeset
   475
            Selector selector = orb.getTransportManager().getSelector(0);
02bb8761fcce Initial load
duke
parents:
diff changeset
   476
            selector.registerInterestOps(this);
02bb8761fcce Initial load
duke
parents:
diff changeset
   477
02bb8761fcce Initial load
duke
parents:
diff changeset
   478
            if (orb.transportDebugFlag) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   479
                dprint(".doWork<-:" + this);
02bb8761fcce Initial load
duke
parents:
diff changeset
   480
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   481
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   482
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   483
02bb8761fcce Initial load
duke
parents:
diff changeset
   484
    public void setEnqueueTime(long timeInMillis)
02bb8761fcce Initial load
duke
parents:
diff changeset
   485
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   486
        enqueueTime = timeInMillis;
02bb8761fcce Initial load
duke
parents:
diff changeset
   487
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   488
02bb8761fcce Initial load
duke
parents:
diff changeset
   489
    public long getEnqueueTime()
02bb8761fcce Initial load
duke
parents:
diff changeset
   490
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   491
        return enqueueTime;
02bb8761fcce Initial load
duke
parents:
diff changeset
   492
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   493
02bb8761fcce Initial load
duke
parents:
diff changeset
   494
02bb8761fcce Initial load
duke
parents:
diff changeset
   495
    //
02bb8761fcce Initial load
duke
parents:
diff changeset
   496
    // Factory methods.
02bb8761fcce Initial load
duke
parents:
diff changeset
   497
    //
02bb8761fcce Initial load
duke
parents:
diff changeset
   498
02bb8761fcce Initial load
duke
parents:
diff changeset
   499
    // REVISIT: refactor into common base or delegate.
02bb8761fcce Initial load
duke
parents:
diff changeset
   500
    public MessageMediator createMessageMediator(Broker broker,
02bb8761fcce Initial load
duke
parents:
diff changeset
   501
                                                 Connection connection)
02bb8761fcce Initial load
duke
parents:
diff changeset
   502
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   503
        // REVISIT - no factoring so cheat to avoid code dup right now.
02bb8761fcce Initial load
duke
parents:
diff changeset
   504
        // REVISIT **** COUPLING !!!!
02bb8761fcce Initial load
duke
parents:
diff changeset
   505
        ContactInfo contactInfo = new SocketOrChannelContactInfoImpl();
02bb8761fcce Initial load
duke
parents:
diff changeset
   506
        return contactInfo.createMessageMediator(broker, connection);
02bb8761fcce Initial load
duke
parents:
diff changeset
   507
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   508
02bb8761fcce Initial load
duke
parents:
diff changeset
   509
    // REVISIT: refactor into common base or delegate.
02bb8761fcce Initial load
duke
parents:
diff changeset
   510
    public MessageMediator finishCreatingMessageMediator(Broker broker,
02bb8761fcce Initial load
duke
parents:
diff changeset
   511
                                                         Connection connection,
02bb8761fcce Initial load
duke
parents:
diff changeset
   512
                                                         MessageMediator messageMediator)
02bb8761fcce Initial load
duke
parents:
diff changeset
   513
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   514
        // REVISIT - no factoring so cheat to avoid code dup right now.
02bb8761fcce Initial load
duke
parents:
diff changeset
   515
        // REVISIT **** COUPLING !!!!
02bb8761fcce Initial load
duke
parents:
diff changeset
   516
        ContactInfo contactInfo = new SocketOrChannelContactInfoImpl();
02bb8761fcce Initial load
duke
parents:
diff changeset
   517
        return contactInfo.finishCreatingMessageMediator(broker,
02bb8761fcce Initial load
duke
parents:
diff changeset
   518
                                          connection, messageMediator);
02bb8761fcce Initial load
duke
parents:
diff changeset
   519
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   520
02bb8761fcce Initial load
duke
parents:
diff changeset
   521
    public InputObject createInputObject(Broker broker,
02bb8761fcce Initial load
duke
parents:
diff changeset
   522
                                         MessageMediator messageMediator)
02bb8761fcce Initial load
duke
parents:
diff changeset
   523
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   524
        CorbaMessageMediator corbaMessageMediator = (CorbaMessageMediator)
02bb8761fcce Initial load
duke
parents:
diff changeset
   525
            messageMediator;
02bb8761fcce Initial load
duke
parents:
diff changeset
   526
        return new CDRInputObject((ORB)broker,
02bb8761fcce Initial load
duke
parents:
diff changeset
   527
                                  (CorbaConnection)messageMediator.getConnection(),
02bb8761fcce Initial load
duke
parents:
diff changeset
   528
                                  corbaMessageMediator.getDispatchBuffer(),
02bb8761fcce Initial load
duke
parents:
diff changeset
   529
                                  corbaMessageMediator.getDispatchHeader());
02bb8761fcce Initial load
duke
parents:
diff changeset
   530
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   531
02bb8761fcce Initial load
duke
parents:
diff changeset
   532
    public OutputObject createOutputObject(Broker broker,
02bb8761fcce Initial load
duke
parents:
diff changeset
   533
                                           MessageMediator messageMediator)
02bb8761fcce Initial load
duke
parents:
diff changeset
   534
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   535
        CorbaMessageMediator corbaMessageMediator = (CorbaMessageMediator)
02bb8761fcce Initial load
duke
parents:
diff changeset
   536
            messageMediator;
02bb8761fcce Initial load
duke
parents:
diff changeset
   537
        return new CDROutputObject((ORB) broker, corbaMessageMediator,
02bb8761fcce Initial load
duke
parents:
diff changeset
   538
                                   corbaMessageMediator.getReplyHeader(),
02bb8761fcce Initial load
duke
parents:
diff changeset
   539
                                   corbaMessageMediator.getStreamFormatVersion());
02bb8761fcce Initial load
duke
parents:
diff changeset
   540
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   541
02bb8761fcce Initial load
duke
parents:
diff changeset
   542
    ////////////////////////////////////////////////////
02bb8761fcce Initial load
duke
parents:
diff changeset
   543
    //
02bb8761fcce Initial load
duke
parents:
diff changeset
   544
    // SocketOrChannelAcceptor
02bb8761fcce Initial load
duke
parents:
diff changeset
   545
    //
02bb8761fcce Initial load
duke
parents:
diff changeset
   546
02bb8761fcce Initial load
duke
parents:
diff changeset
   547
    public ServerSocket getServerSocket()
02bb8761fcce Initial load
duke
parents:
diff changeset
   548
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   549
        return serverSocket;
02bb8761fcce Initial load
duke
parents:
diff changeset
   550
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   551
02bb8761fcce Initial load
duke
parents:
diff changeset
   552
    ////////////////////////////////////////////////////
02bb8761fcce Initial load
duke
parents:
diff changeset
   553
    //
02bb8761fcce Initial load
duke
parents:
diff changeset
   554
    // Implementation.
02bb8761fcce Initial load
duke
parents:
diff changeset
   555
    //
02bb8761fcce Initial load
duke
parents:
diff changeset
   556
02bb8761fcce Initial load
duke
parents:
diff changeset
   557
    public String toString()
02bb8761fcce Initial load
duke
parents:
diff changeset
   558
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   559
        String sock;
02bb8761fcce Initial load
duke
parents:
diff changeset
   560
        if (serverSocketChannel == null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   561
            if (serverSocket == null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   562
                sock = "(not initialized)";
02bb8761fcce Initial load
duke
parents:
diff changeset
   563
            } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   564
                sock = serverSocket.toString();
02bb8761fcce Initial load
duke
parents:
diff changeset
   565
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   566
        } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   567
            sock = serverSocketChannel.toString();
02bb8761fcce Initial load
duke
parents:
diff changeset
   568
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   569
02bb8761fcce Initial load
duke
parents:
diff changeset
   570
        return
02bb8761fcce Initial load
duke
parents:
diff changeset
   571
            toStringName() +
02bb8761fcce Initial load
duke
parents:
diff changeset
   572
            "["
02bb8761fcce Initial load
duke
parents:
diff changeset
   573
            + sock + " "
02bb8761fcce Initial load
duke
parents:
diff changeset
   574
            + type + " "
02bb8761fcce Initial load
duke
parents:
diff changeset
   575
            + shouldUseSelectThreadToWait() + " "
02bb8761fcce Initial load
duke
parents:
diff changeset
   576
            + shouldUseWorkerThreadForEvent()
02bb8761fcce Initial load
duke
parents:
diff changeset
   577
            + "]" ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   578
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   579
02bb8761fcce Initial load
duke
parents:
diff changeset
   580
    protected String toStringName()
02bb8761fcce Initial load
duke
parents:
diff changeset
   581
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   582
        return "SocketOrChannelAcceptorImpl";
02bb8761fcce Initial load
duke
parents:
diff changeset
   583
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   584
02bb8761fcce Initial load
duke
parents:
diff changeset
   585
    protected void dprint(String msg)
02bb8761fcce Initial load
duke
parents:
diff changeset
   586
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   587
        ORBUtility.dprint(toStringName(), msg);
02bb8761fcce Initial load
duke
parents:
diff changeset
   588
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   589
02bb8761fcce Initial load
duke
parents:
diff changeset
   590
    protected void dprint(String msg, Throwable t)
02bb8761fcce Initial load
duke
parents:
diff changeset
   591
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   592
        dprint(msg);
02bb8761fcce Initial load
duke
parents:
diff changeset
   593
        t.printStackTrace(System.out);
02bb8761fcce Initial load
duke
parents:
diff changeset
   594
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   595
02bb8761fcce Initial load
duke
parents:
diff changeset
   596
    // BEGIN Legacy support
02bb8761fcce Initial load
duke
parents:
diff changeset
   597
    ////////////////////////////////////////////////////
02bb8761fcce Initial load
duke
parents:
diff changeset
   598
    //
02bb8761fcce Initial load
duke
parents:
diff changeset
   599
    // LegacyServerSocketEndPointInfo and EndPointInfo
02bb8761fcce Initial load
duke
parents:
diff changeset
   600
    //
02bb8761fcce Initial load
duke
parents:
diff changeset
   601
02bb8761fcce Initial load
duke
parents:
diff changeset
   602
    public String getType()
02bb8761fcce Initial load
duke
parents:
diff changeset
   603
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   604
        return type;
02bb8761fcce Initial load
duke
parents:
diff changeset
   605
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   606
02bb8761fcce Initial load
duke
parents:
diff changeset
   607
    public String getHostName()
02bb8761fcce Initial load
duke
parents:
diff changeset
   608
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   609
        return hostname;
02bb8761fcce Initial load
duke
parents:
diff changeset
   610
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   611
02bb8761fcce Initial load
duke
parents:
diff changeset
   612
    public String getHost()
02bb8761fcce Initial load
duke
parents:
diff changeset
   613
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   614
        return hostname;
02bb8761fcce Initial load
duke
parents:
diff changeset
   615
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   616
02bb8761fcce Initial load
duke
parents:
diff changeset
   617
    public int getPort()
02bb8761fcce Initial load
duke
parents:
diff changeset
   618
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   619
        return port;
02bb8761fcce Initial load
duke
parents:
diff changeset
   620
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   621
02bb8761fcce Initial load
duke
parents:
diff changeset
   622
    public int getLocatorPort()
02bb8761fcce Initial load
duke
parents:
diff changeset
   623
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   624
        return locatorPort;
02bb8761fcce Initial load
duke
parents:
diff changeset
   625
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   626
02bb8761fcce Initial load
duke
parents:
diff changeset
   627
    public void setLocatorPort (int port)
02bb8761fcce Initial load
duke
parents:
diff changeset
   628
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   629
        locatorPort = port;
02bb8761fcce Initial load
duke
parents:
diff changeset
   630
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   631
02bb8761fcce Initial load
duke
parents:
diff changeset
   632
    public String getName()
02bb8761fcce Initial load
duke
parents:
diff changeset
   633
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   634
        // Kluge alert:
02bb8761fcce Initial load
duke
parents:
diff changeset
   635
        // Work and Legacy both define getName.
02bb8761fcce Initial load
duke
parents:
diff changeset
   636
        // Try to make this behave best for most cases.
02bb8761fcce Initial load
duke
parents:
diff changeset
   637
        String result =
02bb8761fcce Initial load
duke
parents:
diff changeset
   638
            name.equals(LegacyServerSocketEndPointInfo.NO_NAME) ?
02bb8761fcce Initial load
duke
parents:
diff changeset
   639
            this.toString() : name;
02bb8761fcce Initial load
duke
parents:
diff changeset
   640
        return result;
02bb8761fcce Initial load
duke
parents:
diff changeset
   641
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   642
    // END Legacy support
02bb8761fcce Initial load
duke
parents:
diff changeset
   643
}
02bb8761fcce Initial load
duke
parents:
diff changeset
   644
02bb8761fcce Initial load
duke
parents:
diff changeset
   645
// End of file.