Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/backbone.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Netty 来自DefaultPromise的过度日志记录_Netty - Fatal编程技术网

Netty 来自DefaultPromise的过度日志记录

Netty 来自DefaultPromise的过度日志记录,netty,Netty,使用PromiseAggregator时,我发现它产生了过多的警告级别日志记录: @Test public void warning() { EventExecutor executor = ImmediateEventExecutor.INSTANCE; // Create a promise, to be completed by the aggregate DefaultChannelPromise promiseForAggregate = new Def

使用PromiseAggregator时,我发现它产生了过多的警告级别日志记录:

@Test
public void warning() {

    EventExecutor executor = ImmediateEventExecutor.INSTANCE;  

    // Create a promise, to be completed by the aggregate
    DefaultChannelPromise promiseForAggregate = new DefaultChannelPromise(null, executor);
    PromiseAggregator<Void, DefaultChannelPromise> aggregate = new PromiseAggregator<>(promiseForAggregate, false);

    // Add the underlying promises to the aggregate 
    DefaultChannelPromise underlyingPromise1 = new DefaultChannelPromise(null, executor);
    DefaultChannelPromise underlyingPromise2 = new DefaultChannelPromise(null, executor); 
    DefaultChannelPromise underlyingPromise3 = new DefaultChannelPromise(null, executor); 
    aggregate.add(underlyingPromise1, underlyingPromise2, underlyingPromise3);

    // (A) First promise fails, OK!
    underlyingPromise1.setFailure(new NullPointerException());

    // (B) WARN!
    underlyingPromise2.setFailure(new NullPointerException());
    // (C) WARN!
    underlyingPromise3.setFailure(new NullPointerException());
}
这是完全无用的日志记录!根据PromiseAggregator的本质,我们可以预期存在多个底层故障的场景


在我的应用程序中,我正在向客户机写入一个大的(分块的)HTTP对象。我正在使用一个
promiseggregator
来聚合每个分块写入的承诺。因此,如果客户机在一次大的写入过程中断开了部分连接,我可能会在日志文件中打印上千次以上的异常


我提出的唯一(远程)明智的解决方案是覆盖promiseForAggregate的实现:

DefaultChannelPromise promiseForAggregate = new DefaultChannelPromise(null, executor) {
    @Override
    public ChannelPromise setFailure(Throwable cause) {
        if (! super.isDone()) {
            super.setFailure(cause);
        }
        return this;
    }
};
我想知道我是否忽略了一些更简单的选择?这似乎是一个相当普通的用例,所以我对将这种性质的解决方案组合在一起感到不安

DefaultChannelPromise promiseForAggregate = new DefaultChannelPromise(null, executor) {
    @Override
    public ChannelPromise setFailure(Throwable cause) {
        if (! super.isDone()) {
            super.setFailure(cause);
        }
        return this;
    }
};