So im building an application in swing that will ping a url or a list of urls to show the machines status. So if a machine disconnects it will show up as disconnected. I have a list of machines but I need it to loop over forever in intervals so I can know the status of the machine. I know you cant reset the enumeration count so im stuck on a workaround for it.
Currently the part of the code that does the pinging and enumeration is below:
class WorkerThread extends Thread {
DefaultListModel model;
public WorkerThread(DefaultListModel aModel) {
model = aModel;
}
public void run() {
Pinging ping = new Pinging();
int num ;
Enumeration<String> e;
for ( e= model.elements(), num=0; e.hasMoreElements(); num ++){
String element = e.nextElement();
for (int i = 0; i<5; i++){
ping.reachUrl(element);
//ping.timer(5, e.nextElement());
final int pos = num;
EventQueue.invokeLater(new Runnable() {
public void run() {
//ping.reachUrl(e.nextElement());
String name = ping.getName();
String addr = ping.getAddr();
boolean reach = ping.getReach();
int time = ping.getTime();
model.set(pos, name+" " + addr+" " + reach + " " + time);
//model.add(pos, name+" " + addr+" " + reach + " " + time);
//model.set(pos, "Hello");
}
});
yield();
}
}
}
}