package radtest.server; import java.util.*; import com.theorem.radserver3.*; public class ProxyPacketTimeout extends TimerTask { // Special realm that indicates we're at the end of the list. final String EOL ="EnDoFtIMeRlISt"; // Our proxy client. private ProxyClient proxyClient; // Timer object for this timer task. private Timer timer; // List of ProxyTargets to try. private ArrayList realmList = new ArrayList(); // Counter in the pc list for the current ProxyClient. private int counter = 0; // Interval between transmissions. long interval; // List of timer objects. ArrayList timerList; /** * Constructor. * @param timer Our timer object for rescheduling. * @param proxyClient Our ProxyClient object. * @param timerList List of existing timers from which we can delete ourselves. */ public ProxyPacketTimeout(Timer timer, ProxyClient proxyClient, ArrayList timerList) { this.timer = timer; this.proxyClient = proxyClient; this.timerList = timerList; } /** * Set the interval in seconds between attempts. * @param seconds Time between sucessive transmissions. */ public void setInterval(int seconds) { interval = (long) seconds * 1000L; } /** * Add a proxy client to the list. * @param realm Realm to try. */ public void addRealm(String realm) { realmList.add(realm); } /** * Start the transmissions. */ public void go() { // Add a special entry that wil delete ourselves from the timerList. realmList.add(EOL); timer.scheduleAtFixedRate(this, new Date(), interval); } public void run() { if (counter >= realmList.size()) { // Stop the timer, we've run out of realms timer.cancel(); return; } String realm = null; realm = (String) realmList.get(counter++); // If the special EOL name is present remove ourselves // from the timerList removing our JVM reference. if (realm.equals(EOL)) { timerList.remove(timer); return; } try { proxyClient.send(realm, this); } catch (RADIUSServerException rse) { System.out.println(rse.getMessage()); } } }