package org.glassfish.grizzly.nio.transport;
import java.io.IOException;
import java.net.SocketAddress;
import org.glassfish.grizzly.Buffer;
import org.glassfish.grizzly.CompletionHandler;
import org.glassfish.grizzly.Connection;
import org.glassfish.grizzly.IOEvent;
import org.glassfish.grizzly.Interceptor;
import org.glassfish.grizzly.ReadResult;
import org.glassfish.grizzly.asyncqueue.AsyncQueueReader;
import org.glassfish.grizzly.asyncqueue.AsyncReadQueueRecord;
import org.glassfish.grizzly.nio.AbstractNIOAsyncQueueReader;
import org.glassfish.grizzly.nio.NIOConnection;
import org.glassfish.grizzly.nio.NIOTransport;
public final class UDPNIOAsyncQueueReader extends AbstractNIOAsyncQueueReader {
public UDPNIOAsyncQueueReader(NIOTransport transport) {
super(transport);
}
@Override
protected int read0(Connection connection, Buffer buffer, ReadResult<Buffer, SocketAddress> currentResult) throws IOException {
return ((UDPNIOTransport) transport).read((UDPNIOConnection) connection, buffer, currentResult);
}
protected void addRecord(Connection connection, Buffer buffer, CompletionHandler completionHandler, Interceptor<ReadResult> interceptor) {
final AsyncReadQueueRecord record = AsyncReadQueueRecord.create(connection, buffer, completionHandler, interceptor);
((UDPNIOConnection) connection).getAsyncReadQueue().offer(record);
}
@Override
protected void onReadyToRead(Connection connection) throws IOException {
final NIOConnection nioConnection = (NIOConnection) connection;
nioConnection.enableIOEvent(IOEvent.READ);
}
}