ServiceManager.java
Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2011 Google Inc.
00003  * 
00004  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
00005  * use this file except in compliance with the License. You may obtain a copy of
00006  * the License at
00007  * 
00008  * http://www.apache.org/licenses/LICENSE-2.0
00009  * 
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
00012  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
00013  * License for the specific language governing permissions and limitations under
00014  * the License.
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   // TODO(damonkohler): Change to ListenerGroup.
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 }


rosjava_core
Author(s):
autogenerated on Wed Aug 26 2015 16:06:49