use of com.mongodb.MongoSocketOpenException in project mongo-java-driver by mongodb.
the class SocketStream method open.
@Override
public void open() throws IOException {
try {
socket = socketFactory.createSocket();
SocketStreamHelper.initialize(socket, address, settings, sslSettings);
outputStream = socket.getOutputStream();
inputStream = socket.getInputStream();
} catch (IOException e) {
close();
throw new MongoSocketOpenException("Exception opening socket", getAddress(), e);
}
}
use of com.mongodb.MongoSocketOpenException in project mongo-java-driver by mongodb.
the class SocketStream method open.
@Override
public void open() {
try {
socket = initializeSocket();
outputStream = socket.getOutputStream();
inputStream = socket.getInputStream();
} catch (IOException e) {
close();
throw new MongoSocketOpenException("Exception opening socket", getAddress(), e);
}
}
use of com.mongodb.MongoSocketOpenException in project mongo-java-driver by mongodb.
the class NettyStream method openAsync.
@Override
public void openAsync(final AsyncCompletionHandler<Void> handler) {
Bootstrap bootstrap = new Bootstrap();
bootstrap.group(workerGroup);
bootstrap.channel(socketChannelClass);
bootstrap.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, settings.getConnectTimeout(MILLISECONDS));
bootstrap.option(ChannelOption.TCP_NODELAY, true);
bootstrap.option(ChannelOption.SO_KEEPALIVE, settings.isKeepAlive());
if (settings.getReceiveBufferSize() > 0) {
bootstrap.option(ChannelOption.SO_RCVBUF, settings.getReceiveBufferSize());
}
if (settings.getSendBufferSize() > 0) {
bootstrap.option(ChannelOption.SO_SNDBUF, settings.getSendBufferSize());
}
bootstrap.option(ChannelOption.ALLOCATOR, allocator);
bootstrap.handler(new ChannelInitializer<SocketChannel>() {
@Override
public void initChannel(final SocketChannel ch) throws Exception {
if (sslSettings.isEnabled()) {
SSLEngine engine = SSLContext.getDefault().createSSLEngine(address.getHost(), address.getPort());
engine.setUseClientMode(true);
SSLParameters sslParameters = engine.getSSLParameters();
enableSni(address, sslParameters);
if (!sslSettings.isInvalidHostNameAllowed()) {
enableHostNameVerification(sslParameters);
}
engine.setSSLParameters(sslParameters);
ch.pipeline().addFirst("ssl", new SslHandler(engine, false));
}
int readTimeout = settings.getReadTimeout(MILLISECONDS);
if (readTimeout > 0) {
ch.pipeline().addLast(READ_HANDLER_NAME, new ReadTimeoutHandler(readTimeout));
}
ch.pipeline().addLast(new InboundBufferHandler());
}
});
final ChannelFuture channelFuture = bootstrap.connect(address.getHost(), address.getPort());
channelFuture.addListener(new ChannelFutureListener() {
@Override
public void operationComplete(final ChannelFuture future) throws Exception {
if (future.isSuccess()) {
channel = channelFuture.channel();
channel.closeFuture().addListener(new ChannelFutureListener() {
@Override
public void operationComplete(final ChannelFuture f2) throws Exception {
handleReadResponse(null, new IOException("The connection to the server was closed"));
}
});
handler.completed(null);
} else {
handler.failed(new MongoSocketOpenException("Exception opening socket", getAddress(), future.cause()));
}
}
});
}
use of com.mongodb.MongoSocketOpenException in project mongo-java-driver by mongodb.
the class SocketChannelStream method open.
@Override
public void open() throws IOException {
try {
socketChannel = SocketChannel.open();
SocketStreamHelper.initialize(socketChannel.socket(), address, settings, sslSettings);
} catch (IOException e) {
close();
throw new MongoSocketOpenException("Exception opening socket", getAddress(), e);
}
}
use of com.mongodb.MongoSocketOpenException in project mongo-java-driver by mongodb.
the class AsynchronousSocketChannelStream method initializeSocketChannel.
private void initializeSocketChannel(final AsyncCompletionHandler<Void> handler, final Queue<SocketAddress> socketAddressQueue) {
if (socketAddressQueue.isEmpty()) {
handler.failed(new MongoSocketException("Exception opening socket", serverAddress));
} else {
SocketAddress socketAddress = socketAddressQueue.poll();
try {
AsynchronousSocketChannel attemptConnectionChannel = AsynchronousSocketChannel.open(group);
attemptConnectionChannel.setOption(StandardSocketOptions.TCP_NODELAY, true);
attemptConnectionChannel.setOption(StandardSocketOptions.SO_KEEPALIVE, true);
if (settings.getReceiveBufferSize() > 0) {
attemptConnectionChannel.setOption(StandardSocketOptions.SO_RCVBUF, settings.getReceiveBufferSize());
}
if (settings.getSendBufferSize() > 0) {
attemptConnectionChannel.setOption(StandardSocketOptions.SO_SNDBUF, settings.getSendBufferSize());
}
attemptConnectionChannel.connect(socketAddress, null, new OpenCompletionHandler(handler, socketAddressQueue, attemptConnectionChannel));
} catch (IOException e) {
handler.failed(new MongoSocketOpenException("Exception opening socket", serverAddress, e));
} catch (Throwable t) {
handler.failed(t);
}
}
}
Aggregations