// Bind and start to accept incoming connections.
InetAddress hostAddressX;
try {
hostAddressX = networkService.resolveBindHostAddress(bindHost);
} catch (IOException e) {
throw new BindHttpException("Failed to resolve host [" + bindHost + "]", e);
}
final InetAddress hostAddress = hostAddressX;
InetAddress publishAddressHostX;
try {
publishAddressHostX = networkService.resolvePublishHostAddress(publishHost);
} catch (IOException e) {
throw new BindHttpException("Failed to resolve publish address host [" + publishHost + "]", e);
}
final InetAddress publishAddressHost = publishAddressHostX;
capiBehavior = new ElasticSearchCAPIBehavior(client, logger, typeSelector, checkpointDocumentType, dynamicTypePath, resolveConflicts.booleanValue(), maxConcurrentRequests, bulkIndexRetries, bulkIndexRetryWaitMs, bucketUUIDCache, documentTypeParentFields, documentTypeRoutingFields);
couchbaseBehavior = new ElasticSearchCouchbaseBehavior(client, logger, checkpointDocumentType, bucketUUIDCache);
PortsRange portsRange = new PortsRange(port);
final AtomicReference<Exception> lastException = new AtomicReference<Exception>();
boolean success = portsRange.iterate(new PortsRange.PortCallback() {
@Override
public boolean onPortNumber(int portNumber) {
try {
server = new CAPIServer(capiBehavior, couchbaseBehavior,
new InetSocketAddress(hostAddress, portNumber),
CouchbaseCAPITransportImpl.this.username,
CouchbaseCAPITransportImpl.this.password,
numVbuckets);
if (publishAddressHost != null) {
server.setPublishAddress(publishAddressHost);
}
server.start();
} catch (Exception e) {
lastException.set(e);
return false;
}
return true;
}
});
if (!success) {
throw new BindHttpException("Failed to bind to [" + port + "]",
lastException.get());
}
InetSocketAddress boundAddress = server.getBindAddress();
InetSocketAddress publishAddress = new InetSocketAddress(publishAddressHost, boundAddress.getPort());