Skip to content

Commit

Permalink
Merge pull request traccar#3862 from Abyss777/switch_queueing
Browse files Browse the repository at this point in the history
Make Commands queueing switchable
  • Loading branch information
tananaev authored Apr 28, 2018
2 parents c763c6c + 4086a60 commit d5db101
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
2 changes: 2 additions & 0 deletions setup/default.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@

<entry key='server.statistics'>https://www.traccar.org/analytics/</entry>

<entry key='commands.queueing'>true</entry>

<!-- DATABASE CONFIG -->

<entry key='database.ignoreUnknown'>true</entry>
Expand Down
2 changes: 1 addition & 1 deletion src/org/traccar/Context.java
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ public static void init(String[] arguments) throws Exception {

driversManager = new DriversManager(dataManager);

commandsManager = new CommandsManager(dataManager);
commandsManager = new CommandsManager(dataManager, config.getBoolean("commands.queueing"));

statisticsManager = new StatisticsManager();

Expand Down
7 changes: 6 additions & 1 deletion src/org/traccar/database/CommandsManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,11 @@ public class CommandsManager extends ExtendedObjectManager<Command> {

private final Map<Long, Queue<Command>> deviceQueues = new ConcurrentHashMap<>();

public CommandsManager(DataManager dataManager) {
private boolean queueing;

public CommandsManager(DataManager dataManager, boolean queueing) {
super(dataManager, Command.class);
this.queueing = queueing;
}

public boolean checkDeviceCommand(long deviceId, long commandId) {
Expand Down Expand Up @@ -70,6 +73,8 @@ public boolean sendCommand(Command command) throws Exception {
ActiveDevice activeDevice = Context.getConnectionManager().getActiveDevice(deviceId);
if (activeDevice != null) {
activeDevice.sendCommand(command);
} else if (!queueing) {
throw new RuntimeException("Device is not online");
} else {
getDeviceQueue(deviceId).add(command);
return false;
Expand Down

0 comments on commit d5db101

Please sign in to comment.