|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object java.net.Socket com.sun.faban.driver.transport.util.TimedSocket
public class TimedSocket
The TimedSocket class extends the Socket class by timing the opening of connections and using TimedInputStream and TimedOutputStream as the streams for this socket. This allows collecting times for the benchmark at a very low level, just before the request goes onto the socket and right after the response comes back.
Constructor Summary | |
---|---|
|
TimedSocket()
Creates an unconnected socket, with the system-default type of SocketImpl. |
|
TimedSocket(InetAddress address,
int port)
Creates a stream socket and connects it to the specified port number at the specified IP address. |
|
TimedSocket(InetAddress address,
int port,
InetAddress localAddr,
int localPort)
Creates a socket and connects it to the specified remote address on the specified remote port. |
|
TimedSocket(Proxy proxy)
Creates an unconnected socket, specifying the type of proxy, if any, that should be used regardless of any other settings. |
protected |
TimedSocket(SocketImpl impl)
Creates an unconnected Socket with a user-specified SocketImpl. |
|
TimedSocket(String host,
int port)
Creates a stream socket and connects it to the specified port number on the named host. |
|
TimedSocket(String host,
int port,
InetAddress localAddr,
int localPort)
Creates a socket and connects it to the specified remote host on the specified remote port. |
Method Summary | |
---|---|
void |
connect(SocketAddress endpoint,
int timeout)
Connects this socket to the server with a specified timeout value. |
InputStream |
getInputStream()
Returns an input stream for this socket. |
OutputStream |
getOutputStream()
Returns an output stream for this socket. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public TimedSocket()
public TimedSocket(Proxy proxy)
If there is a security manager, its checkConnect
method
is called with the proxy host address and port number
as its arguments. This could result in a SecurityException.
Examples:
Socket s = new Socket(Proxy.NO_PROXY);
will create
a plain socket ignoring any other proxy configuration.Socket s = new Socket(new Proxy(Proxy.Type.SOCKS, new InetSocketAddress("socks.mydom.com", 1080)));
will create a socket connecting through the specified SOCKS proxy
server.
proxy
- a Proxy
object specifying what kind
of proxying should be used.
IllegalArgumentException
- if the proxy is of an invalid type
or null
.
SecurityException
- if a security manager is present and
permission to connect to the proxy is
denied.ProxySelector
,
Proxy
public TimedSocket(InetAddress address, int port) throws IOException
createSocketImpl
method is called to create the
actual socket implementation. Otherwise a "plain" socket is created.
If there is a security manager, its
checkConnect
method is called
with the host address and port
as its arguments. This could result in a SecurityException.
address
- the IP address.port
- the port number.
IOException
- if an I/O error occurs when creating the socket.
SecurityException
- if a security manager exists and its
checkConnect
method doesn't allow the operation.Socket.setSocketImplFactory(java.net.SocketImplFactory)
,
SocketImpl
,
SocketImplFactory.createSocketImpl()
,
SecurityManager.checkConnect(java.lang.String, int)
protected TimedSocket(SocketImpl impl) throws SocketException
impl
- an instance of a SocketImpl
the subclass wishes to use on the Socket.
SocketException
- if there is an error in the underlying protocol,
such as a TCP error.public TimedSocket(String host, int port) throws UnknownHostException, IOException
InetAddress.getByName
(null).
In other words, it is equivalent to specifying an address of the
loopback interface.
If the application has specified a server socket factory, that
factory's createSocketImpl
method is called to create
the actual socket implementation. Otherwise a "plain" socket is created.
If there is a security manager, its
checkConnect
method is called
with the host address and port
as its arguments. This could result in a SecurityException.
host
- the host name, or null
for the loopback address.port
- the port number.
UnknownHostException
- if the IP address of
the host could not be determined.
IOException
- if an I/O error occurs when creating the socket.
SecurityException
- if a security manager exists and its
checkConnect
method doesn't allow the operation.Socket.setSocketImplFactory(java.net.SocketImplFactory)
,
SocketImpl
,
SocketImplFactory.createSocketImpl()
,
SecurityManager.checkConnect(java.lang.String, int)
public TimedSocket(String host, int port, InetAddress localAddr, int localPort) throws IOException
InetAddress.getByName
(null).
In other words, it is equivalent to specifying an address of the
loopback interface.
If there is a security manager, its
checkConnect
method is called
with the host address and port
as its arguments. This could result in a SecurityException.
host
- the name of the remote host, or null
for the loopback address.port
- the remote portlocalAddr
- the local address the socket is bound tolocalPort
- the local port the socket is bound to
IOException
- if an I/O error occurs when creating the socket.
SecurityException
- if a security manager exists and its
checkConnect
method doesn't allow the operation.SecurityManager.checkConnect(java.lang.String, int)
public TimedSocket(InetAddress address, int port, InetAddress localAddr, int localPort) throws IOException
checkConnect
method is called
with the host address and port
as its arguments. This could result in a SecurityException.
address
- the remote addressport
- the remote portlocalAddr
- the local address the socket is bound tolocalPort
- the local port the socket is bound to
IOException
- if an I/O error occurs when creating the socket.
SecurityException
- if a security manager exists and its
checkConnect
method doesn't
allow the operation.SecurityManager.checkConnect(java.lang.String, int)
Method Detail |
---|
public void connect(SocketAddress endpoint, int timeout) throws IOException
connect
in class Socket
endpoint
- the SocketAddress
timeout
- the timeout value to be used in milliseconds.
IllegalBlockingModeException
- if this socket has an associated channel,
and the channel is in non-blocking mode
IllegalArgumentException
- if endpoint is null or is a
SocketAddress subclass not supported by this socket
IOException
- if an error occurs during the connection
SocketTimeoutException
- if timeout expires before connectingpublic InputStream getInputStream() throws IOException
If this socket has an associated channel then the resulting input
stream delegates all of its operations to the channel. If the channel
is in non-blocking mode then the input stream's read operations
will throw an IllegalBlockingModeException
.
Under abnormal conditions the underlying connection may be broken by the remote host or the network software (for example a connection reset in the case of TCP connections). When a broken connection is detected by the network software the following applies to the returned input stream :-
The network software may discard bytes that are buffered
by the socket. Bytes that aren't discarded by the network
software can be read using read
.
If there are no bytes buffered on the socket, or all
buffered bytes have been consumed by
read
, then all subsequent
calls to read
will throw an
IOException
.
If there are no bytes buffered on the socket, and the
socket has not been closed using close
, then
available
will
return 0
.
getInputStream
in class Socket
IOException
- if an I/O error occurs when creating the
input stream, the socket is closed, the socket is
not connected, or the socket input has been shutdown
using Socket.shutdownInput()
public OutputStream getOutputStream() throws IOException
If this socket has an associated channel then the resulting output
stream delegates all of its operations to the channel. If the channel
is in non-blocking mode then the output stream's write
operations will throw an IllegalBlockingModeException
.
getOutputStream
in class Socket
IOException
- if an I/O error occurs when creating the
output stream or if the socket is not connected.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |