From f98c3aa5b65e9fa06bcea38d96959b43f6a38245 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Sun, 15 Mar 2020 15:39:12 -0700 Subject: Simplify data commands --- src/main/java/org/traccar/database/ActiveDevice.java | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) (limited to 'src/main/java/org/traccar/database/ActiveDevice.java') diff --git a/src/main/java/org/traccar/database/ActiveDevice.java b/src/main/java/org/traccar/database/ActiveDevice.java index 207fc454b..698cc851e 100644 --- a/src/main/java/org/traccar/database/ActiveDevice.java +++ b/src/main/java/org/traccar/database/ActiveDevice.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 - 2018 Anton Tananaev (anton@traccar.org) + * Copyright 2015 - 2020 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. @@ -45,11 +45,7 @@ public class ActiveDevice { } public void sendCommand(Command command) { - protocol.sendDataCommand(this, command); - } - - public void write(Object message) { - channel.writeAndFlush(new NetworkMessage(message, remoteAddress)); + protocol.sendDataCommand(channel, remoteAddress, command); } } -- cgit v1.2.3 From f9257e664be8c37cc041e004f403d737dd513d6b Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Sun, 15 Mar 2020 15:43:17 -0700 Subject: Remove unused imports --- src/main/java/org/traccar/Protocol.java | 3 +-- src/main/java/org/traccar/database/ActiveDevice.java | 1 - 2 files changed, 1 insertion(+), 3 deletions(-) (limited to 'src/main/java/org/traccar/database/ActiveDevice.java') diff --git a/src/main/java/org/traccar/Protocol.java b/src/main/java/org/traccar/Protocol.java index 9d257be78..aea69b353 100644 --- a/src/main/java/org/traccar/Protocol.java +++ b/src/main/java/org/traccar/Protocol.java @@ -1,5 +1,5 @@ /* - * Copyright 2018 Anton Tananaev (anton@traccar.org) + * Copyright 2018 - 2020 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. @@ -16,7 +16,6 @@ package org.traccar; import io.netty.channel.Channel; -import org.traccar.database.ActiveDevice; import org.traccar.model.Command; import java.net.SocketAddress; diff --git a/src/main/java/org/traccar/database/ActiveDevice.java b/src/main/java/org/traccar/database/ActiveDevice.java index 698cc851e..34b3de227 100644 --- a/src/main/java/org/traccar/database/ActiveDevice.java +++ b/src/main/java/org/traccar/database/ActiveDevice.java @@ -16,7 +16,6 @@ package org.traccar.database; import io.netty.channel.Channel; -import org.traccar.NetworkMessage; import org.traccar.Protocol; import org.traccar.model.Command; -- cgit v1.2.3 From 606afeb37451f921fe3aecffab439cc2bcc7a175 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Sun, 15 Mar 2020 16:02:37 -0700 Subject: Queue HTTP commands --- src/main/java/org/traccar/database/ActiveDevice.java | 6 ++++++ src/main/java/org/traccar/database/CommandsManager.java | 7 ++++++- 2 files changed, 12 insertions(+), 1 deletion(-) (limited to 'src/main/java/org/traccar/database/ActiveDevice.java') diff --git a/src/main/java/org/traccar/database/ActiveDevice.java b/src/main/java/org/traccar/database/ActiveDevice.java index 34b3de227..e3ece6ad9 100644 --- a/src/main/java/org/traccar/database/ActiveDevice.java +++ b/src/main/java/org/traccar/database/ActiveDevice.java @@ -16,6 +16,8 @@ package org.traccar.database; import io.netty.channel.Channel; +import io.netty.handler.codec.http.HttpRequestDecoder; +import org.traccar.BasePipelineFactory; import org.traccar.Protocol; import org.traccar.model.Command; @@ -43,6 +45,10 @@ public class ActiveDevice { return deviceId; } + public boolean supportsLiveCommands() { + return BasePipelineFactory.getHandler(channel.pipeline(), HttpRequestDecoder.class) == null; + } + public void sendCommand(Command command) { protocol.sendDataCommand(channel, remoteAddress, command); } diff --git a/src/main/java/org/traccar/database/CommandsManager.java b/src/main/java/org/traccar/database/CommandsManager.java index 99114db5e..485402807 100644 --- a/src/main/java/org/traccar/database/CommandsManager.java +++ b/src/main/java/org/traccar/database/CommandsManager.java @@ -76,7 +76,12 @@ public class CommandsManager extends ExtendedObjectManager { } else { ActiveDevice activeDevice = Context.getConnectionManager().getActiveDevice(deviceId); if (activeDevice != null) { - activeDevice.sendCommand(command); + if (activeDevice.supportsLiveCommands()) { + activeDevice.sendCommand(command); + } else { + getDeviceQueue(deviceId).add(command); + return false; + } } else if (!queueing) { throw new RuntimeException("Device is not online"); } else { -- cgit v1.2.3