You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@mina.apache.org by Matthew Phillips <ma...@mattp.name> on 2007/08/05 13:52:37 UTC

Injecting synthetic messages

Hi all,

I have a timer thread inside a custom IoFilter that checks for  
request timeouts after sending a message. If a timeout occurs, it  
sends a synthetic message down the filter chain. The question is, is  
this thread safe, or am I violating the MINA thread model?

The following code is what I'm doing in the timer thread to inject  
the message:

   String filterName = ... // name of the timeout-checking filter

   NextFilter filter =
     session.getFilterChain ().getNextFilter (filterName);

   filter.messageReceived
     (session, new RequestTimeoutMessage ());

Any advice appreciated,

Cheers,

Matthew.


Re: Injecting synthetic messages

Posted by Trustin Lee <tr...@gmail.com>.
On 8/7/07, Matthew Phillips <ma...@mattp.name> wrote:
> On 06/08/2007, at 9:32 PM, Trustin Lee wrote:
>
> > On 8/5/07, Matthew Phillips <ma...@mattp.name> wrote:
> >> I have a timer thread inside a custom IoFilter that checks for
> >> request timeouts after sending a message. If a timeout occurs, it
> >> sends a synthetic message down the filter chain. The question is, is
> >> this thread safe, or am I violating the MINA thread model?
> >
> > It should be safe as long as your business logic is thread safe.  If
> > not, please let us know.
>
> Great. So, just to be clear: if my filter is thread safe w.r.t. its
> own timer thread, and my IoHandler is also thread safe within the
> MINA model, this is the correct way to do this kind of thing? It
> doesn't hurt that IoFilter.messageReceived () is being called by my
> timer thread rather than one of MINA's IO processing threads?

It shouldn't hurt.  Please let me know if you found any problem doing so.

HTH,
Trustin
-- 
what we call human nature is actually human habit
--
http://gleamynode.net/
--
PGP Key ID: 0x0255ECA6

Re: Injecting synthetic messages

Posted by Matthew Phillips <ma...@mattp.name>.
On 06/08/2007, at 9:32 PM, Trustin Lee wrote:

> On 8/5/07, Matthew Phillips <ma...@mattp.name> wrote:
>> I have a timer thread inside a custom IoFilter that checks for
>> request timeouts after sending a message. If a timeout occurs, it
>> sends a synthetic message down the filter chain. The question is, is
>> this thread safe, or am I violating the MINA thread model?
>
> It should be safe as long as your business logic is thread safe.  If
> not, please let us know.

Great. So, just to be clear: if my filter is thread safe w.r.t. its  
own timer thread, and my IoHandler is also thread safe within the  
MINA model, this is the correct way to do this kind of thing? It  
doesn't hurt that IoFilter.messageReceived () is being called by my  
timer thread rather than one of MINA's IO processing threads?

Cheers,

Matthew.


Re: Injecting synthetic messages

Posted by Trustin Lee <tr...@gmail.com>.
Hi Matthew,

On 8/5/07, Matthew Phillips <ma...@mattp.name> wrote:
> Hi all,
>
> I have a timer thread inside a custom IoFilter that checks for
> request timeouts after sending a message. If a timeout occurs, it
> sends a synthetic message down the filter chain. The question is, is
> this thread safe, or am I violating the MINA thread model?

It should be safe as long as your business logic is thread safe.  If
not, please let us know.

> The following code is what I'm doing in the timer thread to inject
> the message:
>
>   String filterName = ... // name of the timeout-checking filter
>
>   NextFilter filter =
>     session.getFilterChain ().getNextFilter (filterName);
>
>   filter.messageReceived
>     (session, new RequestTimeoutMessage ());
>
> Any advice appreciated,

Looks great!

HTH,
Trustin
-- 
what we call human nature is actually human habit
--
http://gleamynode.net/
--
PGP Key ID: 0x0255ECA6