You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@directory.apache.org by "Federico Bonelli (JIRA)" <ji...@apache.org> on 2006/01/13 13:36:20 UTC

[jira] Created: (DIRMINA-165) Easy and performant copy of the ByteBuffer

Easy and performant copy of the ByteBuffer
------------------------------------------

         Key: DIRMINA-165
         URL: http://issues.apache.org/jira/browse/DIRMINA-165
     Project: Directory MINA
        Type: Improvement
    Versions: 0.9, 0.8.2, 0.8.1, 0.8    
    Reporter: Federico Bonelli
    Priority: Minor


Until now if you wish to broadcast a message you must create by your own the bytebuffer copies, it would be better to provide a ByteBuffer.asReadOnly() method that create a copy that share the data with the original ByteBuffer

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira


[jira] Updated: (DIRMINA-165) Easy and performant copy of the ByteBuffer

Posted by "Niklas Therning (JIRA)" <ji...@apache.org>.
     [ http://issues.apache.org/jira/browse/DIRMINA-165?page=all ]

Niklas Therning updated DIRMINA-165:
------------------------------------

    Attachment:     (was: ByteBuffer.java)

> Easy and performant copy of the ByteBuffer
> ------------------------------------------
>
>          Key: DIRMINA-165
>          URL: http://issues.apache.org/jira/browse/DIRMINA-165
>      Project: Directory MINA
>         Type: Improvement
>     Versions: 0.8, 0.9, 0.8.1, 0.8.2
>     Reporter: Federico Bonelli
>     Priority: Minor

>
> Until now if you wish to broadcast a message you must create by your own the bytebuffer copies, it would be better to provide a ByteBuffer.asReadOnly() method that create a copy that share the data with the original ByteBuffer

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira


[jira] Commented: (DIRMINA-165) Easy and performant copy of the ByteBuffer

Posted by "Federico Bonelli (JIRA)" <ji...@apache.org>.
    [ http://issues.apache.org/jira/browse/DIRMINA-165?page=comments#action_12363261 ] 

Federico Bonelli commented on DIRMINA-165:
------------------------------------------

I agree that buffers need all the duplicate-like methods, but what about pooling them?

If all the buffers copied _and the parent too_ have to be unpooled, it may increase a lot the time of allocation for direct buffers, especially in case of a massive use of copies that could be very light for CPU.

It is certainly better than all the copies have pooled = false, and could not be changed, but the parent can be pooled, I think, after that all the copies have been released.
WDYT?



> Easy and performant copy of the ByteBuffer
> ------------------------------------------
>
>          Key: DIRMINA-165
>          URL: http://issues.apache.org/jira/browse/DIRMINA-165
>      Project: Directory MINA
>         Type: Improvement
>     Versions: 0.9, 0.8.2, 0.8.1, 0.8
>     Reporter: Federico Bonelli
>     Priority: Minor
>  Attachments: ByteBuffer.java, HubServer_broadCastTCPmessages.zip
>
> Until now if you wish to broadcast a message you must create by your own the bytebuffer copies, it would be better to provide a ByteBuffer.asReadOnly() method that create a copy that share the data with the original ByteBuffer

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira


[jira] Commented: (DIRMINA-165) Easy and performant copy of the ByteBuffer

Posted by "Federico Bonelli (JIRA)" <ji...@apache.org>.
    [ http://issues.apache.org/jira/browse/DIRMINA-165?page=comments#action_12362959 ] 

Federico Bonelli commented on DIRMINA-165:
------------------------------------------

The ByteBuffer version I have published is not a good solution, I have modified it so I have the last version and an echo TCP server that does broadcast with the messages received.

Somebody who have the power can remove here the ByteBuffer so I can publish the right version with the example?

> Easy and performant copy of the ByteBuffer
> ------------------------------------------
>
>          Key: DIRMINA-165
>          URL: http://issues.apache.org/jira/browse/DIRMINA-165
>      Project: Directory MINA
>         Type: Improvement
>     Versions: 0.8, 0.9, 0.8.1, 0.8.2
>     Reporter: Federico Bonelli
>     Priority: Minor
>  Attachments: ByteBuffer.java
>
> Until now if you wish to broadcast a message you must create by your own the bytebuffer copies, it would be better to provide a ByteBuffer.asReadOnly() method that create a copy that share the data with the original ByteBuffer

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira


[jira] Updated: (DIRMINA-165) Easy and performant copy of the ByteBuffer

Posted by "Federico Bonelli (JIRA)" <ji...@apache.org>.
     [ http://issues.apache.org/jira/browse/DIRMINA-165?page=all ]

Federico Bonelli updated DIRMINA-165:
-------------------------------------

    Attachment: ByteBuffer.java

And this is the modified (and working) ByteBuffer, with the asReadOnly() method.
See the hubserver for an example of the right usage.

> Easy and performant copy of the ByteBuffer
> ------------------------------------------
>
>          Key: DIRMINA-165
>          URL: http://issues.apache.org/jira/browse/DIRMINA-165
>      Project: Directory MINA
>         Type: Improvement
>     Versions: 0.8, 0.9, 0.8.1, 0.8.2
>     Reporter: Federico Bonelli
>     Priority: Minor
>  Attachments: ByteBuffer.java, HubServer_broadCastTCPmessages.zip
>
> Until now if you wish to broadcast a message you must create by your own the bytebuffer copies, it would be better to provide a ByteBuffer.asReadOnly() method that create a copy that share the data with the original ByteBuffer

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira


[jira] Commented: (DIRMINA-165) Easy and performant copy of the ByteBuffer

Posted by "Trustin Lee (JIRA)" <ji...@apache.org>.
    [ http://issues.apache.org/jira/browse/DIRMINA-165?page=comments#action_12363218 ] 

Trustin Lee commented on DIRMINA-165:
-------------------------------------

Your patch is very error-prone.  What about this?

* Provide all methods like duplicate, asReadOnlyBuffer, slice, ...
* To invoke these methods, 'pooled' property must be false.
* 'pooled' property of all derived buffers and its parent buffer must be 'false' and cannot be changed anymore.

In case of broadcasting only, we could provide more effective solution as we discussed in DIRMINA-42.

WDYT?

> Easy and performant copy of the ByteBuffer
> ------------------------------------------
>
>          Key: DIRMINA-165
>          URL: http://issues.apache.org/jira/browse/DIRMINA-165
>      Project: Directory MINA
>         Type: Improvement
>     Versions: 0.8, 0.9, 0.8.1, 0.8.2
>     Reporter: Federico Bonelli
>     Priority: Minor
>  Attachments: ByteBuffer.java, HubServer_broadCastTCPmessages.zip
>
> Until now if you wish to broadcast a message you must create by your own the bytebuffer copies, it would be better to provide a ByteBuffer.asReadOnly() method that create a copy that share the data with the original ByteBuffer

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira


[jira] Commented: (DIRMINA-165) Easy and performant copy of the ByteBuffer

Posted by "Niklas Therning (JIRA)" <ji...@apache.org>.
    [ http://issues.apache.org/jira/browse/DIRMINA-165?page=comments#action_12363224 ] 

Niklas Therning commented on DIRMINA-165:
-----------------------------------------

I've already implemented slice() but haven't committed it yet. I've also added a slice(offset, length) method which uses the passed in values instead of the current postion and limit. I think it will be quite useful. I haven't thought of checking pooled == false. I will have to add that before committing.

slice() becomes:

public ByteBuffer slice()
{
  assertNotPooled(); // Throws IllegalStateException if pooled == true
  return wrap( buf().slice() );
}

Does this look OK? If it does the rest of the methods (duplicate(), asReadOnlyBuffer()) could be implemented like this.


> Easy and performant copy of the ByteBuffer
> ------------------------------------------
>
>          Key: DIRMINA-165
>          URL: http://issues.apache.org/jira/browse/DIRMINA-165
>      Project: Directory MINA
>         Type: Improvement
>     Versions: 0.9, 0.8.2, 0.8.1, 0.8
>     Reporter: Federico Bonelli
>     Priority: Minor
>  Attachments: ByteBuffer.java, HubServer_broadCastTCPmessages.zip
>
> Until now if you wish to broadcast a message you must create by your own the bytebuffer copies, it would be better to provide a ByteBuffer.asReadOnly() method that create a copy that share the data with the original ByteBuffer

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira


[jira] Commented: (DIRMINA-165) Easy and performant copy of the ByteBuffer

Posted by "Niklas Therning (JIRA)" <ji...@apache.org>.
    [ http://issues.apache.org/jira/browse/DIRMINA-165?page=comments#action_12363226 ] 

Niklas Therning commented on DIRMINA-165:
-----------------------------------------

There could also be a ByteBuffer.unpool() method which returns an unpooled copy of the buffer. If the buffer isn't pooled it will simply return itself:


> Easy and performant copy of the ByteBuffer
> ------------------------------------------
>
>          Key: DIRMINA-165
>          URL: http://issues.apache.org/jira/browse/DIRMINA-165
>      Project: Directory MINA
>         Type: Improvement
>     Versions: 0.9, 0.8.2, 0.8.1, 0.8
>     Reporter: Federico Bonelli
>     Priority: Minor
>  Attachments: ByteBuffer.java, HubServer_broadCastTCPmessages.zip
>
> Until now if you wish to broadcast a message you must create by your own the bytebuffer copies, it would be better to provide a ByteBuffer.asReadOnly() method that create a copy that share the data with the original ByteBuffer

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira


[jira] Updated: (DIRMINA-165) Easy and performant copy of the ByteBuffer

Posted by "Federico Bonelli (JIRA)" <ji...@apache.org>.
     [ http://issues.apache.org/jira/browse/DIRMINA-165?page=all ]

Federico Bonelli updated DIRMINA-165:
-------------------------------------

    Attachment: HubServer_broadCastTCPmessages.zip

Thanks a lot Niklas 8)
This is the MINA broadcast test server, I have just modified the echoserver, the code is very trivial.
Tested and well-working

> Easy and performant copy of the ByteBuffer
> ------------------------------------------
>
>          Key: DIRMINA-165
>          URL: http://issues.apache.org/jira/browse/DIRMINA-165
>      Project: Directory MINA
>         Type: Improvement
>     Versions: 0.8, 0.9, 0.8.1, 0.8.2
>     Reporter: Federico Bonelli
>     Priority: Minor
>  Attachments: HubServer_broadCastTCPmessages.zip
>
> Until now if you wish to broadcast a message you must create by your own the bytebuffer copies, it would be better to provide a ByteBuffer.asReadOnly() method that create a copy that share the data with the original ByteBuffer

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira


[jira] Commented: (DIRMINA-165) Easy and performant copy of the ByteBuffer

Posted by "Niklas Therning (JIRA)" <ji...@apache.org>.
    [ http://issues.apache.org/jira/browse/DIRMINA-165?page=comments#action_12362962 ] 

Niklas Therning commented on DIRMINA-165:
-----------------------------------------

The original attachment has been removed

> Easy and performant copy of the ByteBuffer
> ------------------------------------------
>
>          Key: DIRMINA-165
>          URL: http://issues.apache.org/jira/browse/DIRMINA-165
>      Project: Directory MINA
>         Type: Improvement
>     Versions: 0.8, 0.9, 0.8.1, 0.8.2
>     Reporter: Federico Bonelli
>     Priority: Minor

>
> Until now if you wish to broadcast a message you must create by your own the bytebuffer copies, it would be better to provide a ByteBuffer.asReadOnly() method that create a copy that share the data with the original ByteBuffer

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira


[jira] Updated: (DIRMINA-165) Easy and performant copy of the ByteBuffer

Posted by "Federico Bonelli (JIRA)" <ji...@apache.org>.
     [ http://issues.apache.org/jira/browse/DIRMINA-165?page=all ]

Federico Bonelli updated DIRMINA-165:
-------------------------------------

    Attachment: ByteBuffer.java

In the MINA byteBuffer.asReadOnly() I create a new mina DefaultByteBuffer container and get into that the nio.buffer copy and the reference to the original mina bytebuffer, and a boolean flag that says if the DefaultByteBuffer wrap a readOnly copy or a real writable nio.bytebuffer. I do an aquire() of the original MINA byteBuffer.
(Errata Corrige: instead of the flag I have used the reference to the original buffer: if it is null I think that it is not a copy)

So when the MINA ByteBuffer copy is released, the release method just look at the flag and release the original mina bytebuffer.
The MINA bytebuffer copy _must_ be not pooled obviusly.
 
In this way there is no need to make a copy of the data, but only a new nio.bytebuffer that use the same byte[] or direct array, and the original ByteBuffer will be released only when all the copies will be already written to the channel.

This implementation do not work well with the expand features.
All the stuff I have added are marked with a "DIRMINA 165" comment.

> Easy and performant copy of the ByteBuffer
> ------------------------------------------
>
>          Key: DIRMINA-165
>          URL: http://issues.apache.org/jira/browse/DIRMINA-165
>      Project: Directory MINA
>         Type: Improvement
>     Versions: 0.8, 0.9, 0.8.1, 0.8.2
>     Reporter: Federico Bonelli
>     Priority: Minor
>  Attachments: ByteBuffer.java
>
> Until now if you wish to broadcast a message you must create by your own the bytebuffer copies, it would be better to provide a ByteBuffer.asReadOnly() method that create a copy that share the data with the original ByteBuffer

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira