tom | 0eb04ca | 2014-08-25 14:34:51 -0700 | [diff] [blame^] | 1 | package org.onlab.onos.net.impl; |
| 2 | |
| 3 | import com.google.common.collect.ImmutableSet; |
| 4 | import org.apache.felix.scr.annotations.Activate; |
| 5 | import org.apache.felix.scr.annotations.Component; |
| 6 | import org.apache.felix.scr.annotations.Deactivate; |
| 7 | import org.apache.felix.scr.annotations.Service; |
| 8 | import org.onlab.onos.net.GreetService; |
| 9 | import org.slf4j.Logger; |
| 10 | import org.slf4j.LoggerFactory; |
| 11 | |
| 12 | import java.util.HashSet; |
| 13 | import java.util.Set; |
| 14 | |
| 15 | import static com.google.common.base.Preconditions.checkNotNull; |
| 16 | |
| 17 | /** |
| 18 | * Trivial implementation of the seed service to demonstrate component and |
| 19 | * service annotations. |
| 20 | */ |
| 21 | @Component(immediate = true) |
| 22 | @Service |
| 23 | public class GreetManager implements GreetService { |
| 24 | |
| 25 | private final Logger log = LoggerFactory.getLogger(getClass()); |
| 26 | |
| 27 | private final Set<String> names = new HashSet<>(); |
| 28 | |
| 29 | @Override |
| 30 | public synchronized String yo(String name) { |
| 31 | checkNotNull(name, "Name cannot be null"); |
| 32 | names.add(name); |
| 33 | log.info("Greeted '{}'", name); |
| 34 | return "Whazup " + name + "?"; |
| 35 | } |
| 36 | |
| 37 | @Override |
| 38 | public synchronized Iterable<String> names() { |
| 39 | return ImmutableSet.copyOf(names); |
| 40 | } |
| 41 | |
| 42 | @Activate |
| 43 | public void activate() { |
| 44 | log.info("SeedManager started"); |
| 45 | } |
| 46 | |
| 47 | @Deactivate |
| 48 | public void deactivate() { |
| 49 | log.info("SeedManager stopped"); |
| 50 | } |
| 51 | |
| 52 | } |