public class NGCommunicator
extends java.lang.Object
implements java.io.Closeable
| Constructor and Description |
|---|
NGCommunicator(java.io.DataInputStream in,
java.io.DataOutputStream out,
int heartbeatTimeoutMillis)
Creates a new NGCommunicator wrapping the specified InputStream.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addClientListener(NGClientListener listener)
Registers a new NGClientListener to be called on client disconnection
|
void |
addHeartbeatListener(NGHeartbeatListener listener) |
int |
available() |
void |
close()
Stop the thread reading from the NailGun client
|
boolean |
isClientConnected() |
int |
receive(byte[] b,
int offset,
int length)
Read data from client's stdin.
|
void |
removeAllClientListeners()
Do not notify anymore about client disconnects
|
void |
removeClientListener(NGClientListener listener) |
void |
removeHeartbeatListener(NGHeartbeatListener listener) |
void |
send(byte streamCode,
byte[] b,
int offset,
int len)
Send data to the client
|
public NGCommunicator(java.io.DataInputStream in,
java.io.DataOutputStream out,
int heartbeatTimeoutMillis)
in - Socket read stream, will be closed with NGCommunicator's close()out - Socket write stream, will be closed with NGCommunicator's close()heartbeatTimeoutMillis - the interval between heartbeats before considering the client
disconnectedpublic void close()
throws java.io.IOException
close in interface java.io.Closeableclose in interface java.lang.AutoCloseablejava.io.IOExceptionpublic int receive(byte[] b,
int offset,
int length)
throws java.io.IOException,
java.lang.InterruptedException
java.io.IOException - in case of socket errorjava.lang.InterruptedExceptionpublic void send(byte streamCode,
byte[] b,
int offset,
int len)
throws java.io.IOException
java.io.IOExceptionpublic boolean isClientConnected()
public int available()
public void addClientListener(NGClientListener listener)
listener - the NGClientListener to be notified of client events.public void removeClientListener(NGClientListener listener)
listener - the NGClientListener to no longer be notified of client eventspublic void removeAllClientListeners()
public void addHeartbeatListener(NGHeartbeatListener listener)
listener - the NGHeartbeatListener to be notified of heartbeatspublic void removeHeartbeatListener(NGHeartbeatListener listener)
listener - the NGHeartbeatListener to no longer be notified of heartbeats