On 2nd thought, the filterWrite() can be invoked by multiple threads for the
same connector session, right ? So it needs to be synchronized. Or am I
mistaken ?
Hanson
On 9/12/06, Hanson Char <[EMAIL PROTECTED]> wrote:
Hi Trustee,
Thanks for the tip. So does it mean, using the 3 messages/sec example,
something as simple as the code below ?
Hanson
SocketConnector socketConnector =
new SocketConnector();
socketConnector.getFilterChain()
.addLast("writeThrottleFilter",
new WriteThrottleFilter(333));
public class WriteThrottleFilter extends IoFilterAdapter
{
private final long delayMillis;
public WriteThrottleFilter(long delay) {
this.delayMillis = delay;
}
@Override
public void filterWrite(NextFilter nextFilter,
IoSession session, ByteBuffer buf, Object marker) throws
InterruptedException
{
Thread.sleep(delayMillis);
nextFilter.filterWrite( session, buf, marker );
}
}
On 9/12/06, Trustin Lee <[EMAIL PROTECTED]> wrote:
>
> ---------- Forwarded message ----------
> From: Trustin Lee <[EMAIL PROTECTED]>
> Date: Sep 13, 2006 1:59 PM
> Subject: Re: Controlling rate of writes in Mina 0.8.2
> To: [email protected]
>
> Hi Hanson,
>
> On 9/13/06, Hanson Char <[EMAIL PROTECTED]> wrote:
> >
> > Hi,
> >
> > A quick question. Is there an easy way in Mina 0.8.2 to control the
> rate
> > of
> > physical network write operations to not exceeding a specific number
> of
> > messages ?
> >
> > For example, can I say for a particular socket connection session Mina
>
> > should write physically no more than 3 messages per second ? Message
> here
> > means the argument that get passed to session.write(Object).
> >
> > AFAIK the session.write() is a logical asyn operation, and Mina
> therefore
> > reserves the right to buffer it underneath. If so, controlling the
> rate
> > of
> > session.write() cannot be relied upon to control the rate of physical
> > messages that get sent down the wire.
> >
> > Or am I mistaken ?
>
>
> You are correct, but you can make session.write() a blocking operation
> by
> inserting a filter which limits the write rate. Please implement your
> filter's filterWrite() to throttle the write request.
>
> BTW this idea is nice. Could you please create a JIRA issue for us so
> we
> can resolve it someday and you can switch over to our version of write
> rate
> limiting filter? Otherwise you could contribute! ;)
>
> Trustin
> --
> what we call human nature is actually human habit
> --
> http://gleamynode.net/
> --
> PGP key fingerprints:
> * E167 E6AF E73A CBCE EE41 4A29 544D DE48 FE95 4E7E
> * B693 628E 6047 4F8F CFA4 455E 1C62 A7DC 0255 ECA6
>
> --
> what we call human nature is actually human habit
> --
> http://gleamynode.net/
> --
> PGP key fingerprints:
> * E167 E6AF E73A CBCE EE41 4A29 544D DE48 FE95 4E7E
> * B693 628E 6047 4F8F CFA4 455E 1C62 A7DC 0255 ECA6
>
>