Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8780437
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T20:02:52+00:00 2026-06-13T20:02:52+00:00

Consider the following server bootstrapping code: ChannelFuture f; ServerBootstrap b = new ServerBootstrap(); try

  • 0

Consider the following server bootstrapping code:

ChannelFuture f;
ServerBootstrap b = new ServerBootstrap();

try {
    b.group(new NioEventLoopGroup(), new NioEventLoopGroup())
            .channel(NioServerSocketChannel.class)
            .localAddress(1234)
            .childOption(ChannelOption.TCP_NODELAY, true)
            .childHandler(new MyChannelInitializer(new DefaultEventExecutorGroup(10)));

    f = b.bind().sync();
    f.channel().closeFuture().sync();
}

And MyChannelInitializer.java:

public class MyChannelInitializer  extends ChannelInitializer<SocketChannel> {
    private EventExecutorGroup executorGroup;

    public MyChannelInitializer(EventExecutorGroup _executorGroup) {
        executorGroup = _executorGroup;
    }

    @Override
    public void initChannel(SocketChannel ch) throws Exception {
        ChannelPipeline pipeline = ch.pipeline();

        pipeline.addLast("framer", new DelimiterBasedFrameDecoder(8192, Delimiters.nulDelimiter()));
        pipeline.addLast("decoder", new StringDecoder(CharsetUtil.UTF_8));
        pipeline.addLast("encoder", new StringEncoder(CharsetUtil.UTF_8));

        // and then business logic.
        pipeline.addLast(this.executorGroup, "handler", new MyHandshakeHandler());
    }    
}

Now- MyHandshakeHandler() listens for messages, and those messages need to interact with the database.

Before we go further- is the above code the correct way to do this? (namely- the way I used EventExecutorGroup for this blocking type of handler)

Assuming for now that it is correct, here’s my question- while it’s true that MyHandshakeHandler() needs to interact with the database, this is only during the initial negotiation with the client and upon channel close. The rest of the time- namely after handshake is completed and before the channel is closed- all that is needed is to bounce ping/pong/heartbeat/keepalive type messages which do not require the database. Therefore- should that A) be a separate handler (let’s call it “MyPingHandler”) which is added to the pipeline before MyHandshakeHandler or B) should I just add that logic to MyHandshakeHandler?

If A) how do I stop the message from propagating further so that MyHandshakeHandler is not needlessly called, unless it is specifically the channel close event (i.e. channelInactive())? As a bonus point- it would be nice if MyPingHandler were only added to the pipeline after handshake is complete so that it is not needlessly called as well.

If B) I don’t understand the purpose of EventExecutorGroup in this case. These connections are the only type which this server will power…. so it seems strange to me to set a dedicated group of threads which will be used for every single handler rather than just use the default. So if B is the way to go- for this specific case- should I just add the handler to the pipeline normally without EventExecutorGroup (if not- why not)?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T20:02:53+00:00Added an answer on June 13, 2026 at 8:02 pm

    The answer is (A).

    To propagate an event to its next handler, you usually call a ctx.fireXXX() method. If you don’t call any of them, the event will not be propagated. So, in your case, you can just swallow event in most case after handshake is complete by NOT calling ctx.fireXXX() methods.

    Also, the pipeline can be dynamically configures. You can add or remove a handler to/from a pipeline at anytime. Therefore, you can either remove the handshake handler after handshake is over or add the ping handler after handshake is over (or perhaps both).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Please consider following snippet: <div class=row> <div class=span12> <div class=control-group> <label class=control-label>Person Name</label> <div
Consider the following code: SqlConnection conn = new SqlConnection(@connection string); SqlCommand ourCommand = new
Consider the following code: <label>Search:</label><asp:TextBox runat=server ID=search ClientIDMode=Static OnKeyUp=$('#searchButton').click(); /><asp:Button runat=server ID=searchButton ClientIDMode=Static />
Please consider the following scenario: VNC Client try to connect with a VNC Server
Consider the following sql server query , DECLARE @Table TABLE( Wages FLOAT ) INSERT
Please consider the following SQL Server table and stored procedure. create table customers(cusnum int,
Can i apply SUM() within an ISNULL() .... Consider my following sql server select
Consider the following output from a Tomcat server under Eclipse: INFO: Initializing Coyote HTTP/1.1
Consider the following script: for host in $(get-all-hosts) do (restart-server $host; wait-for-server-to-come-up $host) &
Consider following code: My problem is: 1) I can't seem to cast the errors

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.