protected void activate()

in src/main/java/org/apache/sling/mongodb/impl/MongoDBResourceProviderFactory.java [95:125]


    protected void activate(final Map<String, Object> props) throws Exception {
        final String[] roots = PropertiesUtil.toStringArray(props.get(ResourceProvider.ROOTS));
        if ( roots == null || roots.length == 0 ) {
            throw new Exception("Roots configuration is missing.");
        }
        if ( roots.length > 1 ) {
            throw new Exception("Only a single root should be configured.");
        }
        if ( roots[0] == null || roots[0].trim().length() == 0 ) {
            throw new Exception("Roots configuration is missing.");
        }
        final String host = PropertiesUtil.toString(props.get(PROP_HOST), DEFAULT_HOST);
        final int port = PropertiesUtil.toInteger(props.get(PROP_PORT), DEFAULT_PORT);
        final String db = PropertiesUtil.toString(props.get(PROP_DB), DEFAULT_DB);
        logger.info("Starting MongoDB resource provider with host={}, port={}, db={}",
                new Object[] {host, port, db});
        final DBAddress address = new DBAddress(host, port, db);
        final MongoOptions options = new MongoOptions();
        
        options.connectionsPerHost = PropertiesUtil.toInteger(props.get(PROP_NUM_CONNECTIONS), DEFAULT_NUMCONNECTIONS);
        options.threadsAllowedToBlockForConnectionMultiplier = PropertiesUtil.toInteger(props.get(PROP_THREAD_MULTIPLIER), DEFAULT_THREAD_MULTIPLIER);
        final Mongo m = new Mongo(address, options);

        final DB database = m.getDB( db );
        logger.info("Connected to database {}", database);

        this.context = new MongoDBContext(database,
                roots[0],
                PropertiesUtil.toStringArray(props.get(PROP_FILTER_COLLECTIONS)),
                this.eventAdmin);
    }