diff artifact-database/src/main/java/org/dive4elements/artifactdatabase/App.java @ 473:d0ac790a6c89 dive4elements-move

Moved directories to org.dive4elements
author Sascha L. Teichmann <teichmann@intevation.de>
date Thu, 25 Apr 2013 10:57:18 +0200
parents artifact-database/src/main/java/de/intevation/artifactdatabase/App.java@f33401ea2a6c
children 415df0fc4fa1
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/artifact-database/src/main/java/org/dive4elements/artifactdatabase/App.java	Thu Apr 25 10:57:18 2013 +0200
@@ -0,0 +1,90 @@
+/*
+ * Copyright (c) 2010 by Intevation GmbH
+ *
+ * This program is free software under the LGPL (>=v2.1)
+ * Read the file LGPL.txt coming with the software for details
+ * or visit http://www.gnu.org/licenses/ if it does not exist.
+ */
+
+package de.intevation.artifactdatabase;
+
+import de.intevation.artifacts.common.utils.Config;
+
+import de.intevation.artifactdatabase.rest.HTTPServer;
+
+import java.io.File;
+
+import java.net.MalformedURLException;
+
+import org.apache.log4j.PropertyConfigurator;
+
+import org.slf4j.bridge.SLF4JBridgeHandler;
+
+/**
+ * Starting point of the artifact database.
+ *
+ * @author <a href="mailto:sascha.teichmann@intevation.de">Sascha L. Teichmann</a>
+ */
+public class App
+{
+    /**
+     * The logging is done via Log4j. To configure the logging
+     * a file 'log4j.properties' is search in the configuration directory.
+     */
+    public static final String LOG4J_PROPERTIES =
+        "log4j.properties";
+
+    /**
+     * Trys to load the Log4j configuration from ${config.dir}/log4j.properties.
+     */
+    public static final void configureLogging() {
+        File configDir = Config.getConfigDirectory();
+        File propFile = new File(configDir, LOG4J_PROPERTIES);
+
+        if (propFile.isFile() && propFile.canRead()) {
+            try {
+                PropertyConfigurator.configure(propFile.toURI().toURL());
+                SLF4JBridgeHandler.install();
+            }
+            catch (MalformedURLException mue) {
+                mue.printStackTrace(System.err);
+            }
+        }
+    }
+
+    /**
+     * Starts the artifact database.
+     * @param args The commandline arguments. Unused.
+     */
+    public static void main(String[] args) {
+
+        configureLogging();
+
+        FactoryBootstrap bootstrap = new FactoryBootstrap();
+
+        bootstrap.boot();
+
+        Backend backend = Backend.getInstance();
+
+        ArtifactDatabaseImpl db = new ArtifactDatabaseImpl(
+            bootstrap, backend);
+
+        DatabaseCleaner cleaner = new DatabaseCleaner(
+            bootstrap.getContext(), backend, backend.getConfig());
+
+        HTTPServer httpServer = bootstrap.getHTTPServer();
+
+        bootstrap = null;
+
+        backend.setCleaner(cleaner);
+
+        cleaner.setLockedIdsProvider(db);
+
+        cleaner.start();
+
+        db.start();
+
+        httpServer.startAsServer(db);
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org