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 **/
|
||||
private List<Class<? extends HalSensorData>> availableSensors = new ArrayList<>();
|
||||
/** 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 **/
|
||||
private List<Sensor> detectedSensors = new ArrayList<>();
|
||||
private List<Sensor> detectedSensors = Collections.synchronizedList(new ArrayList<Sensor>());
|
||||
/** 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 **/
|
||||
private List<Class<? extends HalEventData>> availableEvents = new ArrayList<>();
|
||||
/** 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 **/
|
||||
private List<Event> detectedEvents = new ArrayList<>();
|
||||
private List<Event> detectedEvents = Collections.synchronizedList(new ArrayList<Event>());
|
||||
/** 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 **/
|
||||
|
|
@ -134,7 +134,8 @@ public class ControllerManager implements HalSensorReportListener,
|
|||
}
|
||||
|
||||
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())) {
|
||||
return s;
|
||||
}
|
||||
|
|
@ -222,7 +223,8 @@ public class ControllerManager implements HalSensorReportListener,
|
|||
}
|
||||
|
||||
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())) {
|
||||
return e;
|
||||
}
|
||||
|
|
@ -241,10 +243,6 @@ public class ControllerManager implements HalSensorReportListener,
|
|||
}
|
||||
|
||||
/////////////////////////////// GENERAL ///////////////////////////////////
|
||||
public void initializeScannableControllers(){
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void preConfigurationAction(Configurator configurator, Object obj) {
|
||||
|
|
|
|||
|
|
@ -32,6 +32,8 @@ import java.io.IOException;
|
|||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
|
@ -55,14 +57,14 @@ public class TellstickSerialComm implements Runnable,
|
|||
private HalSensorReportListener sensorListener;
|
||||
private HalEventReportListener eventListener;
|
||||
|
||||
private ArrayList<TellstickProtocol> registeredDevices;
|
||||
private List<TellstickProtocol> registeredDevices;
|
||||
|
||||
|
||||
|
||||
public TellstickSerialComm() {
|
||||
set = new TimedHashSet(TRANSMISSION_UNIQUENESS_TTL);
|
||||
parser = new TellstickParser();
|
||||
registeredDevices = new ArrayList<>();
|
||||
registeredDevices = Collections.synchronizedList(new ArrayList<TellstickProtocol>());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -133,7 +135,8 @@ public class TellstickSerialComm implements Runnable,
|
|||
//Check for registered device that are in the same group
|
||||
if(protocol instanceof TellstickGroupProtocol) {
|
||||
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 &&
|
||||
groupProtocol.equalsGroup(childProtocol) &&
|
||||
!protocol.equals(childProtocol)) {
|
||||
|
|
|
|||
|
|
@ -71,7 +71,7 @@ public abstract class AbstractDevice<T> extends DBBean {
|
|||
if(data != null) {
|
||||
deviceData = data;
|
||||
type = data.getClass().getName();
|
||||
applyConfig();
|
||||
applyConfig(); // TODO: this is a bit clunky, should probably be solved in another way
|
||||
} else {
|
||||
deviceData = null;
|
||||
type = null;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue