Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/trisberg/vert.x
Browse files Browse the repository at this point in the history
  • Loading branch information
purplefox committed May 17, 2012
2 parents f3397a8 + f9c6d23 commit ad454e0
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/mods/mongo-persistor/org/vertx/mods/MongoPersistor.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,16 @@
* Please see the busmods manual for a full description<p>
*
* @author <a href="http://tfox.org">Tim Fox</a>
* @author Thomas Risberg
*/
public class MongoPersistor extends BusModBase implements Handler<Message<JsonObject>> {

private String address;
private String host;
private int port;
private String dbName;
private String username;
private String password;

private Mongo mongo;
private DB db;
Expand All @@ -55,10 +58,15 @@ public void start() {
host = getOptionalStringConfig("host", "localhost");
port = getOptionalIntConfig("port", 27017);
dbName = getOptionalStringConfig("db_name", "default_db");
username = getOptionalStringConfig("username", null);
password = getOptionalStringConfig("password", null);

try {
mongo = new Mongo(host, port);
db = mongo.getDB(dbName);
if (username != null && password != null) {
db.authenticate(username, password.toCharArray());
}
eb.registerHandler(address, this);
} catch (UnknownHostException e) {
logger.error("Failed to connect to mongo server", e);
Expand Down

0 comments on commit ad454e0

Please sign in to comment.