super(), finals;

other; cleaned;
Properties;

git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@755 6c8d7289-2bf4-0310-a012-ef5d649a1542
pull/1/head
borg-0300 20 years ago
parent af9021e956
commit e748ba3f6e

@ -1,43 +1,45 @@
//yacy.java // yacy.java
//----------------------- // -----------------------
//(C) by Michael Peter Christen; mc@anomic.de // (C) by Michael Peter Christen; mc@anomic.de
//first published on http://www.yacy.net // first published on http://www.yacy.net
//Frankfurt, Germany, 2004, 2005 // Frankfurt, Germany, 2004, 2005
//last major change: 24.03.2005
// //
//This program is free software; you can redistribute it and/or modify // $LastChangedDate$
//it under the terms of the GNU General Public License as published by // $LastChangedRevision$
//the Free Software Foundation; either version 2 of the License, or // $LastChangedBy$
//(at your option) any later version.
// //
//This program is distributed in the hope that it will be useful, // This program is free software; you can redistribute it and/or modify
//but WITHOUT ANY WARRANTY; without even the implied warranty of // it under the terms of the GNU General Public License as published by
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // the Free Software Foundation; either version 2 of the License, or
//GNU General Public License for more details. // (at your option) any later version.
// //
//You should have received a copy of the GNU General Public License // This program is distributed in the hope that it will be useful,
//along with this program; if not, write to the Free Software // but WITHOUT ANY WARRANTY; without even the implied warranty of
//Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// //
//Using this software in any meaning (reading, learning, copying, compiling, // You should have received a copy of the GNU General Public License
//running) means that you agree that the Author(s) is (are) not responsible // along with this program; if not, write to the Free Software
//for cost, loss of data or any harm that may be caused directly or indirectly // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//by usage of this softare or this documentation. The usage of this software
//is on your own risk. The installation and usage (starting/running) of this
//software may allow other people or application to access your computer and
//any attached devices and is highly dependent on the configuration of the
//software which must be done by the user of the software; the author(s) is
//(are) also not responsible for proper configuration and usage of the
//software, even if provoked by documentation provided together with
//the software.
// //
//Any changes to this file according to the GPL as documented in the file // Using this software in any meaning (reading, learning, copying, compiling,
//gpl.txt aside this file in the shipment you received can be done to the // running) means that you agree that the Author(s) is (are) not responsible
//lines that follows this copyright notice here, but changes must not be // for cost, loss of data or any harm that may be caused directly or indirectly
//done inside the copyright notive above. A re-distribution must contain // by usage of this softare or this documentation. The usage of this software
//the intact and unchanged copyright notice. // is on your own risk. The installation and usage (starting/running) of this
//Contributions and changes to the program code must be marked as such. // software may allow other people or application to access your computer and
// any attached devices and is highly dependent on the configuration of the
// software which must be done by the user of the software; the author(s) is
// (are) also not responsible for proper configuration and usage of the
// software, even if provoked by documentation provided together with
// the software.
//
// Any changes to this file according to the GPL as documented in the file
// gpl.txt aside this file in the shipment you received can be done to the
// lines that follows this copyright notice here, but changes must not be
// done inside the copyright notive above. A re-distribution must contain
// the intact and unchanged copyright notice.
// Contributions and changes to the program code must be marked as such.
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.BufferedWriter; import java.io.BufferedWriter;
@ -50,7 +52,6 @@ import java.io.IOException;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.net.URL; import java.net.URL;
// import java.util.Enumeration;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
@ -58,7 +59,6 @@ import java.util.Properties;
import java.util.TreeSet; import java.util.TreeSet;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import de.anomic.data.translator; import de.anomic.data.translator;
import de.anomic.http.httpHeader; import de.anomic.http.httpHeader;
import de.anomic.http.httpc; import de.anomic.http.httpc;
@ -66,13 +66,10 @@ import de.anomic.http.httpd;
import de.anomic.http.httpdFileHandler; import de.anomic.http.httpdFileHandler;
import de.anomic.http.httpdProxyHandler; import de.anomic.http.httpdProxyHandler;
import de.anomic.kelondro.kelondroMScoreCluster; import de.anomic.kelondro.kelondroMScoreCluster;
// import de.anomic.kelondro.kelondroTree;
import de.anomic.plasma.plasmaSwitchboard; import de.anomic.plasma.plasmaSwitchboard;
import de.anomic.plasma.plasmaURL; import de.anomic.plasma.plasmaURL;
// import de.anomic.plasma.plasmaWordIndex;
import de.anomic.plasma.plasmaWordIndexEntity; import de.anomic.plasma.plasmaWordIndexEntity;
import de.anomic.plasma.plasmaWordIndexEntry; import de.anomic.plasma.plasmaWordIndexEntry;
// import de.anomic.plasma.plasmaWordIndexEntryContainer;
import de.anomic.plasma.plasmaWordIndexClassicDB; import de.anomic.plasma.plasmaWordIndexClassicDB;
import de.anomic.plasma.plasmaWordIndexCache; import de.anomic.plasma.plasmaWordIndexCache;
import de.anomic.server.serverCodings; import de.anomic.server.serverCodings;
@ -118,8 +115,8 @@ import de.anomic.yacy.yacyCore;
* <li>terminate. * <li>terminate.
* </ul> * </ul>
*/ */
public final class yacy {
public final class yacy {
// static objects // static objects
private static String vString = "@REPL_VERSION@"; private static String vString = "@REPL_VERSION@";
private static float version = (float) 0.1; private static float version = (float) 0.1;
@ -170,6 +167,7 @@ public final class yacy {
*/ */
private static void startup(String homePath, long startupFree) { private static void startup(String homePath, long startupFree) {
long startup = yacyCore.universalTime(); long startup = yacyCore.universalTime();
try { try {
// start up // start up
System.out.println(copyright); System.out.println(copyright);
@ -197,65 +195,65 @@ public final class yacy {
serverLog.logConfig("STARTUP", "Application Root Path: " + homePath); serverLog.logConfig("STARTUP", "Application Root Path: " + homePath);
// create data folder // create data folder
File dataFolder = new File(homePath, "DATA"); final File dataFolder = new File(homePath, "DATA");
if (!(dataFolder.exists())) dataFolder.mkdir(); if (!(dataFolder.exists())) dataFolder.mkdir();
plasmaSwitchboard sb = new plasmaSwitchboard(homePath, "yacy.init", "DATA/SETTINGS/httpProxy.conf"); final plasmaSwitchboard sboard = new plasmaSwitchboard(homePath, "yacy.init", "DATA/SETTINGS/httpProxy.conf");
// save information about available memory at startup time // save information about available memory at startup time
sb.setConfig("memoryFreeAfterStartup", startupFree); // for statistics and memory configuration sboard.setConfig("memoryFreeAfterStartup", startupFree); // for statistics and memory configuration
// hardcoded, forced, temporary value-migration // hardcoded, forced, temporary value-migration
sb.setConfig("htTemplatePath", "htroot/env/templates"); sboard.setConfig("htTemplatePath", "htroot/env/templates");
sb.setConfig("parseableExt", "html,htm,txt,php,shtml,asp"); sboard.setConfig("parseableExt", "html,htm,txt,php,shtml,asp");
// if we are running an SVN version, we try to detect the used svn revision now ... // if we are running an SVN version, we try to detect the used svn revision now ...
Properties buildProp = new Properties(); final Properties buildProp = new Properties();
File buildPropFile = null; File buildPropFile = null;
try { try {
buildPropFile = new File(homePath,"build.properties"); buildPropFile = new File(homePath,"build.properties");
buildProp.load(new FileInputStream(buildPropFile)); buildProp.load(new FileInputStream(buildPropFile));
} catch (Exception e) { } catch (Exception e) {
System.err.println("ERROR: " + buildPropFile.toString() + " not found in settings path"); serverLog.logWarning("STARTUP", buildPropFile.toString() + " not found in settings path");
} }
try { try {
if (buildProp.containsKey("releaseNr")) { if (buildProp.containsKey("releaseNr")) {
// this normally looks like this: $Revision: 181 $ // this normally looks like this: $Revision$
String svnReleaseNrStr = buildProp.getProperty("releaseNr"); final String svnReleaseNrStr = buildProp.getProperty("releaseNr");
Pattern pattern = Pattern.compile("\\$Revision:\\s(.*)\\s\\$",Pattern.DOTALL+Pattern.CASE_INSENSITIVE); final Pattern pattern = Pattern.compile("\\$Revision:\\s(.*)\\s\\$",Pattern.DOTALL+Pattern.CASE_INSENSITIVE);
Matcher matcher = pattern.matcher(svnReleaseNrStr); final Matcher matcher = pattern.matcher(svnReleaseNrStr);
if (matcher.find()) { if (matcher.find()) {
String svrReleaseNr = matcher.group(1); final String svrReleaseNr = matcher.group(1);
try { try {
try {version = Float.parseFloat(vString);} catch (NumberFormatException e) {version = (float) 0.1;} try {version = Float.parseFloat(vString);} catch (NumberFormatException e) {version = (float) 0.1;}
version = versvn2combinedVersion(version, Integer.parseInt(svrReleaseNr)); version = versvn2combinedVersion(version, Integer.parseInt(svrReleaseNr));
} catch (NumberFormatException e) {} } catch (NumberFormatException e) {}
sb.setConfig("svnRevision", svrReleaseNr); sboard.setConfig("svnRevision", svrReleaseNr);
} }
} }
} catch (Exception e) { } catch (Exception e) {
System.err.println("Unable to determine the currently used SVN revision number."); System.err.println("Unable to determine the currently used SVN revision number.");
} }
sb.setConfig("version", Float.toString(version)); sboard.setConfig("version", Float.toString(version));
sb.setConfig("vString", combinedVersionString2PrettyString(Float.toString(version))); sboard.setConfig("vString", combinedVersionString2PrettyString(Float.toString(version)));
sb.setConfig("vdate", vDATE); sboard.setConfig("vdate", vDATE);
sb.setConfig("applicationRoot", homePath); sboard.setConfig("applicationRoot", homePath);
sb.setConfig("startupTime", Long.toString(startup)); sboard.setConfig("startupTime", Long.toString(startup));
serverLog.logConfig("STARTUP", "YACY Version: " + version + ", Built " + vDATE); serverLog.logConfig("STARTUP", "YACY Version: " + version + ", Built " + vDATE);
yacyCore.latestVersion = (float) version; yacyCore.latestVersion = (float) version;
// read environment // read environment
//new //new
int port = Integer.parseInt(sb.getConfig("port", "8080")); final int port = Integer.parseInt(sboard.getConfig("port", "8080"));
int timeout = Integer.parseInt(sb.getConfig("httpdTimeout", "60000")); int timeout = Integer.parseInt(sboard.getConfig("httpdTimeout", "60000"));
if (timeout < 60000) timeout = 60000; if (timeout < 60000) timeout = 60000;
// create some directories // create some directories
File htRootPath = new File(sb.getRootPath(), sb.getConfig("htRootPath", "htroot")); final File htRootPath = new File(sboard.getRootPath(), sboard.getConfig("htRootPath", "htroot"));
File htDocsPath = new File(sb.getRootPath(), sb.getConfig("htDocsPath", "DATA/HTDOCS")); final File htDocsPath = new File(sboard.getRootPath(), sboard.getConfig("htDocsPath", "DATA/HTDOCS"));
File htTemplatePath = new File(sb.getRootPath(), sb.getConfig("htTemplatePath","htdocs")); File htTemplatePath = new File(sboard.getRootPath(), sboard.getConfig("htTemplatePath","htdocs"));
// create default notifier picture // create default notifier picture
if (!((new File(htRootPath, "env/grafics/notifier.gif")).exists())) try { if (!((new File(htRootPath, "env/grafics/notifier.gif")).exists())) try {
@ -264,7 +262,7 @@ public final class yacy {
} catch (IOException e) {} } catch (IOException e) {}
if (!(htDocsPath.exists())) htDocsPath.mkdir(); if (!(htDocsPath.exists())) htDocsPath.mkdir();
File htdocsDefaultReadme = new File(htDocsPath, "readme.txt"); final File htdocsDefaultReadme = new File(htDocsPath, "readme.txt");
if (!(htdocsDefaultReadme.exists())) try {serverFileUtils.write(( if (!(htdocsDefaultReadme.exists())) try {serverFileUtils.write((
"This is your root directory for individual Web Content\r\n" + "This is your root directory for individual Web Content\r\n" +
"\r\n" + "\r\n" +
@ -281,10 +279,10 @@ public final class yacy {
System.out.println("Error creating htdocs readme: " + e.getMessage()); System.out.println("Error creating htdocs readme: " + e.getMessage());
} }
File wwwDefaultPath = new File(htDocsPath, "www"); final File wwwDefaultPath = new File(htDocsPath, "www");
if (!(wwwDefaultPath.exists())) wwwDefaultPath.mkdir(); if (!(wwwDefaultPath.exists())) wwwDefaultPath.mkdir();
File wwwDefaultClass = new File(wwwDefaultPath, "welcome.class"); final File wwwDefaultClass = new File(wwwDefaultPath, "welcome.class");
//if ((!(wwwDefaultClass.exists())) || (wwwDefaultClass.length() != (new File(htRootPath, "htdocsdefault/welcome.class")).length())) try { //if ((!(wwwDefaultClass.exists())) || (wwwDefaultClass.length() != (new File(htRootPath, "htdocsdefault/welcome.class")).length())) try {
if((new File(htRootPath, "htdocsdefault/welcome.java")).exists()) if((new File(htRootPath, "htdocsdefault/welcome.java")).exists())
serverFileUtils.copy(new File(htRootPath, "htdocsdefault/welcome.java"), new File(wwwDefaultPath, "welcome.java")); serverFileUtils.copy(new File(htRootPath, "htdocsdefault/welcome.java"), new File(wwwDefaultPath, "welcome.java"));
@ -292,10 +290,10 @@ public final class yacy {
serverFileUtils.copy(new File(htRootPath, "htdocsdefault/welcome.html"), new File(wwwDefaultPath, "welcome.html")); serverFileUtils.copy(new File(htRootPath, "htdocsdefault/welcome.html"), new File(wwwDefaultPath, "welcome.html"));
//} catch (IOException e) {} //} catch (IOException e) {}
File shareDefaultPath = new File(htDocsPath, "share"); final File shareDefaultPath = new File(htDocsPath, "share");
if (!(shareDefaultPath.exists())) shareDefaultPath.mkdir(); if (!(shareDefaultPath.exists())) shareDefaultPath.mkdir();
File shareDefaultClass = new File(shareDefaultPath, "dir.class"); final File shareDefaultClass = new File(shareDefaultPath, "dir.class");
//if ((!(shareDefaultClass.exists())) || (shareDefaultClass.length() != (new File(htRootPath, "htdocsdefault/dir.class")).length())) try { //if ((!(shareDefaultClass.exists())) || (shareDefaultClass.length() != (new File(htRootPath, "htdocsdefault/dir.class")).length())) try {
if((new File(htRootPath, "htdocsdefault/dir.java")).exists()) if((new File(htRootPath, "htdocsdefault/dir.java")).exists())
serverFileUtils.copy(new File(htRootPath, "htdocsdefault/dir.java"), new File(shareDefaultPath, "dir.java")); serverFileUtils.copy(new File(htRootPath, "htdocsdefault/dir.java"), new File(shareDefaultPath, "dir.java"));
@ -306,49 +304,57 @@ public final class yacy {
// set preset accounts/passwords // set preset accounts/passwords
String acc; String acc;
if ((acc = sb.getConfig("proxyAccount", "")).length() > 0) { if ((acc = sboard.getConfig("proxyAccount", "")).length() > 0) {
sb.setConfig("proxyAccountBase64MD5", serverCodings.standardCoder.encodeMD5Hex(serverCodings.standardCoder.encodeBase64String(acc))); // sboard.setConfig("proxyAccountBase64MD5", serverCodings.standardCoder.encodeMD5Hex(serverCodings.standardCoder.encodeBase64String(acc)));
sb.setConfig("proxyAccount", ""); sboard.setConfig("proxyAccountBase64MD5", de.anomic.server.serverCodings.encodeMD5Hex(serverCodings.standardCoder.encodeBase64String(acc)));
sboard.setConfig("proxyAccount", "");
} }
if ((acc = sb.getConfig("serverAccount", "")).length() > 0) { if ((acc = sboard.getConfig("serverAccount", "")).length() > 0) {
sb.setConfig("serverAccountBase64MD5", serverCodings.standardCoder.encodeMD5Hex(serverCodings.standardCoder.encodeBase64String(acc))); // sboard.setConfig("serverAccountBase64MD5", serverCodings.standardCoder.encodeMD5Hex(serverCodings.standardCoder.encodeBase64String(acc)));
sb.setConfig("serverAccount", ""); sboard.setConfig("serverAccountBase64MD5", de.anomic.server.serverCodings.encodeMD5Hex(serverCodings.standardCoder.encodeBase64String(acc)));
sboard.setConfig("serverAccount", "");
} }
if ((acc = sb.getConfig("adminAccount", "")).length() > 0) { if ((acc = sboard.getConfig("adminAccount", "")).length() > 0) {
sb.setConfig("adminAccountBase64MD5", serverCodings.standardCoder.encodeMD5Hex(serverCodings.standardCoder.encodeBase64String(acc))); // sboard.setConfig("adminAccountBase64MD5", serverCodings.standardCoder.encodeMD5Hex(serverCodings.standardCoder.encodeBase64String(acc)));
sb.setConfig("adminAccount", ""); sboard.setConfig("adminAccountBase64MD5", de.anomic.server.serverCodings.encodeMD5Hex(serverCodings.standardCoder.encodeBase64String(acc)));
sboard.setConfig("adminAccount", "");
} }
// fix unsafe old passwords // fix unsafe old passwords
if ((acc = sb.getConfig("proxyAccountBase64", "")).length() > 0) { if ((acc = sboard.getConfig("proxyAccountBase64", "")).length() > 0) {
sb.setConfig("proxyAccountBase64MD5", serverCodings.standardCoder.encodeMD5Hex(acc)); // sboard.setConfig("proxyAccountBase64MD5", serverCodings.standardCoder.encodeMD5Hex(acc));
sb.setConfig("proxyAccountBase64", ""); sboard.setConfig("proxyAccountBase64MD5", de.anomic.server.serverCodings.encodeMD5Hex(acc));
sboard.setConfig("proxyAccountBase64", "");
} }
if ((acc = sb.getConfig("serverAccountBase64", "")).length() > 0) { if ((acc = sboard.getConfig("serverAccountBase64", "")).length() > 0) {
sb.setConfig("serverAccountBase64MD5", serverCodings.standardCoder.encodeMD5Hex(acc)); // sboard.setConfig("serverAccountBase64MD5", serverCodings.standardCoder.encodeMD5Hex(acc));
sb.setConfig("serverAccountBase64", ""); sboard.setConfig("serverAccountBase64MD5", de.anomic.server.serverCodings.encodeMD5Hex(acc));
sboard.setConfig("serverAccountBase64", "");
} }
if ((acc = sb.getConfig("adminAccountBase64", "")).length() > 0) { if ((acc = sboard.getConfig("adminAccountBase64", "")).length() > 0) {
sb.setConfig("adminAccountBase64MD5", serverCodings.standardCoder.encodeMD5Hex(acc)); // sboard.setConfig("adminAccountBase64MD5", serverCodings.standardCoder.encodeMD5Hex(acc));
sb.setConfig("adminAccountBase64", ""); sboard.setConfig("adminAccountBase64MD5", de.anomic.server.serverCodings.encodeMD5Hex(acc));
sboard.setConfig("adminAccountBase64", "");
} }
if ((acc = sb.getConfig("uploadAccountBase64", "")).length() > 0) { if ((acc = sboard.getConfig("uploadAccountBase64", "")).length() > 0) {
sb.setConfig("uploadAccountBase64MD5", serverCodings.standardCoder.encodeMD5Hex(acc)); // sboard.setConfig("uploadAccountBase64MD5", serverCodings.standardCoder.encodeMD5Hex(acc));
sb.setConfig("uploadAccountBase64", ""); sboard.setConfig("uploadAccountBase64MD5", de.anomic.server.serverCodings.encodeMD5Hex(acc));
sboard.setConfig("uploadAccountBase64", "");
} }
if ((acc = sb.getConfig("downloadAccountBase64", "")).length() > 0) { if ((acc = sboard.getConfig("downloadAccountBase64", "")).length() > 0) {
sb.setConfig("downloadAccountBase64MD5", serverCodings.standardCoder.encodeMD5Hex(acc)); // sboard.setConfig("downloadAccountBase64MD5", serverCodings.standardCoder.encodeMD5Hex(acc));
sb.setConfig("downloadAccountBase64", ""); sboard.setConfig("downloadAccountBase64MD5", de.anomic.server.serverCodings.encodeMD5Hex(acc));
sboard.setConfig("downloadAccountBase64", "");
} }
// start main threads // start main threads
try { try {
httpd protocolHandler = new httpd(sb, new httpdFileHandler(sb), new httpdProxyHandler(sb)); final httpd protocolHandler = new httpd(sboard, new httpdFileHandler(sboard), new httpdProxyHandler(sboard));
serverCore server = new serverCore(port, final serverCore server = new serverCore(port,
timeout /*control socket timeout in milliseconds*/, timeout /*control socket timeout in milliseconds*/,
true /* block attacks (wrong protocol) */, true /* block attacks (wrong protocol) */,
protocolHandler /*command class*/, protocolHandler /*command class*/,
sb, sboard,
30000 /*command max length incl. GET args*/); 30000 /*command max length incl. GET args*/);
server.setName("httpd:"+port); server.setName("httpd:"+port);
server.setPriority(Thread.MAX_PRIORITY); server.setPriority(Thread.MAX_PRIORITY);
@ -356,23 +362,23 @@ public final class yacy {
serverLog.logSevere("STARTUP", "Failed to start server. Probably port " + port + " already in use."); serverLog.logSevere("STARTUP", "Failed to start server. Probably port " + port + " already in use.");
} else { } else {
// first start the server // first start the server
sb.deployThread("10_httpd", "HTTPD Server/Proxy", "the HTTPD, used as web server and proxy", null, server, 0, 0, 0, 0); sboard.deployThread("10_httpd", "HTTPD Server/Proxy", "the HTTPD, used as web server and proxy", null, server, 0, 0, 0, 0);
//server.start(); //server.start();
// open the browser window // open the browser window
boolean browserPopUpTrigger = sb.getConfig("browserPopUpTrigger", "true").equals("true"); final boolean browserPopUpTrigger = sboard.getConfig("browserPopUpTrigger", "true").equals("true");
if (browserPopUpTrigger) { if (browserPopUpTrigger) {
String browserPopUpPage = sb.getConfig("browserPopUpPage", "Status.html"); final String browserPopUpPage = sboard.getConfig("browserPopUpPage", "Status.html");
String browserPopUpApplication = sb.getConfig("browserPopUpApplication", "netscape"); final String browserPopUpApplication = sboard.getConfig("browserPopUpApplication", "netscape");
serverSystem.openBrowser("http://localhost:" + port + "/" + browserPopUpPage, browserPopUpApplication); serverSystem.openBrowser("http://localhost:" + port + "/" + browserPopUpPage, browserPopUpApplication);
} }
//Copy the shipped locales into DATA //Copy the shipped locales into DATA
File localesPath = new File(sb.getRootPath(), sb.getConfig("localesPath", "DATA/LOCALE")); final File localesPath = new File(sboard.getRootPath(), sboard.getConfig("localesPath", "DATA/LOCALE"));
File defaultLocalesPath = new File(sb.getRootPath(), "locales"); final File defaultLocalesPath = new File(sboard.getRootPath(), "locales");
try{ try{
File[] defaultLocales = defaultLocalesPath.listFiles(); final File[] defaultLocales = defaultLocalesPath.listFiles();
localesPath.mkdirs(); localesPath.mkdirs();
for(int i=0;i < defaultLocales.length; i++){ for(int i=0;i < defaultLocales.length; i++){
if(defaultLocales[i].getName().endsWith(".lng")) if(defaultLocales[i].getName().endsWith(".lng"))
@ -384,11 +390,11 @@ public final class yacy {
} }
//regenerate Locales from Translationlist, if needed //regenerate Locales from Translationlist, if needed
String lang = sb.getConfig("htLocaleSelection", ""); final String lang = sboard.getConfig("htLocaleSelection", "");
if(! lang.equals("") && ! lang.equals("default") ){ //locale is used if(! lang.equals("") && ! lang.equals("default") ){ //locale is used
String currentRev = ""; String currentRev = "";
try{ try{
BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(new File( sb.getConfig("htRootPath", "htroot"), "locale/"+lang+"/version" )))); final BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(new File( sboard.getConfig("htRootPath", "htroot"), "locale/"+lang+"/version" ))));
currentRev = br.readLine(); currentRev = br.readLine();
br.close(); br.close();
}catch(IOException e){ }catch(IOException e){
@ -396,14 +402,14 @@ public final class yacy {
} }
try{ //seperate try, because we want this, even when the File "version2 does not exist. try{ //seperate try, because we want this, even when the File "version2 does not exist.
if(! currentRev.equals(sb.getConfig("svnRevision", "")) ){ //is this another version?! if(! currentRev.equals(sboard.getConfig("svnRevision", "")) ){ //is this another version?!
File sourceDir = new File(sb.getConfig("htRootPath", "htroot")); final File sourceDir = new File(sboard.getConfig("htRootPath", "htroot"));
File destDir = new File(sourceDir, "locale/"+lang); final File destDir = new File(sourceDir, "locale/"+lang);
if(translator.translateFiles(sourceDir, destDir, new File("DATA/LOCALE/"+lang+".lng"), "html")){ //translate it if(translator.translateFiles(sourceDir, destDir, new File("DATA/LOCALE/"+lang+".lng"), "html")){ //translate it
//if(translator.translateFilesRecursive(sourceDir, destDir, new File("DATA/LOCALE/"+lang+".lng"), "html")){ //translate it //if(translator.translateFilesRecursive(sourceDir, destDir, new File("DATA/LOCALE/"+lang+".lng"), "html")){ //translate it
//write the new Versionnumber //write the new Versionnumber
BufferedWriter bw = new BufferedWriter(new PrintWriter(new FileWriter(new File(destDir, "version")))); final BufferedWriter bw = new BufferedWriter(new PrintWriter(new FileWriter(new File(destDir, "version"))));
bw.write(sb.getConfig("svnRevision", "Error getting Version")); bw.write(sboard.getConfig("svnRevision", "Error getting Version"));
bw.close(); bw.close();
} }
} }
@ -414,15 +420,15 @@ public final class yacy {
// registering shutdown hook // registering shutdown hook
serverLog.logConfig("STARTUP", "Registering Shutdown Hook"); serverLog.logConfig("STARTUP", "Registering Shutdown Hook");
Runtime run = Runtime.getRuntime(); final Runtime run = Runtime.getRuntime();
run.addShutdownHook(new shutdownHookThread(Thread.currentThread(), sb)); run.addShutdownHook(new shutdownHookThread(Thread.currentThread(), sboard));
// save information about available memory after all initializations // save information about available memory after all initializations
System.gc(); sb.setConfig("memoryFreeAfterInit", Runtime.getRuntime().freeMemory()); System.gc(); sboard.setConfig("memoryFreeAfterInit", Runtime.getRuntime().freeMemory());
// wait for server shutdown // wait for server shutdown
try { try {
sb.waitForShutdown(); sboard.waitForShutdown();
} catch (Exception e) { } catch (Exception e) {
serverLog.logSevere("MAIN CONTROL LOOP", "PANIK: " + e.getMessage(),e); serverLog.logSevere("MAIN CONTROL LOOP", "PANIK: " + e.getMessage(),e);
} }
@ -443,7 +449,7 @@ public final class yacy {
Thread.currentThread().sleep(2000); // wait a while Thread.currentThread().sleep(2000); // wait a while
} }
serverLog.logConfig("SHUTDOWN", "server has terminated"); serverLog.logConfig("SHUTDOWN", "server has terminated");
sb.close(); sboard.close();
} }
} catch (Exception e) { } catch (Exception e) {
serverLog.logSevere("STARTUP", "Unexpected Error: " + e.getClass().getName(),e); serverLog.logSevere("STARTUP", "Unexpected Error: " + e.getClass().getName(),e);
@ -454,6 +460,7 @@ public final class yacy {
} }
serverLog.logConfig("SHUTDOWN", "goodbye. (this is the last line)"); serverLog.logConfig("SHUTDOWN", "goodbye. (this is the last line)");
try { try {
// if (restart) startup(homePath);
System.exit(0); System.exit(0);
} catch (Exception e) {} // was once stopped by de.anomic.net.ftpc$sm.checkExit(ftpc.java:1790) } catch (Exception e) {} // was once stopped by de.anomic.net.ftpc$sm.checkExit(ftpc.java:1790)
} }
@ -818,22 +825,22 @@ public final class yacy {
* machine shuts down. Signals the plasmaSwitchboard to shut down. * machine shuts down. Signals the plasmaSwitchboard to shut down.
*/ */
class shutdownHookThread extends Thread { class shutdownHookThread extends Thread {
private plasmaSwitchboard sb = null; private plasmaSwitchboard sboard = null;
private Thread mainThread = null; private Thread mainThread = null;
public shutdownHookThread(Thread mainThread, plasmaSwitchboard sb) { public shutdownHookThread(Thread mainThread, plasmaSwitchboard sboard) {
this.sb = sb; super();
this.sboard = sboard;
this.mainThread = mainThread; this.mainThread = mainThread;
} }
public void run() { public void run() {
try { try {
if (!this.sb.isTerminated()) { if (!this.sboard.isTerminated()) {
serverLog.logConfig("SHUTDOWN","Shutdown via shutdown hook."); serverLog.logConfig("SHUTDOWN","Shutdown via shutdown hook.");
// sending the yacy main thread a shutdown signal // sending the yacy main thread a shutdown signal
this.sb.terminate(); this.sboard.terminate();
// waiting for the yacy thread to finish execution // waiting for the yacy thread to finish execution
this.mainThread.join(); this.mainThread.join();

Loading…
Cancel
Save