Skip to content

Commit

Permalink
[ihc] Changed pulse command to use scheduling (#5417)
Browse files Browse the repository at this point in the history
Also changed couple of list iterators to streams.

Signed-off-by: Pauli Anttila <[email protected]>
  • Loading branch information
paulianttila authored and David Gräff committed Apr 9, 2019
1 parent 9dbae99 commit a1bbfc6
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -428,25 +428,21 @@ private void sendPulseCommand(ChannelUID channelUID, ChannelParams params, WSRes
// set resource to ON
logger.debug("Update resource value (inverted output={}): {}", params.isInverted(), valOn);
if (updateResource(valOn)) {
scheduler.submit(() -> {
// sleep a while
try {
logger.debug("Sleeping: {}ms", pulseWidth);
Thread.sleep(pulseWidth);
} catch (InterruptedException e) {
// do nothing
}
// set resource back to OFF

logger.debug("Update resource value (inverted output={}): {}", params.isInverted(), valOff);
try {
if (!updateResource(valOff)) {
logger.warn("Channel {} update to resource '{}' failed.", channelUID, valOff);
logger.debug("Sleeping: {}ms", pulseWidth);
scheduler.schedule(new Runnable() {
@Override
public void run() {
// set resource back to OFF
logger.debug("Update resource value (inverted output={}): {}", params.isInverted(), valOff);
try {
if (!updateResource(valOff)) {
logger.warn("Channel {} update to resource '{}' failed.", channelUID, valOff);
}
} catch (IhcExecption e) {
logger.error("Can't update channel '{}' value, cause ", channelUID, e.getMessage(), e);
}
} catch (IhcExecption e) {
logger.error("Can't update channel '{}' value, cause ", channelUID, e.getMessage(), e);
}
});
}, pulseWidth, TimeUnit.MILLISECONDS);
} else {
logger.warn("Channel {} update failed.", channelUID);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import java.util.ArrayList;
import java.util.Base64;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
Expand Down Expand Up @@ -536,38 +535,32 @@ private void mysleep(long milli) {
}

private void sendErrorEvent(IhcExecption err) {
Iterator<IhcEventListener> iterator = eventListeners.iterator();

while (iterator.hasNext()) {
eventListeners.forEach(listener -> {
try {
iterator.next().errorOccured(err);
listener.errorOccured(err);
} catch (RuntimeException e) {
logger.debug("Event listener invoking error. ", e);
logger.debug("Event listener invoking error.", e);
}
}
});
}

private void sendControllerStateUpdateEvent(WSControllerState state) {
Iterator<IhcEventListener> iterator = eventListeners.iterator();

while (iterator.hasNext()) {
eventListeners.forEach(listener -> {
try {
iterator.next().statusUpdateReceived(state);
listener.statusUpdateReceived(state);
} catch (RuntimeException e) {
logger.debug("Event listener invoking error. ", e);
logger.debug("Event listener invoking error.", e);
}
}
});
}

private void sendResourceValueUpdateEvent(WSResourceValue value) {
Iterator<IhcEventListener> iterator = eventListeners.iterator();

while (iterator.hasNext()) {
eventListeners.forEach(listener -> {
try {
iterator.next().resourceValueUpdateReceived(value);
listener.resourceValueUpdateReceived(value);
} catch (RuntimeException e) {
logger.debug("Event listener invoking error. ", e);
logger.debug("Event listener invoking error.", e);
}
}
});
}
}

0 comments on commit a1bbfc6

Please sign in to comment.