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


Java WriteToClosedSessionException类代码示例

本文整理汇总了Java中org.apache.mina.core.write.WriteToClosedSessionException的典型用法代码示例。如果您正苦于以下问题:Java WriteToClosedSessionException类的具体用法?Java WriteToClosedSessionException怎么用?Java WriteToClosedSessionException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


WriteToClosedSessionException类属于org.apache.mina.core.write包,在下文中一共展示了WriteToClosedSessionException类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: clearWriteRequestQueue

import org.apache.mina.core.write.WriteToClosedSessionException; //导入依赖的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: exceptionCaught

import org.apache.mina.core.write.WriteToClosedSessionException; //导入依赖的package包/类
public void exceptionCaught(final FtpIoSession session,
        final Throwable cause) throws Exception {
    
    if(cause instanceof ProtocolDecoderException &&
            cause.getCause() instanceof MalformedInputException) {
        // client probably sent something which is not UTF-8 and we failed to
        // decode it
        
        LOG.warn(
                "Client sent command that could not be decoded: {}",
                ((ProtocolDecoderException)cause).getHexdump());
        session.write(new DefaultFtpReply(FtpReply.REPLY_501_SYNTAX_ERROR_IN_PARAMETERS_OR_ARGUMENTS, "Invalid character in command"));
    } else if (cause instanceof WriteToClosedSessionException) {
        WriteToClosedSessionException writeToClosedSessionException = 
            (WriteToClosedSessionException) cause;
        LOG.warn(
                        "Client closed connection before all replies could be sent, last reply was {}",
                        writeToClosedSessionException.getRequest());
        session.close(false).awaitUninterruptibly(10000);
    } else {
        LOG.error("Exception caught, closing session", cause);
        session.close(false).awaitUninterruptibly(10000);
    }


}
 
开发者ID:saaconsltd,项目名称:mina-ftpserver,代码行数:27,代码来源:DefaultFtpHandler.java

示例3: write

import org.apache.mina.core.write.WriteToClosedSessionException; //导入依赖的package包/类
@Override
public WriteFuture write(Object message) {
	if (message == null) {
		throw new IllegalArgumentException("Trying to write a null message: not allowed");
	}

	// If the session has been closed or is closing, we can't either send a message to the remote side.
	// We generate a future containing an exception.
	if (isClosing() || !isConnected()) {
		return DefaultWriteFuture.newNotWrittenFuture(this, new WriteToClosedSessionException());
	}

	try {
		if ((message instanceof IoBuffer) && !((IoBuffer) message).hasRemaining()) {
			// Nothing to write: probably an error in the user code
			throw new IllegalArgumentException("message is empty. Forgot to call flip()?");
		} else if (message instanceof FileChannel) {
			FileChannel fileChannel = (FileChannel) message;
			message = new DefaultFileRegion(fileChannel, 0, fileChannel.size());
		}
	} catch (IOException e) {
		ExceptionMonitor.getInstance().exceptionCaught(e);
		return DefaultWriteFuture.newNotWrittenFuture(this, e);
	}

	// Now, we can write the message. First, create a future
	WriteFuture writeFuture = new DefaultWriteFuture(this);
	WriteRequest writeRequest = new DefaultWriteRequest(message, writeFuture);

	// Then, get the chain and inject the WriteRequest into it
	getFilterChain().fireFilterWrite(writeRequest);

	// Return the WriteFuture.
	return writeFuture;
}
 
开发者ID:dwing4g,项目名称:jane,代码行数:36,代码来源:AbstractIoSession.java


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