Roger
Roger

Reputation: 573

how to bootstrap netty channel for "slave" application

I'd like to implement a netty "slave" application that listens for requests on an outgoing websocket connection. So on bootstrap, the application would:

  1. open a ws connection to a remote server
  2. listen for commands on the ws connection using a "boss" event loop
  3. handle incomming commands on a "worker" event loop

My question is how to boostrap the channel - I'd rather use a bootstrap object for convenience sake (I mean vs. configuring the channel by hand), but:

  1. ServerBootstrap requires a local listening socket
  2. Bootstrap has only one eventloop
  3. AbstractBootstrap can't be subclassed outside of package, and ServerBootstrap/Bootstrap are final

Any suggestions on how to bootstrap the channel without duplicating a bunch of existing *Bootstrap code?

Upvotes: 0

Views: 124

Answers (1)

Roger
Roger

Reputation: 573

I ended up passing an EventExecutorGroup directly to the pipeline via ChannelPipeline.html.addLast() - I somehow had missed that in the api docs.

From the javadocs:

static final EventExecutorGroup group = new DefaultEventExecutorGroup(16);
...

ChannelPipeline pipeline = ch.pipeline();

pipeline.addLast("decoder", new MyProtocolDecoder());
pipeline.addLast("encoder", new MyProtocolEncoder());

// Tell the pipeline to run MyBusinessLogicHandler's event handler methods
// in a different thread than an I/O thread so that the I/O thread is not blocked by
// a time-consuming task.
// If your business logic is fully asynchronous or finished very quickly, you don't
// need to specify a group.
pipeline.addLast(group, "handler", new MyBusinessLogicHandler());

Upvotes: 0

Related Questions