KickJava   Java API By Example, From Geeks To Geeks.

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


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.ServerSocket JavaDoc;
37 import java.net.UnknownHostException JavaDoc;
38 import java.rmi.server.RMIServerSocketFactory JavaDoc;
39
40 /**
41  * Local RMI Server Socket Factory. This class creates sockets that listen on
42  * only local loopback address.
43  */

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

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

66     public LocalRMIServerSocketFactory(InetAddress JavaDoc localAddr) {
67         localLoopbackAddress = localAddr;
68     }
69
70     /**
71      * Create a new socket that listens to specified port on local loopback
72      * address. The method comes from the interface <code>
73      * java.rmi.server.RMIClientSocketFactory</code>
74      * @param port port to listen to
75      * @throws IOException if an IO error occurs while creating the socket
76      * @return a Socket listening to specified port on local loopback address
77      */

78     public ServerSocket JavaDoc createServerSocket(int port) throws IOException JavaDoc {
79         return new ServerSocket JavaDoc(port, 0, localLoopbackAddress);
80     }
81 }
82
Popular Tags