Ciclo de vida do componente OSGi
Saiba mais sobre o ciclo de vida do componente OSGi, incluindo como vincular um serviço OSGi a:
- Ativar
- Modificado
- e desativar
…eventos de ciclo de vida.
Recursos
Código
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