KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > corba > se > impl > transport > DefaultSocketFactoryImpl


1 /*
2  * @(#)DefaultSocketFactoryImpl.java 1.3 04/07/26
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 package com.sun.corba.se.impl.transport;
9
10 import java.io.IOException JavaDoc;
11 import java.net.InetSocketAddress JavaDoc;
12 import java.net.Socket JavaDoc;
13 import java.net.SocketException JavaDoc;
14 import java.net.ServerSocket JavaDoc;
15 import java.nio.channels.SocketChannel JavaDoc;
16 import java.nio.channels.ServerSocketChannel JavaDoc;
17
18 import com.sun.corba.se.pept.transport.Acceptor;
19
20 import com.sun.corba.se.spi.orb.ORB;
21 import com.sun.corba.se.spi.transport.ORBSocketFactory;
22
23 import com.sun.corba.se.impl.orbutil.ORBConstants;
24
25 public class DefaultSocketFactoryImpl
26     implements ORBSocketFactory
27 {
28     private ORB orb;
29
30     public void setORB(ORB orb)
31     {
32     this.orb = orb;
33     }
34
35     public ServerSocket JavaDoc createServerSocket(String JavaDoc type,
36                        InetSocketAddress JavaDoc inetSocketAddress)
37         throws IOException JavaDoc
38     {
39     ServerSocketChannel JavaDoc serverSocketChannel = null;
40     ServerSocket JavaDoc serverSocket = null;
41
42     if (orb.getORBData().acceptorSocketType().equals(ORBConstants.SOCKETCHANNEL)) {
43         serverSocketChannel = ServerSocketChannel.open();
44         serverSocket = serverSocketChannel.socket();
45     } else {
46         serverSocket = new ServerSocket JavaDoc();
47     }
48     serverSocket.bind(inetSocketAddress);
49     return serverSocket;
50     }
51
52     public Socket JavaDoc createSocket(String JavaDoc type,
53                    InetSocketAddress JavaDoc inetSocketAddress)
54         throws IOException JavaDoc
55     {
56     SocketChannel JavaDoc socketChannel = null;
57     Socket JavaDoc socket = null;
58
59     if (orb.getORBData().connectionSocketType().equals(ORBConstants.SOCKETCHANNEL)) {
60         socketChannel = SocketChannel.open(inetSocketAddress);
61         socket = socketChannel.socket();
62     } else {
63         socket = new Socket JavaDoc(inetSocketAddress.getHostName(),
64                 inetSocketAddress.getPort());
65     }
66
67     // Disable Nagle's algorithm (i.e., always send immediately).
68
socket.setTcpNoDelay(true);
69
70     return socket;
71     }
72
73     public void setAcceptedSocketOptions(Acceptor acceptor,
74                      ServerSocket JavaDoc serverSocket,
75                      Socket JavaDoc socket)
76     throws SocketException JavaDoc
77     {
78     // Disable Nagle's algorithm (i.e., always send immediately).
79
socket.setTcpNoDelay(true);
80     }
81 }
82
83 // End of file.
84
Popular Tags