Skip to content

Commit

Permalink
fixed illegalstate exception
Browse files Browse the repository at this point in the history
  • Loading branch information
Katzen48 committed Dec 17, 2021
1 parent b35a5ff commit 1c0f70c
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions shared/src/main/java/net/chrotos/ingress/minecraft/Watcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,12 @@ public void onAdd(V1Pod obj) {
Stream<V1ContainerStatus> stream = obj.getStatus().getContainerStatuses().stream()
.filter(V1ContainerStatus::getReady);

if (stream.findAny().isPresent()) {
handler.onEventReceived(obj, false);
try {
if (stream.findAny().isPresent()) {
handler.onEventReceived(obj, false);
}
} finally {
stream.close();
}
}

Expand All @@ -74,13 +78,22 @@ public void onUpdate(V1Pod oldObj, V1Pod newObj) {
Stream<V1ContainerStatus> newStream = newObj.getStatus().getContainerStatuses().stream()
.filter(V1ContainerStatus::getReady);

if (!oldStream.findAny().isPresent() && newStream.findAny().isPresent()) {
handler.onEventReceived(newObj, false);
}
boolean oldPresent = oldStream.findAny().isPresent();
boolean newPresent = newStream.findAny().isPresent();

try {
if (!oldPresent && newPresent) {
handler.onEventReceived(newObj, false);
}

if (oldStream.findAny().isPresent() && !newStream.findAny().isPresent()) {
handler.onEventReceived(oldObj, true);
if (oldPresent && !newPresent) {
handler.onEventReceived(oldObj, true);
}
} finally {
oldStream.close();
newStream.close();
}

}

@Override
Expand Down

0 comments on commit 1c0f70c

Please sign in to comment.