추상 인터럽트 가능 채널
추상 인터럽트 가능 채널 (AbstractInterruptibleChannel)
인터럽트 가능한 채널을 위한 기본 구현 클래스예요. 채널의 비동기 닫기와 인터럽트를 구현하는 저수준 메커니즘을 캡슐화합니다.
본문
AbstractInterruptibleChannel은 인터럽트 가능한 채널을 위한 기본 구현 클래스예요. 채널의 비동기 닫기(asynchronous closing)와 인터럽트를 구현하는 데 필요한 저수준 메커니즘을 캡슐화합니다.
public abstract class AbstractInterruptibleChannel extends Object
implements Channel, InterruptibleChannel
구체적인 채널 클래스는 무한정 블록될 수 있는 I/O 연산을 호출하기 전과 후에 각각 begin()과 end() 메서드를 호출해야 해요. end()가 항상 호출되도록 try-finally 블록에서 사용합니다.
boolean completed = false;
try {
begin();
completed = ...; // 블로킹 I/O 연산 수행
return ...; // 결과 반환
} finally {
end(completed);
}
end()의 completed 인자는 I/O 연산이 실제로 완료됐는지, 즉 호출자에게 보이는 효과가 있었는지를 나타내요. 구체적 채널 클래스는 implCloseChannel()도 구현해야 하며, 다른 스레드가 네이티브 I/O에서 블록 중일 때 호출되면 그 연산이 즉시 반환되도록 해야 합니다.
public final void close() throws IOException
public final boolean isOpen()
protected abstract void implCloseChannel() throws IOException
protected final void begin()
protected final void end(boolean completed) throws AsynchronousCloseException
이 클래스는 Channel 명세를 구현하는 데 필요한 동기화를 수행합니다.