本文整理汇总了Java中org.apache.mina.core.write.WriteRequestQueue.poll方法的典型用法代码示例。如果您正苦于以下问题:Java WriteRequestQueue.poll方法的具体用法?Java WriteRequestQueue.poll怎么用?Java WriteRequestQueue.poll使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.mina.core.write.WriteRequestQueue
的用法示例。
在下文中一共展示了WriteRequestQueue.poll方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: clearWriteRequestQueue
import org.apache.mina.core.write.WriteRequestQueue; //导入方法依赖的package包/类
private void clearWriteRequestQueue(S session, IOException ioe) {
WriteRequestQueue writeRequestQueue = session.getWriteRequestQueue();
WriteRequest req = session.getCurrentWriteRequest();
if (req == null) {
req = writeRequestQueue.poll();
if (req == null) {
return;
}
} else {
session.setCurrentWriteRequest(null);
}
// Create an exception and notify.
Throwable cause = (ioe != null ? new WriteToClosedSessionException(ioe) : new WriteToClosedSessionException());
do {
req.getFuture().setException(cause);
Object message = req.getMessage();
if (message instanceof IoBuffer) {
((IoBuffer) message).free();
}
} while ((req = writeRequestQueue.poll()) != null);
session.getFilterChain().fireExceptionCaught(cause);
}
示例2: flush
import org.apache.mina.core.write.WriteRequestQueue; //导入方法依赖的package包/类
private boolean flush( S session, long currentTime ) throws Exception
{
final WriteRequestQueue writeRequestQueue = session.getWriteRequestQueue();
final int maxWrittenBytes = session.getConfig().getMaxReadBufferSize()
+ ( session.getConfig().getMaxReadBufferSize() >>> 1 );
int writtenBytes = 0;
try
{
for ( ;; )
{
WriteRequest req = session.getCurrentWriteRequest();
if ( req == null )
{
req = writeRequestQueue.poll( session );
if ( req == null )
{
setInterestedInWrite( session, false );
break;
}
session.setCurrentWriteRequest( req );
}
IoBuffer buf = ( IoBuffer ) req.getMessage();
if ( buf.remaining() == 0 )
{
// Clear and fire event
session.setCurrentWriteRequest( null );
buf.reset();
session.getFilterChain().fireMessageSent( req );
continue;
}
SocketAddress destination = req.getDestination();
if ( destination == null )
{
destination = session.getRemoteAddress();
}
int localWrittenBytes = send( session, buf, destination );
if ( ( localWrittenBytes == 0 ) || ( writtenBytes >= maxWrittenBytes ) )
{
// Kernel buffer is full or wrote too much
setInterestedInWrite( session, true );
return false;
}
else
{
setInterestedInWrite( session, false );
// Clear and fire event
session.setCurrentWriteRequest( null );
writtenBytes += localWrittenBytes;
buf.reset();
session.getFilterChain().fireMessageSent( req );
}
}
}
finally
{
session.increaseWrittenBytes( writtenBytes, currentTime );
}
return true;
}