Lebenszyklus von OSGi-Komponenten
Erfahren Sie mehr über den Lebenszyklus von OSGi-Komponenten, z. B. wie Sie einen OSGi-Dienst an die Lebenszyklusereignisse vom Typ …
- Aktivieren
- Geändert
- Deaktivieren
… binden können.
Ressourcen
Code
ActivitiesImpl.java
/core/src/main/java/com/adobe/aem/wknd/examples/core/adventures/impl/ActivitiesImpl.java
package com.adobe.aem.wknd.examples.core.adventures.impl;
import java.util.Random;
import com.adobe.aem.wknd.examples.core.adventures.Activities;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Deactivate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Component(
service = { Activities.class }
)
public class ActivitiesImpl implements Activities {
private static final Logger log = LoggerFactory.getLogger(ActivitiesImpl.class);
private String[] activities;
private final Random random = new Random();
/**
* @return the name of a random WKND adventure activity
*/
public String getRandomActivity() {
int randomIndex = random.nextInt(activities.length);
return activities[randomIndex];
}
@Activate
protected void activate() {
this.activities = new String[] {
"Running", "Cycling", "Skateboarding"
};
log.info("Activated ActivitiesImpl with activities [ {} ]", String.join(", ", this.activities));
}
@Deactivate
protected void deactivate() {
log.info("ActivitiesImpl has been deactivated!");
}
}
recommendation-more-help
4859a77c-7971-4ac9-8f5c-4260823c6f69