Search in sources :

Example 1 with OnWebSocketMessage

use of org.eclipse.jetty.websocket.api.annotations.OnWebSocketMessage in project jetty.project by eclipse.

the class BigEchoSocket method onText.

@OnWebSocketMessage
public void onText(Session session, String message) throws IOException {
    if (!session.isOpen()) {
        LOG.warn("Session is closed");
        return;
    }
    RemoteEndpoint remote = session.getRemote();
    remote.sendString(message, null);
    if (remote.getBatchMode() == BatchMode.ON)
        remote.flush();
}
Also used : RemoteEndpoint(org.eclipse.jetty.websocket.api.RemoteEndpoint) OnWebSocketMessage(org.eclipse.jetty.websocket.api.annotations.OnWebSocketMessage)

Example 2 with OnWebSocketMessage

use of org.eclipse.jetty.websocket.api.annotations.OnWebSocketMessage in project pulsar by yahoo.

the class SimpleProducerSocket method onMessage.

@OnWebSocketMessage
public synchronized void onMessage(String msg) throws JsonParseException {
    JsonObject ack = new Gson().fromJson(msg, JsonObject.class);
    producerBuffer.add(ack.get("messageId").getAsString());
}
Also used : JsonObject(com.google.gson.JsonObject) Gson(com.google.gson.Gson) OnWebSocketMessage(org.eclipse.jetty.websocket.api.annotations.OnWebSocketMessage)

Example 3 with OnWebSocketMessage

use of org.eclipse.jetty.websocket.api.annotations.OnWebSocketMessage in project incubator-pulsar by apache.

the class SimpleConsumerSocket method onMessage.

@OnWebSocketMessage
public synchronized void onMessage(String msg) throws JsonParseException, IOException {
    receivedMessages.incrementAndGet();
    JsonObject message = new Gson().fromJson(msg, JsonObject.class);
    JsonObject ack = new JsonObject();
    String messageId = message.get(X_PULSAR_MESSAGE_ID).getAsString();
    consumerBuffer.add(messageId);
    ack.add("messageId", new JsonPrimitive(messageId));
    // Acking the proxy
    this.getRemote().sendString(ack.toString());
}
Also used : JsonPrimitive(com.google.gson.JsonPrimitive) JsonObject(com.google.gson.JsonObject) Gson(com.google.gson.Gson) OnWebSocketMessage(org.eclipse.jetty.websocket.api.annotations.OnWebSocketMessage)

Example 4 with OnWebSocketMessage

use of org.eclipse.jetty.websocket.api.annotations.OnWebSocketMessage in project incubator-pulsar by apache.

the class SimpleTestProducerSocket method onMessage.

@OnWebSocketMessage
public void onMessage(String msg) throws JsonParseException {
    JsonObject json = new Gson().fromJson(msg, JsonObject.class);
    long endTimeNs = System.nanoTime();
    long startTime = endTimeNs;
    if (startTimeMap.get(json.get(CONTEXT).getAsString()) != null) {
        startTime = startTimeMap.get(json.get(CONTEXT).getAsString());
    }
    long latencyNs = endTimeNs - startTime;
    recorder.recordValue(NANOSECONDS.toMicros(latencyNs));
}
Also used : JsonObject(com.google.gson.JsonObject) Gson(com.google.gson.Gson) OnWebSocketMessage(org.eclipse.jetty.websocket.api.annotations.OnWebSocketMessage)

Example 5 with OnWebSocketMessage

use of org.eclipse.jetty.websocket.api.annotations.OnWebSocketMessage in project spring-framework by spring-projects.

the class JettyWebSocketHandlerAdapter method onWebSocketText.

@OnWebSocketMessage
public void onWebSocketText(String message) {
    if (this.delegateSession != null) {
        WebSocketMessage webSocketMessage = toMessage(Type.TEXT, message);
        this.delegateSession.handleMessage(webSocketMessage.getType(), webSocketMessage);
    }
}
Also used : OnWebSocketMessage(org.eclipse.jetty.websocket.api.annotations.OnWebSocketMessage) WebSocketMessage(org.springframework.web.reactive.socket.WebSocketMessage) OnWebSocketMessage(org.eclipse.jetty.websocket.api.annotations.OnWebSocketMessage)

Aggregations

OnWebSocketMessage (org.eclipse.jetty.websocket.api.annotations.OnWebSocketMessage)22 RemoteEndpoint (org.eclipse.jetty.websocket.api.RemoteEndpoint)9 JsonObject (com.google.gson.JsonObject)7 Gson (com.google.gson.Gson)6 ByteBuffer (java.nio.ByteBuffer)5 IOException (java.io.IOException)4 JsonPrimitive (com.google.gson.JsonPrimitive)2 StringReader (java.io.StringReader)2 WebSocketMessage (org.springframework.web.reactive.socket.WebSocketMessage)2 JsonElement (com.google.gson.JsonElement)1 JsonParser (com.google.gson.JsonParser)1 JsonReader (com.google.gson.stream.JsonReader)1 OcppJsonError (de.rwth.idsg.steve.ocpp.ws.data.OcppJsonError)1 OcppJsonResponse (de.rwth.idsg.steve.ocpp.ws.data.OcppJsonResponse)1 OcppJsonResult (de.rwth.idsg.steve.ocpp.ws.data.OcppJsonResult)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 EOFException (java.io.EOFException)1 InputStream (java.io.InputStream)1 ProtocolException (java.net.ProtocolException)1 SocketException (java.net.SocketException)1