Concurrency fixes
This commit is contained in:
parent
5f230a921d
commit
2c1ccb8b57
3 changed files with 17 additions and 16 deletions
|
|
@ -32,21 +32,21 @@ public class ControllerManager implements HalSensorReportListener,
|
||||||
/** All available sensor plugins **/
|
/** All available sensor plugins **/
|
||||||
private List<Class<? extends HalSensorData>> availableSensors = new ArrayList<>();
|
private List<Class<? extends HalSensorData>> availableSensors = new ArrayList<>();
|
||||||
/** List of all registered sensors **/
|
/** List of all registered sensors **/
|
||||||
private List<Sensor> registeredSensors = new ArrayList<>();
|
private List<Sensor> registeredSensors = Collections.synchronizedList(new ArrayList<Sensor>());
|
||||||
/** List of auto detected sensors **/
|
/** List of auto detected sensors **/
|
||||||
private List<Sensor> detectedSensors = new ArrayList<>();
|
private List<Sensor> detectedSensors = Collections.synchronizedList(new ArrayList<Sensor>());
|
||||||
/** List of sensors that are currently being reconfigured **/
|
/** List of sensors that are currently being reconfigured **/
|
||||||
private List<Sensor> limboSensors = new LinkedList<>();
|
private List<Sensor> limboSensors = Collections.synchronizedList(new LinkedList<Sensor>());
|
||||||
|
|
||||||
|
|
||||||
/** All available event plugins **/
|
/** All available event plugins **/
|
||||||
private List<Class<? extends HalEventData>> availableEvents = new ArrayList<>();
|
private List<Class<? extends HalEventData>> availableEvents = new ArrayList<>();
|
||||||
/** List of all registered events **/
|
/** List of all registered events **/
|
||||||
private List<Event> registeredEvents = new ArrayList<>();
|
private List<Event> registeredEvents = Collections.synchronizedList(new ArrayList<Event>());
|
||||||
/** List of auto detected events **/
|
/** List of auto detected events **/
|
||||||
private List<Event> detectedEvents = new ArrayList<>();
|
private List<Event> detectedEvents = Collections.synchronizedList(new ArrayList<Event>());
|
||||||
/** List of all registered events **/
|
/** List of all registered events **/
|
||||||
private List<Event> limboEvents = new LinkedList<>();
|
private List<Event> limboEvents = Collections.synchronizedList(new LinkedList<Event>());
|
||||||
|
|
||||||
|
|
||||||
/** A map of all instantiated controllers **/
|
/** A map of all instantiated controllers **/
|
||||||
|
|
@ -134,7 +134,8 @@ public class ControllerManager implements HalSensorReportListener,
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Sensor findSensor(HalSensorData sensorData, List<Sensor> list){
|
private static Sensor findSensor(HalSensorData sensorData, List<Sensor> list){
|
||||||
for (Sensor s : list) {
|
for (int i=0; i<list.size(); ++i) { // Don't use foreach for concurrency reasons
|
||||||
|
Sensor s = list.get(i);
|
||||||
if (sensorData.equals(s.getDeviceData())) {
|
if (sensorData.equals(s.getDeviceData())) {
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
@ -222,7 +223,8 @@ public class ControllerManager implements HalSensorReportListener,
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Event findEvent(HalEventData eventData, List<Event> list){
|
private static Event findEvent(HalEventData eventData, List<Event> list){
|
||||||
for (Event e : list) {
|
for (int i=0; i<list.size(); ++i) { // Don't use foreach for concurrency reasons
|
||||||
|
Event e = list.get(i);
|
||||||
if (eventData.equals(e.getDeviceData())) {
|
if (eventData.equals(e.getDeviceData())) {
|
||||||
return e;
|
return e;
|
||||||
}
|
}
|
||||||
|
|
@ -241,10 +243,6 @@ public class ControllerManager implements HalSensorReportListener,
|
||||||
}
|
}
|
||||||
|
|
||||||
/////////////////////////////// GENERAL ///////////////////////////////////
|
/////////////////////////////// GENERAL ///////////////////////////////////
|
||||||
public void initializeScannableControllers(){
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void preConfigurationAction(Configurator configurator, Object obj) {
|
public void preConfigurationAction(Configurator configurator, Object obj) {
|
||||||
|
|
|
||||||
|
|
@ -32,6 +32,8 @@ import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
@ -55,14 +57,14 @@ public class TellstickSerialComm implements Runnable,
|
||||||
private HalSensorReportListener sensorListener;
|
private HalSensorReportListener sensorListener;
|
||||||
private HalEventReportListener eventListener;
|
private HalEventReportListener eventListener;
|
||||||
|
|
||||||
private ArrayList<TellstickProtocol> registeredDevices;
|
private List<TellstickProtocol> registeredDevices;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public TellstickSerialComm() {
|
public TellstickSerialComm() {
|
||||||
set = new TimedHashSet(TRANSMISSION_UNIQUENESS_TTL);
|
set = new TimedHashSet(TRANSMISSION_UNIQUENESS_TTL);
|
||||||
parser = new TellstickParser();
|
parser = new TellstickParser();
|
||||||
registeredDevices = new ArrayList<>();
|
registeredDevices = Collections.synchronizedList(new ArrayList<TellstickProtocol>());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -133,7 +135,8 @@ public class TellstickSerialComm implements Runnable,
|
||||||
//Check for registered device that are in the same group
|
//Check for registered device that are in the same group
|
||||||
if(protocol instanceof TellstickGroupProtocol) {
|
if(protocol instanceof TellstickGroupProtocol) {
|
||||||
TellstickGroupProtocol groupProtocol = (TellstickGroupProtocol) protocol;
|
TellstickGroupProtocol groupProtocol = (TellstickGroupProtocol) protocol;
|
||||||
for (TellstickProtocol childProtocol : registeredDevices) {
|
for (int i=0; i<registeredDevices.size(); ++i) { // Don't use foreach for concurrency reasons
|
||||||
|
TellstickProtocol childProtocol = registeredDevices.get(i);
|
||||||
if (childProtocol instanceof TellstickGroupProtocol &&
|
if (childProtocol instanceof TellstickGroupProtocol &&
|
||||||
groupProtocol.equalsGroup(childProtocol) &&
|
groupProtocol.equalsGroup(childProtocol) &&
|
||||||
!protocol.equals(childProtocol)) {
|
!protocol.equals(childProtocol)) {
|
||||||
|
|
|
||||||
|
|
@ -71,7 +71,7 @@ public abstract class AbstractDevice<T> extends DBBean {
|
||||||
if(data != null) {
|
if(data != null) {
|
||||||
deviceData = data;
|
deviceData = data;
|
||||||
type = data.getClass().getName();
|
type = data.getClass().getName();
|
||||||
applyConfig();
|
applyConfig(); // TODO: this is a bit clunky, should probably be solved in another way
|
||||||
} else {
|
} else {
|
||||||
deviceData = null;
|
deviceData = null;
|
||||||
type = null;
|
type = null;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue