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.service;
00018
00019 import com.google.common.collect.ImmutableList;
00020 import com.google.common.collect.Maps;
00021
00022 import org.ros.namespace.GraphName;
00023 import org.ros.node.service.ServiceClient;
00024 import org.ros.node.service.ServiceServer;
00025
00026 import java.util.List;
00027 import java.util.Map;
00028
00034 public class ServiceManager {
00035
00039 private final Map<GraphName, DefaultServiceServer<?, ?>> serviceServers;
00040
00044 private final Map<GraphName, DefaultServiceClient<?, ?>> serviceClients;
00045
00046
00047 private ServiceManagerListener listener;
00048
00049 public ServiceManager() {
00050 serviceServers = Maps.newConcurrentMap();
00051 serviceClients = Maps.newConcurrentMap();
00052 }
00053
00054 public void setListener(ServiceManagerListener listener) {
00055 this.listener = listener;
00056 }
00057
00058 public boolean hasServer(GraphName name) {
00059 return serviceServers.containsKey(name);
00060 }
00061
00062 public void addServer(DefaultServiceServer<?, ?> serviceServer) {
00063 serviceServers.put(serviceServer.getName(), serviceServer);
00064 if (listener != null) {
00065 listener.onServiceServerAdded(serviceServer);
00066 }
00067 }
00068
00069 public void removeServer(DefaultServiceServer<?, ?> serviceServer) {
00070 serviceServers.remove(serviceServer.getName());
00071 if (listener != null) {
00072 listener.onServiceServerRemoved(serviceServer);
00073 }
00074 }
00075
00076 public DefaultServiceServer<?, ?> getServer(GraphName name) {
00077 return serviceServers.get(name);
00078 }
00079
00080 public boolean hasClient(GraphName name) {
00081 return serviceClients.containsKey(name);
00082 }
00083
00084 public void addClient(DefaultServiceClient<?, ?> serviceClient) {
00085 serviceClients.put(serviceClient.getName(), serviceClient);
00086 }
00087
00088 public void removeClient(DefaultServiceClient<?, ?> serviceClient) {
00089 serviceClients.remove(serviceClient.getName());
00090 }
00091
00092 public DefaultServiceClient<?, ?> getClient(GraphName name) {
00093 return serviceClients.get(name);
00094 }
00095
00096 public List<DefaultServiceServer<?, ?>> getServers() {
00097 return ImmutableList.copyOf(serviceServers.values());
00098 }
00099
00100 public List<DefaultServiceClient<?, ?>> getClients() {
00101 return ImmutableList.copyOf(serviceClients.values());
00102 }
00103 }