Search in sources :

Example 1 with AlternateIIOPAddressComponent

use of com.sun.corba.ee.spi.ior.iiop.AlternateIIOPAddressComponent in project Payara by payara.

the class IORToSocketInfoImpl method getSocketInfo.

@Override
public List getSocketInfo(IOR ior, List previous) {
    try {
        if (_logger.isLoggable(Level.FINE)) {
            _logger.log(Level.FINE, baseMsg + ".getSocketInfo->:");
        }
        List result = new ArrayList();
        IIOPProfileTemplate iiopProfileTemplate = (IIOPProfileTemplate) ior.getProfile().getTaggedProfileTemplate();
        IIOPAddress primary = iiopProfileTemplate.getPrimaryAddress();
        Locale loc = Locale.getDefault();
        String host = primary.getHost().toLowerCase(loc);
        String type = null;
        int port = 0;
        ConnectionContext ctx = new ConnectionContext();
        SocketInfo socketInfo = selector.getSSLPort(ior, ctx);
        selector.setClientConnectionContext(ctx);
        if (socketInfo == null) {
            type = SocketInfo.IIOP_CLEAR_TEXT;
            port = primary.getPort();
            if (_logger.isLoggable(Level.FINE)) {
                _logger.log(Level.FINE, baseMsg + ".getSocketInfo: did not find SSL SocketInfo");
            }
        } else {
            type = socketInfo.getType();
            port = socketInfo.getPort();
            if (_logger.isLoggable(Level.FINE)) {
                _logger.log(Level.FINE, baseMsg + ".getSocketInfo: found SSL socketInfo");
            }
        }
        if (_logger.isLoggable(Level.FINE)) {
            _logger.log(Level.FINE, baseMsg + ".getSocketInfo: Connection Context:" + ctx);
            _logger.log(Level.FINE, baseMsg + ".getSocketInfo: ENDPOINT INFO:type=" + type + ",host=" + host + ", port=" + port);
        }
        // for SSL
        if (socketInfo != null) {
            result.add(socketInfo);
            if (_logger.isLoggable(Level.FINE)) {
                _logger.log(Level.FINE, baseMsg + ".getSocketInfo: returning SSL socketInfo:" + " " + socketInfo.getType() + " " + socketInfo.getHost() + " " + socketInfo.getPort());
            }
            // However, SSL and IIOP-FO is not a supported feature.
            return result;
        }
        // for non-SSL
        if (_logger.isLoggable(Level.FINE)) {
            _logger.log(Level.FINE, baseMsg + ".getSocketInfo: returning non SSL socketInfo");
        }
        if (!previous.isEmpty()) {
            if (_logger.isLoggable(Level.FINE)) {
                _logger.log(Level.FINE, baseMsg + ".getSocketInfo: returning previous socketInfo: " + previous);
            }
            return previous;
        }
        // 
        // Save and add primary address
        // 
        SocketInfo primarySocketInfo = createSocketInfo("primary", type, host, port);
        result.add(primarySocketInfo);
        // 
        // List alternate addresses.
        // 
        Iterator iterator = iiopProfileTemplate.iteratorById(org.omg.IOP.TAG_ALTERNATE_IIOP_ADDRESS.value);
        while (iterator.hasNext()) {
            AlternateIIOPAddressComponent alternate = (AlternateIIOPAddressComponent) iterator.next();
            host = alternate.getAddress().getHost().toLowerCase(loc);
            port = alternate.getAddress().getPort();
            result.add(createSocketInfo("AlternateIIOPAddressComponent", SocketInfo.IIOP_CLEAR_TEXT, host, port));
        }
        synchronized (this) {
            List existing = (List) primaryToAddresses.get(primarySocketInfo);
            if (existing == null) {
                // First time we've seen this primary.
                // Save unrandomized list with primary at head.
                primaryToAddresses.put(primarySocketInfo, result);
                // do not randomize primary
                result.remove(0);
                // Randomized the alternates.
                java.util.Collections.shuffle(result);
                // put primary at head
                result.add(0, primarySocketInfo);
                // Save for subsequent use.
                primaryToRandomizedAddresses.put(primarySocketInfo, result);
                if (_logger.isLoggable(Level.FINE)) {
                    _logger.log(Level.FINE, baseMsg + ".getSocketInfo: initial randomized result: " + result);
                }
                return result;
            } else {
                if (result.equals(existing)) {
                    // The are the same so return the randomized version.
                    result = (List) primaryToRandomizedAddresses.get(primarySocketInfo);
                    if (_logger.isLoggable(Level.FINE)) {
                        _logger.log(Level.FINE, baseMsg + ".getSocketInfo: existing randomized result: " + result);
                    }
                    return result;
                } else {
                    // The lists should be the same.
                    // If not log a warning and return the
                    // non-randomized current list since it is different.
                    _logger.log(Level.FINE, baseMsg + ".getSocketInfo:" + " Address lists do not match: primary: " + primarySocketInfo + "; returning current: " + result + "; existing is: " + existing);
                    return result;
                }
            }
        }
    } catch (Exception ex) {
        _logger.log(Level.WARNING, "Exception getting SocketInfo", ex);
        RuntimeException rte = new RuntimeException(ex);
        rte.initCause(ex);
        throw rte;
    } finally {
        if (_logger.isLoggable(Level.FINE)) {
            _logger.log(Level.FINE, baseMsg + ".getSocketInfo<-:");
        }
    }
}
Also used : Locale(java.util.Locale) IIOPAddress(com.sun.corba.ee.spi.ior.iiop.IIOPAddress) ArrayList(java.util.ArrayList) SocketInfo(com.sun.corba.ee.spi.transport.SocketInfo) IORToSocketInfo(com.sun.corba.ee.spi.transport.IORToSocketInfo) IIOPProfileTemplate(com.sun.corba.ee.spi.ior.iiop.IIOPProfileTemplate) Iterator(java.util.Iterator) AlternateIIOPAddressComponent(com.sun.corba.ee.spi.ior.iiop.AlternateIIOPAddressComponent) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

AlternateIIOPAddressComponent (com.sun.corba.ee.spi.ior.iiop.AlternateIIOPAddressComponent)1 IIOPAddress (com.sun.corba.ee.spi.ior.iiop.IIOPAddress)1 IIOPProfileTemplate (com.sun.corba.ee.spi.ior.iiop.IIOPProfileTemplate)1 IORToSocketInfo (com.sun.corba.ee.spi.transport.IORToSocketInfo)1 SocketInfo (com.sun.corba.ee.spi.transport.SocketInfo)1 ArrayList (java.util.ArrayList)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Locale (java.util.Locale)1