use of javax.websocket.MessageHandler.Whole in project jetty.project by eclipse.
the class JsrEndpointEventDriver method onTextFrame.
@Override
public void onTextFrame(ByteBuffer buffer, boolean fin) throws IOException {
if (activeMessage == null) {
final MessageHandlerWrapper wrapper = jsrsession.getMessageHandlerWrapper(MessageType.TEXT);
if (wrapper == null) {
if (LOG.isDebugEnabled()) {
LOG.debug("No TEXT MessageHandler declared");
}
return;
}
if (wrapper.wantsPartialMessages()) {
activeMessage = new TextPartialMessage(wrapper);
} else if (wrapper.wantsStreams()) {
final MessageReader stream = new MessageReader(new MessageInputStream());
activeMessage = stream;
dispatch(new Runnable() {
@SuppressWarnings("unchecked")
@Override
public void run() {
MessageHandler.Whole<Reader> handler = (Whole<Reader>) wrapper.getHandler();
handler.onMessage(stream);
}
});
} else {
activeMessage = new TextWholeMessage(this, wrapper);
}
}
activeMessage.appendFrame(buffer, fin);
if (fin) {
activeMessage.messageComplete();
activeMessage = null;
}
}
use of javax.websocket.MessageHandler.Whole in project jetty.project by eclipse.
the class JsrEndpointEventDriver method onBinaryFrame.
@Override
public void onBinaryFrame(ByteBuffer buffer, boolean fin) throws IOException {
if (activeMessage == null) {
final MessageHandlerWrapper wrapper = jsrsession.getMessageHandlerWrapper(MessageType.BINARY);
if (wrapper == null) {
if (LOG.isDebugEnabled()) {
LOG.debug("No BINARY MessageHandler declared");
}
return;
}
if (wrapper.wantsPartialMessages()) {
activeMessage = new BinaryPartialMessage(wrapper);
} else if (wrapper.wantsStreams()) {
final MessageInputStream stream = new MessageInputStream();
activeMessage = stream;
dispatch(new Runnable() {
@SuppressWarnings("unchecked")
@Override
public void run() {
MessageHandler.Whole<InputStream> handler = (Whole<InputStream>) wrapper.getHandler();
handler.onMessage(stream);
}
});
} else {
activeMessage = new BinaryWholeMessage(this, wrapper);
}
}
activeMessage.appendFrame(buffer, fin);
if (fin) {
activeMessage.messageComplete();
activeMessage = null;
}
}
use of javax.websocket.MessageHandler.Whole in project jetty.project by eclipse.
the class JsrEndpointEventDriver method onPongMessage.
private void onPongMessage(ByteBuffer buffer) {
final MessageHandlerWrapper wrapper = jsrsession.getMessageHandlerWrapper(MessageType.PONG);
if (wrapper == null) {
if (LOG.isDebugEnabled()) {
LOG.debug("No PONG MessageHandler declared");
}
return;
}
ByteBuffer pongBuf = null;
if (BufferUtil.isEmpty(buffer)) {
pongBuf = BufferUtil.EMPTY_BUFFER;
} else {
pongBuf = ByteBuffer.allocate(buffer.remaining());
BufferUtil.put(buffer, pongBuf);
BufferUtil.flipToFlush(pongBuf, 0);
}
@SuppressWarnings("unchecked") Whole<PongMessage> pongHandler = (Whole<PongMessage>) wrapper.getHandler();
pongHandler.onMessage(new JsrPongMessage(pongBuf));
}
Aggregations