Skip to content

Commit

Permalink
Make Commands queueing switchable
Browse files Browse the repository at this point in the history
  • Loading branch information
Abyss777 committed Apr 28, 2018
1 parent c763c6c commit 94f87ea
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("Commands queueing is not enabled");
} else {
getDeviceQueue(deviceId).add(command);
return false;
Expand Down

0 comments on commit 94f87ea

Please sign in to comment.