You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Stephen Colebourne <sc...@btopenworld.com> on 2005/11/22 00:53:16 UTC

[collections] BlockingBuffer and TimeoutBuffer

Having had a look at the new class TimeoutBuffer, I realised that it 
could just be written as an extra parameter to BlockingBuffer. I think 
this would be cleaner.

BlockingBuffer.decorate(buf);  // no timeout
BlockingBuffer.decorate(buf, timeout);  // timeout

The method implementation will simply check if the stored timeout value 
is zero. If it is it does the get()/remove() as is, otherwise it uses 
get(long)/remove(long).

Note that adding a new field inn this case is OK with serialization as 
the field will default to zero if an old version of the class is 
deserialized using the new jar.

Stephen

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


RE: [collections] BlockingBuffer and TimeoutBuffer

Posted by James Carman <ja...@carmanconsulting.com>.
Yep, you're right.  It's not documented very well.  I will make it so.  I
thought about doing this before, but I was afraid to mess up the
serialization stuff.  But, this should work quite well.

-----Original Message-----
From: Stephen Colebourne [mailto:scolebourne@btopenworld.com] 
Sent: Tuesday, November 22, 2005 4:28 PM
To: Jakarta Commons Developers List
Subject: Re: [collections] BlockingBuffer and TimeoutBuffer

I believe that 0 is what the JDK uses in Object.wait(long) for an 
infinite wait. A negative number would also mean infinite.

Stephen


James Carman wrote:
> Stephen,
> 
> I don't know about using 0 to indicate that it's a wait forever situation.
> A negative number would be better for that, wouldn't you say?  A 0 would
> mean that you don't want to wait at all (of course, why would you use
> BlockingBuffer if you're going to supply a 0).
> 
> James
> 
> -----Original Message-----
> From: Stephen Colebourne [mailto:scolebourne@btopenworld.com] 
> Sent: Monday, November 21, 2005 6:53 PM
> To: Jakarta Commons Developers List
> Subject: [collections] BlockingBuffer and TimeoutBuffer
> 
> Having had a look at the new class TimeoutBuffer, I realised that it 
> could just be written as an extra parameter to BlockingBuffer. I think 
> this would be cleaner.
> 
> BlockingBuffer.decorate(buf);  // no timeout
> BlockingBuffer.decorate(buf, timeout);  // timeout
> 
> The method implementation will simply check if the stored timeout value 
> is zero. If it is it does the get()/remove() as is, otherwise it uses 
> get(long)/remove(long).
> 
> Note that adding a new field inn this case is OK with serialization as 
> the field will default to zero if an old version of the class is 
> deserialized using the new jar.
> 
> Stephen
> 
> ---------------------------------------------------------------------
> 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
> 
> 

---------------------------------------------------------------------
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] BlockingBuffer and TimeoutBuffer

Posted by Stephen Colebourne <sc...@btopenworld.com>.
I believe that 0 is what the JDK uses in Object.wait(long) for an 
infinite wait. A negative number would also mean infinite.

Stephen


James Carman wrote:
> Stephen,
> 
> I don't know about using 0 to indicate that it's a wait forever situation.
> A negative number would be better for that, wouldn't you say?  A 0 would
> mean that you don't want to wait at all (of course, why would you use
> BlockingBuffer if you're going to supply a 0).
> 
> James
> 
> -----Original Message-----
> From: Stephen Colebourne [mailto:scolebourne@btopenworld.com] 
> Sent: Monday, November 21, 2005 6:53 PM
> To: Jakarta Commons Developers List
> Subject: [collections] BlockingBuffer and TimeoutBuffer
> 
> Having had a look at the new class TimeoutBuffer, I realised that it 
> could just be written as an extra parameter to BlockingBuffer. I think 
> this would be cleaner.
> 
> BlockingBuffer.decorate(buf);  // no timeout
> BlockingBuffer.decorate(buf, timeout);  // timeout
> 
> The method implementation will simply check if the stored timeout value 
> is zero. If it is it does the get()/remove() as is, otherwise it uses 
> get(long)/remove(long).
> 
> Note that adding a new field inn this case is OK with serialization as 
> the field will default to zero if an old version of the class is 
> deserialized using the new jar.
> 
> Stephen
> 
> ---------------------------------------------------------------------
> 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
> 
> 

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


RE: [collections] BlockingBuffer and TimeoutBuffer

Posted by James Carman <ja...@carmanconsulting.com>.
Stephen,

I don't know about using 0 to indicate that it's a wait forever situation.
A negative number would be better for that, wouldn't you say?  A 0 would
mean that you don't want to wait at all (of course, why would you use
BlockingBuffer if you're going to supply a 0).

James

-----Original Message-----
From: Stephen Colebourne [mailto:scolebourne@btopenworld.com] 
Sent: Monday, November 21, 2005 6:53 PM
To: Jakarta Commons Developers List
Subject: [collections] BlockingBuffer and TimeoutBuffer

Having had a look at the new class TimeoutBuffer, I realised that it 
could just be written as an extra parameter to BlockingBuffer. I think 
this would be cleaner.

BlockingBuffer.decorate(buf);  // no timeout
BlockingBuffer.decorate(buf, timeout);  // timeout

The method implementation will simply check if the stored timeout value 
is zero. If it is it does the get()/remove() as is, otherwise it uses 
get(long)/remove(long).

Note that adding a new field inn this case is OK with serialization as 
the field will default to zero if an old version of the class is 
deserialized using the new jar.

Stephen

---------------------------------------------------------------------
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