OSGi 서비스

다음을 포함한 OSGi 서비스 개발에 대한 기본 사항을 알아봅니다.

  • Java POJO를 OSGi 서비스로 변환하는 방법
  • Java 인터페이스에 OSGi 서비스를 바인딩하는 방법

리소스

코드

Activities.java

/core/src/main/java/com/adobe/aem/wknd/examples/core/adventures/Activities.java

package com.adobe.aem.wknd.examples.core.adventures;

import org.osgi.annotation.versioning.ProviderType;

@ProviderType
public interface Activities {    
    String getRandomActivity();
}

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.Component;

@Component(
    service = { Activities.class }
)
public class ActivitiesImpl implements Activities {

    private static final String[] ACTIVITIES = new String[] { 
        "Camping", "Skiing",  "Skateboarding"
    };

    //private final int randomIndex = new Random().nextInt(ACTIVITIES.length);
    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];
    }    
}

package-info.java

/core/src/main/java/com/adobe/aem/wknd/examples/core/adventures/package-info.java

@Version("1.0")
package com.adobe.aem.wknd.examples.core.adventures;

import org.osgi.annotation.versioning.Version;

이 페이지에서는