Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * JBoss, Home of Professional Open Source
   * Copyright 2006, Red Hat Middleware LLC, and individual contributors
   * as indicated by the @author tags.
   * See the copyright.txt in the distribution for a
   * full listing of individual contributors.
   * This copyrighted material is made available to anyone wishing to use,
   * modify, copy, or redistribute it subject to the terms and conditions
   * of the GNU Lesser General Public License, v. 2.1.
  * This program is distributed in the hope that it will be useful, but WITHOUT A
  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
  * PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more details.
  * You should have received a copy of the GNU Lesser General Public License,
  * v.2.1 along with this distribution; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  * MA  02110-1301, USA.
  *
  * (C) 2005-2006,
  * @author JBoss Inc.
  */
 /*
  * Copyright (C) 1999-2001 by HP Bluestone Software, Inc. All rights Reserved.
  *
  * HP Arjuna Labs,
  * Newcastle upon Tyne,
  * Tyne and Wear,
  * UK.
  *
  * $Id: RecoveryManager.java 2342 2006-03-30 13:06:17Z  $
  */
 
 package com.arjuna.ats.arjuna.recovery;
 
 
 
 class ScanThread extends Thread
 {
 
     public ScanThread (RecoveryManagerImple theImpleRecoveryScan callback)
     {
 	super("RecoveryManagerScanThread");
 
 	 = theImple;
 	 = callback;
 
 	setDaemon(true);
     }
 
     public void run ()
     {
         if ( != null)
         {
             .scan();
 
             if ( != null)
                 .completed();
         }
     }
 
     private RecoveryManagerImple _theImple;
     private RecoveryScan         _callback;
 }

The RecoveryManager daemon.
 
 
 public class RecoveryManager
 {
    
In this mode the recovery manager runs periodically but may also be driven through messages or via the scan operation if it is embedded.
 
 
     public static final int INDIRECT_MANAGEMENT = 0;

    
In this mode the recovery manager does not run periodically and will only work if driven through messages or via the scan operation if it is embedded.
 
 
     public static final int DIRECT_MANAGEMENT = 1;

    
Obtain a reference to the RecoveryManager singleton. If it hasn't been created yet then it will be. The manager will be created in the INDIRECT_MANAGEMENT mode.

Returns:
the manager.
Throws:
java.lang.IllegalArgumentException thrown if the manager has already been created in a different mode to that requested.
    public static synchronized final RecoveryManager manager () throws IllegalArgumentException
    {
   	if ( == null)    		
    return ;
    }

    
Obtain a reference to the RecoveryManager singleton. If it hasn't been created yet then it will be. The manager can be created in a management mode defined by the parameter.

Parameters:
mode the management mode for the manager.
Returns:
the manager.
Throws:
java.lang.IllegalArgumentException thrown if the manager has already been created in a different mode to that requested.
    public static synchronized final RecoveryManager manager (int modethrows IllegalArgumentException
    {
	if ( == null)
	     = new RecoveryManager(mode);
	else
	{
	    if (.mode() != mode)
	}
    }

    
Delay the start of the recovery manager thread when creating an indirect recovery manager.
    public static synchronized void delayRecoveryManagerThread()
    {
         = true ;
    }

    
Force a recovery scan now. This is a blocking operation and will only return once the recovery scan has completed.

Throws:
java.lang.IllegalStateException if the recovery manager has been shutdown.
    public final void scan ()
    {
        checkState();
        .scan();
    }

    
Force a recovery scan now. This is a non-blocking operation and will return immediately. Notification of completion of the scan is done through the RecoveryScan object.

Parameters:
callback callback The callback mechanism used to inform users that the scan has completed. If this is null then no callback will happen and asynchronous scanning will occur.
Throws:
java.lang.IllegalStateException if the recovery manager has been shutdown.
    public final void scan (RecoveryScan callback)
    {
        checkState();
	ScanThread st = new ScanThread(callback);
	st.start();
    }

    
Terminate and cleanup the recovery manager. There is no going back from this. This is a synchronous operation so return means that the recovery has completed.

Throws:
java.lang.IllegalStateException if the recovery manager has been shutdown.
    public final void terminate ()
    {
        terminate(false);
    }

    
Terminate and cleanup the recovery manager. There is no going back from this. Can be called synchronous or asynchronously. If you have any intention of restarting the recovery manager later then you MUST use the async=false option.

Parameters:
async false means wait for any recovery scan in progress to complete.
Throws:
java.lang.IllegalStateException if the recovery manager has been shutdown.
    public final synchronized void terminate (boolean async)
    {
        checkState();
        .stop(async);
         = null;
    }

    
If the recovery manager has been shutdown previously then recreate it in the same mode as before. Otherwise ignore.
    public final synchronized void initialize ()
    {
        if ( == null)
        {
            if (( == .) && !)
                 = new RecoveryManagerImple(true);
            else
                 = new RecoveryManagerImple(false);
        }
    }
    // does nothing when running embedded.

    
wait for the recovery thread to be shutdown. n.b. this will not return unless and until shutdown is called.

Throws:
java.lang.IllegalStateException if the recovery manager has been shutdown.
    public void waitForTermination ()
    {
        checkState();
        .waitForTermination();
         = null;
    }

    
Suspend the recovery manager. If the recovery manager is in the process of doing recovery scans then it will be suspended afterwards, in order to preserve data integrity.

Parameters:
async false means wait for the recovery manager to finish any scans before returning.
Throws:
java.lang.IllegalStateException if the recovery manager has been shutdown.
    public void suspend (boolean async)
    {
        trySuspend(async);
    }
    public RecoveryManagerStatus trySuspend(boolean async) {
        checkState();
        PeriodicRecovery.Mode mode = .trySuspendScan(async);
        switch (mode) {
            case :
                return .;
            case :
                return .;
            case :
                return .;
            default:
                throw new IllegalArgumentException("incompatible enum types");
        }
    }

    

Throws:
java.lang.IllegalStateException if the recovery manager has been shutdown.
    public void resume ()
    {
        checkState();
        .resumeScan();
    }

    
Start the recovery manager thread.

Throws:
java.lang.IllegalStateException if the recovery manager has been shutdown.
    public void startRecoveryManagerThread()
    {
        checkState();
        .start() ;
    }

    
Add a recovery module to the system.

Parameters:
module module The module to add.
Throws:
java.lang.IllegalStateException if the recovery manager has been shutdown.
    public final void addModule (RecoveryModule module)
    {
        checkState();
    }

    
Remove a recovery module from the system.

Parameters:
module The module to remove.
waitOnScan true if the remove operation should wait for any in-progress scan to complete
Throws:
java.lang.IllegalStateException if the recovery manager has been shutdown.
    public final void removeModule (RecoveryModule moduleboolean waitOnScan)
    {
        checkState();
	.removeModule(modulewaitOnScan);
    }

    
Remove all modules. WARNING: Use with extreme care as this will stop recovery from doing anything!
    
    public final void removeAllModules (boolean waitOnScan)
    {
        checkState();
        
        .removeAllModules(waitOnScan);
    }
    
    
Obtain a snapshot list of available recovery modules.

Returns:
a snapshot list of the currently installed recovery modules
Throws:
java.lang.IllegalStateException if the recovery manager has been shutdown.
    public final Vector<RecoveryModulegetModules ()
    {
        checkState();
    }

    
Indicates what mode (INDIRECT_MANAGEMENT or DIRECT_MANAGEMENT) the recovery manager is configured for.

Returns:
the management mode.
    public final int mode ()
    {
	return ;
    }
    public static InetAddress getRecoveryManagerHost() throws UnknownHostException
    {
        String host = recoveryPropertyManager.getRecoveryEnvironmentBean().getRecoveryAddress();
        return Utility.hostNameToInetAddress(host);
    }
    public static int getRecoveryManagerPort()
    {
        return recoveryPropertyManager.getRecoveryEnvironmentBean().getRecoveryPort();
    }

    
Obtain a client connection to the recovery manager

Returns:
a bound client socket connection to the recovery manager
Throws:
java.io.IOException
    public static Socket getClientSocket () throws IOException
    {
        Socket socket = new Socket(getRecoveryManagerHost(), getRecoveryManagerPort());
        return socket;
    }

    
Run the RecoveryManager. See Administration manual for details.
    public static void main (String[] args)
    {
	boolean testMode = false;
	for (int i = 0; i < args.lengthi++)
	{
	    if (args[i].compareTo("-help") == 0)
	    {
		..println("Usage: com.arjuna.ats.arjuna.recovery.RecoveryManager [-help] [-test] [-version]");
		System.exit(0);
	    }
	    if (args[i].compareTo("-version") == 0)
	    {
		..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:
                    ..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)
            {
                ..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();
        }
    }
    private RecoveryManager (int mode)
    {
	     = new RecoveryManagerImple(true);
	else
	     = new RecoveryManagerImple(false);
	 = mode;
    }
    private final void checkState ()
    {
        if ( == null)
            throw new IllegalStateException();
    }
    private RecoveryManagerImple _theImple = null;
    private int _mode;
    private static RecoveryManager _recoveryManager = null;
    private static boolean delayRecoveryManagerThread ;
New to GrepCode? Check out our FAQ X