@WebSocket
public class ReportProtocol
extends java.lang.Object
| Modifier and Type | Class and Description |
|---|---|
private class |
ReportProtocol.ResponseWriter
Writer to which a JSON generator streams JSON output, and which writes it to the remote
endpoint as it is generated.
|
private class |
ReportProtocol.Services
API services that are specific to the protocol and user session.
|
| Modifier and Type | Field and Description |
|---|---|
private static int |
JSON_MAX_CHUNK
Maximum JSON chunk length sent as a response
|
private static ConversionStatus |
LOG
Logger.
|
static int |
MSG_BASE
Base value for message types
|
private static java.util.concurrent.atomic.AtomicLong |
nextSessionId
Next available session ID
|
private static java.util.Map<java.lang.Integer,java.lang.reflect.Method> |
requestApi
Map of API types to API handler methods
|
private static java.util.Set<java.lang.Class<?>> |
requestApiClasses
Set of classes which contain API handler methods
|
private java.util.Map<java.lang.Class<?>,java.lang.Object> |
requestWorkers
Map of API handler classes to instances of these classes which perform API work
|
private org.eclipse.jetty.websocket.api.Session |
session
Active web socket session
|
private long |
sessionId
Current session ID
|
private User |
user
Logged on user (
null if no user is currently logged in) |
| Constructor and Description |
|---|
ReportProtocol()
Default constructor.
|
| Modifier and Type | Method and Description |
|---|---|
private void |
cleanup()
Clean up after a session ends.
|
private void |
generateJsonResponse(com.fasterxml.jackson.core.JsonGenerator gen,
int msgId,
int msgType,
boolean success,
java.lang.Object payload)
Generate a JSON message response which includes a message header and payload.
|
void |
onClose(int statusCode,
java.lang.String reason)
This method is called when the connection is closed.
|
void |
onConnect(org.eclipse.jetty.websocket.api.Session session)
This method is called when the remote peer open a web socket connection.
|
void |
onError(org.eclipse.jetty.websocket.api.Session session,
java.lang.Throwable error)
This method is called on communication errors.
|
void |
onMessage(byte[] message,
int offset,
int length)
This method is called when a binary message is received.
|
void |
onMessage(java.lang.String message)
This method is called when a text message is received.
|
private void |
processIncoming(java.lang.String message)
Process an incoming JSON message string for a request API.
|
static void |
registerRequestApi(java.lang.Class<?> apiClass)
Register an API handler class.
|
private static void |
registerRequestApi(java.lang.Class<?> apiClass,
boolean autoInstantiate)
Register an API handler class.
|
public static final int MSG_BASE
private static final ConversionStatus LOG
private static final int JSON_MAX_CHUNK
private static final java.util.Map<java.lang.Integer,java.lang.reflect.Method> requestApi
private static final java.util.Set<java.lang.Class<?>> requestApiClasses
private static java.util.concurrent.atomic.AtomicLong nextSessionId
private final java.util.Map<java.lang.Class<?>,java.lang.Object> requestWorkers
private org.eclipse.jetty.websocket.api.Session session
private long sessionId
private User user
null if no user is currently logged in)public static void registerRequestApi(java.lang.Class<?> apiClass)
WebApi annotation will
be registered as request API handler methods.apiClass - A class which contains one or more request API handler methods.private static void registerRequestApi(java.lang.Class<?> apiClass,
boolean autoInstantiate)
WebApi annotation will
be registered as request API handler methods.apiClass - A class which contains one or more request API handler methods.autoInstantiate - true to automatically instantiate the API class using reflection when the
web socket connects; false if reflection should not be used (only relevant
for the Services inner class).@OnWebSocketConnect public void onConnect(org.eclipse.jetty.websocket.api.Session session)
session - An active link of communications with a Remote WebSocket Endpoint.@OnWebSocketClose
public void onClose(int statusCode,
java.lang.String reason)
statusCode - The status integer code.reason - A string representing the reason.@OnWebSocketMessage public void onMessage(java.lang.String message)
message - The text message.@OnWebSocketMessage
public void onMessage(byte[] message,
int offset,
int length)
message - Message content as an byte array.offset - Message offset.length - Message size.@OnWebSocketError
public void onError(org.eclipse.jetty.websocket.api.Session session,
java.lang.Throwable error)
session - An active link of communications with a Remote WebSocket Endpoint.error - A Throwable instance representing the error condition.private void processIncoming(java.lang.String message)
message - Incoming JSON message.private void generateJsonResponse(com.fasterxml.jackson.core.JsonGenerator gen,
int msgId,
int msgType,
boolean success,
java.lang.Object payload)
throws java.io.IOException
gen - Jackson JSON generator.msgId - Message identifier sent with message request.msgType - Type of message request to which this is the response.success - True if the API was successfully executed; false if there was an
error.payload - Response payload, which will be the normal payload if the API was successful, or
a Throwable if an exception occurred.java.io.IOException - if there is an error serializing the response to JSON.private void cleanup()