@ -84,40 +84,40 @@ import net.yacy.utils.translation.TranslatorXliff;
/ * *
* This is the main class of YaCy . Several threads are started from here :
* < ul >
* < li > one single instance of the plasmaSwitchboard is generated , which itself
* starts a thread with a plasmaHTMLCache object . This object simply counts
* files sizes in the cache and terminates them . It also generates a
* plasmaCrawlerLoader object , which may itself start some more httpc - calling
* threads to load web pages . They terminate automatically when a page has
* loaded .
* < li > one serverCore - thread is started , which implements a multi - threaded
* server . The process may start itself many more processes that handle
* connections . lo
* < li > finally , all idle - dependent processes are written in a queue in
* plasmaSwitchboard which are worked off inside an idle - sensitive loop of the
* main process . ( here )
* < / ul >
*
* On termination , the following must be done :
* < ul >
* < li > stop feeding of the crawling process because it otherwise fills the
* indexing queue .
* < li > say goodbye to connected peers and disable new connections . Don ' t wait for
* success .
* < li > first terminate the serverCore thread . This prevents that new cache
* objects are queued .
* < li > wait that the plasmaHTMLCache terminates ( it should be normal that this
* process already has terminated ) .
* < li > then wait for termination of all loader process of the
* plasmaCrawlerLoader .
* < li > work off the indexing and cache storage queue . These values are inside a
* RAM cache and would be lost otherwise .
* < li > write all settings .
* < li > terminate .
* < / ul >
* /
* This is the main class of YaCy . Several threads are started from here :
* < ul >
* < li > one single instance of the plasmaSwitchboard is generated , which itself
* starts a thread with a plasmaHTMLCache object . This object simply counts
* files sizes in the cache and terminates them . It also generates a
* plasmaCrawlerLoader object , which may itself start some more httpc - calling
* threads to load web pages . They terminate automatically when a page has
* loaded .
* < li > one serverCore - thread is started , which implements a multi - threaded
* server . The process may start itself many more processes that handle
* connections . lo
* < li > finally , all idle - dependent processes are written in a queue in
* plasmaSwitchboard which are worked off inside an idle - sensitive loop of the
* main process . ( here )
* < / ul >
*
* On termination , the following must be done :
* < ul >
* < li > stop feeding of the crawling process because it otherwise fills the
* indexing queue .
* < li > say goodbye to connected peers and disable new connections . Don ' t wait for
* success .
* < li > first terminate the serverCore thread . This prevents that new cache
* objects are queued .
* < li > wait that the plasmaHTMLCache terminates ( it should be normal that this
* process already has terminated ) .
* < li > then wait for termination of all loader process of the
* plasmaCrawlerLoader .
* < li > work off the indexing and cache storage queue . These values are inside a
* RAM cache and would be lost otherwise .
* < li > write all settings .
* < li > terminate .
* < / ul >
* /
public final class yacy {
@ -139,12 +139,12 @@ public final class yacy {
private static Switchboard sb = null ;
/ * *
* Starts up the whole application . Sets up all datastructures and starts
* the main threads .
*
* @param homePath Root - path where all information is to be found .
* @param startupFree free memory at startup time , to be used later for statistics
* /
* Starts up the whole application . Sets up all datastructures and starts
* the main threads .
*
* @param homePath Root - path where all information is to be found .
* @param startupFree free memory at startup time , to be used later for statistics
* /
private static void startup ( final File dataHome , final File appHome , final long startupMemFree , final long startupMemTotal , final boolean gui ) {
String tmpdir = null ;
try {
@ -185,7 +185,7 @@ public final class yacy {
System . out . println ( "could not find logging properties in homePath=" + dataHome ) ;
ConcurrentLog . logException ( e ) ;
}
ConcurrentLog . config ( "STARTUP" , "YaCy version: " + yacyBuildProperties . get Version( ) + "/" + yacyBuildProperties . getSVNRevision ( ) ) ;
ConcurrentLog . config ( "STARTUP" , "YaCy version: " + yacyBuildProperties . get ReleaseStub ( ) ) ;
ConcurrentLog . config ( "STARTUP" , "Java version: " + System . getProperty ( "java.version" , "no-java-version" ) ) ;
ConcurrentLog . config ( "STARTUP" , "Operation system: " + System . getProperty ( "os.name" , "unknown" ) ) ;
ConcurrentLog . config ( "STARTUP" , "Application root-path: " + appHome ) ;
@ -235,7 +235,7 @@ public final class yacy {
if ( oldRev > 1 ) {
oldVer = Double . parseDouble ( tmpversion ) + oldRev / 100000000.0 ;
} else {
oldVer = Double . parseDouble ( yacyBuildProperties . get Long Version( ) ) ; // failsafe (assume current version = no migration)
oldVer = Double . parseDouble ( yacyBuildProperties . get Version( ) ) ; // failsafe (assume current version = no migration)
}
} else {
oldVer = Double . parseDouble ( tmpversion ) ;
@ -243,8 +243,8 @@ public final class yacy {
} catch ( final NumberFormatException e ) {
oldVer = 0.0d ;
}
final double newRev = Double . parseDouble ( yacyBuildProperties . get Long Version( ) ) ;
sb . setConfig ( Seed . VERSION , yacyBuildProperties . get Long Version( ) ) ;
final double newRev = Double . parseDouble ( yacyBuildProperties . get Version( ) ) ;
sb . setConfig ( Seed . VERSION , yacyBuildProperties . get Version( ) ) ;
sb . setConfig ( "applicationRoot" , appHome . toString ( ) ) ;
sb . setConfig ( "dataRoot" , dataHome . toString ( ) ) ;
@ -262,16 +262,16 @@ public final class yacy {
final File htdocsReadme = new File ( htDocsPath , "readme.txt" ) ;
if ( ! ( htdocsReadme . exists ( ) ) ) try { FileUtils . copy ( (
"This is your root directory for individual Web Content\r\n" +
"\r\n" +
"Please place your html files into the www subdirectory.\r\n" +
"The URL of that path is either\r\n" +
"http://www.<your-peer-name>.yacy or\r\n" +
"http://<your-ip>:<your-port>/www\r\n" +
"\r\n" +
"Other subdirectories may be created; they map to corresponding sub-domains.\r\n" +
"This directory shares it's content with the applications htroot path, so you\r\n" +
"may access your yacy search page with\r\n" +
"http://<your-peer-name>.yacy/\r\n" +
"\r\n" +
"Please place your html files into the www subdirectory.\r\n" +
"The URL of that path is either\r\n" +
"http://www.<your-peer-name>.yacy or\r\n" +
"http://<your-ip>:<your-port>/www\r\n" +
"\r\n" +
"Other subdirectories may be created; they map to corresponding sub-domains.\r\n" +
"This directory shares it's content with the applications htroot path, so you\r\n" +
"may access your yacy search page with\r\n" +
"http://<your-peer-name>.yacy/\r\n" +
"\r\n" ) . getBytes ( ) , htdocsReadme ) ; } catch ( final IOException e ) {
System . out . println ( "Error creating htdocs readme: " + e . getMessage ( ) ) ;
}
@ -314,7 +314,7 @@ public final class yacy {
Browser . openBrowser ( ( "http://localhost:" + port ) + "/" + browserPopUpPage ) ;
}
} . start ( ) ;
// Browser.openBrowser((server.withSSL()?"https":"http") + "://localhost:" + serverCore.getPortNr(port) + "/" + browserPopUpPage);
// Browser.openBrowser((server.withSSL()?"https":"http") + "://localhost:" + serverCore.getPortNr(port) + "/" + browserPopUpPage);
} catch ( final Throwable e ) {
// cannot open browser. This may be normal in headless environments
//Log.logException(e);
@ -377,11 +377,11 @@ public final class yacy {
// save information about available memory after all initializations
//try {
sb . setConfig ( "memoryFreeAfterInitBGC" , MemoryControl . free ( ) ) ;
sb . setConfig ( "memoryTotalAfterInitBGC" , MemoryControl . total ( ) ) ;
System . gc ( ) ;
sb . setConfig ( "memoryFreeAfterInitAGC" , MemoryControl . free ( ) ) ;
sb . setConfig ( "memoryTotalAfterInitAGC" , MemoryControl . total ( ) ) ;
sb . setConfig ( "memoryFreeAfterInitBGC" , MemoryControl . free ( ) ) ;
sb . setConfig ( "memoryTotalAfterInitBGC" , MemoryControl . total ( ) ) ;
System . gc ( ) ;
sb . setConfig ( "memoryFreeAfterInitAGC" , MemoryControl . free ( ) ) ;
sb . setConfig ( "memoryTotalAfterInitAGC" , MemoryControl . total ( ) ) ;
//} catch (final ConcurrentModificationException e) {}
// wait for server shutdown
@ -446,15 +446,15 @@ public final class yacy {
}
/ * *
* Loads the configuration from the data - folder .
* FIXME : Why is this called over and over again from every method , instead
* of setting the configurationdata once for this class in main ?
*
* @param mes Where are we called from , so that the errormessages can be
* more descriptive .
* @param homePath Root - path where all the information is to be found .
* @return Properties read from the configurationfile .
* /
* Loads the configuration from the data - folder .
* FIXME : Why is this called over and over again from every method , instead
* of setting the configurationdata once for this class in main ?
*
* @param mes Where are we called from , so that the errormessages can be
* more descriptive .
* @param homePath Root - path where all the information is to be found .
* @return Properties read from the configurationfile .
* /
private static Properties configuration ( final String mes , final File homePath ) {
ConcurrentLog . config ( mes , "Application Root Path: " + homePath . toString ( ) ) ;
@ -490,11 +490,11 @@ public final class yacy {
}
/ * *
* Call the shutdown - page of YaCy to tell it to shut down . This method is
* called if you start yacy with the argument - shutdown .
*
* @param homePath Root - path where all the information is to be found .
* /
* Call the shutdown - page of YaCy to tell it to shut down . This method is
* called if you start yacy with the argument - shutdown .
*
* @param homePath Root - path where all the information is to be found .
* /
public static void shutdown ( final File homePath ) {
// start up
System . out . println ( copyright ) ;
@ -773,51 +773,51 @@ public final class yacy {
// show yacy version
System . out . println ( copyright ) ;
} else if ( ( args . length > 1 ) & & ( args [ 0 ] . toLowerCase ( Locale . ROOT ) . equals ( "-config" ) ) ) {
// set config parameter. Special handling of adminAccount=user:pwd (generates md5 encoded password)
// on Windows parameter should be enclosed in doublequotes to accept = sign (e.g. -config "port=8090" "port.ssl=8043")
final File f = new File ( dataRoot , "DATA/SETTINGS/" ) ;
if ( ! f . exists ( ) ) {
mkdirsIfNeseccary ( f ) ;
} else {
if ( new File ( dataRoot , "DATA/yacy.running" ) . exists ( ) ) {
System . out . println ( "please restart YaCy" ) ;
}
// set config parameter. Special handling of adminAccount=user:pwd (generates md5 encoded password)
// on Windows parameter should be enclosed in doublequotes to accept = sign (e.g. -config "port=8090" "port.ssl=8043")
final File f = new File ( dataRoot , "DATA/SETTINGS/" ) ;
if ( ! f . exists ( ) ) {
mkdirsIfNeseccary ( f ) ;
} else {
if ( new File ( dataRoot , "DATA/yacy.running" ) . exists ( ) ) {
System . out . println ( "please restart YaCy" ) ;
}
// use serverSwitch to read config properties (including init values from yacy.init
final serverSwitch ss = new serverSwitch ( dataRoot , applicationRoot , "defaults/yacy.init" , "DATA/SETTINGS/yacy.conf" ) ;
for ( int icnt = 1 ; icnt < args . length ; icnt + + ) {
final String cfg = args [ icnt ] ;
final int pos = cfg . indexOf ( '=' ) ;
if ( pos > 0 ) {
final String cmd = cfg . substring ( 0 , pos ) ;
final String val = cfg . substring ( pos + 1 ) ;
if ( ! val . isEmpty ( ) ) {
if ( cmd . equalsIgnoreCase ( SwitchboardConstants . ADMIN_ACCOUNT ) ) { // special command to set adminusername and md5-pwd
final int cpos = val . indexOf ( ':' ) ; //format adminAccount=adminname:adminpwd
if ( cpos > = 0 ) {
String username = val . substring ( 0 , cpos ) ;
final String pwdtxt = val . substring ( cpos + 1 ) ;
if ( ! username . isEmpty ( ) ) {
ss . setConfig ( SwitchboardConstants . ADMIN_ACCOUNT_USER_NAME , username ) ;
System . out . println ( "Set property " + SwitchboardConstants . ADMIN_ACCOUNT_USER_NAME + " = " + username ) ;
} else {
username = ss . getConfig ( SwitchboardConstants . ADMIN_ACCOUNT_USER_NAME , "admin" ) ;
}
ss . setConfig ( SwitchboardConstants . ADMIN_ACCOUNT_B64MD5 , sb . encodeDigestAuth ( username , pwdtxt ) ) ;
System . out . println ( "Set property " + SwitchboardConstants . ADMIN_ACCOUNT_B64MD5 + " = " + ss . getConfig ( SwitchboardConstants . ADMIN_ACCOUNT_B64MD5 , "" ) ) ;
}
// use serverSwitch to read config properties (including init values from yacy.init
final serverSwitch ss = new serverSwitch ( dataRoot , applicationRoot , "defaults/yacy.init" , "DATA/SETTINGS/yacy.conf" ) ;
for ( int icnt = 1 ; icnt < args . length ; icnt + + ) {
final String cfg = args [ icnt ] ;
final int pos = cfg . indexOf ( '=' ) ;
if ( pos > 0 ) {
final String cmd = cfg . substring ( 0 , pos ) ;
final String val = cfg . substring ( pos + 1 ) ;
if ( ! val . isEmpty ( ) ) {
if ( cmd . equalsIgnoreCase ( SwitchboardConstants . ADMIN_ACCOUNT ) ) { // special command to set adminusername and md5-pwd
final int cpos = val . indexOf ( ':' ) ; //format adminAccount=adminname:adminpwd
if ( cpos > = 0 ) {
String username = val . substring ( 0 , cpos ) ;
final String pwdtxt = val . substring ( cpos + 1 ) ;
if ( ! username . isEmpty ( ) ) {
ss . setConfig ( SwitchboardConstants . ADMIN_ACCOUNT_USER_NAME , username ) ;
System . out . println ( "Set property " + SwitchboardConstants . ADMIN_ACCOUNT_USER_NAME + " = " + username ) ;
} else {
username = ss . getConfig ( SwitchboardConstants . ADMIN_ACCOUNT_USER_NAME , "admin" ) ;
}
} else {
ss . setConfig ( cmd , val ) ;
System . out . println ( "Set property " + cmd + " = " + val ) ;
ss . setConfig ( SwitchboardConstants . ADMIN_ACCOUNT_B64MD5 , sb . encodeDigestAuth ( username , pwdtxt ) ) ;
System . out . println ( "Set property " + SwitchboardConstants . ADMIN_ACCOUNT_B64MD5 + " = " + ss . getConfig ( SwitchboardConstants . ADMIN_ACCOUNT_B64MD5 , "" ) ) ;
}
} else {
ss . setConfig ( cmd , val ) ;
System . out . println ( "Set property " + cmd + " = " + val ) ;
}
} else {
System . out . println ( "skip parameter " + cfg + " (equal sign missing, put parameter in doublequotes)" ) ;
}
System . out . println ( ) ;
} else {
System . out . println ( "skip parameter " + cfg + " (equal sign missing, put parameter in doublequotes)" ) ;
}
System . out . println ( ) ;
}
} else {
if ( args . length = = 1 ) {
applicationRoot = new File ( args [ 0 ] ) ;
@ -832,9 +832,9 @@ public final class yacy {
}
/ * *
* This class is a helper class whose instance is started , when the java virtual
* machine shuts down . Signals the plasmaSwitchboard to shut down .
* /
* This class is a helper class whose instance is started , when the java virtual
* machine shuts down . Signals the plasmaSwitchboard to shut down .
* /
class shutdownHookThread extends Thread {
private final Switchboard sb ;
private final Semaphore shutdownSemaphore ;