Exemplo n.º 1
0
    public static void main (String[] args)
    {
	boolean testMode = false;

	for (int i = 0; i < args.length; i++)
	{
	    if (args[i].compareTo("-help") == 0)
	    {
		System.out.println("Usage: com.arjuna.ats.arjuna.recovery.RecoveryManager [-help] [-test] [-version]");
		System.exit(0);
	    }
	    if (args[i].compareTo("-version") == 0)
	    {
		System.out.println("Version " + ConfigurationInfo.getVersion());
		System.exit(0);
	    }
	    if (args[i].compareTo("-test") == 0)
	    {
		testMode = true;
	    }
	}

        try
        {
            RecoveryManager manager = null;

            try
            {
                manager = manager();
            }
            catch(Throwable e)
            {
                if(testMode)
                {
                    // in some test cases the recovery manager is killed and restarted in quick succession.
                    // sometimes the O/S does not free up the port fast enough, so we can't reclaim it on restart.
                    // For test mode only, we therefore have a simple backoff-retry kludge:
                    System.err.println("Warning: got exception '"+e.toString()+"' on startup, will retry in 5 seconds in the hope it is transient.");
                    try
                    {
                        Thread.sleep(5000);
                    }
                    catch(InterruptedException interruptedException)
                    {
                        // do nothing
                    }
                    manager = manager();
                }
                else
                {
                    throw e;
                }
            }

            if (testMode)
            {
                System.out.println("Ready");
            }

            // this is never going to return because it only returns when shutdown is called and
            // there is nothing which is going to call shutdown. we probably aught  to provide a
            // clean way of terminating this process.

            manager.waitForTermination();

        }
        catch (Throwable e)
        {
            e.printStackTrace();
        }
    }