/*
* SIP Communicator, the OpenSource Java VoIP and Instant Messaging client.
*
* Distributable under LGPL license. See terms of license at gnu.org.
*/
package net.java.sip.communicator.plugin.dictaccregwizz;
import java.util.*;
import net.java.sip.communicator.util.*;
/**
* The StrategyThread is the thread called by the wizzard to populate
* the strategies list.
*
* @author ROTH Damien
* @author LITZELMANN Cedric
*/
public class StrategyThread
extends Thread
{
private static Logger logger = Logger.getLogger(StrategyThread.class);
/**
* The hostname of the DICT server.
*/
private String host;
/**
* The port used by the DICT server.
*/
private int port;
/**
* True if the thread is running.
*/
private boolean isRunning = false;
/**
* True if we need to search the strategies handled by the server in order
* to populate the list.
*/
private boolean needProcess = false;
/**
* The first page wizard for the DICT protocole.
*/
private FirstWizardPage wizard;
/**
* The java abstraction of the DICT server.
*/
private DictAdapter adapter = null;
/**
* Create a new StrategyThread
* @param wizard the wizard for callback methods
*/
public StrategyThread(FirstWizardPage wizard)
{
this.wizard = wizard;
}
/**
* Thread method running until it's destroy
*/
public void run()
{
while (true)
{
if (this.needProcess())
{
this.setRunning(true);
this.process();
this.processDone();
this.setRunning(false);
}
try
{
this.sleep(500);
}
catch (InterruptedException ie)
{
// Action de log
logger.info("DICT THREAD : " + ie);
}
}
}
/**
* Search the strategies on the server and populate the list
*/
private void process()
{
ArrayList strategies = null;
String temp[];
if (adapter == null) {
adapter = new DictAdapter();
}
this.wizard.setStrategyButtonEnable(false);
// Initialize the connexion
this.wizard.threadMessage("Trying to connect to server");
if (!adapter.connect(this.host, this.port))
{
// Connexion attempt failed
this.wizard.threadMessage("Connexion attempt failed, this isn't a"
+ "dict server or the server is offline");
return;
}
// Retrieving strategies
this.wizard.threadMessage("Retrieving strategies");
strategies = adapter.getStrategies();
if (strategies == null)
{
// No strategy found
this.wizard.threadMessage("No strategy found on the server");
return;
}
// Insert the strategies in the list
for (int i=0; i