if (channelBanManager.isBanned(channel)) {
continue;
}
- if (networkConnections.containsKey(channel.network())) {
- if (networkConnections.get(channel.network()).established()) {
- missingChannels.add(channel);
- }
+ if (!networkConnections.containsKey(channel.network()) || networkConnections.get(channel.network()).established()) {
+ missingChannels.add(channel);
}
}
Set<Network> missingNetworks = missingChannels.stream()
.filter((network) -> !networkConnections.containsKey(network))
.collect(Collectors.toSet());
- if (!missingChannels.isEmpty()) {
- for (Channel missingChannel : missingChannels) {
- Network network = missingChannel.network();
- eventBus.post(new GenericMessage(String.format("Trying to join %s on %s...", missingChannel.name(), network)));
- try {
- channelsBeingJoined.add(missingChannel);
- networkConnections.get(network).joinChannel(missingChannel.name());
- } catch (IOException ioe1) {
- logger.warn(String.format("Could not join %s on %s!", missingChannel.name(), network.name()), ioe1);
+ if (missingNetworks.isEmpty()) {
+ if (!missingChannels.isEmpty()) {
+ for (Channel missingChannel : missingChannels) {
+ Network network = missingChannel.network();
+ eventBus.post(new GenericMessage(String.format("Trying to join %s on %s...", missingChannel.name(), network)));
+ try {
+ channelsBeingJoined.add(missingChannel);
+ networkConnections.get(network).joinChannel(missingChannel.name());
+ } catch (IOException ioe1) {
+ logger.warn(String.format("Could not join %s on %s!", missingChannel.name(), network.name()), ioe1);
+ }
}
- }
- } else if (missingNetworks.isEmpty()) {
- synchronized (syncObject) {
- try {
- syncObject.wait(TimeUnit.MINUTES.toMillis(1));
- } catch (InterruptedException ie1) {
+ } else {
+ synchronized (syncObject) {
+ try {
+ syncObject.wait(TimeUnit.MINUTES.toMillis(1));
+ } catch (InterruptedException ie1) {
/* ignore. */
+ }
}
}
continue;
Map<Long, Network> timesForNextConnects = new TreeMap<>(missingNetworks.stream()
.collect(Collectors.toMap(connectionBackoff::getBackoff, Function.identity(), (network, ignore) -> network)));
- Entry<Long, Network> firstNetwork = timesForNextConnects.entrySet().stream().findFirst().get();
- if (firstNetwork.getKey() > 0) {
- eventBus.post(new GenericMessage(String.format("Waiting %d seconds to connect to %s...", TimeUnit.MILLISECONDS.toMinutes(firstNetwork.getKey()), firstNetwork.getValue().name())));
+ Optional<Entry<Long, Network>> firstNetwork = Optional.fromNullable(timesForNextConnects.entrySet().stream().findFirst().orElse(null));
+ if (!firstNetwork.isPresent()) {
+ continue;
+ }
+ if (firstNetwork.get().getKey() > 0) {
+ eventBus.post(new GenericMessage(String.format("Waiting %d minutes to connect to %s...", TimeUnit.MILLISECONDS.toMinutes(firstNetwork.get().getKey()), firstNetwork.get().getValue().name())));
synchronized (syncObject) {
try {
- syncObject.wait(firstNetwork.getKey());
+ syncObject.wait(firstNetwork.get().getKey());
} catch (InterruptedException ie1) {
/* ignore. */
}
}
}
- connectNetwork(firstNetwork.getValue());
+ connectNetwork(firstNetwork.get().getValue());
}
}
}
Optional<Channel> channel = getChannel(network.get(), channelNotJoined.channel());
+ synchronized (syncObject) {
+ syncObject.notifyAll();
+ }
if (!channel.isPresent()) {
eventBus.post(new GenericMessage(format("Could not join %s but didn’t try to join, either.", channelNotJoined.channel())));
return;
}
-
channelsBeingJoined.remove(channel.get());
- synchronized (syncObject) {
- syncObject.notifyAll();
- }
+
/* remove all bots for this channel, we might have been kicked. */
Collection<Bot> botsToRemove = networkBots.row(network.get())