Search in sources :

Example 1 with MongoInternalException

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

the class DefaultConnectionPool method get.

@Override
public InternalConnection get(final long timeout, final TimeUnit timeUnit) {
    try {
        if (waitQueueSize.incrementAndGet() > settings.getMaxWaitQueueSize()) {
            throw createWaitQueueFullException();
        }
        try {
            connectionPoolListener.waitQueueEntered(new ConnectionPoolWaitQueueEnteredEvent(serverId, currentThread().getId()));
            PooledConnection pooledConnection = getPooledConnection(timeout, timeUnit);
            if (!pooledConnection.opened()) {
                try {
                    pooledConnection.open();
                } catch (Throwable t) {
                    pool.release(pooledConnection.wrapped, true);
                    if (t instanceof MongoException) {
                        throw (MongoException) t;
                    } else {
                        throw new MongoInternalException(t.toString(), t);
                    }
                }
            }
            return pooledConnection;
        } finally {
            connectionPoolListener.waitQueueExited(new ConnectionPoolWaitQueueExitedEvent(serverId, currentThread().getId()));
        }
    } finally {
        waitQueueSize.decrementAndGet();
    }
}
Also used : MongoException(com.mongodb.MongoException) ConnectionPoolWaitQueueExitedEvent(com.mongodb.event.ConnectionPoolWaitQueueExitedEvent) ConnectionPoolWaitQueueEnteredEvent(com.mongodb.event.ConnectionPoolWaitQueueEnteredEvent) MongoInternalException(com.mongodb.MongoInternalException)

Example 2 with MongoInternalException

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

the class SocketStreamHelper method initialize.

static void initialize(final Socket socket, final ServerAddress address, final SocketSettings settings, final SslSettings sslSettings) throws IOException {
    socket.setTcpNoDelay(true);
    socket.setSoTimeout(settings.getReadTimeout(MILLISECONDS));
    socket.setKeepAlive(settings.isKeepAlive());
    if (settings.getReceiveBufferSize() > 0) {
        socket.setReceiveBufferSize(settings.getReceiveBufferSize());
    }
    if (settings.getSendBufferSize() > 0) {
        socket.setSendBufferSize(settings.getSendBufferSize());
    }
    if (sslSettings.isEnabled() || socket instanceof SSLSocket) {
        if (!(socket instanceof SSLSocket)) {
            throw new MongoInternalException("SSL is enabled but the socket is not an instance of javax.net.ssl.SSLSocket");
        }
        SSLSocket sslSocket = (SSLSocket) socket;
        SSLParameters sslParameters = sslSocket.getSSLParameters();
        enableSni(address, sslParameters);
        if (!sslSettings.isInvalidHostNameAllowed()) {
            enableHostNameVerification(sslParameters);
        }
        sslSocket.setSSLParameters(sslParameters);
    }
    socket.connect(address.getSocketAddress(), settings.getConnectTimeout(MILLISECONDS));
}
Also used : SSLParameters(javax.net.ssl.SSLParameters) SSLSocket(javax.net.ssl.SSLSocket) MongoInternalException(com.mongodb.MongoInternalException)

Example 3 with MongoInternalException

use of com.mongodb.MongoInternalException in project morphia by mongodb.

the class TestQuery method testWhereWithInvalidStringQuery.

@Test
public void testWhereWithInvalidStringQuery() {
    getDs().save(new PhotoWithKeywords());
    final CodeWScope hasKeyword = new CodeWScope("keywords != null", new BasicDBObject());
    try {
        // must fail
        assertNotNull(getDs().find(PhotoWithKeywords.class).where(hasKeyword.getCode()).get());
        fail("Invalid javascript magically isn't invalid anymore?");
    } catch (MongoInternalException e) {
    // fine
    } catch (MongoException e) {
    // fine
    }
}
Also used : BasicDBObject(com.mongodb.BasicDBObject) MongoException(com.mongodb.MongoException) CodeWScope(org.bson.types.CodeWScope) MongoInternalException(com.mongodb.MongoInternalException) Test(org.junit.Test)

Aggregations

MongoInternalException (com.mongodb.MongoInternalException)3 MongoException (com.mongodb.MongoException)2 BasicDBObject (com.mongodb.BasicDBObject)1 ConnectionPoolWaitQueueEnteredEvent (com.mongodb.event.ConnectionPoolWaitQueueEnteredEvent)1 ConnectionPoolWaitQueueExitedEvent (com.mongodb.event.ConnectionPoolWaitQueueExitedEvent)1 SSLParameters (javax.net.ssl.SSLParameters)1 SSLSocket (javax.net.ssl.SSLSocket)1 CodeWScope (org.bson.types.CodeWScope)1 Test (org.junit.Test)1