Created
December 8, 2011 15:13
-
-
Save JanPaulEttles/1447236 to your computer and use it in GitHub Desktop.
tomcat and mongo #2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private final Mongo mongo; | |
| public MongoService() throws UnknownHostException, NamingException { | |
| ArrayList<ServerAddress> addrs = new ArrayList<ServerAddress>(); | |
| int hosts = ContextUtil.getEntryAsInt("mongo.hosts"); | |
| for (int i = 0; i < hosts; i++) { | |
| String address = ContextUtil.getEntryAsString("mongo.host.address." + i); | |
| int port = ContextUtil.getEntryAsInt("mongo.host.port." + i); | |
| addrs.add(new ServerAddress(address, port)); | |
| } | |
| mongo = new Mongo(addrs); | |
| //if we have more 1 instance, then lets check the slave reads ok param | |
| if(hosts > 1) { | |
| if(ContextUtil.getEntryAsBoolean("mongo.slave")) { | |
| mongo.slaveOk(); | |
| } | |
| } | |
| } | |
| public DB getDb(String dbName) { | |
| return mongo.getDB(dbName); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment