try {
if (create) {
if (dbList.isEmpty()) {
Logger log = Logger.getLogger(WebComponent.LOG_NAME);
DB db = DB.createDB(log,dir,"data");
dbList.put(db.getName(),db);
try {
DB.writeList(dir,dbList);
} catch (Exception ex) {
ex.printStackTrace();
return;
}
}
int argCount = args.length-argIndex;
String hostname = argCount>1 ? args[argIndex+1] : "*";
String ipAddress = argCount>1 ? args[argIndex+2] : "*";
int port = argCount>1 ? Integer.parseInt(args[argIndex+3]) : 8080;
File logDir = new File(dir,"logs");
ServerConfiguration.Host host = new ServerConfiguration.Host(conf,"data",hostname,null,port,false,false,new File(logDir,hostname.equals("*") ? "any.log" : hostname+".log"));
conf.getInterfaces().add(new ServerConfiguration.Interface(ipAddress,port,true));
conf.getHosts().put(host.getName(),host);
File keystoreFile = new File(dir,"keystore");
conf.setKeystoreFile(keystoreFile);
conf.setKeystorePassword("atomojo");
conf.setKeyPassword("atomojo");
conf.setLogDirectory(logDir);
conf.setTempDirectory(dir);
if (storageClassName!=null) {
conf.setStorageClassName(storageClassName);
}
File serverConfFile = new File(dir,"server.conf");
Writer out = new OutputStreamWriter(new FileOutputStream(serverConfFile),"UTF-8");
WriterItemDestination dest = new WriterItemDestination(out,"UTF-8");
conf.store(serverConfFile.toURI(),dest);
out.flush();
out.close();
if (!keystoreFile.exists()) {
copyResource("/org/atomojo/app/db/conf/keystore",keystoreFile);
}
initStorageClass();
web = new WebComponent(dir,dbList,getStorageFactory(),conf);
}
System.out.println("Connecting to databases...");
// Connect to all databases
for (DB db : dbList.values()) {
System.out.println("Connecting to DB "+db.getName());
db.connect();
}
System.out.println("Starting server...");