KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > admin > server > core > channel > LocalRMIClientSocketFactory


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 /**
25  * PROPRIETARY/CONFIDENTIAL. Use of this product is subject to license terms.
26  *
27  * Copyright 2001-2002 by iPlanet/Sun Microsystems, Inc.,
28  * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
29  * All rights reserved.
30  */

31 package com.sun.enterprise.admin.server.core.channel;
32
33 import java.io.IOException JavaDoc;
34 import java.io.Serializable JavaDoc;
35 import java.net.InetAddress JavaDoc;
36 import java.net.Socket JavaDoc;
37 import java.net.UnknownHostException JavaDoc;
38 import java.rmi.server.RMIClientSocketFactory JavaDoc;
39
40 /**
41  * Local RMI Client Socket Factory. This class creates client sockets
42  * that connect to local loopback address. This class needs to be Serializable
43  * because RMI stubs contain a reference to client socket factory.
44  */

45 public class LocalRMIClientSocketFactory implements RMIClientSocketFactory JavaDoc,
46         Serializable JavaDoc {
47
48     private InetAddress JavaDoc localLoopbackAddress;
49
50     /**
51      * Create a new local RMI Client Socket Factory. This method uses <code>null
52      * </code> argument to <code>InetAddress.getByName()</code> to determine
53      * local loopback address.
54      * @throws UnknownHostException as thrown from the method <code>
55      * InetAddress.getByName()</code>.
56      */

57     public LocalRMIClientSocketFactory() throws UnknownHostException JavaDoc {
58         localLoopbackAddress = InetAddress.getByName(null);
59     }
60
61     /**
62      * Create a new local RMI Client Socket Factory on specified local IP
63      * address. Use this constructor when you know the local loopback IP
64      * address and do not want to handle UnknownHostException thrown by default
65      * constructor.
66      * @param localAddr local loopback address.
67      */

68     public LocalRMIClientSocketFactory(InetAddress JavaDoc localAddr) {
69         localLoopbackAddress = localAddr;
70     }
71
72     /**
73      * Create a new socket that connects to local loopback address and
74      * specified port. This method ignores host parameter. The method comes
75      * from the interface <code>java.rmi.server.RMIClientSocketFactory</code>
76      * @param host host to connect to, this is ignored and local loopback
77      * address is used.
78      * @param port port to connect to
79      * @throws IOException if an IO error occurs while creating the socket
80      * @return a Socket connected to local loopback address on specified port
81      */

82     public Socket JavaDoc createSocket(String JavaDoc host, int port) throws IOException JavaDoc {
83         return new Socket JavaDoc(localLoopbackAddress, port);
84     }
85
86 }
87
Popular Tags