Skip to content

Introduce NettyCustomizer API #499

Closed

Description

@mp911de

Introduce NettyCustomizer to customize the netty bootstrap:

  • Callback after Bootstrap is configured and before connecting
  • Callback for channel initialization after executing initChannel(Channel)

Should be configured with ClientResources.

Activity

  1. added this to the Lettuce 4.4.0 milestone on Apr 1, 2017
  2. mp911de commented on Apr 13, 2017

    @mp911de
    CollaboratorAuthor

    @jongyeol do you want to give it a try whether NettyCustomizer is sufficient to customize the channel to your requirements?

  3. jongyeol commented on Apr 13, 2017

    @jongyeol
    Contributor

    Oh, thank you very much. 👍
    I checked some codes, and I have a question. As you know, order of handlers is important for inserting custom hander into pipeline.

    https://github.com/lettuce-io/lettuce-core/blob/master/src/main/java/com/lambdaworks/redis/ConnectionBuilder.java#L78-L82

    I wanna insert my handler to the position between CommandEncoder and commandHandler.

    @Override
    public void afterChannelInitialized(Channel channel) {
        channel.pipeline().addBefore(<here>, "my_custom_handler", new MyCustomHandler());
    }
    

    So, I want to use CommandHandler's name to <here>, but it don't have handler name. And, I couldn't find addBefore(<type>, ...) or addAfter(<type>, ...) in Netty's ChannelPipeline class.

    Do you have ideas? or, could you add names for existing handlers in Lettuce?

  4. mp911de commented on Apr 13, 2017

    @mp911de
    CollaboratorAuthor

    You have two options:

    1. ChannelPipeline is Iterable<Entry<String, ChannelHandler>> so you can iterate through existing pipeline items and identify the ChannelHandler you're trying to find
    2. Netty generates default names for the handlers using StringUtil.simpleClassName(handlerType) + "#0". The only named ChannelHandler is the initializer using channelActivator as name.
  5. jongyeol commented on Apr 13, 2017

    @jongyeol
    Contributor

    I worried option2 because it's little implicit way. But, if I use both option1 and option2, it's not implicit. Anyway, it works well. Thank you. 😄

    https://gist.github.com/jongyeol/35ae23fee87e0426fef5faf5c417cc44#file-lettuce-disconnectedwritetimeoutexceptionandreconnecttest-java-L11-L21

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions