handler will receive a sequence of increasing integers starting // from 1. {@code @Override}public void messageReceived( {@link ChannelHandlerContext} ctx, {@link MessageEvent} evt) {Integer a = (Integer) ctx.getAttachment(); Integer b = (Integer) evt.getMessage(); if (a == null) { a = 1; } ctx.setAttachment(Integer.valueOf(a * b)); } } // Different context objects are given to "f1", "f2", "f3", and "f4" even if // they refer to the same handler instance. Because the FactorialHandler // stores its state in a context object (as an attachment), the factorial is // calculated correctly 4 times once the two pipelines (p1 and p2) are active. FactorialHandler fh = new FactorialHandler(); {@link ChannelPipeline} p1 = {@link Channels}.pipeline(); p1.addLast("f1", fh); p1.addLast("f2", fh); {@link ChannelPipeline} p2 = {@link Channels}.pipeline(); p2.addLast("f3", fh); p2.addLast("f4", fh);
Additional resources worth reading
Please refer to the {@link ChannelHandler}, {@link ChannelEvent}, and {@link ChannelPipeline} to find out what a upstream event and a downstreamevent are, what fundamental differences they have, how they flow in a pipeline, and how to handle the event in your application.
@apiviz.owns com.facebook.presto.jdbc.internal.netty.channel.ChannelHandler