S
- the type that will be sent through the socketR
- the type that will be received through the socketpublic class Connection<S extends java.io.Serializable,R extends java.io.Serializable>
extends java.lang.Object
Constructor and Description |
---|
Connection(java.net.Socket socket)
A Connection created with this constructor will fail when an unexpected
type is sent through the socket.
|
Connection(java.net.Socket socket,
java.lang.Class<R> receivingClass)
A Connection created with this constructor will ignore unexpected types
sent through the socket.
|
Connection(java.lang.String host,
int port)
A Connection created with this constructor will fail when an unexpected
type is sent through the socket.
|
Connection(java.lang.String host,
int port,
java.lang.Class<R> receivingClass)
A Connection created with this constructor will ignore unexpected types
sent through the socket.
|
Modifier and Type | Method and Description |
---|---|
void |
close()
Closes the connection
|
boolean |
isClosed()
Checks to see if the connection is closed
|
R |
receive()
Receives a message from the connection.
|
R |
receive(long timeout,
java.util.concurrent.TimeUnit unit)
Receives a message from the connection.
|
boolean |
receiveWillBlock()
Returns whether a call to receive() will block to wait on new data or not
|
boolean |
send(S message)
Sends a message over the connection
|
java.lang.String |
toString() |
void |
waitForEvent()
Blocks until some data is received on the connection or it is closed
|
public Connection(java.net.Socket socket) throws java.io.IOException
socket
- the socket this manager will controljava.io.IOException
- if the connection could not be madepublic Connection(java.net.Socket socket, java.lang.Class<R> receivingClass) throws java.io.IOException
socket
- the socket this manager will controlreceivingClass
- the class of object that will be received by this manager.
Required to circumvent Java generics type erasure.java.io.IOException
- if the connection could not be madepublic Connection(java.lang.String host, int port) throws java.io.IOException
host
- the host to connect toport
- the port to connect onjava.io.IOException
- if the connection could not be madepublic Connection(java.lang.String host, int port, java.lang.Class<R> receivingClass) throws java.io.IOException
host
- the host to connect toport
- the port to connect onreceivingClass
- the class of object that will be received by this manager.
Required to circumvent Java generics type erasure.java.io.IOException
- if the connection could not be madepublic void close()
public boolean isClosed()
public R receive() throws java.lang.InterruptedException
java.lang.InterruptedException
- if the thread waiting was interruptedpublic R receive(long timeout, java.util.concurrent.TimeUnit unit) throws java.lang.InterruptedException
timeout
- the amount of time before timeoutunit
- the unit of timejava.lang.InterruptedException
- if the thread waiting was interruptedpublic boolean receiveWillBlock()
public boolean send(S message) throws java.io.IOException
message
- the message to sendjava.io.IOException
- if the message could not be sentpublic java.lang.String toString()
toString
in class java.lang.Object
public void waitForEvent() throws java.lang.InterruptedException
java.lang.InterruptedException
- if the thread waiting was interrupted