1. /*
  2. * @(#)ORBSocketFactory.java 1.7 03/01/23
  3. *
  4. * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package com.sun.corba.se.connection;
  8. import java.net.ServerSocket;
  9. import java.net.Socket;
  10. import java.io.IOException;
  11. import com.sun.corba.se.internal.core.IOR;
  12. /**
  13. *
  14. * This interface gives one the ability to plug in their own socket
  15. * factory class to an ORB. <p>
  16. *
  17. * Usage: <p>
  18. *
  19. * One specifies a class which implements this interface via the
  20. *
  21. * <code>ORBConstants.SOCKET_FACTORY_CLASS_PROPERTY</code>
  22. *
  23. * property. <p>
  24. *
  25. * Example: <p>
  26. * <pre>
  27. * -Dcom.sun.CORBA.connection.ORBSocketFactoryClass=MySocketFactory
  28. * </pre> <p>
  29. *
  30. * Typically one would use the same socket factory class on both the
  31. * server side and the client side (but this is not required). <p>
  32. *
  33. * A <code>ORBSocketFactory</code> class should have a public default
  34. * constructor which is called once per instantiating ORB.init call.
  35. * That ORB then calls the methods of that <code>ORBSocketFactory</code>
  36. * to obtain client and server sockets. <p>
  37. *
  38. * This interface also supports multiple server end points. See the
  39. * documentation on <code>createServerSocket</code> below.
  40. *
  41. */
  42. public interface ORBSocketFactory
  43. {
  44. /**
  45. * A server ORB always creates an "IIOP_CLEAR_TEXT" listening port.
  46. * That port is put into IOP profiles of object references exported
  47. * by an ORB. <p>
  48. *
  49. * If
  50. *
  51. * <code>createServerSocket(String type, int port)</code>
  52. *
  53. * is passed <code>IIOP_CLEAR_TEXT</code> as a <code>type</code>
  54. * argument it should then call and return
  55. *
  56. * <code>new java.net.ServerSocket(int port)</code> <p>
  57. *
  58. * If
  59. *
  60. * <code>createSocket(EndPointInfo endPointInfo)</code>
  61. *
  62. * is passed <code>IIOP_CLEAR_TEXT</code> in
  63. * <code>endPointInfo.getType()</code> it should
  64. * then call and return
  65. *
  66. * <pre>
  67. * new java.net.Socket(endPointInfo.getHost(),
  68. * endPointInfo.getPort())
  69. * </pre>
  70. *
  71. */
  72. public static final String IIOP_CLEAR_TEXT = "IIOP_CLEAR_TEXT";
  73. /**
  74. * This method is used by a server side ORB. <p>
  75. *
  76. * When an ORB needs to create a listen socket on which connection
  77. * requests are accepted it calls
  78. *
  79. * <code>createServerSocket(String type, int port)</code>.
  80. *
  81. * The type argument says which type of socket should be created. <p>
  82. *
  83. * The interpretation of the type argument is the responsibility of
  84. * an instance of <code>ORBSocketFactory</code>, except in the case
  85. * of <code>IIOP_CLEAR_TEXT</code>, in which case a standard server
  86. * socket should be created. <p>
  87. *
  88. *
  89. * Multiple Server Port API: <p>
  90. *
  91. * In addition to the IIOP_CLEAR_TEXT listening port, it is possible
  92. * to specify that an ORB listen on additional port of specific types. <p>
  93. *
  94. * This API allows one to specify that an ORB should create an X,
  95. * or an X and a Y listen socket. <p>
  96. *
  97. * If X, to the user, means SSL, then one just plugs in an SSL
  98. * socket factory. <p>
  99. *
  100. * Or, another example, if X and Y, to the user, means SSL without
  101. * authentication and SSL with authentication respectively, then they
  102. * plug in a factory which will either create an X or a Y socket
  103. * depending on the type given to
  104. *
  105. * <code>createServerSocket(String type, int port)</code>. <p>
  106. *
  107. * One specifies multiple listening ports (in addition to the
  108. * default IIOP_CLEAR_TEXT port) using the
  109. *
  110. * <code>ORBConstants.LISTEN_SOCKET_PROPERTY</code>
  111. *
  112. * property. <p>
  113. *
  114. * Example usage:<p>
  115. *
  116. * <pre>
  117. * ... \
  118. * -Dcom.sun.CORBA.connection.ORBSocketFactory=com.my.MySockFact \
  119. * -Dcom.sun.CORBA.connection.ORBListenSocket=SSL:0,foo:1 \
  120. * ...
  121. * </pre>
  122. *
  123. * The meaning of the "type" (SSL and foo above) is controlled
  124. * by the user. <p>
  125. *
  126. * ORBListenSocket is only meaningful for servers. <p>
  127. *
  128. * The property value is interpreted as follows. For each
  129. * type/number pair: <p>
  130. *
  131. * If number is 0 then use an emphemeral port for the listener of
  132. * the associated type. <p>
  133. *
  134. * If number is greater then 0 use that port number. <p>
  135. *
  136. * An ORB creates a listener socket for each type
  137. * specified by the user by calling
  138. *
  139. * <code>createServerSocket(String type, int port)</code>
  140. *
  141. * with the type specified by the user. <p>
  142. *
  143. * After an ORB is initialized and the RootPOA has been resolved,
  144. * it is then listening on
  145. * all the end points which were specified. It may be necessary
  146. * to add this additional end point information to object references
  147. * exported by this ORB. <p>
  148. *
  149. * Each object reference will contain the ORB's default IIOP_CLEAR_TEXT
  150. * end point in its IOP profile. To add additional end point information
  151. * (i.e., an SSL port) to an IOR (i.e., an object reference) one needs
  152. * to intercept IOR creation. The are two ways to do that. Use
  153. * the deprecated <code>objectReferenceCreated</code> hook or
  154. * use an <code>PortableInterceptor::IORInterceptor</code>. Both
  155. * of these techniques are now discussed. <p>
  156. *
  157. *
  158. * Deprecated <code>objectReferenceCreated</code> interceptor: <p>
  159. *
  160. * Define an ORB which extends
  161. *
  162. * <code>POA.POAORB</code>
  163. *
  164. * and overrides the
  165. *
  166. * <code>objectReferenceCreated(IOR ior)</code>
  167. *
  168. * method. Inside that method one calls
  169. *
  170. * <code>getServerPort(String type)</code>
  171. *
  172. * (a method on the ORB) giving it
  173. * a type specified via <code>ORBListenSocket</code>.
  174. * <code>getServerPort</code> returns the listen port for the given
  175. * type. <p>
  176. *
  177. * Typically one would add this port number and type to
  178. * some tagged component chosen by the user to represent this
  179. * information. This tagged component would then be added to
  180. * <code>objectReferenceCreated</code>'s <code>IOR</code> argument
  181. * and the augmented <code>IOR</code> would be returned. <p> <p>
  182. *
  183. *
  184. * Using PortableInterceptors (with a non-standard extension): <p>
  185. *
  186. * Register an <code>IORInterceptor</code>. Inside its
  187. * <code>establish_components</code> operation:
  188. *
  189. * <pre>
  190. *
  191. * com.sun.corba.se.interceptor.IORInfoExt ext;
  192. * ext = (com.sun.corba.se.interceptor.IORInfoExt)info;
  193. *
  194. * int port = ext.getServerPort("myType");
  195. *
  196. * </pre>
  197. *
  198. * Once you have the port you may add information to references
  199. * created by the associated adapter by calling
  200. *
  201. * <code>IORInfo::add_ior_component</code><p> <p>
  202. *
  203. *
  204. * Note: if one is using a POA and the lifespan policy of that
  205. * POA is persistent then the port number returned
  206. * by <code>getServerPort</code> <em>may</em>
  207. * be the corresponding ORBD port, depending on whether the POA/ORBD
  208. * protocol is the present port exchange or if, in the future,
  209. * the protocol is based on object reference template exchange.
  210. * In either
  211. * case, the port returned will be correct for the protocol.
  212. * (In more detail, if the port exchange protocol is used then
  213. * getServerPort will return the ORBD's port since the port
  214. * exchange happens before, at ORB initialization.
  215. * If object reference
  216. * exchange is used then the server's transient port will be returned
  217. * since the templates are exchanged after adding components.) <p>
  218. *
  219. *
  220. * Persistent object reference support: <p>
  221. *
  222. * When creating persistent object references with alternate
  223. * type/port info, ones needs to configure the ORBD to also support
  224. * this alternate info. This is done as follows: <p>
  225. *
  226. * - Give the ORBD the same socket factory you gave to the client
  227. * and server. <p>
  228. *
  229. * - specify ORBListenSocket ports of the same types that your
  230. * servers support. You should probably specify explicit port
  231. * numbers for ORBD if you embed these numbers inside IORs. <p>
  232. *
  233. * Note: when using the port exchange protocol
  234. * the ORBD and servers will exchange port
  235. * numbers for each given type so they know about each other.
  236. * When using object reference template exchange the server's
  237. * transient ports are contained in the template. <p>
  238. *
  239. *
  240. * - specify your <code>BadServerIdHandler</code> (discussed below)
  241. * using the
  242. *
  243. * <code>ORBConstants.BAD_SERVER_ID_HANDLER_CLASS_PROPERTY</code> <p>
  244. *
  245. * Example: <p>
  246. *
  247. * <pre>
  248. *
  249. * -Dcom.sun.CORBA.POA.ORBBadServerIdHandlerClass=corba.socketPersistent.MyBadServerIdHandler
  250. *
  251. * </pre>
  252. *
  253. * The <code>BadServerIdHandler</code> ...<p>
  254. *
  255. * See <code>com.sun.corba.se.internal.Activation.ServerManagerImpl.handle</code>
  256. * for example code on writing a bad server id handler. NOTE: This
  257. * is an unsupported internal API. It will not exist in future releases.
  258. * <p>
  259. *
  260. *
  261. * Secure connections to other services: <p>
  262. *
  263. * If one wants secure connections to other services such as
  264. * Naming then one should configure them with the same
  265. *
  266. * <code>SOCKET_FACTORY_CLASS_PROPERTY</code> and
  267. * <code>LISTEN_SOCKET_PROPERTY</code>
  268. *
  269. * as used by other clients and servers in your distributed system. <p>
  270. *
  271. */
  272. public ServerSocket createServerSocket(String type, int port)
  273. throws
  274. IOException;
  275. /**
  276. * This method is used by a client side ORB. <p>
  277. *
  278. * Each time a client invokes on an object reference, the reference's
  279. * associated ORB will call
  280. *
  281. * <pre>
  282. * getEndPointInfo(ORB orb,
  283. * com.sun.corba.se.internal.core.IOR ior,
  284. * EndPointInfo endPointInfo)
  285. * </pre>
  286. *
  287. * NOTE: The type of the <code>ior</code> argument is an internal
  288. * representation for efficiency. If the <code>ORBSocketFactory</code>
  289. * interface ever becomes standardized then the <code>ior</code> will
  290. * most likely change to a standard type (e.g., a stringified ior,
  291. * an <code>org.omg.IOP.IOR</code>, or ...). <p>
  292. *
  293. * Typically, this method will look at tagged components in the
  294. * given <code>ior</code> to determine what type of socket to create. <p>
  295. *
  296. * Typically, the <code>ior</code> will contain a tagged component
  297. * specifying an alternate port type and number. <p>
  298. *
  299. * This method should return an <code>EndPointInfo</code> object
  300. * containing the type/host/port to be used for the connection.
  301. *
  302. * If there are no appropriate tagged components then this method
  303. * should return an <code>EndPointInfo</code> object with the type
  304. * <code>IIOP_CLEAR_TEXT</code> and host/port from the ior's IOP
  305. * profile. <p>
  306. *
  307. * If the ORB already has an existing connection to the returned
  308. * type/host/port, then that connection is used. Otherwise the ORB calls
  309. *
  310. * <code>createSocket(EndPointInfo endPointInfo)</code> <p>
  311. *
  312. * The <code>orb</code> argument is useful for handling
  313. * the <code>ior</code> argument. <p>
  314. *
  315. * The <code>EndpointInfo</code> given to <code>getEndPointInfo</code>
  316. * is either null or an object obtained
  317. * from <code>GetEndPointInfoAgainException</code> <p>
  318. *
  319. */
  320. public EndPointInfo getEndPointInfo(org.omg.CORBA.ORB orb,
  321. IOR ior,
  322. EndPointInfo endPointInfo);
  323. /**
  324. * This method is used by a client side ORB. <p>
  325. *
  326. * This method should return a client socket of the given
  327. * type/host/port. <p>
  328. *
  329. * Note: the <code>EndPointInfo</code> is the same instance as was
  330. * returned by <code>getEndPointInfo</code> so extra cookie info may
  331. * be attached. <p>
  332. *
  333. * If this method throws GetEndPointInfoAgainException then the
  334. * ORB calls <code>getEndPointInfo</code> again, passing it the
  335. * <code>EndPointInfo</code> object contained in the exception. <p>
  336. *
  337. */
  338. public Socket createSocket(EndPointInfo endPointInfo)
  339. throws
  340. IOException,
  341. GetEndPointInfoAgainException;
  342. }
  343. // End of file.