FileDocCategorySizeDatePackage
SocketFactory.javaAPI DocGlassfish v2 API9109Fri May 04 22:34:56 BST 2007com.sun.enterprise.iiop

SocketFactory

public class SocketFactory extends com.sun.corba.ee.impl.legacy.connection.DefaultSocketFactory

Fields Summary
private static Logger
_logger
private Hashtable
endpointTable
private org.omg.IOP.Codec
codec
Constructors Summary
public SocketFactory()
Creates a new instance of SocketFactory


           
      
        super();
    
Methods Summary
private org.omg.IOP.CodecgetCodec(org.omg.CORBA.ORB orb)

        if (codec == null) {
            synchronized (this) {
                CodecFactory codecFactory = null;
                try {
                    codecFactory = CodecFactoryHelper.narrow(
                            orb.resolve_initial_references("CodecFactory"));
                } catch (org.omg.CORBA.ORBPackage.InvalidName e) {
                    System.out.println("Getting org.omg.CORBA.ORBPackage.InvalidName exception");
                }
                Encoding encoding = new Encoding((short)0, (byte)1, (byte)2);
                try {
                    codec = codecFactory.create_codec(encoding);
                } catch (org.omg.IOP.CodecFactoryPackage.UnknownEncoding e) {
                    System.out.println("Getting org.omg.IOP.CodecFactoryPackage.UnknownEncoding exception");
                }
            }
        }
        return codec;
    
public com.sun.corba.ee.spi.transport.SocketInfogetEndPointInfo(org.omg.CORBA.ORB orb, com.sun.corba.ee.spi.ior.IOR ior, com.sun.corba.ee.spi.transport.SocketInfo endPointInfo)

        try {
            IIOPProfileTemplate temp = (IIOPProfileTemplate)ior.
		                 getProfile().getTaggedProfileTemplate();
            IIOPAddress primary = temp.getPrimaryAddress() ;
            String host = primary.getHost().toLowerCase();
            int port = primary.getPort();
      
	    if(_logger.isLoggable(Level.FINE)) {
		_logger.log(Level.FINE,"ENDPOINT INFO:host=" +host + ", port=" + port);
	    }
            
            // If there is already a cached EndPointImpl for the primary host and
            // port return that.
            if ((endPointInfo = (EndPointInfoImpl)endpointTable.get(host + port)) != null)
                return endPointInfo;
            
            TaggedComponent alternateAddressTaggedComponents[] = 
                       ior.getProfile().getTaggedProfileTemplate().
			getIOPComponents((com.sun.corba.ee.spi.orb.ORB)orb,
                               org.omg.IOP.TAG_ALTERNATE_IIOP_ADDRESS.value
	                       //AlternateIIOPAddressComponent.TAG_ALTERNATE_IIOP_ADDRESS_ID
					 );
            if (alternateAddressTaggedComponents.length > 0) {
                getCodec(orb);
                for (int i = 0; i < alternateAddressTaggedComponents.length; i++) {
                    byte[] data = alternateAddressTaggedComponents[i].component_data;
                    Any any = null;
                    try {
                        any = codec.decode_value(data,
                                 AlternateIIOPAddressComponentHelper.type());
                    } catch (org.omg.IOP.CodecPackage.TypeMismatch e) {
                        if (_logger.isLoggable(Level.FINE)){
                            _logger.log(Level.FINE,"Exception codec TypeMismatch",e);
			}
                        throw new RuntimeException(e.toString());
                    } catch (org.omg.IOP.CodecPackage.FormatMismatch e) {
                        if (_logger.isLoggable(Level.FINE) ){
                            _logger.log(Level.FINE,"Exception codec FormatMismatch",e);
			}
                        throw new RuntimeException(e.toString());
                    }
                    AlternateIIOPAddressComponent iiopAddress = 
                        AlternateIIOPAddressComponentHelper.extract(any);
                    // if any host:port has an EndPointImpl in the endpointTable
                    // we should make sure we set the primary host:port with
                    // that EndPointImpl in the endpointTable and return that. 
                    // Subsequently we will not even get here, since for the 
                    // primary host:port the cached value will be returned
                    if ((endPointInfo = (EndPointInfoImpl)endpointTable.
                            get(iiopAddress.host + iiopAddress.port)) != null) {
                                /*
                       if (!type.equals(ORBSocketFactory.IIOP_CLEAR_TEXT)) {
                           // Use this host address to make the connection, since a connection
                           // has already been made using this address, just use the secure port.
                           // It is assumed that the primary host address in the IOR is also 
                           // one of the taggeded alternate addresses, which is a fair assumption. 
                           // Hence the remote machine should be reacheable thru the cached 
                           // host address and new secure port being specified
                           endPointInfo = new EndPointInfoImpl(type, iiopAddress.host, port);
                           endpointTable.put(host + port, endPointInfo);
                           return endPointInfo;
                       } else { */
                           endpointTable.put(host + port, endPointInfo);
                           return endPointInfo;
                       //}
                    }
                }
                // In case nothing is found use primary host:port
                endPointInfo = new EndPointInfoImpl(ORBSocketFactory.IIOP_CLEAR_TEXT, port, host);
                endpointTable.put(host + port, endPointInfo);
           } else {
                
                endPointInfo = new EndPointInfoImpl(ORBSocketFactory.IIOP_CLEAR_TEXT, port, host);
                endpointTable.put(host + port, endPointInfo);
            }
            return endPointInfo;
        } catch ( Exception ex ) {
            if (_logger.isLoggable(Level.FINE)){
                _logger.log(Level.FINE,"Exception getting End point info",ex);
	    }
            throw new RuntimeException(ex.getMessage());
        }
    
private intshortToInt(short value)

        if (value < 0)
            return value + 65536 ;
        return value ;