+ public void afterPropertiesSet() throws Exception {
+ if (pingCycle > 0)
+ new PingThread().start();
+ }
+
+ public synchronized void destroy() throws Exception {
+ pingThreadActive = false;
+ notifyAll();
+ }
+
+ public void setPingCycle(Long pingCycle) {
+ this.pingCycle = pingCycle;
+ }
+
+ protected class PingThread extends Thread {
+ public void run() {
+ while (pingThreadActive) {
+ List<SlcAgentDescriptor> lst = slcAgentDescriptorDao
+ .listSlcAgentDescriptors();
+ List<String> agentIds = new ArrayList<String>();
+ for (SlcAgentDescriptor ad : lst)
+ agentIds.add(ad.getUuid());
+
+ if (log.isDebugEnabled())
+ log.debug("Ping " + agentIds.size() + " agent.");
+ for (String agentId : agentIds) {
+ SlcAgent agent = agentFactory.getAgent(agentId);
+ if (!agent.ping()) {
+ log.info("Agent " + agentId + " did not reply to ping,"
+ + " removing its descriptor...");
+ slcAgentDescriptorDao.delete(agentId);
+ }
+ }
+
+ synchronized (AgentServiceImpl.this) {
+ try {
+ AgentServiceImpl.this.wait(pingCycle);
+ } catch (InterruptedException e) {
+ // silent
+ }
+ }
+ }
+ }
+
+ }