diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2018-06-02 22:12:44 +1200 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2018-06-02 22:12:44 +1200 |
commit | 06e3bd8b16da12baafc9a97ba5949b3f7ffb5e07 (patch) | |
tree | 8f5d7b71ca3fa39448e93b3d0652a7fa8d496932 /src/org/traccar/GeocoderHandler.java | |
parent | 5a9811c3771d92832c9bba718b5ec935844978e8 (diff) | |
download | trackermap-server-06e3bd8b16da12baafc9a97ba5949b3f7ffb5e07.tar.gz trackermap-server-06e3bd8b16da12baafc9a97ba5949b3f7ffb5e07.tar.bz2 trackermap-server-06e3bd8b16da12baafc9a97ba5949b3f7ffb5e07.zip |
Start Netty 4 migration
Diffstat (limited to 'src/org/traccar/GeocoderHandler.java')
-rw-r--r-- | src/org/traccar/GeocoderHandler.java | 32 |
1 files changed, 12 insertions, 20 deletions
diff --git a/src/org/traccar/GeocoderHandler.java b/src/org/traccar/GeocoderHandler.java index 6b55e8162..0f3ba4731 100644 --- a/src/org/traccar/GeocoderHandler.java +++ b/src/org/traccar/GeocoderHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2012 - 2017 Anton Tananaev (anton@traccar.org) + * Copyright 2012 - 2018 Anton Tananaev (anton@traccar.org) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,16 +15,15 @@ */ package org.traccar; -import org.jboss.netty.channel.ChannelEvent; -import org.jboss.netty.channel.ChannelHandlerContext; -import org.jboss.netty.channel.ChannelUpstreamHandler; -import org.jboss.netty.channel.Channels; -import org.jboss.netty.channel.MessageEvent; +import io.netty.channel.ChannelHandler; +import io.netty.channel.ChannelHandlerContext; +import io.netty.channel.ChannelInboundHandlerAdapter; import org.traccar.geocoder.Geocoder; import org.traccar.helper.Log; import org.traccar.model.Position; -public class GeocoderHandler implements ChannelUpstreamHandler { +@ChannelHandler.Sharable +public class GeocoderHandler extends ChannelInboundHandlerAdapter { private final Geocoder geocoder; private final boolean processInvalidPositions; @@ -38,14 +37,7 @@ public class GeocoderHandler implements ChannelUpstreamHandler { } @Override - public void handleUpstream(final ChannelHandlerContext ctx, ChannelEvent evt) throws Exception { - if (!(evt instanceof MessageEvent)) { - ctx.sendUpstream(evt); - return; - } - - final MessageEvent event = (MessageEvent) evt; - Object message = event.getMessage(); + public void channelRead(final ChannelHandlerContext ctx, Object message) throws Exception { if (message instanceof Position) { final Position position = (Position) message; if (processInvalidPositions || position.getValid()) { @@ -54,7 +46,7 @@ public class GeocoderHandler implements ChannelUpstreamHandler { if (lastPosition != null && lastPosition.getAddress() != null && position.getDouble(Position.KEY_DISTANCE) <= geocoderReuseDistance) { position.setAddress(lastPosition.getAddress()); - Channels.fireMessageReceived(ctx, position, event.getRemoteAddress()); + ctx.fireChannelRead(position); return; } } @@ -66,20 +58,20 @@ public class GeocoderHandler implements ChannelUpstreamHandler { @Override public void onSuccess(String address) { position.setAddress(address); - Channels.fireMessageReceived(ctx, position, event.getRemoteAddress()); + ctx.fireChannelRead(position); } @Override public void onFailure(Throwable e) { Log.warning("Geocoding failed", e); - Channels.fireMessageReceived(ctx, position, event.getRemoteAddress()); + ctx.fireChannelRead(position); } }); } else { - Channels.fireMessageReceived(ctx, position, event.getRemoteAddress()); + ctx.fireChannelRead(position); } } else { - Channels.fireMessageReceived(ctx, message, event.getRemoteAddress()); + ctx.fireChannelRead(message); } } |