tom | 5ac5188 | 2014-08-27 18:10:33 -0700 | [diff] [blame] | 1 | package org.onlab.onos.impl; |
tom | 0eb04ca | 2014-08-25 14:34:51 -0700 | [diff] [blame] | 2 | |
| 3 | import org.apache.felix.scr.annotations.Activate; |
| 4 | import org.apache.felix.scr.annotations.Component; |
| 5 | import org.apache.felix.scr.annotations.Deactivate; |
| 6 | import org.apache.felix.scr.annotations.Reference; |
| 7 | import org.apache.felix.scr.annotations.ReferenceCardinality; |
tom | 5ac5188 | 2014-08-27 18:10:33 -0700 | [diff] [blame] | 8 | import org.onlab.onos.GreetService; |
tom | 0eb04ca | 2014-08-25 14:34:51 -0700 | [diff] [blame] | 9 | import org.slf4j.Logger; |
tom | 5f38b3a | 2014-08-27 23:50:54 -0700 | [diff] [blame] | 10 | |
| 11 | import static org.slf4j.LoggerFactory.getLogger; |
tom | 0eb04ca | 2014-08-25 14:34:51 -0700 | [diff] [blame] | 12 | |
| 13 | /** |
| 14 | * Example of a component that does not provide any service, but consumes one. |
| 15 | */ |
| 16 | @Component(immediate = true) |
| 17 | public class SomeOtherComponent { |
| 18 | |
tom | 5f38b3a | 2014-08-27 23:50:54 -0700 | [diff] [blame] | 19 | private final Logger log = getLogger(getClass()); |
tom | 0eb04ca | 2014-08-25 14:34:51 -0700 | [diff] [blame] | 20 | |
| 21 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 22 | protected GreetService service; |
| 23 | // protected to allow injection for testing; |
| 24 | // alternative is to write bindSeedService and unbindSeedService, which is more code |
| 25 | |
| 26 | @Activate |
| 27 | public void activate() { |
| 28 | log.info("SomeOtherComponent started"); |
| 29 | service.yo("neighbour"); |
| 30 | } |
| 31 | |
| 32 | @Deactivate |
| 33 | public void deactivate() { |
| 34 | log.info("SomeOtherComponent stopped"); |
| 35 | } |
| 36 | |
| 37 | } |