1. /*
  2. * @(#)DefaultSocketFactory.java 1.22 04/06/21
  3. *
  4. * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package com.sun.corba.se.impl.legacy.connection;
  8. import java.io.IOException;
  9. import java.net.InetSocketAddress;
  10. import java.net.ServerSocket;
  11. import java.net.Socket;
  12. import java.net.UnknownHostException;
  13. import java.nio.channels.ServerSocketChannel;
  14. import java.nio.channels.SocketChannel;
  15. import org.omg.CORBA.ORB;
  16. import org.omg.CORBA.COMM_FAILURE;
  17. import org.omg.CORBA.CompletionStatus;
  18. import com.sun.corba.se.spi.ior.IOR;
  19. import com.sun.corba.se.spi.ior.iiop.IIOPProfileTemplate ;
  20. import com.sun.corba.se.spi.ior.iiop.IIOPAddress ;
  21. import com.sun.corba.se.spi.legacy.connection.GetEndPointInfoAgainException;
  22. import com.sun.corba.se.spi.legacy.connection.ORBSocketFactory;
  23. import com.sun.corba.se.spi.logging.CORBALogDomains;
  24. import com.sun.corba.se.spi.transport.SocketInfo;
  25. import com.sun.corba.se.impl.legacy.connection.EndPointInfoImpl;
  26. import com.sun.corba.se.impl.logging.ORBUtilSystemException;
  27. import com.sun.corba.se.impl.orbutil.ORBConstants;
  28. public class DefaultSocketFactory
  29. implements
  30. ORBSocketFactory
  31. {
  32. private com.sun.corba.se.spi.orb.ORB orb;
  33. private static ORBUtilSystemException wrapper = ORBUtilSystemException.get(
  34. CORBALogDomains.RPC_TRANSPORT ) ;
  35. public DefaultSocketFactory()
  36. {
  37. }
  38. public void setORB(com.sun.corba.se.spi.orb.ORB orb)
  39. {
  40. this.orb = orb;
  41. }
  42. public ServerSocket createServerSocket(String type, int port)
  43. throws
  44. IOException
  45. {
  46. if (! type.equals(ORBSocketFactory.IIOP_CLEAR_TEXT)) {
  47. throw wrapper.defaultCreateServerSocketGivenNonIiopClearText( type ) ;
  48. }
  49. ServerSocket serverSocket;
  50. if (orb.getORBData().acceptorSocketType().equals(ORBConstants.SOCKETCHANNEL)) {
  51. ServerSocketChannel serverSocketChannel =
  52. ServerSocketChannel.open();
  53. serverSocket = serverSocketChannel.socket();
  54. } else {
  55. serverSocket = new ServerSocket();
  56. }
  57. serverSocket.bind(new InetSocketAddress(port));
  58. return serverSocket;
  59. }
  60. public SocketInfo getEndPointInfo(ORB orb,
  61. IOR ior,
  62. SocketInfo socketInfo)
  63. {
  64. IIOPProfileTemplate temp =
  65. (IIOPProfileTemplate)ior.getProfile().getTaggedProfileTemplate() ;
  66. IIOPAddress primary = temp.getPrimaryAddress() ;
  67. return new EndPointInfoImpl(ORBSocketFactory.IIOP_CLEAR_TEXT,
  68. primary.getPort(),
  69. primary.getHost().toLowerCase());
  70. }
  71. public Socket createSocket(SocketInfo socketInfo)
  72. throws
  73. IOException,
  74. GetEndPointInfoAgainException
  75. {
  76. Socket socket;
  77. if (orb.getORBData().acceptorSocketType().equals(ORBConstants.SOCKETCHANNEL)) {
  78. InetSocketAddress address =
  79. new InetSocketAddress(socketInfo.getHost(),
  80. socketInfo.getPort());
  81. SocketChannel socketChannel = SocketChannel.open(address);
  82. socket = socketChannel.socket();
  83. } else {
  84. socket = new Socket(socketInfo.getHost(),
  85. socketInfo.getPort());
  86. }
  87. // REVISIT - this is done in SocketOrChannelConnectionImpl
  88. try {
  89. socket.setTcpNoDelay(true);
  90. } catch (Exception e) {
  91. ;
  92. }
  93. return socket;
  94. }
  95. }
  96. // End of file.