only load channels when needed

This commit is contained in:
Carsten Otto
2021-11-19 18:41:48 +01:00
parent 256c1cc42a
commit 9e0f4e58aa
2 changed files with 25 additions and 5 deletions

View File

@@ -16,6 +16,7 @@ import org.springframework.stereotype.Component;
import java.util.Collection;
import java.util.Optional;
import java.util.Set;
import java.util.function.Supplier;
import java.util.stream.Collectors;
import java.util.stream.Stream;
@@ -100,15 +101,15 @@ public class ChannelService {
}
public Stream<LocalChannel> getAllLocalChannels() {
Set<LocalOpenChannel> openChannels = getOpenChannels();
Set<WaitingCloseChannel> waitingCloseChannels = getWaitingCloseChannels();
Set<ForceClosingChannel> forceClosingChannels = getForceClosingChannels();
Set<ClosedChannel> closedChannels = getClosedChannels();
Supplier<Set<LocalOpenChannel>> openChannels = this::getOpenChannels;
Supplier<Set<ClosedChannel>> closedChannels = this::getClosedChannels;
Supplier<Set<WaitingCloseChannel>> waitingCloseChannels = this::getWaitingCloseChannels;
Supplier<Set<ForceClosingChannel>> forceClosingChannels = this::getForceClosingChannels;
return Stream.of(
openChannels,
closedChannels,
waitingCloseChannels,
forceClosingChannels
).flatMap(Collection::stream);
).map(Supplier::get).flatMap(Collection::stream);
}
}