mongodb/mongo-hadoop — pull request #104 by josephks (2014-05-01 18:23:07+00:00)
Title: In getCollection() cache MongoClients instead of creating a new one each time

My mongos was refusing connections because too many files were open. I traced the problem to the getCollection() method creating a new MongoClient each time it is called.

This PR adds a cache to getCollection() to fix the problem. This is not very elegant because MongoClientURI doesn't implement hashcode() or equals() so I work around that by creating my own key class. Also I only fixed the problem in getCollection(), not in getCollectionWithAuth().

I consider this PR to be more of a proof of concept than a real fix.

Test results
-----------
gradlew check fails with:

```
14:09:58.308 [ERROR] [org.gradle.BuildExceptionReporter] Caused by: java.lang.ArrayIndexOutOfBoundsException: 35328
14:09:58.309 [ERROR] [org.gradle.BuildExceptionReporter] at org.objectweb.asm.ClassReader.accept(Unknown Source)
14:09:58.309 [ERROR] [org.gradle.BuildExceptionReporter] at edu.umd.cs.findbugs.asm.FBClassReader.accept(FBClassReader.java:44)
14:09:58.309 [ERROR] [org.gradle.BuildExceptionReporter] at org.objectweb.asm.ClassReader.accept(Unknown Source)
14:09:58.310 [ERROR] [org.gradle.BuildExceptionReporter] at edu.umd.cs.findbugs.classfile.engine.ClassParserUsingASM.parse(ClassParserUsingASM.java:110)
14:09:58.310 [ERROR] [org.gradle.BuildExceptionReporter] at edu.umd.cs.findbugs.classfile.engine.ClassParserUsingASM.parse(ClassParserUsingASM.java:554)
14:09:58.310 [ERROR] [org.gradle.BuildExceptionReporter] at edu.umd.cs.findbugs.classfile.engine.ClassInfoAnalysisEngine.analyze(ClassInfoAnalysisEngine.java:76)
14:09:58.310 [ERROR] [org.gradle.BuildExceptionReporter] at edu.umd.cs.findbugs.classfile.engine.ClassInfoAnalysisEngine.analyze(ClassInfoAnalysisEngine.java:38)
14:09:58.311 [ERROR] [org.gradle.BuildExceptionReporter] at edu.umd.cs.findbugs.classfile.impl.AnalysisCache.getClassAnalysis(AnalysisCache.java:266)
14:09:58.311 [ERROR] [org.gradle.BuildExceptionReporter] at edu.umd.cs.findbugs.ba.XFactory.getXClass(XFactory.java:652)
```

This is building with java 1.7.0_07