users@grizzly.java.net

Re: WebSocket server with Grizzly (was Re: WebSocket clinet with Grizzly)

From: Ryan Lubke <ryan.lubke_at_oracle.com>
Date: Thu, 23 May 2013 12:31:44 -0700

Sorry - that's in 2.3.

For 2.2.21, you'll have to avoid using the WebSocketAddon.

Instead you'd do something like this:

WebSocketFilter wsFilter = new WebSocketFilter(<timeout in seconds>);

Then to insert it into the FilterChain properly, you'd do something like:

final int httpServerFilterIdx =
filterChainbuilder.indexOfType(HttpServerFilter.class);
if (httpServerFilterIdx >= 0) {
     // Insert the WebSocketFilter right after HttpCodecFilter
     builder.add(httpServerFilterIdx, wsFilter);
}


That said, if you're able to upgrade to 2.3.2, I'd recommend doing so.

Weiqi Gao wrote:
> I cannot find the method WebSocketAddOn#setTimeoutInSeconds.
>
> On 5/23/2013 1:15 PM, Ryan Lubke wrote:
>> Correct. You can configure the WebSocketFilter timeout via the
>> WebSocketAddon:
>>
>> final WebSocketAddon addon = new WebSocketAddon();
>> addon.setTimeoutInSeconds(...);
>>
>> Then register the addon with the network listener.
>>
>>> Weiqi Gao <mailto:weiqigao_at_gmail.com>
>>> May 23, 2013 5:29 AM
>>> Hi,
>>>
>>> Just to follow up. It seems that the there is a 15 minutes timeout
>>> for WebSockets on the server side as well. I'm running my own
>>> WebSocketApplication (I'm using grizzly-http-server-2.2.21.jar and
>>> friends, and I'm using code very similar to the example in the
>>> WebSocket chapter of the documentation), accepted a connection from
>>> the client. After 15 minutes, the onClose() call back is called
>>> from a thread named "HttpServer-0" with the following stack trace.
>>>
>>> I'd appreciate it if someone can let me know how to turn off this
>>> timeout off as well.
>>>
>>> at foo.MyWebSocketApplication.onClose(MyWebSocketApplication.java:68)
>>> at
>>> org.glassfish.grizzly.websockets.DefaultWebSocket.onClose(DefaultWebSocket.java:128)
>>> at
>>> org.glassfish.grizzly.websockets.ProtocolHandler$1.failed(ProtocolHandler.java:163)
>>> at
>>> org.glassfish.grizzly.websockets.ProtocolHandler$2.failed(ProtocolHandler.java:199)
>>> at
>>> org.glassfish.grizzly.asyncqueue.AsyncQueueRecord.notifyFailure(AsyncQueueRecord.java:108)
>>> at
>>> org.glassfish.grizzly.nio.AbstractNIOAsyncQueueWriter.onWriteFailure(AbstractNIOAsyncQueueWriter.java:573)
>>> at
>>> org.glassfish.grizzly.nio.AbstractNIOAsyncQueueWriter.writeQueueRecord(AbstractNIOAsyncQueueWriter.java:233)
>>> at
>>> org.glassfish.grizzly.nio.AbstractNIOAsyncQueueWriter.write(AbstractNIOAsyncQueueWriter.java:219)
>>> at
>>> org.glassfish.grizzly.nio.transport.TCPNIOTransportFilter.handleWrite(TCPNIOTransportFilter.java:127)
>>> at
>>> org.glassfish.grizzly.filterchain.TransportFilter.handleWrite(TransportFilter.java:191)
>>> at
>>> org.glassfish.grizzly.filterchain.ExecutorResolver$8.execute(ExecutorResolver.java:111)
>>> at
>>> org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:265)
>>> at
>>> org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:200)
>>> at
>>> org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:134)
>>> at
>>> org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:112)
>>> at
>>> org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:78)
>>> at
>>> org.glassfish.grizzly.filterchain.DefaultFilterChain.write(DefaultFilterChain.java:390)
>>> at
>>> org.glassfish.grizzly.nio.NIOConnection.write(NIOConnection.java:397)
>>> at
>>> org.glassfish.grizzly.nio.NIOConnection.write(NIOConnection.java:380)
>>> at
>>> org.glassfish.grizzly.websockets.ProtocolHandler.write(ProtocolHandler.java:186)
>>> at
>>> org.glassfish.grizzly.websockets.ProtocolHandler.send(ProtocolHandler.java:91)
>>> at
>>> org.glassfish.grizzly.websockets.ProtocolHandler.close(ProtocolHandler.java:158)
>>> at
>>> org.glassfish.grizzly.websockets.DefaultWebSocket.close(DefaultWebSocket.java:192)
>>> at
>>> org.glassfish.grizzly.websockets.DefaultWebSocket.close(DefaultWebSocket.java:183)
>>> at
>>> org.glassfish.grizzly.websockets.WebSocketFilter.handleClose(WebSocketFilter.java:156)
>>> at
>>> org.glassfish.grizzly.filterchain.ExecutorResolver$4.execute(ExecutorResolver.java:76)
>>> at
>>> org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:265)
>>> at
>>> org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:200)
>>> at
>>> org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:134)
>>> at
>>> org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:112)
>>> at
>>> org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:78)
>>> at
>>> org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:770)
>>> at
>>> org.glassfish.grizzly.nio.NIOConnection.preClose(NIOConnection.java:702)
>>> at
>>> org.glassfish.grizzly.nio.transport.TCPNIOConnection.preClose(TCPNIOConnection.java:96)
>>> at
>>> org.glassfish.grizzly.nio.NIOConnection.close0(NIOConnection.java:435)
>>> at
>>> org.glassfish.grizzly.nio.transport.TCPNIOConnection.close0(TCPNIOConnection.java:244)
>>> at
>>> org.glassfish.grizzly.nio.NIOConnection.close(NIOConnection.java:419)
>>> at
>>> org.glassfish.grizzly.nio.NIOConnection.closeSilently(NIOConnection.java:425)
>>> at
>>> org.glassfish.grizzly.utils.IdleTimeoutFilter$DefaultWorker.doWork(IdleTimeoutFilter.java:387)
>>> at
>>> org.glassfish.grizzly.utils.IdleTimeoutFilter$DefaultWorker.doWork(IdleTimeoutFilter.java:365)
>>> at
>>> org.glassfish.grizzly.utils.DelayedExecutor$DelayedRunnable.run(DelayedExecutor.java:153)
>>> at
>>> java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
>>> at
>>> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
>>> at java.lang.Thread.run(Thread.java:722)]