Commit c53d65a3 authored by Gaston Dombiak's avatar Gaston Dombiak Committed by gato

Update thread always run.

git-svn-id: http://svn.igniterealtime.org/svn/repos/wildfire/trunk@4200 b35dd754-fafc-0310-a699-88a17e54d16e
parent c3f4b84e
...@@ -32,21 +32,8 @@ import org.jivesoftware.wildfire.container.Plugin; ...@@ -32,21 +32,8 @@ import org.jivesoftware.wildfire.container.Plugin;
import org.xmpp.packet.JID; import org.xmpp.packet.JID;
import org.xmpp.packet.Message; import org.xmpp.packet.Message;
import java.io.BufferedWriter; import java.io.*;
import java.io.File; import java.util.*;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStreamWriter;
import java.io.StringReader;
import java.io.Writer;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
/** /**
* Service that frequently checks for new server or plugins releases. By default the service * Service that frequently checks for new server or plugins releases. By default the service
...@@ -100,12 +87,7 @@ public class UpdateManager extends BasicModule { ...@@ -100,12 +87,7 @@ public class UpdateManager extends BasicModule {
public void start() throws IllegalStateException { public void start() throws IllegalStateException {
super.start(); super.start();
// Load last saved information (if any) startService();
loadSavedInfo();
if (isServiceEnabled()) {
startService();
}
} }
/** /**
...@@ -118,23 +100,32 @@ public class UpdateManager extends BasicModule { ...@@ -118,23 +100,32 @@ public class UpdateManager extends BasicModule {
try { try {
// Sleep for 15 seconds before starting to work // Sleep for 15 seconds before starting to work
Thread.sleep(15000); Thread.sleep(15000);
while (isServiceEnabled()) { // Load last saved information (if any)
waitForNextChecking(); loadSavedInfo();
// Check if the service is still enabled while (true) {
// Check if the service is enabled
if (isServiceEnabled()) { if (isServiceEnabled()) {
try { waitForNextChecking();
// Check for server updates // Check if the service is still enabled
checkForServerUpdate(true); if (isServiceEnabled()) {
// Refresh list of available plugins and check for plugin updates try {
checkForPluginsUpdates(true); // Check for server updates
// Keep track of the last time we checked for updates checkForServerUpdate(true);
JiveGlobals.setProperty("update.lastCheck", // Refresh list of available plugins and check for plugin updates
String.valueOf(System.currentTimeMillis())); checkForPluginsUpdates(true);
} // Keep track of the last time we checked for updates
catch (Exception e) { JiveGlobals.setProperty("update.lastCheck",
Log.error("Error checking for updates", e); String.valueOf(System.currentTimeMillis()));
}
catch (Exception e) {
Log.error("Error checking for updates", e);
}
} }
} }
else {
// Service is not enabled so sleep for 5 minutes
Thread.sleep(300000);
}
} }
} }
catch (InterruptedException e) { catch (InterruptedException e) {
...@@ -151,8 +142,7 @@ public class UpdateManager extends BasicModule { ...@@ -151,8 +142,7 @@ public class UpdateManager extends BasicModule {
if (lastCheck == 0) { if (lastCheck == 0) {
// This is the first time the server is used (since we added this feature) // This is the first time the server is used (since we added this feature)
Thread.sleep(45000); Thread.sleep(45000);
} } else {
else {
long elapsed = System.currentTimeMillis() - lastCheck; long elapsed = System.currentTimeMillis() - lastCheck;
int frequency = getCheckFrequency() * 60 * 60 * 1000; int frequency = getCheckFrequency() * 60 * 60 * 1000;
if (elapsed < frequency) { if (elapsed < frequency) {
...@@ -316,9 +306,6 @@ public class UpdateManager extends BasicModule { ...@@ -316,9 +306,6 @@ public class UpdateManager extends BasicModule {
*/ */
public void setServiceEnabled(boolean enabled) { public void setServiceEnabled(boolean enabled) {
JiveGlobals.setProperty("update.service-enabled", enabled ? "true" : "false"); JiveGlobals.setProperty("update.service-enabled", enabled ? "true" : "false");
if (enabled && thread == null) {
startService();
}
} }
/** /**
...@@ -443,7 +430,7 @@ public class UpdateManager extends BasicModule { ...@@ -443,7 +430,7 @@ public class UpdateManager extends BasicModule {
Element xmlResponse = new SAXReader().read(new StringReader(response)).getRootElement(); Element xmlResponse = new SAXReader().read(new StringReader(response)).getRootElement();
Iterator plugins = xmlResponse.elementIterator("plugin"); Iterator plugins = xmlResponse.elementIterator("plugin");
while (plugins.hasNext()) { while (plugins.hasNext()) {
Element plugin = (Element)plugins.next(); Element plugin = (Element) plugins.next();
String pluginName = plugin.attributeValue("name"); String pluginName = plugin.attributeValue("name");
String latestVersion = plugin.attributeValue("latest"); String latestVersion = plugin.attributeValue("latest");
String icon = plugin.attributeValue("icon"); String icon = plugin.attributeValue("icon");
...@@ -703,7 +690,7 @@ public class UpdateManager extends BasicModule { ...@@ -703,7 +690,7 @@ public class UpdateManager extends BasicModule {
// Parse info and recreate available plugins // Parse info and recreate available plugins
Iterator it = xmlResponse.getRootElement().elementIterator("plugin"); Iterator it = xmlResponse.getRootElement().elementIterator("plugin");
while (it.hasNext()) { while (it.hasNext()) {
Element plugin = (Element)it.next(); Element plugin = (Element) it.next();
String pluginName = plugin.attributeValue("name"); String pluginName = plugin.attributeValue("name");
String latestVersion = plugin.attributeValue("latest"); String latestVersion = plugin.attributeValue("latest");
String icon = plugin.attributeValue("icon"); String icon = plugin.attributeValue("icon");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment