mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-157421 Long shutdown due to built-in server
Reduce timeout to 10 seconds, log channels on timeout
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* 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.
|
||||
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
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;
|
||||
@@ -22,12 +23,15 @@ import io.netty.channel.group.DefaultChannelGroup;
|
||||
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();
|
||||
@@ -64,8 +68,12 @@ public final class ChannelRegistrar extends ChannelInboundHandlerAdapter {
|
||||
|
||||
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 {
|
||||
|
||||
Reference in New Issue
Block a user