blob: 03ae5dd4874bc302f0573bc030906473aa0bccf8 (
plain) (
tree)
|
|
package org.openslx.bwlp.sat;
import java.security.NoSuchAlgorithmException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.TimerTask;
import org.apache.log4j.BasicConfigurator;
import org.apache.log4j.Logger;
import org.apache.thrift.transport.TTransportException;
import org.openslx.bwlp.sat.database.Database;
import org.openslx.bwlp.sat.database.mappers.DbImage;
import org.openslx.bwlp.sat.fileserv.FileServer;
import org.openslx.bwlp.sat.thrift.BinaryListener;
import org.openslx.bwlp.sat.thrift.cache.OperatingSystemList;
import org.openslx.bwlp.sat.thrift.cache.OrganizationList;
import org.openslx.bwlp.sat.util.Configuration;
import org.openslx.bwlp.sat.util.QuickTimer;
import org.openslx.bwlp.thrift.iface.ImageSummaryRead;
import org.openslx.bwlp.thrift.iface.UserInfo;
public class App {
private static Logger log = Logger.getLogger(App.class);
private static List<Thread> servers = new ArrayList<>();
public static boolean DEBUG = false;
public static void main(String[] args) throws TTransportException, NoSuchAlgorithmException {
//get going and show basic information in log file
BasicConfigurator.configure();
if (args.length != 0 && args[0].equals("debug")) {
DEBUG = true;
}
log.info("****************************************************************");
log.info("******************* Starting Application ***********************");
log.info("****************************************************************");
// get Configuration
try {
log.info("Loading configuration");
Configuration.load();
} catch (Exception e1) {
log.fatal("Could not load configuration", e1);
System.exit(1);
}
// Load useful things from master server
OrganizationList.get();
//OperatingSystemList.get();
// Start file transfer server
if (!FileServer.instance().start()) {
log.error("Could not start internal file server.");
return;
}
// Start Server
Thread t;
t = new Thread(new BinaryListener(9090, false));
servers.add(t);
t.start();
// DEBUG
if (DEBUG) {
Database.printCharsetInformation();
List<ImageSummaryRead> allVisible;
try {
allVisible = DbImage.getAllVisible(new UserInfo("bla", "blu", null, null, null), null, 0);
log.info("Got " + allVisible.size());
} catch (SQLException e) {
log.warn("could not test query getallvisible");
}
QuickTimer.scheduleAtFixedDelay(new TimerTask() {
@Override
public void run() {
Database.printDebug();
}
}, 100, 5000);
}
// Wait for servers
for (Thread wait : servers) {
boolean success = false;
while (!success) {
try {
wait.join();
success = true;
} catch (InterruptedException e) {
// Do nothing...
}
}
}
QuickTimer.cancel();
log.info(new Date() + " - all Servers shut down, exiting...\n");
}
}
|