X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;f=runtime%2Forg.argeo.slc.server%2Fsrc%2Fmain%2Fjava%2Forg%2Fargeo%2Fslc%2Fservices%2Fimpl%2FAgentServiceImpl.java;h=9a292c0de9306d3a4d159f6562956e81a00a94e9;hb=abc0180c68f7a53cddd066b0f88bc8213d2ae04a;hp=a27772b26ee351277d50d5e963266383d837892e;hpb=1d1bc92e4aef2b8b889d7482f91b7ed905f0fb47;p=gpl%2Fargeo-slc.git diff --git a/runtime/org.argeo.slc.server/src/main/java/org/argeo/slc/services/impl/AgentServiceImpl.java b/runtime/org.argeo.slc.server/src/main/java/org/argeo/slc/services/impl/AgentServiceImpl.java index a27772b26..9a292c0de 100644 --- a/runtime/org.argeo.slc.server/src/main/java/org/argeo/slc/services/impl/AgentServiceImpl.java +++ b/runtime/org.argeo.slc.server/src/main/java/org/argeo/slc/services/impl/AgentServiceImpl.java @@ -1,10 +1,28 @@ +/* + * Copyright (C) 2010 Mathieu Baudier + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package org.argeo.slc.services.impl; import java.util.ArrayList; import java.util.List; +import java.util.concurrent.Executor; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.argeo.security.ArgeoSecurityService; import org.argeo.slc.dao.runtime.SlcAgentDescriptorDao; import org.argeo.slc.runtime.SlcAgent; import org.argeo.slc.runtime.SlcAgentDescriptor; @@ -20,7 +38,9 @@ public class AgentServiceImpl implements AgentService, InitializingBean, private final SlcAgentDescriptorDao slcAgentDescriptorDao; private final SlcAgentFactory agentFactory; - private Long pingCycle = 60000l; + private Executor securityService; + + private Long pingCycle = 20000l; private Boolean pingThreadActive = true; @@ -31,7 +51,9 @@ public class AgentServiceImpl implements AgentService, InitializingBean, } public void register(SlcAgentDescriptor slcAgentDescriptor) { - slcAgentDescriptorDao.create(slcAgentDescriptor); + if (slcAgentDescriptorDao.getAgentDescriptor(slcAgentDescriptor + .getUuid()) == null) + slcAgentDescriptorDao.create(slcAgentDescriptor); log.info("Registered agent #" + slcAgentDescriptor.getUuid()); } @@ -41,8 +63,17 @@ public class AgentServiceImpl implements AgentService, InitializingBean, } public void afterPropertiesSet() throws Exception { - if (pingCycle > 0) - new PingThread().start(); + // if (pingCycle > 0) + // new PingThread().start(); + if (pingCycle > 0) { + Thread authenticatedThread = new Thread("SLC Agents Ping") { + public void run() { + securityService.execute(new AgentsPing()); + } + }; + authenticatedThread.start(); + + } } public synchronized void destroy() throws Exception { @@ -54,13 +85,17 @@ public class AgentServiceImpl implements AgentService, InitializingBean, this.pingCycle = pingCycle; } - protected class PingThread extends Thread { + public void setSecurityService(Executor securityService) { + this.securityService = securityService; + } + + protected class AgentsPing implements Runnable { public void run() { // FIXME: temporary hack so that the ping starts after the server // has been properly started. try { - Thread.sleep(5 * 1000); + Thread.sleep(10 * 1000); } catch (InterruptedException e1) { // silent } @@ -74,7 +109,7 @@ public class AgentServiceImpl implements AgentService, InitializingBean, agentIds.add(ad.getUuid()); if (log.isTraceEnabled()) - log.debug("Ping " + agentIds.size() + " agent."); + log.trace("Ping " + agentIds.size() + " agent(s)."); for (String agentId : agentIds) { SlcAgent agent = agentFactory.getAgent(agentId); if (!agent.ping()) { @@ -102,4 +137,5 @@ public class AgentServiceImpl implements AgentService, InitializingBean, } } + }