Java Code Examples for org.apache.mina.core.future.DefaultWriteFuture#newNotWrittenFuture()

The following examples show how to use org.apache.mina.core.future.DefaultWriteFuture#newNotWrittenFuture() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SslFilter.java    From neoscada with Eclipse Public License 1.0 6 votes vote down vote up
private WriteFuture initiateClosure(NextFilter nextFilter, IoSession session) throws SSLException {
    SslHandler handler = getSslSessionHandler(session);

    // if already shut down
    if (!handler.closeOutbound()) {
        return DefaultWriteFuture.newNotWrittenFuture(session, new IllegalStateException(
                "SSL session is shut down already."));
    }

    // there might be data to write out here?
    WriteFuture future = handler.writeNetBuffer(nextFilter);

    if (future == null) {
        future = DefaultWriteFuture.newWrittenFuture(session);
    }

    if (handler.isInboundDone()) {
        handler.destroy();
    }

    if (session.containsAttribute(USE_NOTIFICATION)) {
        handler.scheduleMessageReceived(nextFilter, SESSION_UNSECURED);
    }

    return future;
}
 
Example 2
Source File: NioSession.java    From jane with GNU Lesser General Public License v3.0 5 votes vote down vote up
@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(null));

	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.
	WriteFuture writeFuture = new DefaultWriteFuture(this);
	WriteRequest writeRequest = new DefaultWriteRequest(message, writeFuture);
	filterChain.fireFilterWrite(writeRequest);
	return writeFuture;
}
 
Example 3
Source File: SslFilter.java    From jane with GNU Lesser General Public License v3.0 5 votes vote down vote up
private WriteFuture initiateClosure(NextFilter nextFilter, IoSession session, boolean needFuture) throws Exception {
	SslHandler sslHandler = getSslSessionHandler(session);
	WriteFuture future;

	// if already shutdown
	try {
		synchronized (sslHandler) {
			if (!sslHandler.closeOutbound())
				return DefaultWriteFuture.newNotWrittenFuture(session, new IllegalStateException("SSL session is shutdown already"));

			// there might be data to write out here?
			future = sslHandler.writeNetBuffer(nextFilter, needFuture);
			if (needFuture && future == null)
				future = DefaultWriteFuture.newWrittenFuture(session);

			if (sslHandler.isInboundDone())
				sslHandler.destroy();
		}

		if (session.containsAttribute(USE_NOTIFICATION))
			sslHandler.scheduleMessageReceived(nextFilter, SESSION_UNSECURED);
	} catch (SSLException se) {
		sslHandler.release();
		throw se;
	}

	return future;
}