private String createInstance(String name) { logger.debug("createInstance(String name = " + name + " )"); if (name == null) { // no instance exists, create all, the configuration and the instance MongoClient mongoClient = createMongoClient(); if (mongoClient != null && MongoDBConfiguration.checkMongoClient(mongoClient)) { logger.debug("Mongo client works properly"); Implementation impl = CST.apamResolver.findImplByName(null, MongoDBConfiguration.IMPL_NAME); Instance inst = impl.createInstance(null, null); MongoDBConfiguration myConfiguration = (MongoDBConfiguration) inst.getServiceObject(); myConfiguration.setConfiguration( dbHost, dbPort, dbTimeOut, mongoClient, factory, inst.getName()); logger.debug("Instance and MongoDBConfiguration created : " + inst.getName()); return inst.getName(); } else { logger.debug("Error when creating instance of mongoDBConfiguration"); return null; } } else if (CST.componentBroker.getInst(name) != null) { // An instance with this name exists, check if it works properly // if not we destroy it MongoDBConfiguration myConfiguration = (MongoDBConfiguration) CST.componentBroker.getInst(name).getServiceObject(); if (!myConfiguration.isValid()) { logger.debug("Error during creation, removing the Instance and the configuration"); } } return null; }
/** * Constructs a {@link MongoDBBasedUserManager} instance with {@link MongoDBConfiguration}. * * @param configuration Instance of {@link MongoDBConfiguration}. */ public MongoDBBasedUserManager(MongoDBConfiguration configuration) { this( configuration.getHost(), configuration.getPort(), configuration.getDatabase(), configuration.getUsername(), configuration.getPassword()); }
/** * Constructs a {@link MongoDBBasedUserManager} instance with configuration file path. This * constructor will read a specified file. * * @param configFile Configuration file path. The path support prefix "classpath:" or "file:". */ public MongoDBBasedUserManager(String configFile) { this(MongoDBConfiguration.load(configFile)); }