Need Help with understanding the code

Mayank6 years ago

Hey Anton,

I need one help wrt to understanding the code of Traccar Server.
Under DefaultDataHandler.java, while overriding handlePosition, We are returning the Position type object.

 protected Position handlePosition(Position position) {

        try {
            Context.getDataManager().addObject(position);
            //return null;
        } catch (Exception error) {
            LOGGER.warn("Failed to store position", error);
        }

        return position;
    }

Now the thing is, if You see the caller of this can be BaseDataHandler -> channelRead function. But here we are triggering the fireChannelRead event with the same Position object;

public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
        if (msg instanceof Position) {
            Position position = handlePosition((Position) msg);
            if (position != null) {
                ctx.fireChannelRead(position);  // <- Here we are triggerring the same fireChannelRead event
            }
        } else {
            super.channelRead(ctx, msg);
        }
    }

Do not you think, there might be the chance we will be reading the same Position message again here.

TIA!

Anton Tananaev6 years ago

What do you mean by reading the same message? We are just passing it up the pipeline chain.

Mayank6 years ago

Hey Anton,

I got it this by understanding the architecture of the way netty works. Thanks for your reply!
Closing this thread!