[Minor] Code cleanup
This commit is contained in:
parent
2afcd3a4cd
commit
2ed573a408
|
@ -87,14 +87,14 @@ public class DefaultPlc implements Plc {
|
||||||
if (this.listeners.removeElement(address, listener)) {
|
if (this.listeners.removeElement(address, listener)) {
|
||||||
logger.info(address + ": " + listener.getClass().getName());
|
logger.info(address + ": " + listener.getClass().getName());
|
||||||
} else {
|
} else {
|
||||||
logger.warn("Listener not registered with key " + address.toKeyAddress() + ": " + listener.getClass()
|
logger.warn("Listener not registered with key " + address.toKeyAddress() + ": " +
|
||||||
.getSimpleName());
|
listener.getClass().getSimpleName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void syncNotify(String address, Object value) {
|
public void syncNotify(String address, Object value) {
|
||||||
doNotify(address, value, true);
|
doNotify(address, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -102,7 +102,7 @@ public class DefaultPlc implements Plc {
|
||||||
this.notificationTasks.add(new NotificationTask(address, value));
|
this.notificationTasks.add(new NotificationTask(address, value));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void doNotify(String address, Object value, boolean verbose) {
|
private void doNotify(String address, Object value) {
|
||||||
PlcAddress plcAddress = this.notificationMappings.get(address);
|
PlcAddress plcAddress = this.notificationMappings.get(address);
|
||||||
if (plcAddress == null) {
|
if (plcAddress == null) {
|
||||||
logger.warn("No mapping to PlcAddress for hwAddress " + address);
|
logger.warn("No mapping to PlcAddress for hwAddress " + address);
|
||||||
|
@ -113,15 +113,14 @@ public class DefaultPlc implements Plc {
|
||||||
if (value instanceof Boolean)
|
if (value instanceof Boolean)
|
||||||
value = !((boolean) value);
|
value = !((boolean) value);
|
||||||
else
|
else
|
||||||
logger.error(plcAddress + " is marked as inverted, but the value is not a boolean, but a "
|
logger.error(plcAddress + " is marked as inverted, but the value is not a boolean, but a " +
|
||||||
+ value.getClass());
|
value.getClass());
|
||||||
}
|
}
|
||||||
|
|
||||||
doNotify(plcAddress, value, verbose, true, true);
|
doNotify(plcAddress, value, true, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void doNotify(PlcAddress plcAddress, Object value, boolean verbose, boolean catchExceptions,
|
private void doNotify(PlcAddress plcAddress, Object value, boolean catchExceptions, boolean notifyGlobalListener) {
|
||||||
boolean notifyGlobalListener) {
|
|
||||||
|
|
||||||
List<PlcListener> listeners = this.listeners.getList(plcAddress);
|
List<PlcListener> listeners = this.listeners.getList(plcAddress);
|
||||||
if (listeners == null || listeners.isEmpty()) {
|
if (listeners == null || listeners.isEmpty()) {
|
||||||
|
@ -153,7 +152,7 @@ public class DefaultPlc implements Plc {
|
||||||
NotificationTask task = null;
|
NotificationTask task = null;
|
||||||
try {
|
try {
|
||||||
task = this.notificationTasks.take();
|
task = this.notificationTasks.take();
|
||||||
doNotify(task.address, task.value, this.verbose);
|
doNotify(task.address, task.value);
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
logger.error("Interrupted!");
|
logger.error("Interrupted!");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
@ -181,7 +180,7 @@ public class DefaultPlc implements Plc {
|
||||||
logger.info("Sending {}: {} (default)", plcAddress.toKey(), plcAddress.defaultValue);
|
logger.info("Sending {}: {} (default)", plcAddress.toKey(), plcAddress.defaultValue);
|
||||||
if (!isVirtual(plcAddress))
|
if (!isVirtual(plcAddress))
|
||||||
validateConnection(plcAddress).send(plcAddress.address, plcAddress.defaultValue);
|
validateConnection(plcAddress).send(plcAddress.address, plcAddress.defaultValue);
|
||||||
doNotify(plcAddress, plcAddress.defaultValue, false, catchExceptions, notifyGlobalListener);
|
doNotify(plcAddress, plcAddress.defaultValue, catchExceptions, notifyGlobalListener);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -189,7 +188,7 @@ public class DefaultPlc implements Plc {
|
||||||
logger.info("Sending {}: {}", plcAddress.toKey(), value);
|
logger.info("Sending {}: {}", plcAddress.toKey(), value);
|
||||||
if (!isVirtual(plcAddress))
|
if (!isVirtual(plcAddress))
|
||||||
validateConnection(plcAddress).send(plcAddress.address, value);
|
validateConnection(plcAddress).send(plcAddress.address, value);
|
||||||
doNotify(plcAddress, value, false, catchExceptions, notifyGlobalListener);
|
doNotify(plcAddress, value, catchExceptions, notifyGlobalListener);
|
||||||
}
|
}
|
||||||
|
|
||||||
private PlcConnection validateConnection(PlcAddress plcAddress) {
|
private PlcConnection validateConnection(PlcAddress plcAddress) {
|
||||||
|
@ -210,8 +209,8 @@ public class DefaultPlc implements Plc {
|
||||||
public void addConnection(PlcConnection connection) {
|
public void addConnection(PlcConnection connection) {
|
||||||
this.connections.put(connection.getId(), connection);
|
this.connections.put(connection.getId(), connection);
|
||||||
Set<String> addresses = connection.getAddresses();
|
Set<String> addresses = connection.getAddresses();
|
||||||
logger.info("Adding connection " + connection.getId() + " " + connection.getClass().getName() + " with "
|
logger.info("Adding connection " + connection.getId() + " " + connection.getClass().getName() + " with " +
|
||||||
+ addresses.size() + " addresses...");
|
addresses.size() + " addresses...");
|
||||||
for (String address : addresses) {
|
for (String address : addresses) {
|
||||||
logger.info(" Adding " + address + "...");
|
logger.info(" Adding " + address + "...");
|
||||||
this.connectionsByAddress.put(address, connection);
|
this.connectionsByAddress.put(address, connection);
|
||||||
|
|
Loading…
Reference in New Issue