]> WPIA git - gigi.git/blobdiff - src/org/cacert/gigi/ping/PingerDaemon.java
dbg: test-output for pinging
[gigi.git] / src / org / cacert / gigi / ping / PingerDaemon.java
index ceb88e9a68b80447207749c4797a3599cd8049c6..7243a3ebde0a3785b6b497cfe260c55d81eda05b 100644 (file)
@@ -31,30 +31,39 @@ public class PingerDaemon extends Thread {
 
     @Override
     public void run() {
-        searchNeededPings = DatabaseConnection.getInstance().prepare("SELECT pingconfig.id FROM pingconfig LEFT JOIN domainPinglog ON domainPinglog.configId=pingconfig.id INNER JOIN domains ON domains.id=pingconfig.domainid WHERE ( domainPinglog.configId IS NULL) AND domains.deleted IS NULL GROUP BY pingconfig.id");
-        enterPingResult = DatabaseConnection.getInstance().prepare("INSERT INTO domainPinglog SET configId=?, state=?, result=?, challenge=?");
+        searchNeededPings = DatabaseConnection.getInstance().prepare("SELECT `pingconfig`.`id` FROM `pingconfig` LEFT JOIN `domainPinglog` ON `domainPinglog`.`configId` = `pingconfig`.`id` INNER JOIN `domains` ON `domains`.`id` = `pingconfig`.`domainid` WHERE ( `domainPinglog`.`configId` IS NULL) AND `domains`.`deleted` IS NULL GROUP BY `pingconfig`.`id`");
+        enterPingResult = DatabaseConnection.getInstance().prepare("INSERT INTO `domainPinglog` SET `configId`=?, `state`=?::`pingState`, `result`=?, `challenge`=?");
         pingers.put(PingType.EMAIL, new EmailPinger());
         pingers.put(PingType.SSL, new SSLPinger(truststore));
         pingers.put(PingType.HTTP, new HTTPFetch());
         pingers.put(PingType.DNS, new DNSPinger());
 
         while (true) {
-            synchronized (this) {
-                DomainPingConfiguration conf;
-                while ((conf = toExecute.peek()) != null) {
-                    handle(conf);
-                    toExecute.remove();
+            try {
+                boolean worked = false;
+                synchronized (this) {
+                    DomainPingConfiguration conf;
+                    while ((conf = toExecute.peek()) != null) {
+                        worked = true;
+                        handle(conf);
+                        toExecute.remove();
+                    }
+                    notifyAll();
                 }
-                notifyAll();
-            }
 
-            GigiResultSet rs = searchNeededPings.executeQuery();
-            while (rs.next()) {
-                handle(DomainPingConfiguration.getById(rs.getInt("id")));
-            }
-            try {
-                Thread.sleep(5000);
-            } catch (InterruptedException e) {
+                GigiResultSet rs = searchNeededPings.executeQuery();
+                while (rs.next()) {
+                    worked = true;
+                    handle(DomainPingConfiguration.getById(rs.getInt("id")));
+                }
+                try {
+                    if ( !worked) {
+                        Thread.sleep(5000);
+                    }
+                } catch (InterruptedException e) {
+                }
+            } catch (Throwable t) {
+                t.printStackTrace();
             }
         }
     }
@@ -71,7 +80,9 @@ public class PingerDaemon extends Thread {
             }
             enterPingResult.setInt(1, conf.getId());
             Domain target = conf.getTarget();
+            System.err.println("Executing " + dp + " on " + target + " (" + System.currentTimeMillis() + ")");
             String resp = dp.ping(target, config, target.getOwner());
+            System.err.println("done (" + System.currentTimeMillis() + ")");
             enterPingResult.setString(2, DomainPinger.PING_STILL_PENDING == resp ? "open" : DomainPinger.PING_SUCCEDED.equals(resp) ? "success" : "failed");
             enterPingResult.setString(3, resp);
             enterPingResult.setString(4, token);