/** * Starts the {@link Mongo} instance and explicitly checks whether it is * actually alive. * * @throws PersistenceStartException if we can't make a connection to MongoDb. */ private void start() { Preconditions.checkState(!isRunning(), "Can't start after a connection has been established"); String host = dbHost; int port = Integer.parseInt(dbPort); try { // New MongoDB Client, see http://docs.mongodb.org/manual/release-notes/drivers-write-concern/ mongo = new MongoClient(host, port); } catch (UnknownHostException e) { throw new PersistenceStartException("Unable to resolve the MongoDb hostname", e); } try { // Check to see if we are alive mongo.getDB(dbName).command("ping"); } catch (MongoException e) { throw new PersistenceStartException("Can't ping MongoDb", e); } isRunning = true; LOG.info("Started MongoDb persistence"); }