Author: nextgens
Date: 2008-06-21 13:28:23 +0000 (Sat, 21 Jun 2008)
New Revision: 20565
Modified:
trunk/freenet/src/freenet/node/NodeStarter.java
Log:
indent
Modified: trunk/freenet/src/freenet/node/NodeStarter.java
===================================================================
--- trunk/freenet/src/freenet/node/NodeStarter.java 2008-06-21 12:54:03 UTC
(rev 20564)
+++ trunk/freenet/src/freenet/node/NodeStarter.java 2008-06-21 13:28:23 UTC
(rev 20565)
@@ -23,103 +23,101 @@
import freenet.support.SimpleFieldSet;
import freenet.support.LoggerHook.InvalidThresholdException;
import freenet.support.io.NativeThread;
-
/**
* @author nextgens
*
* A class to tie the wrapper and the node (needed for self-restarting
support)
*/
-public class NodeStarter implements WrapperListener
-{
- private Node node;
+public class NodeStarter implements WrapperListener {
+
+ private Node node;
private static LoggingConfigHandler logConfigHandler;
public final static int RECOMMENDED_EXT_BUILD_NUMBER = 20;
-
/*
(File.separatorChar == '\\') &&
(System.getProperty("os.arch").toLowerCase().matches("(i?[x0-9]86_64|amd64)"))
? 6 : 2;
- */
+ */
public static int extBuildNumber;
public static String extRevisionNumber;
private FreenetFilePersistentConfig cfg;
- /*---------------------------------------------------------------
- * Constructors
- *-------------------------------------------------------------*/
- private NodeStarter(){}
-
- public NodeStarter get(){
- return this;
- }
+ /*---------------------------------------------------------------
+ * Constructors
+ *-------------------------------------------------------------*/
+ private NodeStarter() {
+ }
- /*---------------------------------------------------------------
- * WrapperListener Methods
- *-------------------------------------------------------------*/
- /**
- * The start method is called when the WrapperManager is signaled by the
- * native wrapper code that it can start its application. This
- * method call is expected to return, so a new thread should be launched
- * if necessary.
- *
- * @param args List of arguments used to initialize the application.
- *
- * @return Any error code if the application should exit on completion
- * of the start method. If there were no problems then this
- * method should return null.
- */
- public Integer start( String[] args )
- {
- if(args.length>1) {
- System.out.println("Usage: $ java freenet.node.Node
<configFile>");
- return new Integer(-1);
- }
-
- getExtBuild();
-
- File configFilename;
- if(args.length == 0) {
- System.out.println("Using default config filename freenet.ini");
- configFilename = new File("freenet.ini");
- } else
- configFilename = new File(args[0]);
-
- // set Java's DNS cache not to cache forever, since many people
- // use dyndns hostnames
- java.security.Security.setProperty("networkaddress.cache.ttl" , "0");
- java.security.Security.setProperty("networkaddress.cache.negative.ttl"
, "0");
-
- try{
- cfg =
FreenetFilePersistentConfig.constructFreenetFilePersistentConfig(configFilename);
- }catch(IOException e){
- System.out.println("Error : "+e);
- e.printStackTrace();
- return new Integer(-1);
- }
-
- // First, set up logging. It is global, and may be shared between
several nodes.
- SubConfig loggingConfig = new SubConfig("logger", cfg);
-
- PooledExecutor executor = new PooledExecutor();
-
- try {
- logConfigHandler = new LoggingConfigHandler(loggingConfig,
executor);
- } catch (InvalidConfigValueException e) {
- System.err.println("Error: could not set up logging:
"+e.getMessage());
- e.printStackTrace();
- return new Integer(-2);
- }
+ public NodeStarter get() {
+ return this;
+ }
- executor.start();
-
- // Prevent timeouts for a while. The DiffieHellman init for example
could take some time on a very slow system.
- WrapperManager.signalStarting(500000);
-
- // Setup RNG
- RandomSource random = new Yarrow();
-
- DiffieHellman.init(random);
-
+ /*---------------------------------------------------------------
+ * WrapperListener Methods
+ *-------------------------------------------------------------*/
+ /**
+ * The start method is called when the WrapperManager is signaled by
the
+ * native wrapper code that it can start its application. This
+ * method call is expected to return, so a new thread should be
launched
+ * if necessary.
+ *
+ * @param args List of arguments used to initialize the application.
+ *
+ * @return Any error code if the application should exit on completion
+ * of the start method. If there were no problems then this
+ * method should return null.
+ */
+ public Integer start(String[] args) {
+ if(args.length > 1) {
+ System.out.println("Usage: $ java freenet.node.Node
<configFile>");
+ return new Integer(-1);
+ }
+
+ getExtBuild();
+
+ File configFilename;
+ if(args.length == 0) {
+ System.out.println("Using default config filename
freenet.ini");
+ configFilename = new File("freenet.ini");
+ } else
+ configFilename = new File(args[0]);
+
+ // set Java's DNS cache not to cache forever, since many people
+ // use dyndns hostnames
+ java.security.Security.setProperty("networkaddress.cache.ttl",
"0");
+
java.security.Security.setProperty("networkaddress.cache.negative.ttl", "0");
+
+ try {
+ cfg =
FreenetFilePersistentConfig.constructFreenetFilePersistentConfig(configFilename);
+ } catch(IOException e) {
+ System.out.println("Error : " + e);
+ e.printStackTrace();
+ return new Integer(-1);
+ }
+
+ // First, set up logging. It is global, and may be shared
between several nodes.
+ SubConfig loggingConfig = new SubConfig("logger", cfg);
+
+ PooledExecutor executor = new PooledExecutor();
+
+ try {
+ logConfigHandler = new
LoggingConfigHandler(loggingConfig, executor);
+ } catch(InvalidConfigValueException e) {
+ System.err.println("Error: could not set up logging: "
+ e.getMessage());
+ e.printStackTrace();
+ return new Integer(-2);
+ }
+
+ executor.start();
+
+ // Prevent timeouts for a while. The DiffieHellman init for
example could take some time on a very slow system.
+ WrapperManager.signalStarting(500000);
+
+ // Setup RNG
+ RandomSource random = new Yarrow();
+
+ DiffieHellman.init(random);
+
// Thread to keep the node up.
// JVM deadlocks losing a lock when two threads of different
types (daemon|app)
// are contended for the same lock. So make USM daemon, and use
useless to keep the JVM
@@ -127,53 +125,55 @@
//
http://forum.java.sun.com/thread.jspa?threadID=343023&messageID=2942637 - last
message
Runnable useless =
new Runnable() {
- public void run() {
- while(true)
- try {
- Thread.sleep(60*60*1000);
- } catch (InterruptedException e) {
- // Ignore
- } catch (Throwable t) {
+
+ public void run() {
+ while(true) {
try {
- Logger.error(this,
"Caught "+t, t);
- } catch (Throwable t1) {
+ Thread.sleep(60 * 60 *
1000);
+ } catch(InterruptedException e)
{
// Ignore
+ } catch(Throwable t) {
+ try {
+
Logger.error(this, "Caught " + t, t);
+ } catch(Throwable t1) {
+ // Ignore
+ }
}
}
- }
- };
+ }
+ };
NativeThread plug = new NativeThread(useless, "Plug",
NativeThread.MAX_PRIORITY, false);
// Not daemon, but doesn't do anything.
// Keeps the JVM alive.
// DO NOT do anything in the plug thread, if you do you risk
the EvilJVMBug.
plug.setDaemon(false);
plug.start();
-
+
// Initialize SSL
- SubConfig sslConfig = new SubConfig("ssl", cfg);
- SSL.init(sslConfig);
-
- try {
- node = new Node(cfg, random, logConfigHandler,this, executor);
- node.start(false);
- System.out.println("Node initialization completed.");
- } catch (NodeInitException e) {
- System.err.println("Failed to load node: "+e.getMessage());
- e.printStackTrace();
- System.exit(e.exitCode);
- }
-
+ SubConfig sslConfig = new SubConfig("ssl", cfg);
+ SSL.init(sslConfig);
+
+ try {
+ node = new Node(cfg, random, logConfigHandler, this,
executor);
+ node.start(false);
+ System.out.println("Node initialization completed.");
+ } catch(NodeInitException e) {
+ System.err.println("Failed to load node: " +
e.getMessage());
+ e.printStackTrace();
+ System.exit(e.exitCode);
+ }
+
return null;
- }
+ }
- private void getExtBuild() {
- try{
- extBuildNumber = ExtVersion.buildNumber;
+ private void getExtBuild() {
+ try {
+ extBuildNumber = ExtVersion.buildNumber;
extRevisionNumber = ExtVersion.cvsRevision;
- String builtWithMessage = "freenet.jar built with
freenet-ext.jar Build #"+extBuildNumber+" r"+extRevisionNumber;
+ String builtWithMessage = "freenet.jar built with
freenet-ext.jar Build #" + extBuildNumber + " r" + extRevisionNumber;
Logger.normal(this, builtWithMessage);
System.out.println(builtWithMessage);
- extBuildNumber = ExtVersion.buildNumber();
+ extBuildNumber = ExtVersion.buildNumber();
if(extBuildNumber == -42) {
extBuildNumber = ExtVersion.extBuildNumber();
extRevisionNumber =
ExtVersion.extRevisionNumber();
@@ -190,145 +190,142 @@
System.err.println(revisionMessage);
extRevisionNumber = "INVALID";
}
- }catch(Throwable t){
- // Compatibility code ... will be removed
- Logger.error(this, "Unable to get the version of your
freenet-ext file : it's probably corrupted!");
- System.err.println("Unable to get the version of your
freenet-ext file : it's probably corrupted!");
- System.err.println(t.getMessage());
- extRevisionNumber = "INVALID";
- extBuildNumber = -1;
- }
+ } catch(Throwable t) {
+ // Compatibility code ... will be removed
+ Logger.error(this, "Unable to get the version of your
freenet-ext file : it's probably corrupted!");
+ System.err.println("Unable to get the version of your
freenet-ext file : it's probably corrupted!");
+ System.err.println(t.getMessage());
+ extRevisionNumber = "INVALID";
+ extBuildNumber = -1;
+ }
}
/**
- * Called when the application is shutting down. The Wrapper assumes that
- * this method will return fairly quickly. If the shutdown code code
- * could potentially take a long time, then
WrapperManager.signalStopping()
- * should be called to extend the timeout period. If for some reason,
- * the stop method can not return, then it must call
- * WrapperManager.stopped() to avoid warning messages from the Wrapper.
- *
- * @param exitCode The suggested exit code that will be returned to the OS
- * when the JVM exits.
- *
- * @return The exit code to actually return to the OS. In most cases, this
- * should just be the value of exitCode, however the user code has
- * the option of changing the exit code if there are any problems
- * during shutdown.
- */
- public int stop( int exitCode )
- {
- System.err.println("Shutting down with exit code "+exitCode);
- node.park();
- // see #354
- WrapperManager.signalStopping(120000);
-
- return exitCode;
- }
-
- public void restart(){
- WrapperManager.restart();
- }
-
- /**
- * Called whenever the native wrapper code traps a system control signal
- * against the Java process. It is up to the callback to take any actions
- * necessary. Possible values are: WrapperManager.WRAPPER_CTRL_C_EVENT,
- * WRAPPER_CTRL_CLOSE_EVENT, WRAPPER_CTRL_LOGOFF_EVENT, or
- * WRAPPER_CTRL_SHUTDOWN_EVENT
- *
- * @param event The system control signal.
- */
- public void controlEvent( int event )
- {
- if (WrapperManager.isControlledByNativeWrapper()) {
- // The Wrapper will take care of this event
- } else {
- // We are not being controlled by the Wrapper, so
- // handle the event ourselves.
- if ((event == WrapperManager.WRAPPER_CTRL_C_EVENT) ||
- (event == WrapperManager.WRAPPER_CTRL_CLOSE_EVENT) ||
- (event == WrapperManager.WRAPPER_CTRL_SHUTDOWN_EVENT)){
- WrapperManager.stop(0);
- }
- }
- }
-
- /*---------------------------------------------------------------
- * Main Method
- *-------------------------------------------------------------*/
- public static void main( String[] args )
- {
- // Start the application. If the JVM was launched from the native
- // Wrapper then the application will wait for the native Wrapper to
- // call the application's start method. Otherwise the start method
- // will be called immediately.
- WrapperManager.start( new NodeStarter(), args );
- }
+ * Called when the application is shutting down. The Wrapper assumes
that
+ * this method will return fairly quickly. If the shutdown code code
+ * could potentially take a long time, then
WrapperManager.signalStopping()
+ * should be called to extend the timeout period. If for some reason,
+ * the stop method can not return, then it must call
+ * WrapperManager.stopped() to avoid warning messages from the Wrapper.
+ *
+ * @param exitCode The suggested exit code that will be returned to the
OS
+ * when the JVM exits.
+ *
+ * @return The exit code to actually return to the OS. In most cases,
this
+ * should just be the value of exitCode, however the user code
has
+ * the option of changing the exit code if there are any
problems
+ * during shutdown.
+ */
+ public int stop(int exitCode) {
+ System.err.println("Shutting down with exit code " + exitCode);
+ node.park();
+ // see #354
+ WrapperManager.signalStopping(120000);
- /**
- * VM-specific init.
- * Not Node-specific; many nodes may be created later.
- * @param testName The name of the test instance.
- */
+ return exitCode;
+ }
+
+ public void restart() {
+ WrapperManager.restart();
+ }
+
+ /**
+ * Called whenever the native wrapper code traps a system control signal
+ * against the Java process. It is up to the callback to take any
actions
+ * necessary. Possible values are:
WrapperManager.WRAPPER_CTRL_C_EVENT,
+ * WRAPPER_CTRL_CLOSE_EVENT, WRAPPER_CTRL_LOGOFF_EVENT, or
+ * WRAPPER_CTRL_SHUTDOWN_EVENT
+ *
+ * @param event The system control signal.
+ */
+ public void controlEvent(int event) {
+ if(WrapperManager.isControlledByNativeWrapper()) {
+ // The Wrapper will take care of this event
+ } else
+ // We are not being controlled by the Wrapper, so
+ // handle the event ourselves.
+ if((event == WrapperManager.WRAPPER_CTRL_C_EVENT) ||
+ (event ==
WrapperManager.WRAPPER_CTRL_CLOSE_EVENT) ||
+ (event ==
WrapperManager.WRAPPER_CTRL_SHUTDOWN_EVENT))
+ WrapperManager.stop(0);
+ }
+
+ /*---------------------------------------------------------------
+ * Main Method
+ *-------------------------------------------------------------*/
+ public static void main(String[] args) {
+ // Start the application. If the JVM was launched from the
native
+ // Wrapper then the application will wait for the native
Wrapper to
+ // call the application's start method. Otherwise the start
method
+ // will be called immediately.
+ WrapperManager.start(new NodeStarter(), args);
+ }
+
+ /**
+ * VM-specific init.
+ * Not Node-specific; many nodes may be created later.
+ * @param testName The name of the test instance.
+ */
public static RandomSource globalTestInit(String testName, boolean
enablePlug, int logThreshold, String details) throws InvalidThresholdException {
-
+
File dir = new File(testName);
if((!dir.mkdir()) && ((!dir.exists()) || (!dir.isDirectory())))
{
System.err.println("Cannot create directory for test");
System.exit(NodeInitException.EXIT_TEST_ERROR);
}
-
- Logger.setupStdoutLogging(logThreshold, details);
-
- // set Java's DNS cache not to cache forever, since many people
- // use dyndns hostnames
- java.security.Security.setProperty("networkaddress.cache.ttl" , "0");
- java.security.Security.setProperty("networkaddress.cache.negative.ttl"
, "0");
-
- // Setup RNG
- RandomSource random = new Yarrow();
-
- DiffieHellman.init(random);
-
- if(enablePlug) {
-
- // Thread to keep the node up.
- // JVM deadlocks losing a lock when two threads of different
types (daemon|app)
- // are contended for the same lock. So make USM daemon, and use
useless to keep the JVM
- // up.
- //
http://forum.java.sun.com/thread.jspa?threadID=343023&messageID=2942637 - last
message
- Runnable useless =
- new Runnable() {
- public void run() {
- while(true)
- try {
- Thread.sleep(60*60*1000);
- } catch (InterruptedException e) {
- // Ignore
- } catch (Throwable t) {
- try {
- Logger.error(this,
"Caught "+t, t);
- } catch (Throwable t1) {
- // Ignore
+
+ Logger.setupStdoutLogging(logThreshold, details);
+
+ // set Java's DNS cache not to cache forever, since many people
+ // use dyndns hostnames
+ java.security.Security.setProperty("networkaddress.cache.ttl",
"0");
+
java.security.Security.setProperty("networkaddress.cache.negative.ttl", "0");
+
+ // Setup RNG
+ RandomSource random = new Yarrow();
+
+ DiffieHellman.init(random);
+
+ if(enablePlug) {
+
+ // Thread to keep the node up.
+ // JVM deadlocks losing a lock when two threads of
different types (daemon|app)
+ // are contended for the same lock. So make USM daemon,
and use useless to keep the JVM
+ // up.
+ //
http://forum.java.sun.com/thread.jspa?threadID=343023&messageID=2942637 - last
message
+ Runnable useless =
+ new Runnable() {
+
+ public void run() {
+ while(true) {
+ try {
+ Thread.sleep(60
* 60 * 1000);
+ }
catch(InterruptedException e) {
+ // Ignore
+ } catch(Throwable t) {
+ try {
+
Logger.error(this, "Caught " + t, t);
+ }
catch(Throwable t1) {
+ //
Ignore
+ }
+ }
}
}
- }
- };
- Thread plug = new Thread(useless, "Plug");
- // Not daemon, but doesn't do anything.
- // Keeps the JVM alive.
- // DO NOT do anything in the plug thread, if you do you risk
the EvilJVMBug.
- plug.setDaemon(false);
- plug.start();
- }
-
- FNPPacketMangler.LOG_UNMATCHABLE_ERROR = true;
- DNSRequester.DISABLE = true;
-
+ };
+ Thread plug = new Thread(useless, "Plug");
+ // Not daemon, but doesn't do anything.
+ // Keeps the JVM alive.
+ // DO NOT do anything in the plug thread, if you do you
risk the EvilJVMBug.
+ plug.setDaemon(false);
+ plug.start();
+ }
+
+ FNPPacketMangler.LOG_UNMATCHABLE_ERROR = true;
+ DNSRequester.DISABLE = true;
+
return random;
}
-
+
/**
* Create a test node.
* @param port The node port number. Each test node must have a
different port
@@ -339,21 +336,21 @@
* @throws NodeInitException If the node cannot start up for some
reason, most
* likely a config problem.
*/
- public static Node createTestNode(int port, String testName, boolean
doClient,
- boolean doSwapping, boolean disableProbabilisticHTLs,
short maxHTL,
- int dropProb, RandomSource random, Executor executor,
int threadLimit,
- long storeSize, boolean ramStore, boolean
enableSwapping, boolean enableARKs,
- boolean enableULPRs, boolean
enablePerNodeFailureTables,
- boolean enableSwapQueueing, boolean
enablePacketCoalescing,
- int outputBandwidthLimit) throws NodeInitException {
-
+ public static Node createTestNode(int port, String testName, boolean
doClient,
+ boolean doSwapping, boolean disableProbabilisticHTLs, short
maxHTL,
+ int dropProb, RandomSource random, Executor executor, int
threadLimit,
+ long storeSize, boolean ramStore, boolean enableSwapping,
boolean enableARKs,
+ boolean enableULPRs, boolean enablePerNodeFailureTables,
+ boolean enableSwapQueueing, boolean enablePacketCoalescing,
+ int outputBandwidthLimit) throws NodeInitException {
+
File baseDir = new File(testName);
File portDir = new File(baseDir, Integer.toString(port));
if((!portDir.mkdir()) && ((!portDir.exists()) ||
(!portDir.isDirectory()))) {
System.err.println("Cannot create directory for test");
System.exit(NodeInitException.EXIT_TEST_ERROR);
}
-
+
// Set up config for testing
SimpleFieldSet configFS = new SimpleFieldSet(false); // only
happens once in entire simulation
if(outputBandwidthLimit > 0) {
@@ -362,7 +359,7 @@
} else {
// Even with throttleLocalTraffic=false, requests still
count in NodeStats.
// So set outputBandwidthLimit to something insanely
high.
- configFS.put("node.outputBandwidthLimit", 16*1024*1024);
+ configFS.put("node.outputBandwidthLimit", 16 * 1024 *
1024);
configFS.put("node.throttleLocalTraffic", false);
}
configFS.put("node.listenPort", port);
@@ -383,7 +380,7 @@
configFS.put("node.includeLocalAddressesInNoderefs", true);
configFS.put("node.enableARKs", false);
configFS.put("node.load.threadLimit", threadLimit);
- if(ramStore)
+ if(ramStore)
configFS.putSingle("node.storeType", "ram");
configFS.put("storeSize", storeSize);
configFS.put("node.disableHangCheckers", true);
@@ -393,14 +390,14 @@
configFS.put("node.enableULPRDataPropagation", enableULPRs);
configFS.put("node.enablePerNodeFailureTables",
enablePerNodeFailureTables);
configFS.put("node.enablePacketCoalescing",
enablePacketCoalescing);
-
+
PersistentConfig config = new PersistentConfig(configFS);
-
- Node node=new Node(config, random, null, null, executor);
-
+
+ Node node = new Node(config, random, null, null, executor);
+
//All testing environments connect the nodes as they want, even
if the old setup is restored, it is not desired.
node.peers.removeAllPeers();
-
+
return node;
}
}