Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 package org.ros.internal.node.parameter;
00018
00019 import com.google.common.collect.Maps;
00020
00021 import org.ros.concurrent.ListenerGroup;
00022 import org.ros.concurrent.SignalRunnable;
00023 import org.ros.namespace.GraphName;
00024 import org.ros.node.parameter.ParameterListener;
00025
00026 import java.util.Map;
00027 import java.util.concurrent.ExecutorService;
00028
00032 public class ParameterManager {
00033
00034 private final ExecutorService executorService;
00035 private final Map<GraphName, ListenerGroup<ParameterListener>> listeners;
00036
00037 public ParameterManager(ExecutorService executorService) {
00038 this.executorService = executorService;
00039 listeners = Maps.newHashMap();
00040 }
00041
00042 public void addListener(GraphName parameterName, ParameterListener listener) {
00043 synchronized (listeners) {
00044 if (!listeners.containsKey(parameterName)) {
00045 listeners.put(parameterName, new ListenerGroup<ParameterListener>(executorService));
00046 }
00047 listeners.get(parameterName).add(listener);
00048 }
00049 }
00050
00056 public int updateParameter(GraphName parameterName, final Object value) {
00057 int numberOfListeners = 0;
00058 synchronized (listeners) {
00059 if (listeners.containsKey(parameterName)) {
00060 ListenerGroup<ParameterListener> listenerCollection = listeners.get(parameterName);
00061 numberOfListeners = listenerCollection.size();
00062 listenerCollection.signal(new SignalRunnable<ParameterListener>() {
00063 @Override
00064 public void run(ParameterListener listener) {
00065 listener.onNewValue(value);
00066 }
00067 });
00068 }
00069 }
00070 return numberOfListeners;
00071 }
00072 }