@ FFDCIgnore ( Throwable . class ) @ Trivial private void setReadPreference ( Class < ? > MongoClientOptions_Builder , Object optionsBuilder , String creatorMethod ) throws ClassNotFoundException , IllegalArgumentException , SecurityException , IllegalAccessException , InvocationTargetException , NoSuchMethodException { try { if ( TraceComponent . isAnyTracingEnabled ( ) && tc . isDebugEnabled ( ) ) Tr . debug ( this , tc , READ_PREFERENCE + ' ' + creatorMethod ) ; Class < ? > ReadPreference = MongoClientOptions_Builder . getClassLoader ( ) . loadClass ( "com.mongodb.ReadPreference" ) ; // Calls static ReadPreference.nearest() (or whatever conf is set to) to get a ReadPreference object Object readPreference = ReadPreference . getMethod ( creatorMethod ) . invoke ( ReadPreference ) ; // Set static ReadPreference on Builder. MongoClientOptions_Builder . getMethod ( "readPreference" , ReadPreference ) . invoke ( optionsBuilder , readPreference ) ; } catch ( Throwable x ) { if ( x instanceof InvocationTargetException ) x = x . getCause ( ) ; IllegalArgumentException failure = ignoreWarnOrFail ( x , IllegalArgumentException . class , "CWKKD0010.prop.error" , READ_PREFERENCE , MONGO , id , x ) ; if ( failure != null ) { FFDCFilter . processException ( failure , getClass ( ) . getName ( ) , "422" , this ) ; throw failure ; } } }
Configure the readPreference mongo option which is a special case .