You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by James Carman <ja...@carmanconsulting.com> on 2005/11/09 15:15:25 UTC

[collections] New Buffer Wrapper Classes...

Based on my response to Sandy McArthur about using Buffers to implements
Commons Pool, I started digging around the API.  I came up with a couple of
ideas:

1.  A BoundedBuffer wrapper/decorator class, which basically enforces a
maximum size of the enclosed buffer.

2.  A TimeoutBuffer wrapper/decorator class which waits until a specified
timeout value expires when asking to remove() objects from an empty Buffer. 

With these two classes, we can make any underlying implementation (stack,
queue, priority queue, etc.) bounded or cause them to wait rather than throw
a BufferUnderflowException immediately when removing objects from them.  We
may have to come up with two timeout wrappers, one for read and one for
write (optionally they could be in the same class with potentially different
values for each).  What do you guys think?



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


RE: [collections] New Buffer Wrapper Classes...

Posted by James Carman <ja...@carmanconsulting.com>.
Oh, I see what you mean.  You're right.  I don't know what I was thinking
(not enough coffee yet or something).  The BoundedBuffer wrapper would
actually enforce a maximum size and wait until something was removed from it
(there you'd have to also override the remove and clear methods and the
iterator implementation I believe).  So, the BoundedBuffer class would need
a few settings:

boolean waitWhenFull;
long maximumWait;
int maximumSize;

If waitWhenFull is false, then it just throws a BufferOverflowException
(sounds so villainous).  The maximumWait would default to -1 (wait forever).

The TimoutBuffer wouldn't need to have a "waitOnEmpty" setting, since you'd
just use the default implementation which would throw a
BufferUnderflowException.  We would need a maximumWait property on
TimeoutBuffer, though (defaulting to -1 also).  Does this sound right?



-----Original Message-----
From: Stephen Colebourne [mailto:scolebourne@btopenworld.com] 
Sent: Thursday, November 10, 2005 7:40 AM
To: Jakarta Commons Developers List
Subject: Re: [collections] New Buffer Wrapper Classes...

These sound like good ideas.

Not sure why you need two TimeoutWrappers though, as
you are only trapping the remove() aren't you?

Stephen

--- James Carman <ja...@carmanconsulting.com> wrote:
> Based on my response to Sandy McArthur about using
> Buffers to implements
> Commons Pool, I started digging around the API.  I
> came up with a couple of
> ideas:
> 
> 1.  A BoundedBuffer wrapper/decorator class, which
> basically enforces a
> maximum size of the enclosed buffer.
> 
> 2.  A TimeoutBuffer wrapper/decorator class which
> waits until a specified
> timeout value expires when asking to remove()
> objects from an empty Buffer. 
> 
> With these two classes, we can make any underlying
> implementation (stack,
> queue, priority queue, etc.) bounded or cause them
> to wait rather than throw
> a BufferUnderflowException immediately when removing
> objects from them.  We
> may have to come up with two timeout wrappers, one
> for read and one for
> write (optionally they could be in the same class
> with potentially different
> values for each).  What do you guys think?


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


RE: [collections] New Buffer Wrapper Classes...

Posted by James Carman <ja...@carmanconsulting.com>.
No, you'd need to override add also, so you'd know when to fire
notify()/notifyAll().  Correct?

-----Original Message-----
From: Stephen Colebourne [mailto:scolebourne@btopenworld.com] 
Sent: Thursday, November 10, 2005 7:40 AM
To: Jakarta Commons Developers List
Subject: Re: [collections] New Buffer Wrapper Classes...

These sound like good ideas.

Not sure why you need two TimeoutWrappers though, as
you are only trapping the remove() aren't you?

Stephen

--- James Carman <ja...@carmanconsulting.com> wrote:
> Based on my response to Sandy McArthur about using
> Buffers to implements
> Commons Pool, I started digging around the API.  I
> came up with a couple of
> ideas:
> 
> 1.  A BoundedBuffer wrapper/decorator class, which
> basically enforces a
> maximum size of the enclosed buffer.
> 
> 2.  A TimeoutBuffer wrapper/decorator class which
> waits until a specified
> timeout value expires when asking to remove()
> objects from an empty Buffer. 
> 
> With these two classes, we can make any underlying
> implementation (stack,
> queue, priority queue, etc.) bounded or cause them
> to wait rather than throw
> a BufferUnderflowException immediately when removing
> objects from them.  We
> may have to come up with two timeout wrappers, one
> for read and one for
> write (optionally they could be in the same class
> with potentially different
> values for each).  What do you guys think?


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Re: [collections] New Buffer Wrapper Classes...

Posted by Stephen Colebourne <sc...@btopenworld.com>.
These sound like good ideas.

Not sure why you need two TimeoutWrappers though, as
you are only trapping the remove() aren't you?

Stephen

--- James Carman <ja...@carmanconsulting.com> wrote:
> Based on my response to Sandy McArthur about using
> Buffers to implements
> Commons Pool, I started digging around the API.  I
> came up with a couple of
> ideas:
> 
> 1.  A BoundedBuffer wrapper/decorator class, which
> basically enforces a
> maximum size of the enclosed buffer.
> 
> 2.  A TimeoutBuffer wrapper/decorator class which
> waits until a specified
> timeout value expires when asking to remove()
> objects from an empty Buffer. 
> 
> With these two classes, we can make any underlying
> implementation (stack,
> queue, priority queue, etc.) bounded or cause them
> to wait rather than throw
> a BufferUnderflowException immediately when removing
> objects from them.  We
> may have to come up with two timeout wrappers, one
> for read and one for
> write (optionally they could be in the same class
> with potentially different
> values for each).  What do you guys think?


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org