Timeout listener?
이희승 (Trustin Lee)
trustin at gmail.com
Tue Aug 25 04:12:49 EDT 2009
On Fri, 21 Aug 2009 08:20:19 +0900 (KST)
Nitrostar <nitrostar1 at gmail.com> wrote:
>
> Hi,
> I'm trying to build a platform to process hundreds of
> encodings/decodings of a message per second. I'm very pleased to be
> using Netty! It's been really fun and helpful at the same time.
It's great to hear that Netty helps high school students! :)
> I'm building an encoder/decoder system for my highschool and I have a
> separate process that tries to do the encoding/decoding. However, some
> messages cannot be decoded in a timely manner, so I kind of need to
> send a response back with some sort of a failure. I don't know how to
> do this without having some blocking code.
>
> Is there any way I can add like a listener in milliseconds and send a
> response back if I haven't yet finished computing the decode?
>
> I'm using an HTTP Server (based on the file example that was
> provided!)
>
> Any help would be greatly appreciated!
It is not very accurate, but I would use IdleStateHandler and send the
response when the idle state of the channel is WRITER_IDLE. Please
refer to org.jboss.netty.handler.timeout for more information.
If you need much more accurate solution, you could use
java.util.concurrent.ScheduledExecutorService to schedule a timeout
right before beginning decode, but I'd recommend the approach with
IdleStateHandler as it is simpler.
HTH,
Trustin
More information about the netty-users
mailing list