Package eu.ill.webx
Class WebXTunnel
java.lang.Object
eu.ill.webx.WebXTunnel
The WebXTunnel provides the main entry point to connecting to a WebX Host. Session creation and client connection is handled
through the connect method.
Each client connected to the relay has an individual tunnel through which instructions can be passed to the WebX Engine and
messages can be read from the engine.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidconnect(WebXHostConfiguration hostConfiguration, WebXClientConfiguration clientConfiguration) Connects to a WebX Engine on a specific host/port and connects the client to a WebX Session.static WebXTunnelConnect(WebXHostConfiguration hostConfiguration, WebXClientConfiguration clientConfiguration) Static method to create a WebXTunnel, connect to the host and create a client.voidDisconnects the client from the WebX Session: message sent to the WebX Engine do disconnect the client.Returns the connection Id of the client: corresponds to the session Id of the WebX EnginebooleanReturns true if the client is connectedbyte[]read()Blocking call to get next message from the Client.voidwrite(byte[] payload) Writes data to the WebX Engine, sending instructions from the client.
-
Constructor Details
-
WebXTunnel
public WebXTunnel()Default constructor of a tunnel
-
-
Method Details
-
Connect
public static WebXTunnel Connect(WebXHostConfiguration hostConfiguration, WebXClientConfiguration clientConfiguration) throws WebXConnectionException Static method to create a WebXTunnel, connect to the host and create a client.- Parameters:
hostConfiguration- Configuration for the WebX Host (eg hostname and port)clientConfiguration- Configuration for the client (login parameters or session Id)- Returns:
- a connected WebXTunnel
- Throws:
WebXConnectionException- thrown if the connection fails
-
connect
public void connect(WebXHostConfiguration hostConfiguration, WebXClientConfiguration clientConfiguration) throws WebXConnectionException Connects to a WebX Engine on a specific host/port and connects the client to a WebX Session. The connection parameters determine whether a new session is created or connection is required to a session that is already running.- Parameters:
hostConfiguration- Configuration for the WebX Host (eg hostname and port)clientConfiguration- Configuration for the client (login parameters or session Id)- Throws:
WebXConnectionException- thrown if the connection fails
-
getConnectionId
Returns the connection Id of the client: corresponds to the session Id of the WebX Engine- Returns:
- The connection Id of the client: corresponds to the session Id of the WebX Engine
- Throws:
WebXClientException- thrown if the tunnel is not connected
-
disconnect
public void disconnect()Disconnects the client from the WebX Session: message sent to the WebX Engine do disconnect the client. Client removed from the session. Session closed if no more connected clients (session pinging will be halted accordingly) Host disconnected if no sessions are running on the specific host. -
isConnected
public boolean isConnected()Returns true if the client is connected- Returns:
- True if the client is connected.
-
read
public byte[] read() throws WebXClientException, WebXConnectionInterruptException, WebXDisconnectedExceptionBlocking call to get next message from the Client. The client stores all messages in a queue liberating the ZMQ thread as quickly as possible. Client applications must read the messages from the queue and send them to the client. The read method is blocking and returns only when a message is available.- Returns:
- The byte array data for the next message
- Throws:
WebXClientException- thrown when an error occurs with the client or if an error is detected in the message dataWebXConnectionInterruptException- thrown when the read is interrupted for example the session doesn't respond to a pingWebXDisconnectedException- thrown when the client is disconnected from the server
-
write
Writes data to the WebX Engine, sending instructions from the client. The instruction is queued and the client thread is liberated quickly. Instruction headers are automatically modified to include the session Id and the Client Id so that they are correctly routed and controlled in the server.- Parameters:
payload- The instruction data to send to the WebX Engine.- Throws:
WebXClientException- Thrown if the client is in error
-