Search in sources :

Example 1 with ConnectionMessagesSentEvent

use of com.mongodb.event.ConnectionMessagesSentEvent in project mongo-java-driver by mongodb.

the class InternalStreamConnection method sendMessage.

@Override
public void sendMessage(final List<ByteBuf> byteBuffers, final int lastRequestId) {
    notNull("stream is open", stream);
    if (isClosed()) {
        throw new MongoSocketClosedException("Cannot write to a closed stream", getServerAddress());
    }
    writerLock.lock();
    try {
        int messageSize = getMessageSize(byteBuffers);
        stream.write(byteBuffers);
        connectionListener.messagesSent(new ConnectionMessagesSentEvent(getId(), lastRequestId, messageSize));
    } catch (Exception e) {
        close();
        throw translateWriteException(e);
    } finally {
        writerLock.unlock();
    }
}
Also used : ConnectionMessagesSentEvent(com.mongodb.event.ConnectionMessagesSentEvent) MongoSocketClosedException(com.mongodb.MongoSocketClosedException) MongoInternalException(com.mongodb.MongoInternalException) MongoSocketReadException(com.mongodb.MongoSocketReadException) MongoSocketClosedException(com.mongodb.MongoSocketClosedException) MongoSocketWriteException(com.mongodb.MongoSocketWriteException) InterruptedIOException(java.io.InterruptedIOException) SocketTimeoutException(java.net.SocketTimeoutException) MongoInterruptedException(com.mongodb.MongoInterruptedException) MongoException(com.mongodb.MongoException) IOException(java.io.IOException) ClosedByInterruptException(java.nio.channels.ClosedByInterruptException) MongoSocketReadTimeoutException(com.mongodb.MongoSocketReadTimeoutException)

Aggregations

MongoException (com.mongodb.MongoException)1 MongoInternalException (com.mongodb.MongoInternalException)1 MongoInterruptedException (com.mongodb.MongoInterruptedException)1 MongoSocketClosedException (com.mongodb.MongoSocketClosedException)1 MongoSocketReadException (com.mongodb.MongoSocketReadException)1 MongoSocketReadTimeoutException (com.mongodb.MongoSocketReadTimeoutException)1 MongoSocketWriteException (com.mongodb.MongoSocketWriteException)1 ConnectionMessagesSentEvent (com.mongodb.event.ConnectionMessagesSentEvent)1 IOException (java.io.IOException)1 InterruptedIOException (java.io.InterruptedIOException)1 SocketTimeoutException (java.net.SocketTimeoutException)1 ClosedByInterruptException (java.nio.channels.ClosedByInterruptException)1