Dynamically adding handlers to channel pipelines

"Trustin Lee (이희승)" trustin at gmail.com
Mon Mar 29 09:57:22 EDT 2010


Hi,

imk wrote:
> Hi - 
> 
> I am trying to see whether or not I should use Netty for implementing a
> client/server TCP/IP based protocol in Java. The client/server interactions
> are goint to based on arbitrary 'bits' rather than bytes'.
> 
> My first question is, is there anyone out there who tried to work at the bit
> level rather than bytes? Is there any source code/examples? Best practices??

Maybe you need a queue (such as bit set) that allows you to fetch an
arbitrary number of bits because Netty's ChannelBuffer is basically an
abstraction of a byte array?  For example:

    BitBuffer bb = ...;
    bb.readBitsAsInt(2); // Read 2 bits

However, such facility is not available in Netty, so you need to
implement one by yourself.  As far as I know, there's no NIO framework
that has built-in bit buffer implementation, but it can always be built
on top of existing buffer API.

> My second, and actual!, question is, I do have the following situation that
> I need to handle, and again I need best practices on how to proceed:  
> 
> In the protocol, there is so-called an 'Header' comprising X bits. Depending
> on the value of particular bits or a single bit of the 'Header', what
> follows the ApplicationHeader dynamically changes. Therefore, my pipeline
> should (I presume) would need to get hold of X bits first, and then check
> specific bits out of that value, and dynamically change the pipeline..Are
> there any examples of dynamically changing pipelines??

You might be interested in the port unification example:

    http://is.gd/b5aZO

> Also, I need to compute (and actually write to database) *lots* of
> statistical data. (i.e. kilobytes received, messages received, etc etc.).
> What is the best way of doing this? Program thread objects which have
> references to handlers? or else?

Since database operation takes time, you'd better have a dedicated
thread pool for such operations.  You might want to take a look into the
ExecutionHandler and OrderedMemoryAwareThreadPoolExecutor:

    http://is.gd/b5b8m

HTH,
Trustin
-- 
what we call human nature in actuality is human habit
http://gleamynode.net/


-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 260 bytes
Desc: OpenPGP digital signature
Url : http://lists.jboss.org/pipermail/netty-users/attachments/20100329/8ddf4a5c/attachment-0001.bin 


More information about the netty-users mailing list