当前位置: 首页>>代码示例>>Java>>正文


Java WriteRequestQueue.poll方法代码示例

本文整理汇总了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);
}
 
开发者ID:dwing4g,项目名称:jane,代码行数:27,代码来源:AbstractPollingIoProcessor.java

示例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;
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:74,代码来源:AbstractPollingConnectionlessIoAcceptor.java


注:本文中的org.apache.mina.core.write.WriteRequestQueue.poll方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。