Parsing Engine

danbikel.util
Class TimeoutSocketFactory

java.lang.Object
  extended by danbikel.util.TimeoutSocketFactory
All Implemented Interfaces:
Serializable, RMIClientSocketFactory, RMIServerSocketFactory

public class TimeoutSocketFactory
extends Object
implements RMIClientSocketFactory, RMIServerSocketFactory, Serializable

Delivers sockets with timeout values (set via Socket.setSoTimeout). In the case of createServerSocket, the ServerSocket returned is of type TimeoutServerSocket, which delivers sockets via its implementation of accept with the specified server-side timeout value.

See Also:
Socket.setSoTimeout(int), Serialized Form

Constructor Summary
TimeoutSocketFactory(int clientTimeout, int serverTimeout)
          Constructs a new TimeoutSocketFactory with the specified timeout values for server and client sockets.
 
Method Summary
 ServerSocket createServerSocket(int port)
          Returns a TimeoutServerSocket constructed with the serverTimeout value specified at construction of this factory and with the specified port.
 Socket createSocket(String host, int port)
          Returns a Socket object created on the specified host and port, having set its timeout value to the clientTimeout value specified at construction of this factory.
 boolean equals(Object obj)
           
 int hashCode()
           
 void setTimeout(int clientTimeout, int serverTimeout)
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TimeoutSocketFactory

public TimeoutSocketFactory(int clientTimeout,
                            int serverTimeout)
Constructs a new TimeoutSocketFactory with the specified timeout values for server and client sockets.

Parameters:
clientTimeout - the timeout value to be set for client-side sockets; a value of 0 indicates an infinite timeout
serverTimeout - the timeout value to be set for server-side sockets; a value of 0 indicates an infinite timeout
Throws:
IllegalArgumentException - if either clientTimeout or serverTimeout is less than 0
Method Detail

createServerSocket

public ServerSocket createServerSocket(int port)
                                throws IOException
Returns a TimeoutServerSocket constructed with the serverTimeout value specified at construction of this factory and with the specified port. A TimeoutServerSocket delivers sockets via its implementation of accept with the specified server-side timeout value.

Specified by:
createServerSocket in interface RMIServerSocketFactory
Throws:
IOException
See Also:
TimeoutServerSocket, TimeoutServerSocket.accept()

createSocket

public Socket createSocket(String host,
                           int port)
                    throws IOException
Returns a Socket object created on the specified host and port, having set its timeout value to the clientTimeout value specified at construction of this factory.

Specified by:
createSocket in interface RMIClientSocketFactory
Throws:
IOException
See Also:
Socket.setSoTimeout(int)

setTimeout

public void setTimeout(int clientTimeout,
                       int serverTimeout)

equals

public boolean equals(Object obj)
Overrides:
equals in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object

Parsing Engine

Author: Dan Bikel.