67 lines
2.0 KiB
Java
67 lines
2.0 KiB
Java
package com.foundation.web.interfaces;
|
|
|
|
|
|
/**
|
|
* The base class for a websocket handler passed to the IConnectionContext object when converting an HTTP connection into a websocket.
|
|
*/
|
|
public abstract class WebsocketHandler {
|
|
/** The websocket connection reference. */
|
|
private IConnectionContext connection;
|
|
/**
|
|
* WebsocketHandler constructor.
|
|
* @param connection The websocket connection reference.
|
|
*/
|
|
public WebsocketHandler(IConnectionContext connection) {
|
|
this.connection = connection;
|
|
}//WebsocketHandler()//
|
|
/**
|
|
* Receives a text message from the client.
|
|
* @param message The message received.
|
|
*/
|
|
public abstract void receiveTextMessage(String message);
|
|
/**
|
|
* Receives a binary message from the client.
|
|
* @param message The message received.
|
|
*/
|
|
public abstract void receiveBinaryMessage(byte[] message);
|
|
/**
|
|
* Receives a pong control message from the client (in reponse to a ping from the server).
|
|
*/
|
|
public void receivePong() {
|
|
//Does nothing.//
|
|
}//receivePong()//
|
|
/**
|
|
* Sends a text message to the client without blocking.
|
|
* <br/>This is a thread safe call.
|
|
* @param message The message to be sent.
|
|
*/
|
|
public void sendTextMessage(String message) {
|
|
connection.sendWebsocketMessage(message);
|
|
}//sendTextMessage()//
|
|
/**
|
|
* Sends a binary message to the client without blocking.
|
|
* <br/>This is a thread safe call.
|
|
* @param message The message to be sent.
|
|
*/
|
|
public void sendBinaryMessage(byte[] message) {
|
|
connection.sendWebsocketMessage(message);
|
|
}//sendBinaryMessage()//
|
|
/**
|
|
* Sends a streamed message to the client without blocking.
|
|
* <br/>This is a thread safe call.
|
|
* @param message The message to be sent.
|
|
*/
|
|
public void sendStreamedMessage(IStreamedWebsocketMessage message) {
|
|
connection.sendWebsocketMessage(message);
|
|
}//sendStreamedMessage()//
|
|
/**
|
|
* Sends a ping control message to the client which will respond with a pong control message.
|
|
*/
|
|
public void sendPing() {
|
|
connection.sendWebsocketPing();
|
|
}//sendPing()//
|
|
/**
|
|
* Called by the connection when it is closed for any reason.
|
|
*/
|
|
public abstract void connectionClosed();
|
|
}//WebsocketHandler// |