Created
July 6, 2019 08:45
-
-
Save athiththan11/c29e2a352a625aaf66fc33264a8e9846 to your computer and use it in GitHub Desktop.
Shopper OSGi service component implementation on activation and reference to the Fabricator service component
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Component( | |
name = "com.sample.athiththan.shopper.internal.service", | |
immediate = true | |
) | |
public class ShopperServiceComponent { | |
private static final Logger LOGGER = Logger.getLogger(ShopperServiceComponent.class.getName()); | |
private static FactFabricator fabricator; | |
@Activate | |
protected void activate(ComponentContext context) { | |
LOGGER.info("OSGI Shopper :: Shopper bundle is activated"); | |
FactShopper shopper = new FactShopper(); | |
shopper.printFacts(); | |
} | |
@Deactivate | |
protected void deactivate(ComponentContext context) { | |
LOGGER.info("OSGI Shopper :: Shopper bundle is deactivated"); | |
} | |
@Reference( | |
name = "com.sample.athiththan.fabricator.internal.service", | |
service = FactFabricator.class, | |
cardinality = ReferenceCardinality.MANDATORY, | |
policy = ReferencePolicy.DYNAMIC, | |
unbind = "unsetFactProvider" | |
) | |
protected void setFactProducer(FactFabricator pfabricator) { | |
LOGGER.info("OSGI Shopper :: FactFabricator is set to Shopper bundle"); | |
fabricator = pfabricator; | |
} | |
public static FactFabricator getFactProducer() { | |
return fabricator; | |
} | |
protected void unsetFactProvider(FactFabricator fabricator) { | |
LOGGER.info("OSGI Shopper :: FactFabricator is unset from Shopper bundle"); | |
fabricator = null; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment