diff options
Diffstat (limited to 'src/org/traccar/GeolocationHandler.java')
-rw-r--r-- | src/org/traccar/GeolocationHandler.java | 30 |
1 files changed, 11 insertions, 19 deletions
diff --git a/src/org/traccar/GeolocationHandler.java b/src/org/traccar/GeolocationHandler.java index 346ad5904..0c204dc0b 100644 --- a/src/org/traccar/GeolocationHandler.java +++ b/src/org/traccar/GeolocationHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 - 2017 Anton Tananaev (anton@traccar.org) + * Copyright 2015 - 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.helper.Log; import org.traccar.geolocation.GeolocationProvider; import org.traccar.model.Position; -public class GeolocationHandler implements ChannelUpstreamHandler { +@ChannelHandler.Sharable +public class GeolocationHandler extends ChannelInboundHandlerAdapter { private final GeolocationProvider geolocationProvider; private final boolean processInvalidPositions; @@ -35,14 +34,7 @@ public class GeolocationHandler 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 ((position.getOutdated() || processInvalidPositions && !position.getValid()) @@ -63,20 +55,20 @@ public class GeolocationHandler implements ChannelUpstreamHandler { position.setSpeed(0); position.setCourse(0); position.set(Position.KEY_RSSI, 0); - Channels.fireMessageReceived(ctx, position, event.getRemoteAddress()); + ctx.fireChannelRead(position); } @Override public void onFailure(Throwable e) { Log.warning(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); } } |