/*
- * Copyright 2000-2015 JetBrains s.r.o.
+ * Copyright 2000-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
*/
package org.jetbrains.io;
+import com.intellij.openapi.diagnostic.Logger;
import io.netty.channel.*;
import io.netty.channel.group.ChannelGroup;
import io.netty.channel.group.ChannelGroupFuture;
import io.netty.util.concurrent.ImmediateEventExecutor;
import org.jetbrains.annotations.NotNull;
+import java.util.Arrays;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
@ChannelHandler.Sharable
public final class ChannelRegistrar extends ChannelInboundHandlerAdapter {
- private final ChannelGroup openChannels = new DefaultChannelGroup(ImmediateEventExecutor.INSTANCE);
+ private static final Logger LOG = Logger.getInstance(ChannelRegistrar.class);
+
+ private final ChannelGroup openChannels = new DefaultChannelGroup(ImmediateEventExecutor.INSTANCE, true);
public boolean isEmpty() {
return openChannels.isEmpty();
Future<?> result;
try {
+ Object[] channels = openChannels.toArray(new Channel[]{});
ChannelGroupFuture groupFuture = openChannels.close();
- groupFuture.awaitUninterruptibly(30, TimeUnit.SECONDS);
+ // server channels are closed in first turn, so, small timeout is relatively ok
+ if (!groupFuture.awaitUninterruptibly(10, TimeUnit.SECONDS)) {
+ LOG.warn("Cannot close all channels for 10 seconds, channels: " + Arrays.toString(channels));
+ }
result = groupFuture;
}
finally {