2012-11-18 2 views
1

안녕하십니까, messageReceived이 예상 시간 내에 호출되지 않는 이벤트를 받고 싶습니다. 나는 에서 처리 할 수있는 곳에서 예외를 생성하는 곳에서 ReadTimeoutHandler을 시도해 보았다. 여기서 나는 어떤 일을하고 문맥을 닫지 않고 돌아올 것이다. 하지만 그 후에 바로 예외가 발생했습니다네트워크 시간 제한 이벤트 4

Nov 18, 2012 8:56:34 AM io.netty.channel.ChannelInitializer 
WARNING: Failed to initialize a channel. Closing: [id: 0xa81de260, /127.0.0.1:59763 => /127.0.0.1:59724] 
io.netty.channel.ChannelHandlerLifeCycleException: io.netty.handler.timeout.ReadTimeoutHandler is not a @Sharable handler, so can't be added or removed multiple times. 
    at io.netty.channel.DefaultChannelPipeline.callBeforeAdd(DefaultChannelPipeline.java:629) 
    at io.netty.channel.DefaultChannelPipeline.addLast0(DefaultChannelPipeline.java:173) 

올바르게하고 있습니까?

감사

당신이 많은 채널을 io.netty.handler.timeout.ReadTimeoutHandler의 동일한 인스턴스를 추가하는 것 같습니다
+0

당신이 당신의 코드를 공유 할 수 있습니다 @Sharable의

ch.pipeline() .addLast(new ReadTimeoutHandler(3000)) 

문서를보십시오? 나는 당신이 예외를 처리하기 위해 무엇을하는지보고 싶을 것이다 –

+0

if this (if instanceof ReadTimeoutException) { return; } –

+0

io.netty.handler.timeout.ReadTimeoutHandler의 동일한 인스턴스를 여러 파이프 라인에 추가하려는 것처럼 보입니다. 그럴 수 있습니까? –

답변

2

.

/** 
* Indicates that the same instance of the annotated {@link ChannelHandler} 
* can be added to one or more {@link ChannelPipeline}s multiple times 
* without a race condition. 
* <p> 
* If this annotation is not specified, you have to create a new handler 
* instance every time you add it to a pipeline because it has unshared 
* state such as member variables. 
* <p> 
* This annotation is provided for documentation purpose, just like 
* <a href="http://www.javaconcurrencyinpractice.com/annotations/doc/">the JCIP annotations</a>. 
*/ 
@Inherited 
@Documented 
@Target(ElementType.TYPE) 
@Retention(RetentionPolicy.RUNTIME) 
@interface Sharable { 
    // no value 
}