本文整理汇总了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);
}
示例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);
}
}
示例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;
}