0
저는 스칼라 (초보자)와 놀고 있었고 Java 7 NIO를 사용하려고했습니다 (시작하기 쉽기 때문에). 하지만 받아들이 기 위해 CompletionHandler을 인스턴스화하는 방법을 알아낼 수 없습니다. 다음 코드는 잘못하고 나는 그것을 고칠 수 : 인터페이스 유형이기 때문에,스칼라에서 Java 7 완료 핸들러를 인스턴스화하는 방법
...
val connectionHandler = new CompletionHandler[AsynchronousSocketChannel, Integer] {
def completed(result: AsynchronousSocketChannel, attachment: Integer) {}
def failed(exc: Throwable , attachment: Integer) {}
}
...
을 그리고 :
가connectHandler
인스턴스를 생성하기 위해
package async
import java.nio.channels.AsynchronousServerSocketChannel
import java.net.InetAddress
import java.net.InetSocketAddress
import java.nio.channels.CompletionHandler
import java.nio.channels.AsynchronousSocketChannel
class AsyncServer (port: Int) {
val socketServer = AsynchronousServerSocketChannel.open();
socketServer.bind(new InetSocketAddress(port))
val connectionHandler = new CompletionHandler[AsynchronousSocketChannel, Integer](){
}
def init() = socketServer accept(1 , connectionHandler)
}