corba/src/share/classes/com/sun/corba/se/impl/legacy/connection/LegacyServerSocketManagerImpl.java
author ohair
Tue, 25 May 2010 15:52:11 -0700
changeset 5555 b2b5ed3f0d0d
parent 4 02bb8761fcce
permissions -rw-r--r--
6943119: Rebrand source copyright notices Reviewed-by: darcy
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4
02bb8761fcce Initial load
duke
parents:
diff changeset
     1
/*
5555
b2b5ed3f0d0d 6943119: Rebrand source copyright notices
ohair
parents: 4
diff changeset
     2
 * Copyright (c) 1998, 2003, 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.legacy.connection;
02bb8761fcce Initial load
duke
parents:
diff changeset
    27
02bb8761fcce Initial load
duke
parents:
diff changeset
    28
import java.net.ServerSocket;
02bb8761fcce Initial load
duke
parents:
diff changeset
    29
import java.util.ArrayList;
02bb8761fcce Initial load
duke
parents:
diff changeset
    30
import java.util.Collection;
02bb8761fcce Initial load
duke
parents:
diff changeset
    31
import java.util.Iterator;
02bb8761fcce Initial load
duke
parents:
diff changeset
    32
02bb8761fcce Initial load
duke
parents:
diff changeset
    33
import org.omg.CORBA.INITIALIZE;
02bb8761fcce Initial load
duke
parents:
diff changeset
    34
import org.omg.CORBA.INTERNAL;
02bb8761fcce Initial load
duke
parents:
diff changeset
    35
import org.omg.CORBA.CompletionStatus;
02bb8761fcce Initial load
duke
parents:
diff changeset
    36
02bb8761fcce Initial load
duke
parents:
diff changeset
    37
import com.sun.corba.se.pept.transport.Acceptor;
02bb8761fcce Initial load
duke
parents:
diff changeset
    38
import com.sun.corba.se.pept.transport.ByteBufferPool;
02bb8761fcce Initial load
duke
parents:
diff changeset
    39
import com.sun.corba.se.pept.transport.ContactInfo;
02bb8761fcce Initial load
duke
parents:
diff changeset
    40
import com.sun.corba.se.pept.transport.Selector;
02bb8761fcce Initial load
duke
parents:
diff changeset
    41
02bb8761fcce Initial load
duke
parents:
diff changeset
    42
import com.sun.corba.se.spi.ior.IOR;
02bb8761fcce Initial load
duke
parents:
diff changeset
    43
import com.sun.corba.se.spi.ior.iiop.IIOPProfile ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    44
import com.sun.corba.se.spi.ior.ObjectKeyTemplate;
02bb8761fcce Initial load
duke
parents:
diff changeset
    45
import com.sun.corba.se.spi.ior.ObjectId ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    46
import com.sun.corba.se.spi.orb.ORB;
02bb8761fcce Initial load
duke
parents:
diff changeset
    47
import com.sun.corba.se.spi.transport.CorbaTransportManager;
02bb8761fcce Initial load
duke
parents:
diff changeset
    48
import com.sun.corba.se.spi.legacy.connection.LegacyServerSocketEndPointInfo;
02bb8761fcce Initial load
duke
parents:
diff changeset
    49
import com.sun.corba.se.spi.legacy.connection.LegacyServerSocketManager;
02bb8761fcce Initial load
duke
parents:
diff changeset
    50
import com.sun.corba.se.spi.transport.SocketOrChannelAcceptor;
02bb8761fcce Initial load
duke
parents:
diff changeset
    51
import com.sun.corba.se.spi.logging.CORBALogDomains;
02bb8761fcce Initial load
duke
parents:
diff changeset
    52
02bb8761fcce Initial load
duke
parents:
diff changeset
    53
import com.sun.corba.se.impl.encoding.EncapsOutputStream;
02bb8761fcce Initial load
duke
parents:
diff changeset
    54
import com.sun.corba.se.impl.legacy.connection.SocketFactoryAcceptorImpl;
02bb8761fcce Initial load
duke
parents:
diff changeset
    55
import com.sun.corba.se.impl.legacy.connection.USLPort;
02bb8761fcce Initial load
duke
parents:
diff changeset
    56
import com.sun.corba.se.impl.orbutil.ORBUtility;
02bb8761fcce Initial load
duke
parents:
diff changeset
    57
import com.sun.corba.se.impl.transport.SocketOrChannelAcceptorImpl;
02bb8761fcce Initial load
duke
parents:
diff changeset
    58
import com.sun.corba.se.impl.logging.ORBUtilSystemException;
02bb8761fcce Initial load
duke
parents:
diff changeset
    59
02bb8761fcce Initial load
duke
parents:
diff changeset
    60
public class LegacyServerSocketManagerImpl
02bb8761fcce Initial load
duke
parents:
diff changeset
    61
    implements
02bb8761fcce Initial load
duke
parents:
diff changeset
    62
        LegacyServerSocketManager
02bb8761fcce Initial load
duke
parents:
diff changeset
    63
{
02bb8761fcce Initial load
duke
parents:
diff changeset
    64
    protected ORB orb;
02bb8761fcce Initial load
duke
parents:
diff changeset
    65
    private ORBUtilSystemException wrapper ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    66
02bb8761fcce Initial load
duke
parents:
diff changeset
    67
    public LegacyServerSocketManagerImpl(ORB orb)
02bb8761fcce Initial load
duke
parents:
diff changeset
    68
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
    69
        this.orb = orb;
02bb8761fcce Initial load
duke
parents:
diff changeset
    70
        wrapper = ORBUtilSystemException.get( orb,
02bb8761fcce Initial load
duke
parents:
diff changeset
    71
            CORBALogDomains.RPC_TRANSPORT ) ;
02bb8761fcce Initial load
duke
parents:
diff changeset
    72
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
    73
02bb8761fcce Initial load
duke
parents:
diff changeset
    74
    ////////////////////////////////////////////////////
02bb8761fcce Initial load
duke
parents:
diff changeset
    75
    //
02bb8761fcce Initial load
duke
parents:
diff changeset
    76
    // LegacyServerSocketManager
02bb8761fcce Initial load
duke
parents:
diff changeset
    77
    //
02bb8761fcce Initial load
duke
parents:
diff changeset
    78
02bb8761fcce Initial load
duke
parents:
diff changeset
    79
    // Only used in ServerManagerImpl.
02bb8761fcce Initial load
duke
parents:
diff changeset
    80
    public int legacyGetTransientServerPort(String type)
02bb8761fcce Initial load
duke
parents:
diff changeset
    81
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
    82
        return legacyGetServerPort(type, false);
02bb8761fcce Initial load
duke
parents:
diff changeset
    83
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
    84
02bb8761fcce Initial load
duke
parents:
diff changeset
    85
    // Only used by POAPolicyMediatorBase.
02bb8761fcce Initial load
duke
parents:
diff changeset
    86
    public synchronized int legacyGetPersistentServerPort(String socketType)
02bb8761fcce Initial load
duke
parents:
diff changeset
    87
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
    88
        if (orb.getORBData().getServerIsORBActivated()) {
02bb8761fcce Initial load
duke
parents:
diff changeset
    89
            // this server is activated by orbd
02bb8761fcce Initial load
duke
parents:
diff changeset
    90
            return legacyGetServerPort(socketType, true);
02bb8761fcce Initial load
duke
parents:
diff changeset
    91
        } else if (orb.getORBData().getPersistentPortInitialized()) {
02bb8761fcce Initial load
duke
parents:
diff changeset
    92
            // this is a user-activated server
02bb8761fcce Initial load
duke
parents:
diff changeset
    93
            return orb.getORBData().getPersistentServerPort();
02bb8761fcce Initial load
duke
parents:
diff changeset
    94
        } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
    95
            throw wrapper.persistentServerportNotSet(
02bb8761fcce Initial load
duke
parents:
diff changeset
    96
                CompletionStatus.COMPLETED_MAYBE);
02bb8761fcce Initial load
duke
parents:
diff changeset
    97
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
    98
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
    99
02bb8761fcce Initial load
duke
parents:
diff changeset
   100
    // Only used by PI IORInfoImpl.
02bb8761fcce Initial load
duke
parents:
diff changeset
   101
    public synchronized int legacyGetTransientOrPersistentServerPort(
02bb8761fcce Initial load
duke
parents:
diff changeset
   102
        String socketType)
02bb8761fcce Initial load
duke
parents:
diff changeset
   103
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   104
            return legacyGetServerPort(socketType,
02bb8761fcce Initial load
duke
parents:
diff changeset
   105
                                       orb.getORBData()
02bb8761fcce Initial load
duke
parents:
diff changeset
   106
                                       .getServerIsORBActivated());
02bb8761fcce Initial load
duke
parents:
diff changeset
   107
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   108
02bb8761fcce Initial load
duke
parents:
diff changeset
   109
    // Used in RepositoryImpl, ServerManagerImpl, POAImpl,
02bb8761fcce Initial load
duke
parents:
diff changeset
   110
    // POAPolicyMediatorBase, TOAImpl.
02bb8761fcce Initial load
duke
parents:
diff changeset
   111
    // To get either default or bootnaming endpoint.
02bb8761fcce Initial load
duke
parents:
diff changeset
   112
    public synchronized LegacyServerSocketEndPointInfo legacyGetEndpoint(
02bb8761fcce Initial load
duke
parents:
diff changeset
   113
        String name)
02bb8761fcce Initial load
duke
parents:
diff changeset
   114
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   115
        Iterator iterator = getAcceptorIterator();
02bb8761fcce Initial load
duke
parents:
diff changeset
   116
        while (iterator.hasNext()) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   117
            LegacyServerSocketEndPointInfo endPoint = cast(iterator.next());
02bb8761fcce Initial load
duke
parents:
diff changeset
   118
            if (endPoint != null && name.equals(endPoint.getName())) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   119
                return endPoint;
02bb8761fcce Initial load
duke
parents:
diff changeset
   120
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   121
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   122
        throw new INTERNAL("No acceptor for: " + name);
02bb8761fcce Initial load
duke
parents:
diff changeset
   123
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   124
02bb8761fcce Initial load
duke
parents:
diff changeset
   125
    // Check to see if the given port is equal to any of the ORB Server Ports.
02bb8761fcce Initial load
duke
parents:
diff changeset
   126
    // XXX Does this need to change for the multi-homed case?
02bb8761fcce Initial load
duke
parents:
diff changeset
   127
    // Used in IIOPProfileImpl, ORBImpl.
02bb8761fcce Initial load
duke
parents:
diff changeset
   128
    public boolean legacyIsLocalServerPort(int port)
02bb8761fcce Initial load
duke
parents:
diff changeset
   129
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   130
        Iterator iterator = getAcceptorIterator();
02bb8761fcce Initial load
duke
parents:
diff changeset
   131
        while (iterator.hasNext()) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   132
            LegacyServerSocketEndPointInfo endPoint = cast(iterator.next());
02bb8761fcce Initial load
duke
parents:
diff changeset
   133
            if (endPoint != null && endPoint.getPort() == port) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   134
                return true;
02bb8761fcce Initial load
duke
parents:
diff changeset
   135
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   136
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   137
        return false;
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
    //
02bb8761fcce Initial load
duke
parents:
diff changeset
   142
    // Implementation.
02bb8761fcce Initial load
duke
parents:
diff changeset
   143
    //
02bb8761fcce Initial load
duke
parents:
diff changeset
   144
02bb8761fcce Initial load
duke
parents:
diff changeset
   145
    private int legacyGetServerPort (String socketType, boolean isPersistent)
02bb8761fcce Initial load
duke
parents:
diff changeset
   146
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   147
        Iterator endpoints = getAcceptorIterator();
02bb8761fcce Initial load
duke
parents:
diff changeset
   148
        while (endpoints.hasNext()) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   149
            LegacyServerSocketEndPointInfo ep = cast(endpoints.next());
02bb8761fcce Initial load
duke
parents:
diff changeset
   150
            if (ep != null && ep.getType().equals(socketType)) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   151
                if (isPersistent) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   152
                    return ep.getLocatorPort();
02bb8761fcce Initial load
duke
parents:
diff changeset
   153
                } else {
02bb8761fcce Initial load
duke
parents:
diff changeset
   154
                    return ep.getPort();
02bb8761fcce Initial load
duke
parents:
diff changeset
   155
                }
02bb8761fcce Initial load
duke
parents:
diff changeset
   156
            }
02bb8761fcce Initial load
duke
parents:
diff changeset
   157
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   158
        return -1;
02bb8761fcce Initial load
duke
parents:
diff changeset
   159
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   160
02bb8761fcce Initial load
duke
parents:
diff changeset
   161
    private Iterator getAcceptorIterator()
02bb8761fcce Initial load
duke
parents:
diff changeset
   162
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   163
        Collection acceptors =
02bb8761fcce Initial load
duke
parents:
diff changeset
   164
            orb.getCorbaTransportManager().getAcceptors(null, null);
02bb8761fcce Initial load
duke
parents:
diff changeset
   165
        if (acceptors != null) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   166
            return acceptors.iterator();
02bb8761fcce Initial load
duke
parents:
diff changeset
   167
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   168
02bb8761fcce Initial load
duke
parents:
diff changeset
   169
        throw wrapper.getServerPortCalledBeforeEndpointsInitialized() ;
02bb8761fcce Initial load
duke
parents:
diff changeset
   170
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   171
02bb8761fcce Initial load
duke
parents:
diff changeset
   172
    private LegacyServerSocketEndPointInfo cast(Object o)
02bb8761fcce Initial load
duke
parents:
diff changeset
   173
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   174
        if (o instanceof LegacyServerSocketEndPointInfo) {
02bb8761fcce Initial load
duke
parents:
diff changeset
   175
            return (LegacyServerSocketEndPointInfo) o;
02bb8761fcce Initial load
duke
parents:
diff changeset
   176
        }
02bb8761fcce Initial load
duke
parents:
diff changeset
   177
        return null;
02bb8761fcce Initial load
duke
parents:
diff changeset
   178
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   179
02bb8761fcce Initial load
duke
parents:
diff changeset
   180
    protected void dprint(String msg)
02bb8761fcce Initial load
duke
parents:
diff changeset
   181
    {
02bb8761fcce Initial load
duke
parents:
diff changeset
   182
        ORBUtility.dprint("LegacyServerSocketManagerImpl", msg);
02bb8761fcce Initial load
duke
parents:
diff changeset
   183
    }
02bb8761fcce Initial load
duke
parents:
diff changeset
   184
}
02bb8761fcce Initial load
duke
parents:
diff changeset
   185
02bb8761fcce Initial load
duke
parents:
diff changeset
   186
// End of file.