Restart.java
| Index Score | ||
|---|---|---|
![]() |
![]() |
omschaub.azcvsupdater.utilities |
![]() |
![]() |
AZCVSUpdater |
View: Reasons, Metrics, Source Code
These are the metrics that contribute to the Enerjy Score for this file, ranked by impact. So the metrics listed at the top influence the score to a greater extent that the metrics listed at the bottom.
/*
* Created on Feb 6, 2005
* Created by omschaub
*
*/
package omschaub.azcvsupdater.utilities;
import java.io.File;
import java.io.FileInputStream;
import omschaub.azcvsupdater.main.StatusBoxUtils;
import omschaub.azcvsupdater.main.View;
import org.gudy.azureus2.plugins.PluginInterface;
import org.gudy.azureus2.plugins.logging.LoggerChannel;
import org.gudy.azureus2.plugins.update.UpdateInstaller;
import org.gudy.azureus2.plugins.update.UpdateManager;
/**
* Restarting Mechanism
*/
public class Restart {
/** updatePlugin is the main restart function. Handled by stacks 'From' and 'To' and restart boolean
*
*/
public static void updateRestart(final PluginInterface pluginInterface, final StackX complete_file_from, final StackX complete_file_to, final boolean restart)
{
Thread restart_thread = new Thread()
{
public void run()
{
try
{
UpdateManager um = pluginInterface.getUpdateManager();
UpdateInstaller updateInstaller = um.createInstaller();
int i = 0;
while (!complete_file_from.isEmpty()){
File from = new File (complete_file_from.pop());
if(!from.isFile())
{
StatusBoxUtils.mainStatusAdd(" Could not update because " + from.getName() + " is not a real file",2);
}
//System.out.println("From: " + from.getPath() + " To: " + complete_file_to.peek());
//System.out.println("addResource: azcvsupdater_" + i);
updateInstaller.addResource("azcvsupdater_" + i , new FileInputStream (from));
if(!complete_file_to.isEmpty())
{
updateInstaller.addMoveAction("azcvsupdater_" + i , complete_file_to.pop());
}
i++;
}
//System.out.println("AZCVSUpdater: Sleeping for 5 seconds to ensure all has completed");
Thread.sleep(5000);
um.applyUpdates(restart);
}
catch (Exception e)
{
StatusBoxUtils.mainStatusAdd(" Major Error Inserting/Restarting please report to omschaub@users.sourceforge.net",2);
System.out.println(e);
}
}
};
restart_thread.setDaemon(true);
restart_thread.start();
}
/** updateNORestart is an insert but not restart function. Handled by stacks 'From' and 'To' and restart boolean
*
*/
public static void updateNORestart(final PluginInterface pluginInterface, final StackX complete_file_from, final StackX complete_file_to)
{
Thread insert_thread = new Thread()
{
public void run()
{
try
{
UpdateManager um = pluginInterface.getUpdateManager();
UpdateInstaller updateInstaller = um.createInstaller();
int i = 0;
while (!complete_file_from.isEmpty()){
File from = new File (complete_file_from.pop());
if(!from.isFile())
{
StatusBoxUtils.mainStatusAdd(" Could not update because " + from.getName() + " is not a real file",2);
}
String file_to = complete_file_to.peek();
// System.out.println("From: " + from.getPath() + " To: " + file_to);
updateInstaller.addResource("azcvsupdater_" + i , new FileInputStream (from));
if(!complete_file_to.isEmpty())
{
updateInstaller.addMoveAction("azcvsupdater_" + i , complete_file_to.pop());
}
StatusBoxUtils.mainStatusAdd(" Successfully added " + from.getName() + " for insertion as " + file_to + " on next restart ",1);
/* if(from.getName().startsWith("azcvsupdater")){
StatusBoxUtils.mainStatusAdd(" Successfully deleted " + from.getName());
from.delete();
}*/
i++;
}
//um.applyUpdates(restart);
}
catch (Exception e)
{
StatusBoxUtils.mainStatusAdd(" Major Error Inserting/Restarting please report to omschaub@users.sourceforge.net",2);
System.out.println(e);
}
}
};
insert_thread.setDaemon(true);
insert_thread.start();
}
public static void updateTestRestart(final PluginInterface pluginInterface, final StackX complete_file_from, final StackX complete_file_to, final boolean restart)
{
Thread test_thread = new Thread()
{
public void run()
{
try
{
UpdateManager um = pluginInterface.getUpdateManager();
UpdateInstaller updateInstaller = um.createInstaller();
int i = 0;
while (!complete_file_from.isEmpty()){
//System.out.println("From: " + complete_file_from.peek() + " To: " + complete_file_to.peek());
if(!complete_file_to.isEmpty())
{
updateInstaller.addMoveAction(complete_file_from.pop(),complete_file_to.pop());
}
i++;
}
//System.out.println("AZCVSUpdater: Sleeping for 5 seconds to ensure all has completed");
Thread.sleep(5000);
um.applyUpdates(restart);
}
catch (Exception e)
{
StatusBoxUtils.mainStatusAdd(" Major Error Inserting/Restarting please report to omschaub@users.sourceforge.net",2);
System.out.println(e);
}
}
};
test_thread.setDaemon(true);
test_thread.start();
}
public static void updateRestart_OneFile(final String complete_file_from, final String complete_file_to, final boolean restart)
{
Thread restart_thread = new Thread()
{
public void run()
{
try
{
LoggerChannel logger =View.getPluginInterface().getLogger().getTimeStampedChannel("AZCVSUpdater");
UpdateManager um = View.getPluginInterface().getUpdateManager();
UpdateInstaller updateInstaller = um.createInstaller();
File from = new File (complete_file_from);
if(!from.isFile())
{
StatusBoxUtils.mainStatusAdd(" Could not update because " + from.getName() + " is not a real file",2);
}
//System.out.println("AZCVSUpdater: One File Restart/Exit Action");
//System.out.println("From: " + from.getPath() + " To: " + complete_file_to);
//updateInstaller.addResource("azcvsupdater_restart_stream" , new FileInputStream (from));
updateInstaller.addMoveAction(complete_file_from , complete_file_to);
//System.out.println("AZCVSUpdater: Sleeping for 5 seconds to ensure all has completed, because Tim says my plugin is lazy ;)");
logger.log("Sleeping for 5 seconds to ensure all has completed");
Thread.sleep(5000);
um.applyUpdates(restart);
logger.log("Still here.. even after um.applyUpdates :*(");
}
catch (Exception e)
{
StatusBoxUtils.mainStatusAdd(" Major Error Inserting/Restarting please report to omschaub@users.sourceforge.net",2);
System.out.println(e);
}
}
};
restart_thread.setDaemon(true);
restart_thread.start();
}
public static void updateInsert_OneFile(final String complete_file_from, final String complete_file_to)
{
Thread insert_thread = new Thread()
{
public void run()
{
try
{
UpdateManager um = View.getPluginInterface().getUpdateManager();
UpdateInstaller updateInstaller = um.createInstaller();
File from = new File (complete_file_from);
if(!from.isFile())
{
StatusBoxUtils.mainStatusAdd(" Could not update because " + from.getName() + " is not a real file",2);
}
//System.out.println("AZCVSUpdater: One File Insert only Action");
//System.out.println("From: " + from.getPath() + " To: " + complete_file_to);
//updateInstaller.addResource("azcvsupdater_restart_stream" , new FileInputStream (from));
updateInstaller.addMoveAction(complete_file_from , complete_file_to);
StatusBoxUtils.mainStatusAdd(" Successfully added " + from.getName() + " for insertion as " + complete_file_to + " on next restart ",1);
//System.out.println("AZCVSUpdater: Sleeping for 5 seconds to ensure all has completed, because Tim says my plugin is lazy)");
//Thread.sleep(5000);
//um.applyUpdates(restart);
}
catch (Exception e)
{
StatusBoxUtils.mainStatusAdd(" Major Error Inserting/Restarting please report to omschaub@users.sourceforge.net",2);
System.out.println(e);
}
}
};
insert_thread.setDaemon(true);
insert_thread.start();
}
//EOF
}
The table below shows all metrics for Restart.java.




