KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > net > sockets > TimeoutServerSocketFactory


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2005, JBoss Inc., and individual contributors as indicated
4   * by the @authors tag. See the copyright.txt in the distribution for a
5   * full listing of individual contributors.
6   *
7   * This is free software; you can redistribute it and/or modify it
8   * under the terms of the GNU Lesser General Public License as
9   * published by the Free Software Foundation; either version 2.1 of
10   * the License, or (at your option) any later version.
11   *
12   * This software is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15   * Lesser General Public License for more details.
16   *
17   * You should have received a copy of the GNU Lesser General Public
18   * License along with this software; if not, write to the Free
19   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21   */

22 package org.jboss.net.sockets;
23
24 import java.io.IOException JavaDoc;
25 import java.io.Serializable JavaDoc;
26 import java.net.InetAddress JavaDoc;
27 import java.net.ServerSocket JavaDoc;
28 import java.net.UnknownHostException JavaDoc;
29 import java.rmi.server.RMIServerSocketFactory JavaDoc;
30
31 /**
32  * A RMIServerSocketFactory that installs a InterruptableInputStream to be
33  * responsive to thead interruption events.
34  *
35  * @author Scott.Stark@jboss.org
36  * @version $Revision: 1958 $
37  */

38 public class TimeoutServerSocketFactory
39    implements RMIServerSocketFactory JavaDoc, Serializable JavaDoc
40 {
41    /** @since 3.2.6 */
42    static final long serialVersionUID = 7006964274840965634L;
43    protected transient InetAddress JavaDoc bindAddress;
44    protected int backlog = 200;
45
46    /**
47     * Create a socket factory that binds on any address with a default
48     * backlog of 200
49     */

50    public TimeoutServerSocketFactory()
51    {
52       this(null, 200);
53    }
54
55    /**
56     * Create a socket factory with the given bind address
57     */

58    public TimeoutServerSocketFactory(InetAddress JavaDoc bindAddress)
59    {
60       this(bindAddress, 200);
61    }
62
63    /**
64     * Create a socket factory with the given backlog
65     */

66    public TimeoutServerSocketFactory(int backlog)
67    {
68       this(null, backlog);
69    }
70
71    /**
72     * Create a socket factory with the given bind address and backlog
73     */

74    public TimeoutServerSocketFactory(InetAddress JavaDoc bindAddress, int backlog)
75    {
76       this.bindAddress = bindAddress;
77       this.backlog = backlog;
78    }
79
80    public String JavaDoc getBindAddress()
81    {
82       String JavaDoc address = null;
83       if (bindAddress != null)
84          address = bindAddress.getHostAddress();
85       return address;
86    }
87
88    public void setBindAddress(String JavaDoc host) throws UnknownHostException JavaDoc
89    {
90       bindAddress = InetAddress.getByName(host);
91    }
92    public void setBindAddress(InetAddress JavaDoc bindAddress)
93    {
94       this.bindAddress = bindAddress;
95    }
96
97    /**
98     * Create a server socket on the specified port (port 0 indicates
99     * an anonymous port).
100     *
101     * @param port the port number
102     * @return the server socket on the specified port
103     * @throws java.io.IOException if an I/O error occurs during server socket
104     * creation
105     * @since 1.2
106     */

107    public ServerSocket JavaDoc createServerSocket(int port) throws IOException JavaDoc
108    {
109       ServerSocket JavaDoc activeSocket = new TimeoutServerSocket(port, backlog, bindAddress);
110       return activeSocket;
111    }
112
113    public boolean equals(Object JavaDoc obj)
114    {
115       return obj instanceof TimeoutServerSocketFactory;
116    }
117
118    public int hashCode()
119    {
120       return getClass().getName().hashCode();
121    }
122 }
Popular Tags