[undertow-dev] Websocket messages : should we start a new Thread to handle them?

electrotype electrotype at gmail.com
Mon May 30 22:41:51 EDT 2016


Hi,

I'm quite new to Undertow, so please let me know if this is not the right place to ask those 
questions! Maybe Stack Overflow is preferred?

Undertow is the default server of a new framework I'm the main developer, Spincast : 
https://www.spincast.org . Everything works very well, but Spincast is still in beta, we haven't 
really do performance testing yet. I'm not totally sure if we use Undertow properly... But, for now, 
everything works well.

By the way, we use "Undertow 1.2.12.Final" because Spincast is Java 7 compatible. Also, we do not 
use the Servlet API.

We're currently trying to use Undertow for /Websocket//s/ in addition to HTTP. Our first tests work 
very well here too. But here's my question:

Spincast is a /synchronous/ Java framework. If I understand correctly, the first thing to do, when 
Undertow is used in such synchronous environments, is to call, in the main handler:

----------------------------------------------
/if(exchange.isInIoThread()) {//
//    exchange.dispatch(this);//
//    return;//
//}
/----------------------------------------------

This is what we do.

But what about Websocket messages handling?

Our Webssocket server code currently looks something like this:

----------------------------------------------
/WebSocketChannel channel = ...//
//
//channel.getReceiveSetter().set(new AbstractReceiveListener() {//
//
//    @Override//
//    protected void onFullTextMessage(final WebSocketChannel channel,//
//                                     BufferedTextMessage bufferedTextMessage) throws IOException {//
//
//        String message = bufferedTextMessage.getData();//
//
//        applicationHandlingOfTheMessage(message);//
//    }//
//
//    //...//
//}//
//channel.resumeReceives();/
----------------------------------------------

Here, is it correct to say that the /applicationHandlingOfTheMessage(message)/ method shouldn't 
block? This code is executed in an NIO Thread, right? So we /have/ to start a new Thread to call 
/applicationHandlingOfTheMessage(message)/, is that correct? We have no idea how the application 
will actually handle the message.

Pretty much all the code examples I found of handling such Websocket messages with Undertow are 
simple echos, where blocking code is not an issue.

Thanks in advance!

Julien



-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/undertow-dev/attachments/20160530/2a89e0df/attachment.html 


More information about the undertow-dev mailing list