}
@Override
public void initializeContext(CompositeType context) {
ManagerModel model = context.getModel(this);
logger.debug("HISTMAN, newComposite(ManagerModel model = "
+(model==null?"null":model.getManagerName())
+ "CompositeType compositeType = "
+(context==null?"null":context.getName()));
if (model == null) { // model is root
model = CompositeTypeImpl.getRootCompositeType().getModel(this);
}
HistManData data =new HistManData(loadProperties(model));
try {
Builder options = new MongoClientOptions.Builder();
options.connectTimeout(data.histDBTimeout);
if(mongoClient==null) {
mongoClient = new MongoClient(data.histURL, options.build());
}
logger.info("trying to connect with database {} in host {}",
data.histDBName, data.histURL);
// force connection to be established
mongoClient.getDatabaseNames();
db = mongoClient.getDB(data.histDBName);
} catch (Exception e) {
logger.error("{} is inactive, it was unable to find the DB in {}",
this.getName(), data.histURL);
}
histDbURLs.put(context.getName(), data.histURL);
try {
// force connection to be established
mongoClient.getDatabaseNames();
/*
* if attribute dropComection is true, drop all collections
*/
if (data.dropCollections.equals("true")) {
db.getCollection(Entities).drop();
db.getCollection(ChangedAttributes).drop();
db.getCollection(Links).drop();
}
} catch (MongoException e) {
logger.error("no Mongo Database at URL {} name {}", model.getURL(),
data.histDBName);
stop();
}
}