]> git.argeo.org Git - gpl/argeo-slc.git/blob - runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/execution/DefaultAgentFactory.java
e80db134619a75773db2373f04d66d8b51bc2d2a
[gpl/argeo-slc.git] / runtime / org.argeo.slc.core / src / main / java / org / argeo / slc / core / execution / DefaultAgentFactory.java
1 /*
2 * Copyright (C) 2007-2012 Argeo GmbH
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 package org.argeo.slc.core.execution;
17
18 import java.util.HashMap;
19 import java.util.List;
20 import java.util.Map;
21
22 import org.apache.commons.logging.Log;
23 import org.apache.commons.logging.LogFactory;
24 import org.argeo.slc.runtime.SlcAgent;
25 import org.argeo.slc.runtime.SlcAgentFactory;
26
27 /** Register agents (typically via OSGi listeners) */
28 public class DefaultAgentFactory implements SlcAgentFactory {
29 private final static Log log = LogFactory.getLog(DefaultAgentFactory.class);
30
31 private Map<String, SlcAgent> agents = new HashMap<String, SlcAgent>();
32
33 public SlcAgent getAgent(String uuid) {
34 if (agents.containsKey(uuid))
35 return agents.get(uuid);
36 else
37 return null;
38 }
39
40 public void pingAll(List<String> activeAgentIds) {
41 for (SlcAgent agent : agents.values())
42 agent.ping();
43 }
44
45 public synchronized void register(SlcAgent agent,
46 Map<String, String> properties) {
47 agents.put(agent.getAgentUuid(), agent);
48 if (log.isDebugEnabled())
49 log.debug("Agent " + agent.getAgentUuid() + " registered");
50 }
51
52 public synchronized void unregister(SlcAgent agent,
53 Map<String, String> properties) {
54 agents.remove(agent.getAgentUuid());
55 if (log.isDebugEnabled())
56 log.debug("Agent " + agent.getAgentUuid() + " unregistered");
57 }
58
59 }